Compare commits

...

2 Commits

8 changed files with 178 additions and 12 deletions

View File

@ -33,5 +33,6 @@
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="output" path="target/detachedres-library-1.0.0-SNAPSHOT/WEB-INF/classes"/> <classpathentry kind="output" path="target/detachedres-library-1.0.0-SNAPSHOT/WEB-INF/classes"/>
</classpath> </classpath>

15
CHANGELOG.md Normal file
View File

@ -0,0 +1,15 @@
# Changelog
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [v1-1-0] [r4-24-0]- 2020-06-05
**New features**
[#19440] Added the property cataloguePortletURL and the method
## [1-0-0] - [2020-04-01]
First release

View File

@ -11,7 +11,7 @@
<groupId>org.gcube.infrastructure.detachedres</groupId> <groupId>org.gcube.infrastructure.detachedres</groupId>
<artifactId>detachedres-library</artifactId> <artifactId>detachedres-library</artifactId>
<name>detachedres-library</name> <name>detachedres-library</name>
<version>1.0.0</version> <version>1.1.0-SNAPSHOT</version>
<description>Detached Resource Entities Library</description> <description>Detached Resource Entities Library</description>

View File

@ -7,14 +7,18 @@ import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.infrastructure.detachedres.detachedreslibrary.server.is.DetachedREsBuilder; import org.gcube.infrastructure.detachedres.detachedreslibrary.server.is.DetachedREsBuilder;
import org.gcube.infrastructure.detachedres.detachedreslibrary.shared.Constants; import org.gcube.infrastructure.detachedres.detachedreslibrary.shared.Constants;
import org.gcube.infrastructure.detachedres.detachedreslibrary.shared.re.DetachedREs; import org.gcube.infrastructure.detachedres.detachedreslibrary.shared.re.DetachedREs;
import org.gcube.infrastructure.detachedres.detachedreslibrary.shared.re.Gateway;
import org.gcube.infrastructure.detachedres.detachedreslibrary.shared.re.VO;
import org.gcube.infrastructure.detachedres.detachedreslibrary.shared.re.VRE;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
* The Class DetachedREsClient.
* *
* @author Giancarlo Panichi * @author Giancarlo Panichi
* *
* * @author updated by Francesco Mangiacrapa at ISTI-CNR
*/ */
public class DetachedREsClient { public class DetachedREsClient {
@ -24,16 +28,27 @@ public class DetachedREsClient {
private String scope; private String scope;
/** /**
* * Instantiates a new detached R es client.
*/ */
public DetachedREsClient() { public DetachedREsClient() {
} }
/**
* Instantiates a new detached R es client.
*
* @param token the token
*/
public DetachedREsClient(String token) { public DetachedREsClient(String token) {
this.token = token; this.token = token;
} }
/**
* Gets the detached R es.
*
* @return the detached R es
* @throws Exception the exception
*/
public DetachedREs getDetachedREs() throws Exception { public DetachedREs getDetachedREs() throws Exception {
retrieveAuthInfo(); retrieveAuthInfo();
logger.debug("Use: [userName={}, scope={}, token={}]",userName,scope,token); logger.debug("Use: [userName={}, scope={}, token={}]",userName,scope,token);
@ -41,6 +56,13 @@ public class DetachedREsClient {
} }
/**
* Gets the detached R es in scope.
*
* @param scope the scope
* @return the detached R es in scope
* @throws Exception the exception
*/
public DetachedREs getDetachedREsInScope(String scope) throws Exception { public DetachedREs getDetachedREsInScope(String scope) throws Exception {
retrieveAuthInfo(); retrieveAuthInfo();
this.scope=scope; this.scope=scope;
@ -49,6 +71,11 @@ public class DetachedREsClient {
} }
/**
* Retrieve auth info.
*
* @throws Exception the exception
*/
private void retrieveAuthInfo() throws Exception { private void retrieveAuthInfo() throws Exception {
if (Constants.DEBUG_MODE) { if (Constants.DEBUG_MODE) {
logger.debug("Debug Mode"); logger.debug("Debug Mode");
@ -78,4 +105,38 @@ public class DetachedREsClient {
} }
/**
* Find detached VRE for VRE name.
*
* @param vreName the vre name
* @return the vre detached if it is found.
*/
public VRE findDetachedVREforVREName(String vreName) {
logger.debug("Find the VRE name: "+vreName+" called");
try {
DetachedREs detachedREs = getDetachedREs();
for (Gateway gateway : detachedREs.getGateways().values()) {
for (VO vo : gateway.getVos().values()) {
for (VRE vre : vo.getVres().values()) {
logger.trace("Does the scope: "+vre.getScope() +" ends with "+vreName +"?");
if(vre.getScope().toLowerCase().endsWith(vreName)){
logger.info("The scope: "+vre.getScope() +" ends with: "+vreName);
return vre;
}
}
}
}
logger.info("The VRE name "+vreName+" was not found in the detached VREs");
return null;
} catch (Exception e) {
logger.error(e.getLocalizedMessage(), e);
return null;
}
}
} }

View File

@ -192,6 +192,7 @@ public class DetachedREsBuilder {
} }
} }
vre.setCatalogUrl(vreJAXB.getCatalogUrl()); vre.setCatalogUrl(vreJAXB.getCatalogUrl());
vre.setCatalogPortletURL(vreJAXB.getCatalogPortletURL());
vre.setManagers(vreJAXB.getManagers()); vre.setManagers(vreJAXB.getManagers());
vres.put(key,vre); vres.put(key,vre);
} }

View File

@ -14,7 +14,7 @@ import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
* *
* @author Giancarlo Panichi * @author Giancarlo Panichi
* *
* * @author updated by Francesco Mangiacrapa at ISTI-CNR
*/ */
@XmlRootElement(name = "vre") @XmlRootElement(name = "vre")
@XmlAccessorType(XmlAccessType.FIELD) @XmlAccessorType(XmlAccessType.FIELD)
@ -43,6 +43,9 @@ public class VREJAXB {
@XmlElement(name = "catalogurl", required = false) @XmlElement(name = "catalogurl", required = false)
private String catalogUrl; private String catalogUrl;
@XmlElement(name = "catalogportleturl", required = false)
private String catalogPortletURL;
public String getScope() { public String getScope() {
return scope; return scope;
} }
@ -99,10 +102,19 @@ public class VREJAXB {
this.catalogUrl = catalogUrl; this.catalogUrl = catalogUrl;
} }
public String getCatalogPortletURL() {
return catalogPortletURL;
}
public void setCatalogPortletURL(String catalogPortletURL) {
this.catalogPortletURL = catalogPortletURL;
}
@Override @Override
public String toString() { public String toString() {
return "VREJAXB [scope=" + scope + ", name=" + name + ", description=" + description + ", managers=" + managers return "VREJAXB [scope=" + scope + ", name=" + name + ", description=" + description + ", managers=" + managers
+ ", startDate=" + startDate + ", endDate=" + endDate + ", catalogUrl=" + catalogUrl + "]"; + ", startDate=" + startDate + ", endDate=" + endDate + ", catalogUrl=" + catalogUrl
+ ", catalogPortletURL=" + catalogPortletURL + "]";
} }
} }

View File

@ -18,6 +18,7 @@ public class VRE implements Serializable, Comparable<VRE> {
private String startDate; private String startDate;
private String endDate; private String endDate;
private String catalogUrl; private String catalogUrl;
private String catalogPortletURL;
public VRE() { public VRE() {
super(); super();
@ -92,6 +93,16 @@ public class VRE implements Serializable, Comparable<VRE> {
this.catalogUrl = catalogUrl; this.catalogUrl = catalogUrl;
} }
public String getCatalogPortletURL() {
return catalogPortletURL;
}
public void setCatalogPortletURL(String catalogPortletURL) {
this.catalogPortletURL = catalogPortletURL;
}
@Override @Override
public int compareTo(VRE vre) { public int compareTo(VRE vre) {
if (name == null) { if (name == null) {
@ -108,7 +119,10 @@ public class VRE implements Serializable, Comparable<VRE> {
@Override @Override
public String toString() { public String toString() {
return "VRE [scope=" + scope + ", name=" + name + ", description=" + description + ", managers=" + managers return "VRE [scope=" + scope + ", name=" + name + ", description=" + description + ", managers=" + managers
+ ", startDate=" + startDate + ", endDate=" + endDate + ", catalogUrl=" + catalogUrl + "]"; + ", startDate=" + startDate + ", endDate=" + endDate + ", catalogUrl=" + catalogUrl
+ ", catalogPortletURL=" + catalogPortletURL + "]";
} }
} }

View File

@ -16,6 +16,8 @@ import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller; import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller; import javax.xml.bind.Unmarshaller;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.infrastructure.detachedres.detachedreslibrary.server.DetachedREsClient; import org.gcube.infrastructure.detachedres.detachedreslibrary.server.DetachedREsClient;
import org.gcube.infrastructure.detachedres.detachedreslibrary.server.is.obj.DetachedREsJAXB; import org.gcube.infrastructure.detachedres.detachedreslibrary.server.is.obj.DetachedREsJAXB;
import org.gcube.infrastructure.detachedres.detachedreslibrary.server.is.obj.GatewayJAXB; import org.gcube.infrastructure.detachedres.detachedreslibrary.server.is.obj.GatewayJAXB;
@ -23,6 +25,9 @@ import org.gcube.infrastructure.detachedres.detachedreslibrary.server.is.obj.VOJ
import org.gcube.infrastructure.detachedres.detachedreslibrary.server.is.obj.VREJAXB; import org.gcube.infrastructure.detachedres.detachedreslibrary.server.is.obj.VREJAXB;
import org.gcube.infrastructure.detachedres.detachedreslibrary.shared.Constants; import org.gcube.infrastructure.detachedres.detachedreslibrary.shared.Constants;
import org.gcube.infrastructure.detachedres.detachedreslibrary.shared.re.DetachedREs; import org.gcube.infrastructure.detachedres.detachedreslibrary.shared.re.DetachedREs;
import org.gcube.infrastructure.detachedres.detachedreslibrary.shared.re.Gateway;
import org.gcube.infrastructure.detachedres.detachedreslibrary.shared.re.VO;
import org.gcube.infrastructure.detachedres.detachedreslibrary.shared.re.VRE;
import org.junit.Test; import org.junit.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -45,9 +50,57 @@ public class DetachedREsTest extends TestCase {
logger.debug("Test Enabled"); logger.debug("Test Enabled");
try { try {
ScopeProvider.instance.set(Constants.DEFAULT_SCOPE);
SecurityTokenProvider.instance.set(Constants.DEFAULT_TOKEN);
DetachedREsClient detachedREsClient = new DetachedREsClient(); DetachedREsClient detachedREsClient = new DetachedREsClient();
DetachedREs detachedREs = detachedREsClient.getDetachedREs(); DetachedREs detachedREs = detachedREsClient.getDetachedREs();
logger.debug("DetachedREs: " + detachedREs);
int totalVREDimissed = 0;
for (Gateway gateway : detachedREs.getGateways().values()) {
logger.debug("\n\n");
logger.debug("Gateway: " + gateway.getName());
int vreDismissedPerGatew = 0;
for (VO vo : gateway.getVos().values()) {
logger.debug("VO: " + vo.getName());
for (VRE vre : vo.getVres().values()) {
logger.debug("VRE name: " + vre.getName() +
" scope: "+vre.getScope() +
" VRE catalogue url: " + vre.getCatalogUrl() +
" VRE catalog Portlet URL: "+vre.getCatalogPortletURL());
vreDismissedPerGatew++;
}
}
logger.debug("\n\t\t\t******** VREs dismissed per " + gateway.getName() + " are: "+vreDismissedPerGatew);
totalVREDimissed+=vreDismissedPerGatew;
}
logger.debug("\n\nTotal VREs dismissed: " + totalVREDimissed);
assertTrue(true);
} catch (Exception e) {
logger.error(e.getLocalizedMessage(), e);
assertTrue("Error searching the resource!", false);
}
} else {
logger.debug("Test Disabled");
assertTrue(true);
}
}
@Test
public void testFindDetachedVREForVREName() {
if (Constants.TEST_ENABLE) {
logger.debug("Test Enabled");
try {
String vreName = "bluebridgeproject";
ScopeProvider.instance.set(Constants.DEFAULT_SCOPE);
SecurityTokenProvider.instance.set(Constants.DEFAULT_TOKEN);
DetachedREsClient detachedREsClient = new DetachedREsClient();
VRE vre = detachedREsClient.findDetachedVREforVREName(vreName);
logger.debug("The detached VRE for name: " + vreName + " found as: "+vre);
assertTrue(true); assertTrue(true);
} catch (Exception e) { } catch (Exception e) {
@ -382,7 +435,16 @@ public class DetachedREsTest extends TestCase {
gCubeAppsVREJAXB.setName(new String(vre).replace("_", " ")); gCubeAppsVREJAXB.setName(new String(vre).replace("_", " "));
gCubeAppsVREJAXB.setStartDate(new GregorianCalendar(2018, GregorianCalendar.JANUARY, 1).getTime()); gCubeAppsVREJAXB.setStartDate(new GregorianCalendar(2018, GregorianCalendar.JANUARY, 1).getTime());
gCubeAppsVREJAXB.setEndDate(new GregorianCalendar(2020, GregorianCalendar.MARCH, 3).getTime()); gCubeAppsVREJAXB.setEndDate(new GregorianCalendar(2020, GregorianCalendar.MARCH, 3).getTime());
// UPDATED BY FRANCESCO
if (vre.compareToIgnoreCase("BlueBridgeProject") == 0 || vre.compareToIgnoreCase("SIASPA") == 0) {
gCubeAppsVREJAXB.setCatalogUrl("https://ckan-imarine.d4science.org");
gCubeAppsVREJAXB.setCatalogPortletURL("https://i-marine.d4science.org/group/imarine-gateway/data-catalogue");
} else {
//not usable
gCubeAppsVREJAXB.setCatalogUrl("http://data.d4science.org/ctlg/" + vre); gCubeAppsVREJAXB.setCatalogUrl("http://data.d4science.org/ctlg/" + vre);
}
gCubeAppsVREJAXB.setManagers(new ArrayList<String>(Arrays.asList("Leonardo Candela", "Pasquale Pagano"))); gCubeAppsVREJAXB.setManagers(new ArrayList<String>(Arrays.asList("Leonardo Candela", "Pasquale Pagano")));
gCubeAppsVREsOfBlueBridgeGateway.put( gCubeAppsVREsOfBlueBridgeGateway.put(
"/d4science.research-infrastructures.eu/" + VOProduction.GCUBEAPPS.getId() + "/" + vre, "/d4science.research-infrastructures.eu/" + VOProduction.GCUBEAPPS.getId() + "/" + vre,