|
|
@ -166,13 +166,20 @@ public class TagManagementProviderServiceImpl implements TagManagementProviderSe
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
DeviceManagementDAOFactory.beginTransaction();
|
|
|
|
DeviceManagementDAOFactory.beginTransaction();
|
|
|
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
Tag existingTag = tagDAO.getTagById(tag.getId(), tenantId);
|
|
|
|
Tag tagWithName = tagDAO.getTagByName(tag.getName(), tenantId);
|
|
|
|
if (existingTag == null) {
|
|
|
|
if (tagWithName != null && tagWithName.getId() != tag.getId()) {
|
|
|
|
|
|
|
|
String msg = "Tag with name: " + tag.getName() + " already exists.";
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new BadRequestException(msg);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tagWithName == null || tagWithName.getId() == tag.getId()) {
|
|
|
|
|
|
|
|
tagDAO.updateTag(tag, tenantId);
|
|
|
|
|
|
|
|
DeviceManagementDAOFactory.commitTransaction();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
String msg = "Tag with ID: " + tag.getId() + " does not exist.";
|
|
|
|
String msg = "Tag with ID: " + tag.getId() + " does not exist.";
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
|
throw new TagNotFoundException(msg);
|
|
|
|
throw new TagNotFoundException(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
tagDAO.updateTag(tag, tenantId);
|
|
|
|
|
|
|
|
DeviceManagementDAOFactory.commitTransaction();
|
|
|
|
DeviceManagementDAOFactory.commitTransaction();
|
|
|
|
} catch (TagManagementDAOException | TransactionManagementException e) {
|
|
|
|
} catch (TagManagementDAOException | TransactionManagementException e) {
|
|
|
|
DeviceManagementDAOFactory.rollbackTransaction();
|
|
|
|
DeviceManagementDAOFactory.rollbackTransaction();
|
|
|
|