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"/>
</attributes>
</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"/>
</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>
<artifactId>detachedres-library</artifactId>
<name>detachedres-library</name>
<version>1.0.0</version>
<version>1.1.0-SNAPSHOT</version>
<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.shared.Constants;
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.LoggerFactory;
/**
*
* The Class DetachedREsClient.
*
* @author Giancarlo Panichi
*
*
*
* @author updated by Francesco Mangiacrapa at ISTI-CNR
*/
public class DetachedREsClient {
@ -24,16 +28,27 @@ public class DetachedREsClient {
private String scope;
/**
*
* Instantiates a new detached R es client.
*/
public DetachedREsClient() {
}
/**
* Instantiates a new detached R es client.
*
* @param token the token
*/
public DetachedREsClient(String token) {
this.token = token;
}
/**
* Gets the detached R es.
*
* @return the detached R es
* @throws Exception the exception
*/
public DetachedREs getDetachedREs() throws Exception {
retrieveAuthInfo();
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 {
retrieveAuthInfo();
this.scope=scope;
@ -49,6 +71,11 @@ public class DetachedREsClient {
}
/**
* Retrieve auth info.
*
* @throws Exception the exception
*/
private void retrieveAuthInfo() throws Exception {
if (Constants.DEBUG_MODE) {
logger.debug("Debug Mode");
@ -77,5 +104,39 @@ 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.setCatalogPortletURL(vreJAXB.getCatalogPortletURL());
vre.setManagers(vreJAXB.getManagers());
vres.put(key,vre);
}

View File

@ -13,8 +13,8 @@ import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
/**
*
* @author Giancarlo Panichi
*
*
*
* @author updated by Francesco Mangiacrapa at ISTI-CNR
*/
@XmlRootElement(name = "vre")
@XmlAccessorType(XmlAccessType.FIELD)
@ -43,6 +43,9 @@ public class VREJAXB {
@XmlElement(name = "catalogurl", required = false)
private String catalogUrl;
@XmlElement(name = "catalogportleturl", required = false)
private String catalogPortletURL;
public String getScope() {
return scope;
}
@ -99,10 +102,19 @@ public class VREJAXB {
this.catalogUrl = catalogUrl;
}
public String getCatalogPortletURL() {
return catalogPortletURL;
}
public void setCatalogPortletURL(String catalogPortletURL) {
this.catalogPortletURL = catalogPortletURL;
}
@Override
public String toString() {
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 endDate;
private String catalogUrl;
private String catalogPortletURL;
public VRE() {
super();
@ -92,6 +93,16 @@ public class VRE implements Serializable, Comparable<VRE> {
this.catalogUrl = catalogUrl;
}
public String getCatalogPortletURL() {
return catalogPortletURL;
}
public void setCatalogPortletURL(String catalogPortletURL) {
this.catalogPortletURL = catalogPortletURL;
}
@Override
public int compareTo(VRE vre) {
if (name == null) {
@ -108,7 +119,10 @@ public class VRE implements Serializable, Comparable<VRE> {
@Override
public String toString() {
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.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.is.obj.DetachedREsJAXB;
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.shared.Constants;
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.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -45,9 +50,57 @@ public class DetachedREsTest extends TestCase {
logger.debug("Test Enabled");
try {
ScopeProvider.instance.set(Constants.DEFAULT_SCOPE);
SecurityTokenProvider.instance.set(Constants.DEFAULT_TOKEN);
DetachedREsClient detachedREsClient = new DetachedREsClient();
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);
} catch (Exception e) {
@ -225,7 +278,7 @@ public class DetachedREsTest extends TestCase {
file.delete();
logger.info("Success!");
assertTrue(true);
} catch (Throwable e) {
logger.error(e.getLocalizedMessage(), e);
assertTrue("Error in DetachedREs Marshal!", false);
@ -382,7 +435,16 @@ public class DetachedREsTest extends TestCase {
gCubeAppsVREJAXB.setName(new String(vre).replace("_", " "));
gCubeAppsVREJAXB.setStartDate(new GregorianCalendar(2018, GregorianCalendar.JANUARY, 1).getTime());
gCubeAppsVREJAXB.setEndDate(new GregorianCalendar(2020, GregorianCalendar.MARCH, 3).getTime());
gCubeAppsVREJAXB.setCatalogUrl("http://data.d4science.org/ctlg/" + vre);
// 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.setManagers(new ArrayList<String>(Arrays.asList("Leonardo Candela", "Pasquale Pagano")));
gCubeAppsVREsOfBlueBridgeGateway.put(
"/d4science.research-infrastructures.eu/" + VOProduction.GCUBEAPPS.getId() + "/" + vre,