Commit 147be85b authored by Nikita Ruzhevsky's avatar Nikita Ruzhevsky
Browse files

refactored entity docs, added SchemaInfoDto, started implementation of the...

refactored entity docs, added SchemaInfoDto, started implementation of the SchemaInfoStoreHelper (WIP), added converter for dto-doc pair
parent 2db18fb3
Pipeline #59568 passed with stages
in 6 minutes and 14 seconds
package org.opengroup.osdu.core.mongodb.converter;
import org.opengroup.osdu.core.mongodb.dto.SchemaInfoDto;
import org.opengroup.osdu.core.mongodb.entity.SchemaInfoDoc;
import org.springframework.stereotype.Component;
@Component
public class SchemaInfoConverter {
public SchemaInfoDto toDto(SchemaInfoDoc doc) {
return null;
}
public SchemaInfoDoc toDoc(SchemaInfoDto dto, String tenant) {
return null;
}
}
package org.opengroup.osdu.core.mongodb.dto;
import lombok.Data;
@Data
public class SchemaIdentityDto {
private String authority;
private String source;
private String entityType;
private Long schemaVersionMajor;
private Long schemaVersionMinor;
private Long schemaVersionPatch;
private String id;
}
package org.opengroup.osdu.core.mongodb.dto;
import lombok.Data;
import org.opengroup.osdu.core.mongodb.entity.SchemaScope;
import org.opengroup.osdu.core.mongodb.entity.SchemaStatus;
import java.util.Date;
@Data
public class SchemaInfoDto {
private SchemaIdentityDto schemaIdentity;
private String createdBy;
private Date dateCreated;
private SchemaStatus status;
private SchemaScope scope;
private SchemaIdentityDto supersededBy;
}
package org.opengroup.osdu.core.mongodb.entity;
import lombok.Data;
import org.springframework.data.annotation.Id;
import java.util.Date;
@Data
public class SchemaInfoDoc {
@Id
private EntityId id;
private SchemaIdentityDoc schemaIdentity;
private String createdBy;
private Date dateCreated;
......@@ -14,11 +18,4 @@ public class SchemaInfoDoc {
private SchemaScope scope;
private SchemaIdentityDoc supersededBy;
public enum SchemaStatus {
PUBLISHED, OBSOLETE, DEVELOPMENT
}
public enum SchemaScope {
INTERNAL, SHARED
}
}
package org.opengroup.osdu.core.mongodb.entity;
public enum SchemaScope {
INTERNAL, SHARED
}
\ No newline at end of file
package org.opengroup.osdu.core.mongodb.entity;
public enum SchemaStatus {
PUBLISHED, OBSOLETE, DEVELOPMENT
}
......@@ -24,6 +24,9 @@ public class AuthorityStoreHelper {
public AuthorityDto get(String authorityId, String tenant) {
EntityId id = new EntityId(authorityId, tenant);
AuthorityDoc doc = mongoDBHelper.get(ID, id, CLASS);
if (doc == null) {
throw ExceptionGenerator.notFound(String.format("%s %s", authorityId, tenant));
}
return authorityConverter.toDto(doc);
}
......
......@@ -22,6 +22,9 @@ public class EntityTypeStoreHelper extends SchemaStoreHelperParent {
public EntityTypeDto get(String entityId, String tenant) {
EntityId id = new EntityId(entityId, tenant);
EntityTypeDoc doc = mongoDBHelper.get(ID, id, CLASS);
if (doc == null) {
throw ExceptionGenerator.notFound(String.format("%s %s", entityId, tenant));
}
return converter.toDto(doc);
}
......
package org.opengroup.osdu.core.mongodb.helper;
import org.opengroup.osdu.core.mongodb.converter.SchemaInfoConverter;
import org.opengroup.osdu.core.mongodb.dto.SchemaInfoDto;
import org.opengroup.osdu.core.mongodb.entity.EntityId;
import org.opengroup.osdu.core.mongodb.entity.SchemaInfoDoc;
import org.opengroup.osdu.core.mongodb.util.ExceptionGenerator;
import org.springframework.stereotype.Component;
import java.util.List;
@Component
public class SchemaInfoStoreHelper {
/*
SchemaInfo updateSchemaInfo(SchemaRequest schema) throws ApplicationException, BadRequestException;
private static final Class<SchemaInfoDoc> CLASS = SchemaInfoDoc.class;
SchemaInfo createSchemaInfo(SchemaRequest schema) throws ApplicationException, BadRequestException;
private final BasicMongoDBHelper mongoDBHelper;
private final SchemaInfoConverter schemaInfoConverter;
SchemaInfo getSchemaInfo(String schemaId) throws ApplicationException, NotFoundException;
public SchemaInfoStoreHelper(BasicMongoDBHelper mongoDBHelper, SchemaInfoConverter schemaInfoConverter) {
this.mongoDBHelper = mongoDBHelper;
this.schemaInfoConverter = schemaInfoConverter;
}
String getLatestMinorVerSchema(SchemaInfo schemaInfo) throws ApplicationException;
public SchemaInfoDto getSchemaInfo(String schemaId, String tenant) {
EntityId id = new EntityId(schemaId, tenant);
SchemaInfoDoc doc = mongoDBHelper.get("_id", id, CLASS);
if (doc == null) {
throw ExceptionGenerator.notFound(id.toString());
}
return schemaInfoConverter.toDto(doc);
}
List<SchemaInfo> getSchemaInfoList(QueryParams queryParams, String tenantId) throws ApplicationException;
/**
* Actually, according to other provider's implementations, only schema info is used is this method and some others
*/
public SchemaInfoDto createSchemaInfo(SchemaInfoDto dto, String tenant) {
SchemaInfoDoc doc = schemaInfoConverter.toDoc(dto, tenant);
EntityId id = doc.getId();
if (mongoDBHelper.existsByField("_id", id, CLASS)) {
throw ExceptionGenerator.alreadyExists(id.toString());
}
mongoDBHelper.save(doc);
return schemaInfoConverter.toDto(doc);
}
public SchemaInfoDto updateSchemaInfo(SchemaInfoDto dto, String tenant) {
SchemaInfoDoc doc = schemaInfoConverter.toDoc(dto, tenant);
EntityId id = doc.getId();
if (!mongoDBHelper.existsByField("_id", id, CLASS)) {
throw ExceptionGenerator.notFound(id.toString());
}
mongoDBHelper.save(doc);
return schemaInfoConverter.toDto(doc);
}
/**
* By default, mongo-core module doesn't know about global system configs, so you have to get tenant list prior to
* this method
* @param tenants tenant list to find the non-unique entry
* @return true if any of the combination tenant-id exists in DB
*/
public boolean isUnique(String schemaId, List<String> tenants) {
for (String tenant : tenants) {
EntityId id = new EntityId(schemaId, tenant);
if (mongoDBHelper.existsByField("_id", id, CLASS)) {
return false;
}
}
return true;
}
public boolean cleanSchema(String schemaId, String tenant) {
EntityId id = new EntityId(schemaId, tenant);
return mongoDBHelper.delete("_id", id, CLASS);
}
boolean isUnique(String schemaId, String tenantId) throws ApplicationException;
boolean cleanSchema(String schemaId) throws ApplicationException;
/*
String getLatestMinorVerSchema(SchemaInfo schemaInfo) throws ApplicationException;
List<SchemaInfo> getSchemaInfoList(QueryParams queryParams, String tenantId) throws ApplicationException;
*/
}
......@@ -24,6 +24,9 @@ public class SourceStoreHelper {
public SourceDto get(String sourceId, String tenant) {
EntityId id = new EntityId(sourceId, tenant);
SourceDoc doc = mongoDBHelper.get(ID, id, CLASS);
if (doc == null) {
throw ExceptionGenerator.notFound(String.format("%s %s", sourceId, tenant));
}
return sourceConverter.toDto(doc);
}
......
......@@ -5,4 +5,8 @@ public class ExceptionGenerator {
public static RuntimeException alreadyExists(String reason) {
return new IllegalArgumentException("already exists: " + reason);
}
public static RuntimeException notFound(String reason) {
return new IllegalArgumentException("was not found: " + reason);
}
}
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