@Override public void create(final TagModelDao tag, final InternalCallContext context) throws TagApiException { if (tagStore.get(tag.getObjectId()) == null) { tagStore.put(tag.getObjectId(), new ArrayList<TagModelDao>()); } // add it to the account tags if (tagStore.get(getAccountId(context.getAccountRecordId())) == null) { tagStore.put(getAccountId(context.getAccountRecordId()), new ArrayList<TagModelDao>()); } tagStore.get(tag.getObjectId()).add(tag); tagStore.get(getAccountId(context.getAccountRecordId())).add(tag); }
@Override public Tag apply(final TagModelDao input) { return TagModelDaoHelper.isControlTag(input.getTagDefinitionId()) ? new DefaultControlTag(ControlTagType.getTypeFromId(input.getTagDefinitionId()), input.getObjectType(), input.getObjectId(), input.getCreatedDate()) : new DescriptiveTag(input.getTagDefinitionId(), input.getObjectType(), input.getObjectId(), input.getCreatedDate()); } }));
@Override public Tag apply(final TagModelDao input) { return TagModelDaoHelper.isControlTag(input.getTagDefinitionId()) ? new DefaultControlTag(input.getId(), ControlTagType.getTypeFromId(input.getTagDefinitionId()), input.getObjectType(), input.getObjectId(), input.getCreatedDate()) : new DescriptiveTag(input.getId(), input.getTagDefinitionId(), input.getObjectType(), input.getObjectId(), input.getCreatedDate()); } };
@Test(groups = "slow", description = "Test Account DAO: tags") public void testTags() throws TagApiException, TagDefinitionApiException { final AccountModelDao account = createTestAccount(); final TagDefinitionModelDao tagDefinition = tagDefinitionDao.create(UUID.randomUUID().toString().substring(0, 4), UUID.randomUUID().toString(), ObjectType.ACCOUNT.name(), internalCallContext); final Tag tag = new DescriptiveTag(tagDefinition.getId(), ObjectType.ACCOUNT, account.getId(), internalCallContext.getCreatedDate()); tagDao.create(new TagModelDao(tag), internalCallContext); final List<TagModelDao> tags = tagDao.getTagsForObject(account.getId(), ObjectType.ACCOUNT, false, internalCallContext); Assert.assertEquals(tags.size(), 1); Assert.assertEquals(tags.get(0).getTagDefinitionId(), tagDefinition.getId()); Assert.assertEquals(tags.get(0).getObjectId(), account.getId()); Assert.assertEquals(tags.get(0).getObjectType(), ObjectType.ACCOUNT); }
@Test(groups = "slow") public void testVerifyAuditCachesAreCleared() throws Exception { addTag(); final List<AuditLog> firstAuditLogs = auditDao.getAuditLogsForId(TableName.TAG, tag.getId(), AuditLevel.FULL, internalCallContext); Assert.assertEquals(firstAuditLogs.size(), 1); Assert.assertEquals(firstAuditLogs.get(0).getChangeType(), ChangeType.INSERT); eventsListener.pushExpectedEvent(NextEvent.TAG); tagDao.deleteTag(tag.getObjectId(), tag.getObjectType(), tag.getTagDefinitionId(), internalCallContext); assertListenerStatus(); final List<AuditLog> secondAuditLogs = auditDao.getAuditLogsForId(TableName.TAG, tag.getId(), AuditLevel.FULL, internalCallContext); Assert.assertEquals(secondAuditLogs.size(), 2); Assert.assertEquals(secondAuditLogs.get(0).getChangeType(), ChangeType.INSERT); Assert.assertEquals(secondAuditLogs.get(1).getChangeType(), ChangeType.DELETE); }
case INSERT: tagEvent = (isControlTag) ? tagEventBuilder.newControlTagCreationEvent(tag.getId(), tag.getObjectId(), tag.getObjectType(), tagDefinition, context.getAccountRecordId(), context.getTenantRecordId(), context.getUserToken()) : tagEventBuilder.newUserTagCreationEvent(tag.getId(), tag.getObjectId(), tag.getObjectType(), tagDefinition, context.getAccountRecordId(), context.getTenantRecordId(), context.getUserToken()); break; case DELETE: tagEvent = (isControlTag) ? tagEventBuilder.newControlTagDeletionEvent(tag.getId(), tag.getObjectId(), tag.getObjectType(), tagDefinition, context.getAccountRecordId(), context.getTenantRecordId(), context.getUserToken()) : tagEventBuilder.newUserTagDeletionEvent(tag.getId(), tag.getObjectId(), tag.getObjectType(), tagDefinition, context.getAccountRecordId(), context.getTenantRecordId(), context.getUserToken()); break;
@Override public void create(final TagModelDao tag, final InternalCallContext context) throws TagApiException { if (tagStore.get(tag.getObjectId()) == null) { tagStore.put(tag.getObjectId(), new ArrayList<TagModelDao>()); } // add it to the account tags if (tagStore.get(getAccountId(context.getAccountRecordId())) == null) { tagStore.put(getAccountId(context.getAccountRecordId()), new ArrayList<TagModelDao>()); } tagStore.get(tag.getObjectId()).add(tag); tagStore.get(getAccountId(context.getAccountRecordId())).add(tag); }
@Override public Tag apply(final TagModelDao input) { return TagModelDaoHelper.isControlTag(input.getTagDefinitionId()) ? new DefaultControlTag(ControlTagType.getTypeFromId(input.getTagDefinitionId()), input.getObjectType(), input.getObjectId(), input.getCreatedDate()) : new DescriptiveTag(input.getTagDefinitionId(), input.getObjectType(), input.getObjectId(), input.getCreatedDate()); } }));
@Override public Tag apply(final TagModelDao input) { return TagModelDaoHelper.isControlTag(input.getTagDefinitionId()) ? new DefaultControlTag(input.getId(), ControlTagType.getTypeFromId(input.getTagDefinitionId()), input.getObjectType(), input.getObjectId(), input.getCreatedDate()) : new DescriptiveTag(input.getId(), input.getTagDefinitionId(), input.getObjectType(), input.getObjectId(), input.getCreatedDate()); } };
@Test(groups = "slow") public void testVerifyAuditCachesAreCleared() throws Exception { addTag(); final List<AuditLog> firstAuditLogs = auditDao.getAuditLogsForId(TableName.TAG, tag.getId(), AuditLevel.FULL, internalCallContext); Assert.assertEquals(firstAuditLogs.size(), 1); Assert.assertEquals(firstAuditLogs.get(0).getChangeType(), ChangeType.INSERT); eventsListener.pushExpectedEvent(NextEvent.TAG); tagDao.deleteTag(tag.getObjectId(), tag.getObjectType(), tag.getTagDefinitionId(), internalCallContext); assertListenerStatus(); final List<AuditLog> secondAuditLogs = auditDao.getAuditLogsForId(TableName.TAG, tag.getId(), AuditLevel.FULL, internalCallContext); Assert.assertEquals(secondAuditLogs.size(), 2); Assert.assertEquals(secondAuditLogs.get(0).getChangeType(), ChangeType.INSERT); Assert.assertEquals(secondAuditLogs.get(1).getChangeType(), ChangeType.DELETE); }
case INSERT: tagEvent = (isControlTag) ? tagEventBuilder.newControlTagCreationEvent(tag.getId(), tag.getObjectId(), tag.getObjectType(), tagDefinition, context.getAccountRecordId(), context.getTenantRecordId(), context.getUserToken()) : tagEventBuilder.newUserTagCreationEvent(tag.getId(), tag.getObjectId(), tag.getObjectType(), tagDefinition, context.getAccountRecordId(), context.getTenantRecordId(), context.getUserToken()); break; case DELETE: tagEvent = (isControlTag) ? tagEventBuilder.newControlTagDeletionEvent(tag.getId(), tag.getObjectId(), tag.getObjectType(), tagDefinition, context.getAccountRecordId(), context.getTenantRecordId(), context.getUserToken()) : tagEventBuilder.newUserTagDeletionEvent(tag.getId(), tag.getObjectId(), tag.getObjectType(), tagDefinition, context.getAccountRecordId(), context.getTenantRecordId(), context.getUserToken()); break;