Skip to content

Commit

Permalink
Fix style in ControlService and related classes
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirill380 committed Sep 29, 2016
1 parent f6e8bf4 commit 2b50b71
Show file tree
Hide file tree
Showing 13 changed files with 763 additions and 426 deletions.
Expand Up @@ -292,8 +292,8 @@ Schema validateSchema(String avroSchema, boolean isCtl) throws KaaAdminServiceEx
RecordField createRecordFieldFromCtlSchemaAndBody(String ctlSchemaId, String body) throws KaaAdminServiceException {
try {
RecordField recordField;
CTLSchemaDto ctlSchema = controlService.getCTLSchemaById(ctlSchemaId);
Schema schema = controlService.exportCTLSchemaFlatAsSchema(ctlSchema);
CTLSchemaDto ctlSchema = controlService.getCtlSchemaById(ctlSchemaId);
Schema schema = controlService.exportCtlSchemaFlatAsSchema(ctlSchema);
if (!isEmpty(body)) {
GenericAvroConverter<GenericRecord> converter = new GenericAvroConverter<>(schema);
GenericRecord record = converter.decodeJson(body);
Expand Down Expand Up @@ -417,7 +417,7 @@ CtlSchemaFormDto toCtlSchemaForm(CTLSchemaDto ctlSchema, ConverterType converter
ctlSchemaForm.getMetaInfo().getApplicationId(), converterType);
RecordField form = converter.createSchemaFormFromSchema(ctlSchema.getBody());
ctlSchemaForm.setSchema(form);
List<Integer> availableVersions = controlService.getAllCTLSchemaVersionsByFqnTenantIdAndApplicationId(
List<Integer> availableVersions = controlService.getAllCtlSchemaVersionsByFqnTenantIdAndApplicationId(
ctlSchema.getMetaInfo().getFqn(), ctlSchema.getMetaInfo().getTenantId(), ctlSchema.getMetaInfo().getApplicationId());
availableVersions = availableVersions == null ? Collections.<Integer>emptyList() : availableVersions;
Collections.sort(availableVersions);
Expand All @@ -444,23 +444,23 @@ SchemaFormAvroConverter getCtlSchemaConverterForScope(String tenantId, String ap

private SchemaFormAvroConverter getCtlSchemaConverterForSystem(ConverterType converterType) throws KaaAdminServiceException {
try {
return createSchemaConverterFromCtlTypes(controlService.getAvailableCTLSchemaVersionsForSystem(), converterType);
return createSchemaConverterFromCtlTypes(controlService.getAvailableCtlSchemaVersionsForSystem(), converterType);
} catch (Exception cause) {
throw Utils.handleException(cause);
}
}

private SchemaFormAvroConverter getCtlSchemaConverterForTenant(String tenantId, ConverterType converterType) throws KaaAdminServiceException {
try {
return createSchemaConverterFromCtlTypes(controlService.getAvailableCTLSchemaVersionsForTenant(tenantId), converterType);
return createSchemaConverterFromCtlTypes(controlService.getAvailableCtlSchemaVersionsForTenant(tenantId), converterType);
} catch (Exception cause) {
throw Utils.handleException(cause);
}
}

private SchemaFormAvroConverter getCtlSchemaConverterForApplication(String tenantId, String applicationId, ConverterType converterType) throws KaaAdminServiceException {
try {
return createSchemaConverterFromCtlTypes(controlService.getAvailableCTLSchemaVersionsForApplication(tenantId, applicationId), converterType);
return createSchemaConverterFromCtlTypes(controlService.getAvailableCtlSchemaVersionsForApplication(tenantId, applicationId), converterType);
} catch (Exception cause) {
throw Utils.handleException(cause);
}
Expand Down
Expand Up @@ -122,17 +122,17 @@ public FileData getRecordData(RecordKey key) throws KaaAdminServiceException {
public FileData getExportedCtlSchema(CtlSchemaExportKey key)
throws KaaAdminServiceException {
try {
CTLSchemaDto schemaFound = controlService.getCTLSchemaById(key.getCtlSchemaId());
CTLSchemaDto schemaFound = controlService.getCtlSchemaById(key.getCtlSchemaId());
Utils.checkNotNull(schemaFound);
switch (key.getExportMethod()) {
case SHALLOW:
return controlService.exportCTLSchemaShallow(schemaFound);
return controlService.exportCtlSchemaShallow(schemaFound);
case FLAT:
return controlService.exportCTLSchemaFlat(schemaFound);
return controlService.exportCtlSchemaFlat(schemaFound);
case DEEP:
return controlService.exportCTLSchemaDeep(schemaFound);
return controlService.exportCtlSchemaDeep(schemaFound);
case LIBRARY:
return controlService.exportCTLSchemaFlatAsLibrary(schemaFound);
return controlService.exportCtlSchemaFlatAsLibrary(schemaFound);
default:
throw new IllegalArgumentException("The export method " + key.getExportMethod().name() + " is not currently supported!");
}
Expand Down
Expand Up @@ -166,7 +166,7 @@ public ConfigurationSchemaViewDto getConfigurationSchemaView(String configuratio
checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER);
try {
ConfigurationSchemaDto confSchema = getConfigurationSchema(configurationSchemaId);
CTLSchemaDto ctlSchemaDto = controlService.getCTLSchemaById(confSchema.getCtlSchemaId());
CTLSchemaDto ctlSchemaDto = controlService.getCtlSchemaById(confSchema.getCtlSchemaId());
return new ConfigurationSchemaViewDto(confSchema, toCtlSchemaForm(ctlSchemaDto, ConverterType.CONFIGURATION_FORM_AVRO_CONVERTER));
} catch (Exception e) {
throw Utils.handleException(e);
Expand Down
Expand Up @@ -71,7 +71,7 @@ public CTLSchemaDto saveCTLSchema(CTLSchemaDto schema) throws KaaAdminServiceExc
if (schema.getDependencySet() != null) {
for (CTLSchemaDto dependency : schema.getDependencySet()) {
CTLSchemaDto schemaFound =
controlService.getAnyCTLSchemaByFqnVersionTenantIdAndApplicationId(
controlService.getAnyCtlSchemaByFqnVersionTenantIdAndApplicationId(
dependency.getMetaInfo().getFqn(), dependency.getVersion(),
schema.getMetaInfo().getTenantId(), schema.getMetaInfo().getApplicationId());
if (schemaFound == null) {
Expand All @@ -90,7 +90,7 @@ public CTLSchemaDto saveCTLSchema(CTLSchemaDto schema) throws KaaAdminServiceExc
CTLSchemaParser parser = new CTLSchemaParser(controlService, schema.getMetaInfo().getTenantId());
parser.validate(schema);

CTLSchemaDto result = controlService.saveCTLSchema(schema);
CTLSchemaDto result = controlService.saveCtlSchema(schema);
return result;
} catch (Exception cause) {
throw Utils.handleException(cause);
Expand All @@ -116,7 +116,7 @@ public CTLSchemaDto saveCTLSchema(String body, String tenantId, String applicati
checkCTLSchemaVersion(schema.getVersion());
// Check if the schema body is valid
parser.validate(schema);
CTLSchemaDto result = controlService.saveCTLSchema(schema);
CTLSchemaDto result = controlService.saveCtlSchema(schema);
return result;
} catch (Exception cause) {
throw Utils.handleException(cause);
Expand All @@ -141,17 +141,17 @@ public void deleteCTLSchemaByFqnVersionTenantIdAndApplicationId(String fqn, Inte
if (!isEmpty(applicationId)) {
this.checkApplicationId(applicationId);
}
CTLSchemaDto schemaFound = controlService.getCTLSchemaByFqnVersionTenantIdAndApplicationId(fqn, version, tenantId, applicationId);
CTLSchemaDto schemaFound = controlService.getCtlSchemaByFqnVersionTenantIdAndApplicationId(fqn, version, tenantId, applicationId);
Utils.checkNotNull(schemaFound);
checkCTLSchemaEditScope(schemaFound.getMetaInfo().getTenantId(), schemaFound.getMetaInfo().getApplicationId());
List<CTLSchemaDto> schemaDependents = controlService.getCTLSchemaDependents(fqn, version, tenantId, applicationId);
List<CTLSchemaDto> schemaDependents = controlService.getCtlSchemaDependents(fqn, version, tenantId, applicationId);
if (schemaDependents != null && !schemaDependents.isEmpty()) {
String message = "Can't delete the common type version as it is referenced by the following common type(s): "
+ this.asText(schemaDependents);
throw new IllegalArgumentException(message);
}

controlService.deleteCTLSchemaByFqnAndVersionTenantIdAndApplicationId(fqn, version, tenantId, applicationId);
controlService.deleteCtlSchemaByFqnAndVersionTenantIdAndApplicationId(fqn, version, tenantId, applicationId);
} catch (Exception cause) {
throw Utils.handleException(cause);
}
Expand All @@ -177,7 +177,7 @@ public CTLSchemaDto getCTLSchemaByFqnVersionTenantIdAndApplicationId(String fqn,
if (!isEmpty(applicationId)) {
this.checkApplicationId(applicationId);
}
CTLSchemaDto schemaFound = controlService.getCTLSchemaByFqnVersionTenantIdAndApplicationId(fqn, version, tenantId, applicationId);
CTLSchemaDto schemaFound = controlService.getCtlSchemaByFqnVersionTenantIdAndApplicationId(fqn, version, tenantId, applicationId);
Utils.checkNotNull(schemaFound);
checkCTLSchemaReadScope(schemaFound.getMetaInfo().getTenantId(), schemaFound.getMetaInfo().getApplicationId());
return schemaFound;
Expand All @@ -191,7 +191,7 @@ public CTLSchemaDto getCTLSchemaById(String schemaId) throws KaaAdminServiceExce
this.checkAuthority(KaaAuthorityDto.values());
try {
this.checkCTLSchemaId(schemaId);
CTLSchemaDto schemaFound = controlService.getCTLSchemaById(schemaId);
CTLSchemaDto schemaFound = controlService.getCtlSchemaById(schemaId);
Utils.checkNotNull(schemaFound);
checkCTLSchemaReadScope(schemaFound.getMetaInfo().getTenantId(), schemaFound.getMetaInfo().getApplicationId());
return schemaFound;
Expand Down Expand Up @@ -249,19 +249,19 @@ public CTLSchemaMetaInfoDto promoteScopeToTenant(String applicationId, String fq

try {
Set<CTLSchemaDto> dependencies = new HashSet<>();
List<Integer> versions = controlService.getAllCTLSchemaVersionsByFqnTenantIdAndApplicationId(fqn, tenantId, applicationId);
List<Integer> versions = controlService.getAllCtlSchemaVersionsByFqnTenantIdAndApplicationId(fqn, tenantId, applicationId);

if (versions.isEmpty()) {
throw new KaaAdminServiceException("The requested item was not found!", ServiceErrorCode.ITEM_NOT_FOUND);
}

// meta info same for all versions
CTLSchemaMetaInfoDto ctlSchemaMetaInfo = controlService.getCTLSchemaByFqnVersionTenantIdAndApplicationId(fqn, versions.get(0), tenantId, applicationId).getMetaInfo();
CTLSchemaMetaInfoDto ctlSchemaMetaInfo = controlService.getCtlSchemaByFqnVersionTenantIdAndApplicationId(fqn, versions.get(0), tenantId, applicationId).getMetaInfo();
ctlSchemaMetaInfo.setApplicationId(null); //promote to tenant

// get dep of all versions
for (Integer version : versions) {
CTLSchemaDto schema = controlService.getCTLSchemaByFqnVersionTenantIdAndApplicationId(fqn, version, tenantId, applicationId);
CTLSchemaDto schema = controlService.getCtlSchemaByFqnVersionTenantIdAndApplicationId(fqn, version, tenantId, applicationId);
Set<CTLSchemaDto> schemaDependents = schema.getDependencySet();
dependencies.addAll(schemaDependents.stream()
.filter(dep -> dep.getMetaInfo().getScope() == CTLSchemaScopeDto.APPLICATION)
Expand All @@ -275,7 +275,7 @@ public CTLSchemaMetaInfoDto promoteScopeToTenant(String applicationId, String fq
throw new KaaAdminServiceException(message, ServiceErrorCode.CONFLICT);
}

return controlService.updateCTLSchemaMetaInfoScope(ctlSchemaMetaInfo);
return controlService.updateCtlSchemaMetaInfoScope(ctlSchemaMetaInfo);
} catch (Exception cause) {
throw Utils.handleException(cause);
}
Expand All @@ -285,7 +285,7 @@ public CTLSchemaMetaInfoDto promoteScopeToTenant(String applicationId, String fq
public List<CTLSchemaMetaInfoDto> getSystemLevelCTLSchemas() throws KaaAdminServiceException {
checkAuthority(KaaAuthorityDto.values());
try {
return controlService.getSystemCTLSchemasMetaInfo();
return controlService.getSystemCtlSchemasMetaInfo();
} catch (Exception cause) {
throw Utils.handleException(cause);
}
Expand All @@ -296,7 +296,7 @@ public List<CTLSchemaMetaInfoDto> getTenantLevelCTLSchemas() throws KaaAdminServ
checkAuthority(KaaAuthorityDto.TENANT_ADMIN, KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER);
try {
AuthUserDto currentUser = getCurrentUser();
return controlService.getAvailableCTLSchemasMetaInfoForTenant(currentUser.getTenantId());
return controlService.getAvailableCtlSchemasMetaInfoForTenant(currentUser.getTenantId());
} catch (Exception cause) {
throw Utils.handleException(cause);
}
Expand All @@ -307,8 +307,8 @@ public List<CtlSchemaReferenceDto> getTenantLevelCTLSchemaReferenceForECF(String
checkAuthority(KaaAuthorityDto.TENANT_ADMIN);
try {
AuthUserDto currentUser = getCurrentUser();
List<CTLSchemaMetaInfoDto> ctlSchemaReferenceDtoListForTenant = controlService.getAvailableCTLSchemasMetaInfoForTenant(currentUser.getTenantId());
Set<String> fqnListOfCurrentECF = controlService.getFqnSetForECF(ecfId);
List<CTLSchemaMetaInfoDto> ctlSchemaReferenceDtoListForTenant = controlService.getAvailableCtlSchemasMetaInfoForTenant(currentUser.getTenantId());
Set<String> fqnListOfCurrentECF = controlService.getFqnSetForEcf(ecfId);
if (eventClassViewDtoList != null) {
for (EventClassViewDto eventClassViewDto : eventClassViewDtoList) {
String fqn = eventClassViewDto.getCtlSchemaForm().getMetaInfo().getFqn();
Expand Down Expand Up @@ -340,7 +340,7 @@ public List<CTLSchemaMetaInfoDto> getApplicationLevelCTLSchemas(String applicati
try {
this.checkApplicationId(applicationId);
AuthUserDto currentUser = getCurrentUser();
return controlService.getAvailableCTLSchemasMetaInfoForApplication(currentUser.getTenantId(), applicationId);
return controlService.getAvailableCtlSchemasMetaInfoForApplication(currentUser.getTenantId(), applicationId);
} catch (Exception cause) {
throw Utils.handleException(cause);
}
Expand All @@ -361,16 +361,16 @@ public FileData exportCTLSchema(String fqn, int version, String applicationId, C
this.checkCTLSchemaFqn(fqn);
this.checkCTLSchemaVersion(version);
String tenantId = getCurrentUser().getTenantId();
CTLSchemaDto schemaFound = controlService.getCTLSchemaByFqnVersionTenantIdAndApplicationId(fqn, version, tenantId, applicationId);
CTLSchemaDto schemaFound = controlService.getCtlSchemaByFqnVersionTenantIdAndApplicationId(fqn, version, tenantId, applicationId);
Utils.checkNotNull(schemaFound);
checkCTLSchemaReadScope(schemaFound.getMetaInfo().getTenantId(), schemaFound.getMetaInfo().getApplicationId());
switch (method) {
case SHALLOW:
return controlService.exportCTLSchemaShallow(schemaFound);
return controlService.exportCtlSchemaShallow(schemaFound);
case FLAT:
return controlService.exportCTLSchemaFlat(schemaFound);
return controlService.exportCtlSchemaFlat(schemaFound);
case DEEP:
return controlService.exportCTLSchemaDeep(schemaFound);
return controlService.exportCtlSchemaDeep(schemaFound);
default:
throw new IllegalArgumentException("The export method " + method.name() + " is not currently supported!");
}
Expand Down Expand Up @@ -406,7 +406,7 @@ public CtlSchemaFormDto saveCTLSchemaForm(CtlSchemaFormDto ctlSchemaForm, Conver
Set<CTLSchemaDto> dependencies = new HashSet<>();
List<FqnVersion> missingDependencies = new ArrayList<>();
for (FqnVersion fqnVersion : dependenciesList) {
CTLSchemaDto dependency = controlService.getAnyCTLSchemaByFqnVersionTenantIdAndApplicationId(
CTLSchemaDto dependency = controlService.getAnyCtlSchemaByFqnVersionTenantIdAndApplicationId(
fqnVersion.getFqnString(), fqnVersion.getVersion(),
ctlSchema.getMetaInfo().getTenantId(), ctlSchema.getMetaInfo().getApplicationId());
if (dependency != null) {
Expand Down Expand Up @@ -444,7 +444,7 @@ public List<CtlSchemaReferenceDto> getAvailableApplicationCTLSchemaReferences(St
try {
AuthUserDto currentUser = getCurrentUser();
List<CtlSchemaReferenceDto> result = new ArrayList<>();
List<CTLSchemaMetaInfoDto> availableMetaInfo = controlService.getAvailableCTLSchemasMetaInfoForApplication(currentUser.getTenantId(), applicationId);
List<CTLSchemaMetaInfoDto> availableMetaInfo = controlService.getAvailableCtlSchemasMetaInfoForApplication(currentUser.getTenantId(), applicationId);
for (CTLSchemaMetaInfoDto metaInfo : availableMetaInfo) {
for (int version : metaInfo.getVersions()) {
result.add(new CtlSchemaReferenceDto(metaInfo, version));
Expand All @@ -462,7 +462,7 @@ public CtlSchemaFormDto getLatestCTLSchemaForm(String metaInfoId) throws KaaAdmi
checkAuthority(KaaAuthorityDto.values());
try {
this.checkCTLSchemaMetaInfoId(metaInfoId);
CTLSchemaDto ctlSchema = controlService.getLatestCTLSchemaByMetaInfoId(metaInfoId);
CTLSchemaDto ctlSchema = controlService.getLatestCtlSchemaByMetaInfoId(metaInfoId);
Utils.checkNotNull(ctlSchema);
checkCTLSchemaReadScope(ctlSchema.getMetaInfo().getTenantId(), ctlSchema.getMetaInfo().getApplicationId());
return toCtlSchemaForm(ctlSchema, ConverterType.FORM_AVRO_CONVERTER);
Expand All @@ -477,7 +477,7 @@ public CtlSchemaFormDto getCTLSchemaFormByMetaInfoIdAndVer(String metaInfoId, in
try {
this.checkCTLSchemaMetaInfoId(metaInfoId);
this.checkCTLSchemaVersion(version);
CTLSchemaDto schemaFound = controlService.getCTLSchemaByMetaInfoIdAndVer(metaInfoId, version);
CTLSchemaDto schemaFound = controlService.getCtlSchemaByMetaInfoIdAndVer(metaInfoId, version);
Utils.checkNotNull(schemaFound);
checkCTLSchemaReadScope(schemaFound.getMetaInfo().getTenantId(), schemaFound.getMetaInfo().getApplicationId());
return toCtlSchemaForm(schemaFound, ConverterType.FORM_AVRO_CONVERTER);
Expand Down Expand Up @@ -545,7 +545,7 @@ public String prepareCTLSchemaExport(String ctlSchemaId,
CTLSchemaExportMethod method) throws KaaAdminServiceException {
checkAuthority(KaaAuthorityDto.values());
try {
CTLSchemaDto schemaFound = controlService.getCTLSchemaById(ctlSchemaId);
CTLSchemaDto schemaFound = controlService.getCtlSchemaById(ctlSchemaId);
Utils.checkNotNull(schemaFound);
checkCTLSchemaReadScope(schemaFound.getMetaInfo().getTenantId(), schemaFound.getMetaInfo().getApplicationId());
CtlSchemaExportKey key = new CtlSchemaExportKey(ctlSchemaId, method);
Expand Down Expand Up @@ -686,7 +686,7 @@ private String asText(Collection<CTLSchemaDto> types) {
public CtlSchemaReferenceDto getLastCtlSchemaReferenceDto(String ctlSchemaId) throws KaaAdminServiceException {
try {
if (!isEmpty(ctlSchemaId)) {
CTLSchemaDto ctlSchemaDto = controlService.getCTLSchemaById(ctlSchemaId);
CTLSchemaDto ctlSchemaDto = controlService.getCtlSchemaById(ctlSchemaId);
CtlSchemaReferenceDto ctlSchemaReference = getAvailableApplicationCTLSchemaReferences(null).stream().
filter(ctlSchemaReferenceDto -> ctlSchemaReferenceDto.getMetaInfo().getId().equals(ctlSchemaDto.getMetaInfo().getId())).findFirst().get();
return ctlSchemaReference;
Expand Down
Expand Up @@ -137,8 +137,8 @@ private ServerProfileSchemaDto getServerProfileSchema(String applicationId, Inte
}

private void validateServerProfile(ServerProfileSchemaDto serverProfileSchema, String serverProfileBody) throws Exception {
CTLSchemaDto commonType = this.controlService.getCTLSchemaById(serverProfileSchema.getCtlSchemaId());
Schema typeSchema = this.controlService.exportCTLSchemaFlatAsSchema(commonType);
CTLSchemaDto commonType = this.controlService.getCtlSchemaById(serverProfileSchema.getCtlSchemaId());
Schema typeSchema = this.controlService.exportCtlSchemaFlatAsSchema(commonType);
try {
new GenericAvroConverter<GenericRecord>(typeSchema).decodeJson(serverProfileBody);
} catch (Exception cause) {
Expand Down

0 comments on commit 2b50b71

Please sign in to comment.