diff --git a/.classpath b/.classpath index e43402f..fae1a2b 100644 --- a/.classpath +++ b/.classpath @@ -22,7 +22,7 @@ - + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs index ec4300d..714351a 100644 --- a/.settings/org.eclipse.jdt.core.prefs +++ b/.settings/org.eclipse.jdt.core.prefs @@ -1,5 +1,5 @@ eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 -org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning -org.eclipse.jdt.core.compiler.source=1.7 +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/distro/changelog.xml b/distro/changelog.xml index 53b70b9..f8dc724 100644 --- a/distro/changelog.xml +++ b/distro/changelog.xml @@ -1,7 +1,10 @@ - + + Removed List and Set usage as workaround fo OrientDB bug #9021 + + First Release \ No newline at end of file diff --git a/pom.xml b/pom.xml index 39a5e34..3a2d2df 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ org.gcube.information-system is-exporter-se-plugin - 1.0.0-SNAPSHOT + 1.1.0-SNAPSHOT IS Exporter Exports GenericReosurce and ServiceEndpoint from gCoreIS to Resource Registry @@ -55,12 +55,6 @@ [1.5.0-SNAPSHOT, 2.0.0-SNAPSHOT) provided - - - org.gcube.core - common-scope - provided - org.gcube.resources common-gcore-resources @@ -76,7 +70,21 @@ org.gcube.common authorization-client + provided + + + org.gcube.core + common-encryption + provided + + + + org.gcube.core + common-scope-maps + provided + + org.gcube.information-system information-system-model @@ -96,6 +104,27 @@ resource-registry-publisher + + com.fasterxml.jackson.core + jackson-databind + provided + + + + com.fasterxml.jackson.core + jackson-annotations + provided + + + + com.fasterxml.jackson.core + jackson-core + provided + + + + + + + + + + + + org.json json @@ -129,6 +178,7 @@ + junit junit @@ -142,11 +192,7 @@ test - - - - diff --git a/src/main/java/org/gcube/informationsystem/exporter/ISExporterPlugin.java b/src/main/java/org/gcube/informationsystem/exporter/ISExporterPlugin.java index 9083185..13abe76 100644 --- a/src/main/java/org/gcube/informationsystem/exporter/ISExporterPlugin.java +++ b/src/main/java/org/gcube/informationsystem/exporter/ISExporterPlugin.java @@ -21,6 +21,9 @@ public class ISExporterPlugin extends Plugin { */ private static Logger logger = LoggerFactory.getLogger(ISExporterPlugin.class); + public static final String FILTERED_REPORT = "FILTERED_REPORT"; + + public ISExporterPlugin(ISExporterPluginDeclaration pluginDeclaration) { super(pluginDeclaration); logger.debug("contructor"); @@ -32,16 +35,26 @@ public class ISExporterPlugin extends Plugin { String token = SecurityTokenProvider.instance.get(); AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token); String scope = authorizationEntry.getContext(); - logger.debug("Launching {} execution on scope {}", + logger.info("Launching {} execution on scope {}", ISExporterPluginDeclaration.NAME, scope); - GenericResourceExporter genericResourceExporter = new GenericResourceExporter(); + boolean filteredReport = false; + + try { + filteredReport = (boolean) inputs.getOrDefault(FILTERED_REPORT, false); + }catch (Exception e) { + filteredReport = false; + } + + logger.debug("Failure Report are filtered (e.g. Failing UUID are not shown to avoid to produce to much uneeded reports)"); + + GenericResourceExporter genericResourceExporter = new GenericResourceExporter(filteredReport); genericResourceExporter.export(); - ServiceEndpointExporter serviceEndpointExporter = new ServiceEndpointExporter(); + ServiceEndpointExporter serviceEndpointExporter = new ServiceEndpointExporter(filteredReport); serviceEndpointExporter.export(); - logger.debug("{} execution finished", ISExporterPluginDeclaration.NAME); + logger.info("{} execution finished", ISExporterPluginDeclaration.NAME); } /**{@inheritDoc}*/ diff --git a/src/main/java/org/gcube/informationsystem/exporter/mapper/GCoreResourceMapper.java b/src/main/java/org/gcube/informationsystem/exporter/mapper/GCoreResourceMapper.java index 3372177..7e70d82 100644 --- a/src/main/java/org/gcube/informationsystem/exporter/mapper/GCoreResourceMapper.java +++ b/src/main/java/org/gcube/informationsystem/exporter/mapper/GCoreResourceMapper.java @@ -2,7 +2,6 @@ package org.gcube.informationsystem.exporter.mapper; import java.io.BufferedWriter; import java.io.File; -import java.io.FileInputStream; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; @@ -17,16 +16,7 @@ import java.util.UUID; import org.gcube.common.authorization.client.Constants; import org.gcube.common.authorization.library.AuthorizationEntry; import org.gcube.common.authorization.library.provider.SecurityTokenProvider; -import org.gcube.common.homelibrary.home.Home; -import org.gcube.common.homelibrary.home.HomeLibrary; -import org.gcube.common.homelibrary.home.HomeManager; -import org.gcube.common.homelibrary.home.HomeManagerFactory; -import org.gcube.common.homelibrary.home.workspace.Workspace; -import org.gcube.common.homelibrary.home.workspace.WorkspaceFolder; -import org.gcube.common.homelibrary.home.workspace.folder.FolderItem; -import org.gcube.common.homelibrary.util.WorkspaceUtil; import org.gcube.common.scope.api.ScopeProvider; -import org.gcube.informationsystem.exporter.ISExporterPluginDeclaration; import org.gcube.informationsystem.exporter.mapper.exception.CreateException; import org.gcube.informationsystem.exporter.mapper.exception.UpdateException; import org.gcube.informationsystem.impl.utils.ISMapper; @@ -52,35 +42,36 @@ import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ObjectNode; public abstract class GCoreResourceMapper { - + /** * Logger */ private static Logger logger = LoggerFactory.getLogger(GCoreResourceMapper.class); - + public static final String EXPORTED = "EXPORTED"; public static final String EXPORTED_FROM_OLD_GCORE_IS = "EXPORTED_FROM_OLD_GCORE_IS"; - + public static final String MAPPING_ERROR = "mapping"; public static final String PUBLISHING_ERROR = "publishing"; public static final String TYPE = "type"; public static final String ID = "id"; public static final String ERROR = "error"; public static final String DATE = "date"; - + public static final String EXCEPTION_TYPE = "exceptionType"; public static final String CREATE = "create"; public static final String UPDATE = "update"; - - protected Class grClass; - protected Class rClass; - + + protected final Class grClass; + protected final Class rClass; + protected final boolean filteredReport; + public static final String UTF8 = "UTF-8"; protected ResourceRegistryPublisher resourceRegistryPublisher; protected ResourceRegistryClient resourceRegistryClient; - public static String getCurrentContextName(){ + public static String getCurrentContextName() { String token = SecurityTokenProvider.instance.get(); AuthorizationEntry authorizationEntry = null; try { @@ -90,22 +81,24 @@ public abstract class GCoreResourceMapper grClass, String contextFullName, String dateString){ - return new File(contextFullName.replace("/", "_") + "-" + grClass.getSimpleName() + "-" + dateString + "-exporter.json"); + + public File getFile(Class grClass, String contextFullName, String dateString) { + return new File(contextFullName.replace("/", "_") + "-" + grClass.getSimpleName() + "-" + dateString + + "-exporter.json"); } - - protected GCoreResourceMapper(Class grClass, Class rClass){ + + protected GCoreResourceMapper(Class grClass, Class rClass, boolean filteredReport) { this.grClass = grClass; this.rClass = rClass; this.resourceRegistryPublisher = ResourceRegistryPublisherFactory.create(); this.resourceRegistryClient = ResourceRegistryClientFactory.create(); + this.filteredReport = filteredReport; } protected List getAll() { @@ -113,62 +106,64 @@ public abstract class GCoreResourceMapper client = ICFactory.clientFor(grClass); return client.submit(query); } - - protected String getStringAsUTF8(String s) throws UnsupportedEncodingException{ + + protected String getStringAsUTF8(String s) throws UnsupportedEncodingException { byte bytes[] = s.getBytes("ISO-8859-1"); - return new String(bytes, UTF8); + return new String(bytes, UTF8); } - + protected R create(R r) throws ResourceRegistryException { return resourceRegistryPublisher.createResource(rClass, r); } - + protected R update(R r) throws ResourceRegistryException { return resourceRegistryPublisher.updateResource(rClass, r); } - + protected R read(UUID uuid) throws ResourceRegistryException { return resourceRegistryClient.getInstance(rClass, uuid); } - + protected R createOrUpdate(R r) throws ResourceRegistryException { - + UUID uuid = r.getHeader().getUUID(); - boolean update = false; - + boolean update = false; + try { resourceRegistryClient.exists(rClass, uuid); update = true; - }catch (ResourceNotFoundException e) { + } catch (ResourceNotFoundException e) { update = false; } catch (ResourceAvailableInAnotherContextException e) { - // This code should never be reached because this should be fixed in map function + // This code should never be reached because this should be fixed in + // map function resourceRegistryPublisher.addResourceToContext(uuid); - try{ + try { Thread.sleep(100); - }catch (Exception ee) {} - update= true; + } catch (Exception ee) { + } + update = true; } - - if(update){ + + if (update) { logger.debug("Resource with UUID {} exist. It will be updated", uuid); - try{ + try { return update(r); - }catch (ResourceRegistryException e) { + } catch (ResourceRegistryException e) { throw new UpdateException(e); } - }else{ + } else { logger.debug("Resource with UUID {} does not exist. It will be created", uuid); - try{ + try { return create(r); - }catch (ResourceRegistryException e) { + } catch (ResourceRegistryException e) { throw new CreateException(e); } } - + } - - private ObjectNode addNodeToArray(ArrayNode arrayNode, ObjectMapper objectMapper, GR gr, Exception e){ + + private ObjectNode addNodeToArray(ArrayNode arrayNode, ObjectMapper objectMapper, GR gr, Exception e) { ObjectNode objectNode = objectMapper.createObjectNode(); objectNode.put(TYPE, grClass.getSimpleName()); objectNode.put(ID, gr.id()); @@ -176,192 +171,202 @@ public abstract class GCoreResourceMapper failed){ + + protected void notifyFailures(int allSize, List failed) { String contextName = getCurrentContextName(); - - if(failed.size()==0){ - logger.debug("No needs to create an empty report besause there were no exporting failures on {}", contextName); + + if (failed.size() == 0) { + logger.debug("No needs to create an empty report besause there were no exporting failures on {}", + contextName); return; } - + logger.warn("-------------------------------------------------------"); - logger.warn("{} : {} of {} ({} failures) {}s were exported as {}s", contextName, - allSize-failed.size(), allSize, failed.size(), grClass.getSimpleName(), rClass.getSimpleName()); + logger.warn("{} : {} of {} ({} failures) {}s were exported as {}s", contextName, allSize - failed.size(), + allSize, failed.size(), grClass.getSimpleName(), rClass.getSimpleName()); logger.warn("-------------------------------------------------------\n\n"); - + ObjectMapper objectMapper = new ObjectMapper(); - + ObjectNode objectNode = objectMapper.createObjectNode(); - + Calendar calendar = Calendar.getInstance(); String dateString = getDateString(calendar); objectNode.put(DATE, dateString); ObjectNode context = objectNode.putObject(contextName); ArrayNode mappingArrayNode = context.putArray(MAPPING_ERROR); ArrayNode publishingArrayNode = context.putArray(PUBLISHING_ERROR); - - for(GR gr : failed){ + + for (GR gr : failed) { logger.trace("-------------------------------------------------------"); + + if (filteredReport) { + try { + UUID.fromString(gr.id()); + } catch (Exception e) { + logger.debug( + "{} with has id {} which is not a valid UUID. The reports are filtered and such an error is not reported.", + gr.getClass().getSimpleName(), gr.id()); + continue; + } + } + R r = null; try { r = map(gr); } catch (Exception e) { addNodeToArray(mappingArrayNode, objectMapper, gr, e); - logger.trace("Error exporting {}. The problem was on mapping {} with UUID {}", gr, grClass.getSimpleName(), gr.id()); + logger.trace("Error exporting {}. The problem was on mapping {} with UUID {}", gr, + grClass.getSimpleName(), gr.id()); logger.trace("-------------------------------------------------------\n"); continue; } - + try { createOrUpdate(r); - }catch (Exception e) { - if(e.getCause() instanceof NullPointerException){ + } catch (Exception e) { + if (e.getCause() instanceof NullPointerException) { logger.error("This MUST BE A BUG. Please Investigate"); } - - if(e.getMessage().contains("com.orientechnologies.orient.server.distributed.task.ODistributedOperationException")){ + + if (e.getMessage().contains( + "com.orientechnologies.orient.server.distributed.task.ODistributedOperationException")) { logger.error("This is an OrientDB distributed Issue"); } - + ObjectNode node = addNodeToArray(publishingArrayNode, objectMapper, gr, e); - if(e instanceof CreateException) { + if (e instanceof CreateException) { node.put(EXCEPTION_TYPE, CREATE); } - - if(e instanceof UpdateException){ + + if (e instanceof UpdateException) { node.put(EXCEPTION_TYPE, UPDATE); } - + try { - logger.trace("Error exporting {}. The problem was on publishing {} as {}", gr, rClass.getSimpleName(), ISMapper.marshal(r)); + logger.trace("Error exporting {}. The problem was on publishing {} as {}", gr, + rClass.getSimpleName(), ISMapper.marshal(r)); } catch (JsonProcessingException e1) { logger.trace("", e1); } } logger.trace("-------------------------------------------------------\n"); } + + if(filteredReport){ + if(mappingArrayNode.size()==0 && publishingArrayNode.size()==0){ + logger.debug("No need to produce JSON reports because alla the errors where filtered as requested by the input parameters."); + return; + } + } try { String json = objectMapper.writeValueAsString(objectNode); - + File file = getFile(rClass, contextName, dateString); synchronized (file) { - try(FileWriter fw = new FileWriter(file, true); - BufferedWriter bw = new BufferedWriter(fw); - PrintWriter out = new PrintWriter(bw)){ - out.println(json); - out.flush(); - } catch( IOException e ){ - throw e; + try (FileWriter fw = new FileWriter(file, true); + BufferedWriter bw = new BufferedWriter(fw); + PrintWriter out = new PrintWriter(bw)) { + out.println(json); + out.flush(); + } catch (IOException e) { + throw e; } } - - try { - publishFileToWorkspace(file); - file.delete(); - }catch (Exception e) { - logger.error("Error while saving file {} on Workspace", file.getName(), e); - // TODO Use the Social Notification - } - + + /* + * try { publishFileToWorkspace(file); file.delete(); }catch + * (Exception e) { + * logger.error("Error while saving file {} on Workspace", + * file.getName(), e); // TODO Use the Social Notification } + */ + } catch (Exception e) { logger.error("Error exporting JSON error result", e); } - + logger.trace("-------------------------------------------------------\n\n\n\n\n"); } - + protected R mapAndPublish(GR gr) throws Exception { R r = map(gr); - + List facets = r.getIdentificationFacets(); - for(Facet f : facets){ + for (Facet f : facets) { f.setAdditionalProperty(EXPORTED, EXPORTED_FROM_OLD_GCORE_IS); } - + return createOrUpdate(r); } - + public void export() { - + List all = getAll(); - + logger.debug("-------------------------------------------------------"); - logger.debug("Going to export {} {}s as {}s", - all.size(), grClass.getSimpleName(), rClass.getSimpleName()); + logger.debug("Going to export {} {}s as {}s", all.size(), grClass.getSimpleName(), rClass.getSimpleName()); logger.debug("-------------------------------------------------------"); - - + List failed = new ArrayList<>(); - - for(GR gr : all){ + + for (GR gr : all) { try { Thread.sleep(300); mapAndPublish(gr); - }catch (Exception e) { + } catch (Exception e) { failed.add(gr); } } - + notifyFailures(all.size(), failed); - + } - - - - - + } diff --git a/src/main/java/org/gcube/informationsystem/exporter/mapper/GenericResourceExporter.java b/src/main/java/org/gcube/informationsystem/exporter/mapper/GenericResourceExporter.java index eff99a2..7ea3423 100644 --- a/src/main/java/org/gcube/informationsystem/exporter/mapper/GenericResourceExporter.java +++ b/src/main/java/org/gcube/informationsystem/exporter/mapper/GenericResourceExporter.java @@ -29,8 +29,8 @@ public class GenericResourceExporter extends GCoreResourceMapper { private static Logger logger = LoggerFactory.getLogger(ServiceEndpointExporter.class); @@ -51,25 +54,23 @@ public class ServiceEndpointExporter extends GCoreResourceMapper properties = accessPoint.properties(); + if(properties!=null && properties.size()>0){ + ObjectNode propertiesObjectNode = ISMapper.getObjectMapper().createObjectNode(); + ArrayNode arrayNode = propertiesObjectNode.putArray(ARRAY); + + for(Property property : properties){ + ObjectNode objectNode = ISMapper.getObjectMapper().createObjectNode(); + objectNode.put(NAME, property.name()); + objectNode.put(VALUE, property.value()); + objectNode.put(ENCRYPTED, Boolean.toString(property.isEncrypted())); - List properties = new ArrayList<>(); - - for(Property property : accessPoint.properties()){ - ValueSchema valueSchema = new ValueSchemaImpl(); - String propertyValue = PROPERTY_SCHEMA.toString(); - propertyValue = propertyValue.replace(NAME, property.name()); - propertyValue = propertyValue.replace(ENCRYPTED, Boolean.toString(property.isEncrypted())); - propertyValue = propertyValue.replace(VALUE, property.value()); - - valueSchema.setValue(propertyValue); - valueSchema.setSchema(PROPERTY_SCHEMA); - - properties.add(valueSchema); + arrayNode.add(objectNode); + } + accessPointFacets[i].setAdditionalProperty(PROPERTIES, propertiesObjectNode); } - //accessPointFacets[i].setProperties(properties); i++; } diff --git a/src/main/resources/META-INF/services/org.gcube.vremanagement.executor.plugin.PluginDeclaration b/src/main/resources/META-INF/services/org.gcube.vremanagement.executor.plugin.PluginDeclaration new file mode 100644 index 0000000..7134463 --- /dev/null +++ b/src/main/resources/META-INF/services/org.gcube.vremanagement.executor.plugin.PluginDeclaration @@ -0,0 +1 @@ +org.gcube.informationsystem.exporter.ISExporterPluginDeclaration \ No newline at end of file diff --git a/src/test/java/org/gcube/informationsystem/exporter/ISExporterPluginTest.java b/src/test/java/org/gcube/informationsystem/exporter/ISExporterPluginTest.java index 0b6a532..24c3d64 100644 --- a/src/test/java/org/gcube/informationsystem/exporter/ISExporterPluginTest.java +++ b/src/test/java/org/gcube/informationsystem/exporter/ISExporterPluginTest.java @@ -1,5 +1,8 @@ package org.gcube.informationsystem.exporter; +import java.util.HashMap; +import java.util.Map; + import org.gcube.common.authorization.client.exceptions.ObjectNotFound; import org.gcube.informationsystem.exporter.mapper.GenericResourceExporterTest; import org.gcube.informationsystem.exporter.mapper.ServiceEndpointExporterTest; @@ -25,13 +28,15 @@ public class ISExporterPluginTest { logger.info("\n\n\n-------------------------------------------------------------------------"); ScopedTest.setContext(token); ISExporterPlugin isExporterPlugin = new ISExporterPlugin(new ISExporterPluginDeclaration()); - isExporterPlugin.launch(null); + Map inputs = new HashMap(); + inputs.put(ISExporterPlugin.FILTERED_REPORT, true); + isExporterPlugin.launch(inputs); logger.info("\n\n\n"); } } //@Test - public void delAllExported() throws ObjectNotFound, Exception{ + public void removeExported() throws ObjectNotFound, Exception{ String[] tokens = { ScopedTest.GCUBE, ScopedTest.GCUBE_DEVSEC, @@ -44,10 +49,10 @@ public class ISExporterPluginTest { ScopedTest.setContext(token); GenericResourceExporterTest genericResourceExporterTest = new GenericResourceExporterTest(); - genericResourceExporterTest.del(); + genericResourceExporterTest.removeExported(); ServiceEndpointExporterTest serviceEndpointExporterTest = new ServiceEndpointExporterTest(); - serviceEndpointExporterTest.del(); + serviceEndpointExporterTest.removeExported(); } } } diff --git a/src/test/java/org/gcube/informationsystem/exporter/mapper/GCoreResourceMapperTest.java b/src/test/java/org/gcube/informationsystem/exporter/mapper/GCoreResourceMapperTest.java index 25638a6..9e7b8f7 100644 --- a/src/test/java/org/gcube/informationsystem/exporter/mapper/GCoreResourceMapperTest.java +++ b/src/test/java/org/gcube/informationsystem/exporter/mapper/GCoreResourceMapperTest.java @@ -47,11 +47,14 @@ public class GCoreResourceMapperTest extends ScopedTest { for(String token : tokens){ logger.info("\n\n\n-------------------------------------------------------------------------"); ScopedTest.setContext(token); - GenericResourceExporter gre = new GenericResourceExporter(); + GenericResourceExporter gre = new GenericResourceExporter(false); File file = getFile(gre); + logger.info("\n\n\n {}", file); + /* gre.publishFileToWorkspace(file); logger.info("\n\n\n"); file.delete(); + */ } } diff --git a/src/test/java/org/gcube/informationsystem/exporter/mapper/GenericResourceExporterTest.java b/src/test/java/org/gcube/informationsystem/exporter/mapper/GenericResourceExporterTest.java index 8910df2..43d748a 100644 --- a/src/test/java/org/gcube/informationsystem/exporter/mapper/GenericResourceExporterTest.java +++ b/src/test/java/org/gcube/informationsystem/exporter/mapper/GenericResourceExporterTest.java @@ -4,11 +4,11 @@ import java.util.ArrayList; import java.util.List; import java.util.UUID; +import org.gcube.common.authorization.client.exceptions.ObjectNotFound; import org.gcube.common.resources.gcore.GenericResource; import org.gcube.informationsystem.exporter.ScopedTest; import org.gcube.informationsystem.model.entity.Facet; import org.gcube.informationsystem.model.entity.resource.Configuration; -import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClient; import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClientFactory; import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPublisher; @@ -23,89 +23,68 @@ import org.slf4j.LoggerFactory; /** * @author Luca Frosini (ISTI - CNR) */ -public class GenericResourceExporterTest extends ScopedTest{ - +public class GenericResourceExporterTest extends ScopedTest { + private static Logger logger = LoggerFactory.getLogger(GenericResourceExporterTest.class); - + @Test - public void export(){ - GenericResourceExporter gre = new GenericResourceExporter(); + public void export() { + GenericResourceExporter gre = new GenericResourceExporter(false); gre.export(); } - - - public void del() throws ResourceRegistryException{ + + public void removeExported() throws ObjectNotFound, Exception { ResourceRegistryClient client = ResourceRegistryClientFactory.create(); ResourceRegistryPublisher publisher = ResourceRegistryPublisherFactory.create(); - + @SuppressWarnings("unchecked") List configurations = (List) client.getInstances(Configuration.NAME, false); List failed = new ArrayList<>(); - - logger.debug("Going to delete {} {}s", - configurations.size(), Configuration.NAME); - + + logger.debug("Going to delete {} {}s", configurations.size(), Configuration.NAME); + int excluded = 0; - - for(Configuration configuration : configurations){ + + for (Configuration configuration : configurations) { try { Facet facet = configuration.getIdentificationFacets().get(0); String string = (String) facet.getAdditionalProperty(GCoreResourceMapper.EXPORTED); publisher.deleteResource(configuration); - if(string!=null && string.compareTo(GCoreResourceMapper.EXPORTED_FROM_OLD_GCORE_IS)==0){ + if (string != null && string.compareTo(GCoreResourceMapper.EXPORTED_FROM_OLD_GCORE_IS) == 0) { publisher.deleteResource(configuration); - }else{ + } else { excluded++; } - }catch (Exception e) { + } catch (Exception e) { failed.add(configuration); } } - - logger.debug("{} of {} ({} failures) {}s were deleted. {} {}s were excluded because there was not exported from gCore IS.", - configurations.size()-failed.size()-excluded, configurations.size(), failed.size(), Configuration.NAME, excluded, Configuration.NAME); + + logger.debug( + "{} of {} ({} failures) {}s were deleted. {} {}s were excluded because there was not exported from gCore IS.", + configurations.size() - failed.size() - excluded, configurations.size(), failed.size(), + Configuration.NAME, excluded, Configuration.NAME); } - - //@Test + + // @Test public void investigateSingleResource() throws Exception { - ScopedTest.setContext(ScopedTest.GCUBE); - + //ScopedTest.setContext(ScopedTest.GCUBE_DEVSEC); + UUID uuid = UUID.fromString(""); - + //ResourceRegistryPublisher publisher = ResourceRegistryPublisherFactory.create(); //publisher.deleteResource(uuid); - - //ResourceRegistryClient resourceRegistryClient = ResourceRegistryClientFactory.create(); - + + // ResourceRegistryClient resourceRegistryClient = ResourceRegistryClientFactory.create(); + SimpleQuery query = ICFactory.queryFor(GenericResource.class) .addCondition(String.format("$resource/ID/text() eq '%1s'", uuid.toString())); DiscoveryClient client = ICFactory.clientFor(GenericResource.class); List seList = client.submit(query); - - GenericResourceExporter see = new GenericResourceExporter(); + + GenericResourceExporter see = new GenericResourceExporter(false); see.mapAndPublish(seList.get(0)); - + } - - //@Test - public void addToAllScopes() throws Exception { - - UUID uuid = UUID.fromString(""); - ResourceRegistryPublisher publisher = ResourceRegistryPublisherFactory.create(); - - String[] tokens = { - ScopedTest.GCUBE, - ScopedTest.GCUBE_DEVSEC, - ScopedTest.GCUBE_DEVSEC_DEVVRE, - ScopedTest.GCUBE_DEVNEXT, - ScopedTest.GCUBE_DEVNEXT_NEXTNEXT - }; - - for(String token : tokens){ - ScopedTest.setContext(token); - publisher.addResourceToContext(uuid); - } - - } - + } diff --git a/src/test/java/org/gcube/informationsystem/exporter/mapper/ServiceEndpointExporterTest.java b/src/test/java/org/gcube/informationsystem/exporter/mapper/ServiceEndpointExporterTest.java index 6fabe4e..e2378c8 100644 --- a/src/test/java/org/gcube/informationsystem/exporter/mapper/ServiceEndpointExporterTest.java +++ b/src/test/java/org/gcube/informationsystem/exporter/mapper/ServiceEndpointExporterTest.java @@ -4,11 +4,11 @@ import java.util.ArrayList; import java.util.List; import java.util.UUID; +import org.gcube.common.authorization.client.exceptions.ObjectNotFound; import org.gcube.common.resources.gcore.ServiceEndpoint; import org.gcube.informationsystem.exporter.ScopedTest; import org.gcube.informationsystem.model.entity.Facet; import org.gcube.informationsystem.model.entity.resource.EService; -import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClient; import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClientFactory; import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPublisher; @@ -29,15 +29,14 @@ public class ServiceEndpointExporterTest extends ScopedTest{ @Test public void export(){ - ServiceEndpointExporter see = new ServiceEndpointExporter(); + ServiceEndpointExporter see = new ServiceEndpointExporter(false); see.export(); } - - public void del() throws ResourceRegistryException{ + + public void removeExported() throws ObjectNotFound, Exception{ ResourceRegistryClient client = ResourceRegistryClientFactory.create(); ResourceRegistryPublisher publisher = ResourceRegistryPublisherFactory.create(); - @SuppressWarnings("unchecked") List eServices = (List) client.getInstances(EService.NAME, false); List failed = new ArrayList<>(); @@ -65,11 +64,13 @@ public class ServiceEndpointExporterTest extends ScopedTest{ eServices.size()-failed.size()-excluded, eServices.size(), failed.size(), EService.NAME, excluded, EService.NAME); } - @Test + // @Test public void investigateSingleResource() throws Exception { - UUID uuid = UUID.fromString("66a674a2-8319-43b4-86c1-bd092bc7c490"); - ResourceRegistryPublisher publisher = ResourceRegistryPublisherFactory.create(); - publisher.addResourceToContext(uuid); + // ScopedTest.setContext(GCUBE); + + UUID uuid = UUID.fromString(""); + //ResourceRegistryPublisher publisher = ResourceRegistryPublisherFactory.create(); + //publisher.deleteResource(uuid); //ResourceRegistryClient resourceRegistryClient = ResourceRegistryClientFactory.create(); @@ -78,7 +79,7 @@ public class ServiceEndpointExporterTest extends ScopedTest{ DiscoveryClient client = ICFactory.clientFor(ServiceEndpoint.class); List seList = client.submit(query); - ServiceEndpointExporter see = new ServiceEndpointExporter(); + ServiceEndpointExporter see = new ServiceEndpointExporter(false); see.notifyFailures(seList.size(), seList); }