@Override public List<CTLSchemaDto> findCtlSchemas() { LOG.debug("Find all ctl schemas"); return convertDtoList(ctlSchemaDao.find()); }
@Override public List<CtlSchemaMetaInfoDto> findAvailableCtlSchemasMetaInfoForTenant(String tenantId) { LOG.debug("Find system and tenant scopes ctl schemas by tenant id {}", tenantId); return getMetaInfoFromCtlSchema(ctlSchemaDao.findAvailableSchemasForTenant(tenantId)); }
@Override public List<CTLSchemaDto> findCtlSchemaDependents(String fqn, Integer version, String tenantId, String applicationId) { if (isBlank(fqn) || version == null) { throw new IncorrectParameterException("Incorrect parameters for ctl schema request."); } LOG.debug("Find dependents schemas for schema with fqn {} version {}, tenantId {} and " + "applicationId ()", fqn, version, tenantId, applicationId); List<CTLSchemaDto> schemas = Collections.emptyList(); CtlSchema schema = ctlSchemaDao.findByFqnAndVerAndTenantIdAndApplicationId(fqn, version, tenantId, applicationId); if (schema != null) { schemas = convertDtoList(ctlSchemaDao.findDependentSchemas(schema.getStringId())); } return schemas; }
@Override public List<CTLSchemaDto> findCtlSchemaDependents(String schemaId) { validateSqlId(schemaId, "Incorrect schema id for ctl schema request."); LOG.debug("Find dependents schemas for schema with id [{}]", schemaId); List<CTLSchemaDto> list = Collections.emptyList(); CtlSchema schemaDto = ctlSchemaDao.findById(schemaId); if (schemaDto != null) { list = convertDtoList(ctlSchemaDao.findDependentSchemas(schemaDto.getStringId())); } return list; }
CtlSchema ctlSchema = ctlSchemaDao.findByFqnAndVerAndTenantIdAndApplicationId(fqn, version, tenantId, applicationId); if (ctlSchema != null) { List<CtlSchema> dependsList = ctlSchemaDao.findDependentSchemas(ctlSchema.getStringId()); if (dependsList.isEmpty()) { synchronized (this) { ctlSchemaMetaInfoDao.lockRequest(lockOptions).setScope(true).lock(metaInfo); try { ctlSchemaDao.removeById(ctlSchema.getStringId()); List<CtlSchema> schemas = ctlSchemaDao.findAllByMetaInfoId(metaInfo.getStringId()); if (schemas == null || schemas.isEmpty()) { ctlSchemaMetaInfoDao.removeById(metaInfo.getStringId());
@Override public CTLSchemaDto findCtlSchemaByFqnAndVerAndTenantIdAndApplicationId(String fqn, Integer version, String tenantId, String applicationId) { if (isBlank(fqn) || version == null) { throw new IncorrectParameterException("Incorrect parameters for ctl schema request."); } LOG.debug("Find ctl schema by fqn {} version {}, tenant id {} and application id {}", fqn, version, tenantId, applicationId); return DaoUtil.getDto(ctlSchemaDao.findByFqnAndVerAndTenantIdAndApplicationId(fqn, version, tenantId, applicationId)); }
@Override public List<CTLSchemaDto> findSystemCtlSchemas() { LOG.debug("Find system ctl schemas"); return convertDtoList(ctlSchemaDao.findSystemSchemas()); }
@Override public CTLSchemaDto updateCtlSchema(CTLSchemaDto ctlSchema) { validateCtlSchemaObject(ctlSchema); LOG.debug("Update ctl schema with id [{}]", ctlSchema.getId()); CtlSchema schema = ctlSchemaDao.findById(ctlSchema.getId()); if (schema != null) { synchronized (this) { if (ctlSchema.getVersion() != schema.getVersion()) { throw new DatabaseProcessingException("Can't change version of existing common type " + "version."); } CtlSchemaMetaInfo metaInfo = schema.getMetaInfo(); if (!ctlSchema.getMetaInfo().equals(metaInfo.toDto())) { throw new DatabaseProcessingException("Can't update scope of existing common type " + "version within update procedure."); } ctlSchemaMetaInfoDao.lockRequest(lockOptions).setScope(true).lock(metaInfo); schema.update(ctlSchema); return DaoUtil.getDto(ctlSchemaDao.save(schema, true)); } } else { throw new DatabaseProcessingException("Can't find common type version by id."); } }
@Override public CTLSchemaDto findLatestCtlSchemaByFqnAndTenantIdAndApplicationId(String fqn, String tenantId, String applicationId) { validateString(fqn, "Incorrect fqn for ctl schema request."); LOG.debug("Find latest ctl schema by fqn {}, tenantId {} and applicationId {}", fqn, tenantId, applicationId); return DaoUtil.getDto(ctlSchemaDao.findLatestByFqnAndTenantIdAndApplicationId(fqn, tenantId, applicationId)); }
@Test public void saveCTLSchemaWithDependency() throws InterruptedException { List<CTLSchemaDto> dep = convertDtoList(ctlSchemaDao.findDependentSchemas(mainSchema.getId())); Assert.assertTrue(dep.isEmpty()); List<CTLSchemaDto> expected = Arrays.asList(mainSchema); dep = convertDtoList(ctlSchemaDao.findDependentSchemas(firstSchema.getId())); Assert.assertEquals(expected.size(), dep.size()); dep = convertDtoList(ctlSchemaDao.findDependentSchemas(secondSchema.getId())); Assert.assertEquals(expected.size(), dep.size()); dep = convertDtoList(ctlSchemaDao.findDependentSchemas(thirdSchema.getId())); Assert.assertEquals(expected.size(), dep.size()); dep = convertDtoList(ctlSchemaDao.findDependentSchemas(fourthSchema.getId())); Assert.assertEquals(expected.size(), dep.size()); }
@Override public CTLSchemaDto findAnyCtlSchemaByFqnAndVerAndTenantIdAndApplicationId(String fqn, Integer version, String tenantId, String applicationId) { if (isBlank(fqn) || version == null) { throw new IncorrectParameterException("Incorrect parameters for ctl schema request."); } LOG.debug("Find any ctl schema by fqn {} version {}, tenant id {} and application id {}", fqn, version, tenantId, applicationId); return DaoUtil.getDto(ctlSchemaDao.findAnyByFqnAndVerAndTenantIdAndApplicationId(fqn, version, tenantId, applicationId)); }
@Override public List<CTLSchemaDto> findAllCtlSchemasByFqnAndTenantIdAndApplicationId(String fqn, String tenantId, String applicationId) { validateString(fqn, "Incorrect fqn for ctl schema request."); LOG.debug("Find all ctl schemas by fqn {}, tenantId {} and applicationId {}", fqn, tenantId, applicationId); return convertDtoList(ctlSchemaDao.findAllByFqnAndTenantIdAndApplicationId(fqn, tenantId, applicationId)); }
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; }
@Test public void testFindSystemByFqnAndVerAndTenantIdAndApplicationId() { CtlSchema found = ctlSchemaDao.findByFqnAndVerAndTenantIdAndApplicationId(systemSchema.getMetaInfo().getFqn(), systemSchema.getVersion(), null, null); Assert.assertEquals(systemSchema, found.toDto()); }
@Override public List<CtlSchemaMetaInfoDto> findSystemCtlSchemasMetaInfo() { LOG.debug("Find system ctl schemas"); return getMetaInfoFromCtlSchema(ctlSchemaDao.findSystemSchemas()); }
@Test public void testFindLatestByFqn() { CtlSchema latest = ctlSchemaDao.findLatestByFqnAndTenantIdAndApplicationId(SYSTEM_FQN, null, null); Assert.assertEquals(systemSchema, latest.toDto()); }
ctlSchemaMetaInfoDao.refresh(uniqueMetaInfo); try { dto = getDto(ctlSchemaDao.save(ctlSchema, true)); } catch (DataIntegrityViolationException ex) { throw new DatabaseProcessingException("Can't save common type: such FQN and version "
@Test public void testFindByFqnAndVerAndTenantIdAndApplicationId() { CtlSchema found = ctlSchemaDao.findByFqnAndVerAndTenantIdAndApplicationId(firstSchema.getMetaInfo().getFqn(), firstSchema.getVersion(), firstSchema.getMetaInfo().getTenantId(), firstSchema.getMetaInfo().getApplicationId()); Assert.assertEquals(firstSchema, found.toDto()); }
@Test public void testFindSystemSchemas() { List<CtlSchema> found = ctlSchemaDao.findSystemSchemas(); Assert.assertEquals(getIdsDto(Arrays.asList(systemSchema)), getIds(found)); }