@Override public CtlSchemaReferenceDto getLastCtlSchemaReferenceDto(String ctlSchemaId) throws KaaAdminServiceException { try { if (!isEmpty(ctlSchemaId)) { CTLSchemaDto ctlSchemaDto = controlService.getCtlSchemaById(ctlSchemaId); CtlSchemaReferenceDto ctlSchemaReference = getAvailableApplicationCtlSchemaReferences(null).stream() .filter(ctlSchemaReferenceDto -> ctlSchemaReferenceDto.getMetaInfo() .getId() .equals(ctlSchemaDto.getMetaInfo().getId())) .findFirst() .get(); return ctlSchemaReference; } } catch (Exception ex) { throw Utils.handleException(ex); } return null; }
@Override public CtlSchemaMetaInfoDto updateCtlSchemaMetaInfoScope(CtlSchemaMetaInfoDto ctlSchemaMetaInfo) { validateObject(ctlSchemaMetaInfo, "Incorrect ctl schema meta info object"); LOG.debug("Update ctl schema meta info scope with id [{}]", ctlSchemaMetaInfo.getId()); CtlSchemaMetaInfo schemaMetaInfo = ctlSchemaMetaInfoDao.findById(ctlSchemaMetaInfo.getId()); if (schemaMetaInfo != null) { synchronized (this) { ctlSchemaMetaInfoDao.lockRequest(lockOptions).setScope(true).lock(schemaMetaInfo); if (checkScopeUpdate(ctlSchemaMetaInfo, schemaMetaInfo.toDto())) { List<CtlSchemaMetaInfo> others = ctlSchemaMetaInfoDao.findOthersByFqnAndTenantId( ctlSchemaMetaInfo.getFqn(), ctlSchemaMetaInfo.getTenantId(), ctlSchemaMetaInfo .getId()); if (others != null && !others.isEmpty()) { throw new DatabaseProcessingException("Can't update scope of the common type due to " + "an FQN conflict."); } schemaMetaInfo = ctlSchemaMetaInfoDao.updateScope( new CtlSchemaMetaInfo(ctlSchemaMetaInfo)); } return DaoUtil.getDto(schemaMetaInfo); } } else { throw new DatabaseProcessingException("Can't find common type by id."); } }
/** * Create new instance of CTL schema meta info. * * @param dto data transfer object that used for creating new instance, * it hold id, full qualified name, tenant id and application id * of new instance */ public CtlSchemaMetaInfo(CtlSchemaMetaInfoDto dto) { this.id = ModelUtils.getLongId(dto.getId()); this.fqn = dto.getFqn(); Long tenantId = getLongId(dto.getTenantId()); this.tenant = tenantId != null ? new Tenant(tenantId) : null; Long appId = getLongId(dto.getApplicationId()); this.application = appId != null ? new Application(appId) : null; }