Commit 53eaac3b authored by Aman Verma's avatar Aman Verma
Browse files

adding method to create schemas

parent 31e86c39
......@@ -175,6 +175,47 @@ public class SchemaService implements ISchemaService {
}
}
public SchemaInfo createSystemSchema(SchemaRequest schemaRequest) throws ApplicationException, BadRequestException {
String dataPartitionId = headers.getPartitionId();
String schemaId = createAndSetSchemaId(schemaRequest);
if (schemaInfoStore.isUniqueSystemSchema(schemaId)) {
setScope(schemaRequest,false);
String schema = resolveAndCheckBreakingChanges(schemaRequest);
Boolean authority = authorityService.checkAndRegisterAuthorityIfNotPresent(
schemaRequest.getSchemaInfo().getSchemaIdentity().getAuthority());
Boolean source = sourceService
.checkAndRegisterSourceIfNotPresent(schemaRequest.getSchemaInfo().getSchemaIdentity().getSource());
Boolean entity = entityTypeService.checkAndRegisterEntityTypeIfNotPresent(
schemaRequest.getSchemaInfo().getSchemaIdentity().getEntityType());
if (authority && source && entity) {
log.info(SchemaConstants.SCHEMA_CREATION_STARTED);
try {
SchemaInfo schemaInfo = schemaInfoStore.createSchemaInfo(schemaRequest);
schemaStore.createSchema(schemaId, schema);
auditLogger.schemaRegisteredSuccess(Collections.singletonList(schemaRequest.toString()));
messageBus.publishMessage(schemaId, SchemaConstants.SCHEMA_CREATE_EVENT_TYPE);
return schemaInfo;
} catch (ApplicationException ex) {
auditLogger.schemaRegisteredFailure(
Collections.singletonList(schemaRequest.toString()));
log.warning(SchemaConstants.SCHEMA_CREATION_FAILED);
schemaInfoStore.cleanSchema(schemaId);
schemaStore.cleanSchemaProject(schemaId);
log.info(SchemaConstants.SCHEMA_CREATE_CLEAN);
throw ex;
}
} else {
log.error("The schema could not be created due invalid authority,source or entityType");
throw new ApplicationException(SchemaConstants.INTERNAL_SERVER_ERROR);
}
} else {
throw new BadRequestException(SchemaConstants.SCHEMA_ID_EXISTS);
}
}
/**
* Method to update schema. Schemas that are in Development state can be
* updated. This method checks for the presence of schema based on the schema Id
......@@ -225,7 +266,6 @@ public class SchemaService implements ISchemaService {
private SchemaInfo updateSystemSchema(SchemaRequest schemaRequest) throws ApplicationException, BadRequestException {
String dataPartitionId = headers.getPartitionId();
String createdSchemaId = createAndSetSchemaId(schemaRequest);
SchemaInfo schemaInfo = null;
try {
......@@ -361,7 +401,7 @@ public class SchemaService implements ISchemaService {
httpCode = HttpStatus.OK;
} catch (NoSchemaFoundException noSchemaFound) {
try {
response = createSchema(schemaRequest);
response = createSystemSchema(schemaRequest);
httpCode = HttpStatus.CREATED;
}catch (BadRequestException badreqEx) {
//If there is same schema-id for other tenant then throw different error message
......@@ -375,7 +415,6 @@ public class SchemaService implements ISchemaService {
}
public SchemaUpsertResponse upsertSystemSchema(SchemaRequest schemaRequest) throws ApplicationException, BadRequestException {
updateDataPartitionId();
return this.upsertSystemSchemaInternal(schemaRequest);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment