Fixed bug which does not allow to create PropertyTypeDefiniton of

Property during DB initialization
This commit is contained in:
Luca Frosini 2020-01-27 17:57:24 +01:00
parent d5c2ecd896
commit d780357089
4 changed files with 29 additions and 4 deletions

View File

@ -245,7 +245,6 @@ public class DatabaseEnvironment {
definitionToBeCreated.add(ConsistsOfTypeDefinition.class); definitionToBeCreated.add(ConsistsOfTypeDefinition.class);
SchemaAction schemaAction = new SchemaActionImpl(); SchemaAction schemaAction = new SchemaActionImpl();
for(Class<? extends ISManageable> clz : definitionToBeCreated) { for(Class<? extends ISManageable> clz : definitionToBeCreated) {
if(BaseProperty.class.isAssignableFrom(clz)) { if(BaseProperty.class.isAssignableFrom(clz)) {

View File

@ -6,6 +6,8 @@ import org.gcube.informationsystem.base.reference.properties.BaseProperty;
import org.gcube.informationsystem.base.reference.relations.BaseRelation; import org.gcube.informationsystem.base.reference.relations.BaseRelation;
import org.gcube.informationsystem.model.reference.entities.Facet; import org.gcube.informationsystem.model.reference.entities.Facet;
import org.gcube.informationsystem.model.reference.entities.Resource; import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.model.reference.properties.Header;
import org.gcube.informationsystem.model.reference.properties.Property;
import org.gcube.informationsystem.model.reference.relations.ConsistsOf; import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
import org.gcube.informationsystem.model.reference.relations.IsRelatedTo; import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaAlreadyPresentException; import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaAlreadyPresentException;
@ -74,7 +76,14 @@ public class SchemaActionImpl implements SchemaAction {
schemaManagement.setTypeName(TypeBinder.getType(p)); schemaManagement.setTypeName(TypeBinder.getType(p));
String json = TypeBinder.serializeType(p); String json = TypeBinder.serializeType(p);
logger.trace(json); logger.trace(json);
schemaManagement.create(json, AccessType.BASE_PROPERTY); if(Property.class.isAssignableFrom(p)) {
if(p.equals(Property.class) || p.equals(Header.class) ) {
((SchemaManagementImpl) schemaManagement).setSkipTypeDefinitionCreation(true);
}
schemaManagement.create(json, AccessType.PROPERTY);
}else {
schemaManagement.create(json, AccessType.BASE_PROPERTY);
}
} catch(SchemaAlreadyPresentException sape) { } catch(SchemaAlreadyPresentException sape) {
logger.warn("{} already exists. It will be ignored", TypeBinder.getType(p)); logger.warn("{} already exists. It will be ignored", TypeBinder.getType(p));
} catch(Exception ex) { } catch(Exception ex) {

View File

@ -68,6 +68,22 @@ public class SchemaManagementImpl implements SchemaManagement {
protected String typeName; protected String typeName;
protected boolean skipTypeDefinitionCreation;
public boolean isSkipTypeDefinitionCreation() {
return skipTypeDefinitionCreation;
}
public void setSkipTypeDefinitionCreation(boolean skipTypeDefinitionCreation) {
this.skipTypeDefinitionCreation = skipTypeDefinitionCreation;
}
public SchemaManagementImpl() {
this.skipTypeDefinitionCreation = false;
}
protected OClass getOClass(OSchema oSchema, String type) throws SchemaException { protected OClass getOClass(OSchema oSchema, String type) throws SchemaException {
return oSchema.getClass(type); return oSchema.getClass(type);
} }
@ -418,7 +434,7 @@ public class SchemaManagementImpl implements SchemaManagement {
} }
String ret = null; String ret = null;
if(erManagement!=null) { if(erManagement!=null && !skipTypeDefinitionCreation) {
erManagement.setJson(jsonSchema); erManagement.setJson(jsonSchema);
ret = erManagement.create(); ret = erManagement.create();
}else { }else {

View File

@ -191,7 +191,8 @@ public class SchemaManagementImplTest {
} }
@Test(expected=SchemaAlreadyPresentException.class) //@Test(expected=SchemaAlreadyPresentException.class)
@Test
public void createPropertyType() throws Exception { public void createPropertyType() throws Exception {
PropertyTypeDefinition<ValueSchema> propertyTypeDefinition = new PropertyTypeDefinitionImpl<>(ValueSchema.class); PropertyTypeDefinition<ValueSchema> propertyTypeDefinition = new PropertyTypeDefinitionImpl<>(ValueSchema.class);