@Override protected GenericModel<CtlSchemaMetaInfoDto> newInstance(Long id) { return new CtlSchemaMetaInfo(id); }
@Override public CtlSchemaMetaInfo updateScope(CtlSchemaMetaInfo ctlSchemaMetaInfo) { LOG.debug("Updating ctl meta info scope {}", ctlSchemaMetaInfo); CtlSchemaMetaInfo metaInfo = findById(ctlSchemaMetaInfo.getStringId()); if (metaInfo != null) { metaInfo.setTenant(ctlSchemaMetaInfo.getTenant()); metaInfo.setApplication(ctlSchemaMetaInfo.getApplication()); metaInfo = super.save(metaInfo); } LOG.debug("Update result: {}", metaInfo != null); return metaInfo; }
@Override @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) public CtlSchemaMetaInfo save(CtlSchemaMetaInfo object) { String tenantId = object.getTenant() != null ? object.getTenant().getStringId() : null; String applicationId = object.getApplication() != null ? object.getApplication().getStringId() : null; LOG.debug("Try to save or find meta info with fqn [{}], tenantId [{}] and applicationId [{}]", object.getFqn(), tenantId, applicationId); CtlSchemaMetaInfo uniqueMetaInfo = findByFqnTenantIdAndApplicationId( object.getFqn(), tenantId, applicationId); if (uniqueMetaInfo == null) { uniqueMetaInfo = super.save(object, true); LOG.debug("Save result: {}", uniqueMetaInfo); } else { LOG.debug("Search result: {}", uniqueMetaInfo); } return uniqueMetaInfo; }
protected CtlSchema generateCTLSchema(String fqn, int version, Tenant tenant, CTLSchemaScopeDto scope) { if (scope == null) { if (tenant == null) { scope = CTLSchemaScopeDto.SYSTEM; } else { scope = CTLSchemaScopeDto.TENANT; } } CtlSchemaMetaInfo metaInfo = new CtlSchemaMetaInfo(); metaInfo.setFqn(fqn); metaInfo.setTenant(tenant); metaInfo = ctlSchemaMetaInfoDao.save(metaInfo); CtlSchema ctlSchema = new CtlSchema(); ctlSchema.setMetaInfo(metaInfo); ctlSchema.setVersion(version); ctlSchema.setBody(UUID.randomUUID().toString()); ctlSchema.setDependencySet(new HashSet<CtlSchema>()); ctlSchema = ctlSchemaDao.save(ctlSchema); return ctlSchema; }
@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."); } }
@Override public CtlSchemaMetaInfoDto toDto() { CtlSchemaMetaInfoDto ctlSchemaMetaInfoDto = createDto(); ctlSchemaMetaInfoDto.setId(getStringId()); ctlSchemaMetaInfoDto.setFqn(fqn); ctlSchemaMetaInfoDto.setApplicationId(application != null ? application.getStringId() : null); ctlSchemaMetaInfoDto.setTenantId(tenant != null ? tenant.getStringId() : null); return ctlSchemaMetaInfoDto; }
private List<CtlSchemaMetaInfoDto> getMetaInfoFromCtlSchema(List<CtlSchema> schemas) { Map<String, CtlSchemaMetaInfoDto> metaInfoMap = new HashMap<>(); if (!schemas.isEmpty()) { for (CtlSchema schema : schemas) { String metaInfoId = schema.getMetaInfo().getStringId(); CtlSchemaMetaInfoDto metaInfoDto = metaInfoMap.get(metaInfoId); if (metaInfoDto == null) { metaInfoDto = getDto(schema.getMetaInfo()); metaInfoMap.put(metaInfoId, metaInfoDto); } List<Integer> versions = metaInfoDto.getVersions(); if (versions == null) { versions = new ArrayList<>(); metaInfoDto.setVersions(versions); } versions.add(schema.getVersion()); } } List<CtlSchemaMetaInfoDto> result = new ArrayList<>(metaInfoMap.values()); return result; }
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((body == null) ? 0 : body.hashCode()); result = prime * result + (int) (createdTime ^ (createdTime >>> 32)); result = prime * result + ((createdUsername == null) ? 0 : createdUsername.hashCode()); result = prime * result + ((defaultRecord == null) ? 0 : defaultRecord.hashCode()); result = prime * result + ((dependencySet == null) ? 0 : dependencySet.hashCode()); result = prime * result + ((metaInfo == null) ? 0 : metaInfo.hashCode()); result = prime * result + ((version == null) ? 0 : version.hashCode()); return result; }
return false; } else if (!metaInfo.equals(other.metaInfo)) { return false;
try { ctlSchemaDao.removeById(ctlSchema.getStringId()); List<CtlSchema> schemas = ctlSchemaDao.findAllByMetaInfoId(metaInfo.getStringId()); if (schemas == null || schemas.isEmpty()) { ctlSchemaMetaInfoDao.removeById(metaInfo.getStringId());
private CtlSchema generateCTLSchema(String fqn, Tenant tenant, int version, String body) { CtlSchema ctlSchema = new CtlSchema(); if (tenant == null) { tenant = generateTenant(); } ctlSchema.setMetaInfo(new CtlSchemaMetaInfo(fqn, tenant, null)); ctlSchema.setVersion(version); if (isBlank(body)) { body = UUID.randomUUID().toString(); } ctlSchema.setBody(body); return ctlSchema; }
/** * Create instance of <code>CtlSchema</code>. * * @param dto data transfer object */ public CtlSchema(CTLSchemaDto dto) { this.id = getLongId(dto.getId()); this.metaInfo = new CtlSchemaMetaInfo(dto.getMetaInfo()); this.version = dto.getVersion(); this.createdUsername = dto.getCreatedUsername(); this.createdTime = dto.getCreatedTime(); update(dto); }
new CtlSchemaMetaInfo(metaInfo)); ctlSchemaMetaInfoDao.lockRequest(lockOptions).setScope(true).lock(uniqueMetaInfo); CtlSchema ctlSchema = new CtlSchema(unSavedSchema);