Superclasses are now filtered (i.e. internal types are not added to the
list)and ordered (first the immediate superclass and the last the basic type e.g. Resource, Facet, IsRelatedTo, ConsistsOf) #20319
This commit is contained in:
parent
96dc5c8516
commit
55b79bc835
|
@ -66,11 +66,17 @@ public abstract class ElementManagement<El extends OElement> {
|
|||
|
||||
private static Logger staticLogger = LoggerFactory.getLogger(ElementManagement.class);
|
||||
|
||||
public final String AT = "@";
|
||||
public final String UNDERSCORE = "_";
|
||||
|
||||
public final static String DELETED = "deleted";
|
||||
|
||||
public final static String AT = "@";
|
||||
public final static String UNDERSCORE = "_";
|
||||
|
||||
/**
|
||||
* The classes which has not to be included in the superClasses property when serialize and instance
|
||||
* e.g. for any Resource instance when mast not include Entity and any Entity super class
|
||||
*/
|
||||
public final Set<String> superClassesToBeExcluded;
|
||||
|
||||
protected final Set<String> ignoreKeys;
|
||||
protected final Set<String> ignoreStartWithKeys;
|
||||
|
||||
|
@ -186,11 +192,12 @@ public abstract class ElementManagement<El extends OElement> {
|
|||
|
||||
this.ignoreStartWithKeys = new HashSet<String>();
|
||||
|
||||
this.ignoreStartWithKeys.add(AT);
|
||||
this.ignoreStartWithKeys.add(UNDERSCORE);
|
||||
this.ignoreStartWithKeys.add(ElementManagement.AT);
|
||||
this.ignoreStartWithKeys.add(ElementManagement.UNDERSCORE);
|
||||
|
||||
this.reload = false;
|
||||
|
||||
this.superClassesToBeExcluded = new HashSet<>();
|
||||
|
||||
/*
|
||||
* By the default the system execute the the operation of
|
||||
|
@ -1158,18 +1165,25 @@ public abstract class ElementManagement<El extends OElement> {
|
|||
}
|
||||
}
|
||||
|
||||
protected Collection<String> getSuperclasses() throws SchemaException, ResourceRegistryException {
|
||||
Collection<OClass> allSuperClasses = getOClass().getAllSuperClasses();
|
||||
Collection<String> superClasses = new HashSet<>();
|
||||
for(OClass oSuperClass : allSuperClasses) {
|
||||
String name = oSuperClass.getName();
|
||||
if(name.compareTo(StringFactory.V.toUpperCase()) == 0 || name.compareTo(StringFactory.E.toUpperCase()) == 0
|
||||
|| name.compareTo(DatabaseEnvironment.O_RESTRICTED_CLASS) == 0) {
|
||||
continue;
|
||||
protected List<String> getSuperclasses() throws SchemaException, ResourceRegistryException {
|
||||
List<String> superClasses = new ArrayList<>();
|
||||
List<OClass> allSuperClasses = getOClass().getSuperClasses();
|
||||
while(allSuperClasses.size()>0) {
|
||||
List<OClass> toBeAnalysed = new ArrayList<>(allSuperClasses);
|
||||
allSuperClasses = new ArrayList<>();
|
||||
for(OClass oSuperClass : toBeAnalysed) {
|
||||
String name = oSuperClass.getName();
|
||||
if(name.compareTo(StringFactory.V.toUpperCase()) == 0 || name.compareTo(StringFactory.E.toUpperCase()) == 0
|
||||
|| name.compareTo(DatabaseEnvironment.O_RESTRICTED_CLASS) == 0) {
|
||||
continue;
|
||||
}
|
||||
if(superClassesToBeExcluded.contains(name)) {
|
||||
continue;
|
||||
}
|
||||
superClasses.add(superClasses.size(), name);
|
||||
allSuperClasses.addAll(oSuperClass.getSuperClasses());
|
||||
}
|
||||
superClasses.add(name);
|
||||
}
|
||||
|
||||
return superClasses;
|
||||
}
|
||||
|
||||
|
|
|
@ -35,16 +35,13 @@ public class PropertyElementManagement {
|
|||
|
||||
public static final Set<String> PROPERTY_IGNORE_KEYS;
|
||||
public static final Set<String> PROPERTY_IGNORE_START_WITH_KEYS;
|
||||
|
||||
public static final String AT = "@";
|
||||
public static final String UNDERSCORE = "_";
|
||||
|
||||
|
||||
static {
|
||||
PROPERTY_IGNORE_KEYS = new HashSet<String>();
|
||||
|
||||
PROPERTY_IGNORE_START_WITH_KEYS = new HashSet<String>();
|
||||
PROPERTY_IGNORE_START_WITH_KEYS.add(AT);
|
||||
PROPERTY_IGNORE_START_WITH_KEYS.add(UNDERSCORE);
|
||||
PROPERTY_IGNORE_START_WITH_KEYS.add(ElementManagement.AT);
|
||||
PROPERTY_IGNORE_START_WITH_KEYS.add(ElementManagement.UNDERSCORE);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -71,6 +71,8 @@ public abstract class EntityManagement<E extends EntityElement> extends EntityEl
|
|||
|
||||
this.relationManagements = new HashMap<>();
|
||||
|
||||
this.superClassesToBeExcluded.add(AccessType.ENTITY_ELEMENT.getName());
|
||||
this.superClassesToBeExcluded.add(AccessType.ENTITY.getName());
|
||||
}
|
||||
|
||||
protected EntityManagement(AccessType accessType, SecurityContext workingContext, ODatabaseDocument orientGraph) {
|
||||
|
|
|
@ -63,6 +63,9 @@ public abstract class RelationManagement<T extends EntityManagement<? extends En
|
|||
super(accessType, Resource.class, targetEntityClass);
|
||||
this.defaultPropagationConstraint = defaultPropagationConstraint;
|
||||
this.checkContextOfSourceEntity = false;
|
||||
|
||||
this.superClassesToBeExcluded.add(AccessType.RELATION_ELEMENT.getName());
|
||||
this.superClassesToBeExcluded.add(AccessType.RELATION.getName());
|
||||
}
|
||||
|
||||
protected RelationManagement(AccessType accessType, Class<? extends Entity> targetEntityClass, SecurityContext workingContext, ODatabaseDocument orientGraph,
|
||||
|
|
|
@ -51,6 +51,7 @@ import org.gcube.resourcemanagement.model.impl.entities.facets.SoftwareFacetImpl
|
|||
import org.gcube.resourcemanagement.model.impl.entities.facets.StateFacetImpl;
|
||||
import org.gcube.resourcemanagement.model.impl.entities.resources.EServiceImpl;
|
||||
import org.gcube.resourcemanagement.model.impl.entities.resources.HostingNodeImpl;
|
||||
import org.gcube.resourcemanagement.model.impl.entities.resources.RunningPluginImpl;
|
||||
import org.gcube.resourcemanagement.model.impl.properties.ValueSchemaImpl;
|
||||
import org.gcube.resourcemanagement.model.impl.relations.consistsof.IsIdentifiedByImpl;
|
||||
import org.gcube.resourcemanagement.model.impl.relations.isrelatedto.ActivatesImpl;
|
||||
|
@ -68,6 +69,7 @@ import org.gcube.resourcemanagement.model.reference.entities.resources.Configura
|
|||
import org.gcube.resourcemanagement.model.reference.entities.resources.EService;
|
||||
import org.gcube.resourcemanagement.model.reference.entities.resources.GCubeResource;
|
||||
import org.gcube.resourcemanagement.model.reference.entities.resources.HostingNode;
|
||||
import org.gcube.resourcemanagement.model.reference.entities.resources.RunningPlugin;
|
||||
import org.gcube.resourcemanagement.model.reference.entities.resources.Service;
|
||||
import org.gcube.resourcemanagement.model.reference.properties.ValueSchema;
|
||||
import org.gcube.resourcemanagement.model.reference.relations.consistsof.IsIdentifiedBy;
|
||||
|
@ -104,14 +106,14 @@ public class ERManagementTest extends ContextTest {
|
|||
logger.debug("{}", json);
|
||||
facetManagement.setJson(json);
|
||||
|
||||
/*
|
||||
/* A facet cannot be created per se */
|
||||
String cpuFacetJson = facetManagement.create();
|
||||
CPUFacet createdCpuFacet = ISMapper.unmarshal(CPUFacet.class,
|
||||
CPUFacet createdCpuFacet = ElementMapper.unmarshal(CPUFacet.class,
|
||||
cpuFacetJson);
|
||||
logger.debug("Created:\nRaw Json : {}\nUnmarshalled : {}",
|
||||
cpuFacetJson, createdCpuFacet);
|
||||
*/
|
||||
|
||||
facetManagement.delete();
|
||||
}
|
||||
|
||||
|
||||
|
@ -165,6 +167,35 @@ public class ERManagementTest extends ContextTest {
|
|||
Assert.assertTrue(deleted);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateRunningPlugin() throws Exception {
|
||||
RunningPlugin runningPlugin = new RunningPluginImpl();
|
||||
|
||||
SoftwareFacet softwareFacet = new SoftwareFacetImpl();
|
||||
softwareFacet.setGroup("information-system");
|
||||
softwareFacet.setName("is-exporter-se-plugin");
|
||||
softwareFacet.setVersion("1.0.0");
|
||||
IsIdentifiedBy<RunningPlugin, Facet> isIdentifiedBy = new IsIdentifiedByImpl<>(
|
||||
runningPlugin, softwareFacet, null);
|
||||
runningPlugin.addFacet(isIdentifiedBy);
|
||||
|
||||
ResourceManagement resourceManagement = new ResourceManagement();
|
||||
resourceManagement.setElementType(RunningPlugin.NAME);
|
||||
resourceManagement.setJson(ElementMapper.marshal(runningPlugin));
|
||||
|
||||
String json = resourceManagement.create();
|
||||
logger.debug("Created : {}", json);
|
||||
runningPlugin = ElementMapper.unmarshal(RunningPlugin.class, json);
|
||||
logger.debug("Unmarshalled {} {}", RunningPlugin.NAME, runningPlugin);
|
||||
|
||||
resourceManagement = new ResourceManagement();
|
||||
resourceManagement.setUUID(runningPlugin.getHeader().getUUID());
|
||||
|
||||
boolean deleted = resourceManagement.delete();
|
||||
Assert.assertTrue(deleted);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testCreateEService() throws Exception {
|
||||
|
|
Loading…
Reference in New Issue