@Override public TagDefinitionModelDao inTransaction(final EntitySqlDaoWrapperFactory<EntitySqlDao> entitySqlDaoWrapperFactory) throws Exception { for (final ControlTagType controlTag : ControlTagType.values()) { if (controlTag.getId().equals(definitionId)) { return new TagDefinitionModelDao(controlTag); } } return entitySqlDaoWrapperFactory.become(TagDefinitionSqlDao.class).getById(definitionId.toString(), context); } });
@Override public Void inTransaction(final EntitySqlDaoWrapperFactory<EntitySqlDao> entitySqlDaoWrapperFactory) throws Exception { final TagDefinitionSqlDao tagDefinitionSqlDao = entitySqlDaoWrapperFactory.become(TagDefinitionSqlDao.class); // Make sure the tag definition exists final TagDefinitionModelDao tagDefinition = tagDefinitionSqlDao.getById(definitionId.toString(), context); if (tagDefinition == null) { throw new TagDefinitionApiException(ErrorCode.TAG_DEFINITION_DOES_NOT_EXIST, definitionId); } // Make sure it is not used currently if (tagDefinitionSqlDao.tagDefinitionUsageCount(definitionId.toString(), context) > 0) { throw new TagDefinitionApiException(ErrorCode.TAG_DEFINITION_IN_USE, definitionId); } // Delete it tagDefinitionSqlDao.markTagDefinitionAsDeleted(definitionId.toString(), context); postBusEventFromTransaction(tagDefinition, tagDefinition, ChangeType.DELETE, entitySqlDaoWrapperFactory, context); return null; } });
private TagDefinitionModelDao getTagDefinitionFromTransaction(final UUID tagDefinitionId, final EntitySqlDaoWrapperFactory<EntitySqlDao> entitySqlDaoWrapperFactory, final InternalTenantContext context) throws TagApiException { TagDefinitionModelDao tagDefintion = null; for (final ControlTagType t : ControlTagType.values()) { if (t.getId().equals(tagDefinitionId)) { tagDefintion = new TagDefinitionModelDao(t); break; } } if (tagDefintion == null) { final TagDefinitionSqlDao transTagDefintionSqlDao = entitySqlDaoWrapperFactory.become(TagDefinitionSqlDao.class); tagDefintion = transTagDefintionSqlDao.getById(tagDefinitionId.toString(), context); } if (tagDefintion == null) { throw new TagApiException(ErrorCode.TAG_DEFINITION_DOES_NOT_EXIST, tagDefinitionId); } return tagDefintion; }