commit ca1327f5c3959aa9b16a3d75e61c93eab6bafb68 Author: Giancarlo Panichi Date: Wed Apr 1 17:28:00 2020 +0200 ref 18964: Create a Generic Resource to record Dismissed VREs https://support.d4science.org/issues/18964 Create a library to support the resource access diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..82bb758 --- /dev/null +++ b/.classpath @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..30c3a67 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/target/ +/test.log diff --git a/.project b/.project new file mode 100644 index 0000000..9abdaf8 --- /dev/null +++ b/.project @@ -0,0 +1,36 @@ + + + detachedres-library + + + + + + org.eclipse.wst.common.project.facet.core.builder + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.wst.validation.validationbuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jem.workbench.JavaEMFNature + org.eclipse.wst.common.modulecore.ModuleCoreNature + org.eclipse.m2e.core.maven2Nature + org.eclipse.jdt.core.javanature + org.eclipse.wst.common.project.facet.core.nature + + diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..afad906 --- /dev/null +++ b/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +encoding//src/main/java=UTF-8 +encoding//src/main/resources=UTF-8 +encoding//src/test/java=UTF-8 +encoding//src/test/resources=UTF-8 +encoding/=UTF-8 +encoding/src=UTF-8 diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..b257af7 --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.source=1.7 diff --git a/.settings/org.eclipse.m2e.core.prefs b/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component new file mode 100644 index 0000000..538888a --- /dev/null +++ b/.settings/org.eclipse.wst.common.component @@ -0,0 +1,6 @@ + + + + + + diff --git a/.settings/org.eclipse.wst.common.project.facet.core.xml b/.settings/org.eclipse.wst.common.project.facet.core.xml new file mode 100644 index 0000000..4f92af5 --- /dev/null +++ b/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/.settings/org.eclipse.wst.validation.prefs b/.settings/org.eclipse.wst.validation.prefs new file mode 100644 index 0000000..04cad8c --- /dev/null +++ b/.settings/org.eclipse.wst.validation.prefs @@ -0,0 +1,2 @@ +disabled=06target +eclipse.preferences.version=1 diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..1932b4c --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,311 @@ +#European Union Public Licence V.1.1 + +##*EUPL © the European Community 2007* + + +This **European Union Public Licence** (the **“EUPL”**) applies to the Work or Software +(as defined below) which is provided under the terms of this Licence. Any use of +the Work, other than as authorised under this Licence is prohibited (to the +extent such use is covered by a right of the copyright holder of the Work). + +The Original Work is provided under the terms of this Licence when the Licensor +(as defined below) has placed the following notice immediately following the +copyright notice for the Original Work: + +**Licensed under the EUPL V.1.1** + +or has expressed by any other mean his willingness to license under the EUPL. + + + +##1. Definitions + +In this Licence, the following terms have the following meaning: + +- The Licence: this Licence. + +- The Original Work or the Software: the software distributed and/or + communicated by the Licensor under this Licence, available as Source Code and + also as Executable Code as the case may be. + +- Derivative Works: the works or software that could be created by the Licensee, + based upon the Original Work or modifications thereof. This Licence does not + define the extent of modification or dependence on the Original Work required + in order to classify a work as a Derivative Work; this extent is determined by + copyright law applicable in the country mentioned in Article 15. + +- The Work: the Original Work and/or its Derivative Works. + +- The Source Code: the human-readable form of the Work which is the most + convenient for people to study and modify. + +- The Executable Code: any code which has generally been compiled and which is + meant to be interpreted by a computer as a program. + +- The Licensor: the natural or legal person that distributes and/or communicates + the Work under the Licence. + +- Contributor(s): any natural or legal person who modifies the Work under the + Licence, or otherwise contributes to the creation of a Derivative Work. + +- The Licensee or “You”: any natural or legal person who makes any usage of the + Software under the terms of the Licence. + +- Distribution and/or Communication: any act of selling, giving, lending, + renting, distributing, communicating, transmitting, or otherwise making + available, on-line or off-line, copies of the Work or providing access to its + essential functionalities at the disposal of any other natural or legal + person. + + + +##2. Scope of the rights granted by the Licence + +The Licensor hereby grants You a world-wide, royalty-free, non-exclusive, +sub-licensable licence to do the following, for the duration of copyright vested +in the Original Work: + +- use the Work in any circumstance and for all usage, reproduce the Work, modify +- the Original Work, and make Derivative Works based upon the Work, communicate +- to the public, including the right to make available or display the Work or +- copies thereof to the public and perform publicly, as the case may be, the +- Work, distribute the Work or copies thereof, lend and rent the Work or copies +- thereof, sub-license rights in the Work or copies thereof. + +Those rights can be exercised on any media, supports and formats, whether now +known or later invented, as far as the applicable law permits so. + +In the countries where moral rights apply, the Licensor waives his right to +exercise his moral right to the extent allowed by law in order to make effective +the licence of the economic rights here above listed. + +The Licensor grants to the Licensee royalty-free, non exclusive usage rights to +any patents held by the Licensor, to the extent necessary to make use of the +rights granted on the Work under this Licence. + + + +##3. Communication of the Source Code + +The Licensor may provide the Work either in its Source Code form, or as +Executable Code. If the Work is provided as Executable Code, the Licensor +provides in addition a machine-readable copy of the Source Code of the Work +along with each copy of the Work that the Licensor distributes or indicates, in +a notice following the copyright notice attached to the Work, a repository where +the Source Code is easily and freely accessible for as long as the Licensor +continues to distribute and/or communicate the Work. + + + +##4. Limitations on copyright + +Nothing in this Licence is intended to deprive the Licensee of the benefits from +any exception or limitation to the exclusive rights of the rights owners in the +Original Work or Software, of the exhaustion of those rights or of other +applicable limitations thereto. + + + +##5. Obligations of the Licensee + +The grant of the rights mentioned above is subject to some restrictions and +obligations imposed on the Licensee. Those obligations are the following: + +Attribution right: the Licensee shall keep intact all copyright, patent or +trademarks notices and all notices that refer to the Licence and to the +disclaimer of warranties. The Licensee must include a copy of such notices and a +copy of the Licence with every copy of the Work he/she distributes and/or +communicates. The Licensee must cause any Derivative Work to carry prominent +notices stating that the Work has been modified and the date of modification. + +Copyleft clause: If the Licensee distributes and/or communicates copies of the +Original Works or Derivative Works based upon the Original Work, this +Distribution and/or Communication will be done under the terms of this Licence +or of a later version of this Licence unless the Original Work is expressly +distributed only under this version of the Licence. The Licensee (becoming +Licensor) cannot offer or impose any additional terms or conditions on the Work +or Derivative Work that alter or restrict the terms of the Licence. + +Compatibility clause: If the Licensee Distributes and/or Communicates Derivative +Works or copies thereof based upon both the Original Work and another work +licensed under a Compatible Licence, this Distribution and/or Communication can +be done under the terms of this Compatible Licence. For the sake of this clause, +“Compatible Licence” refers to the licences listed in the appendix attached to +this Licence. Should the Licensee’s obligations under the Compatible Licence +conflict with his/her obligations under this Licence, the obligations of the +Compatible Licence shall prevail. + +Provision of Source Code: When distributing and/or communicating copies of the +Work, the Licensee will provide a machine-readable copy of the Source Code or +indicate a repository where this Source will be easily and freely available for +as long as the Licensee continues to distribute and/or communicate the Work. + +Legal Protection: This Licence does not grant permission to use the trade names, +trademarks, service marks, or names of the Licensor, except as required for +reasonable and customary use in describing the origin of the Work and +reproducing the content of the copyright notice. + + + +##6. Chain of Authorship + +The original Licensor warrants that the copyright in the Original Work granted +hereunder is owned by him/her or licensed to him/her and that he/she has the +power and authority to grant the Licence. + +Each Contributor warrants that the copyright in the modifications he/she brings +to the Work are owned by him/her or licensed to him/her and that he/she has the +power and authority to grant the Licence. + +Each time You accept the Licence, the original Licensor and subsequent +Contributors grant You a licence to their contributions to the Work, under the +terms of this Licence. + + + +##7. Disclaimer of Warranty + +The Work is a work in progress, which is continuously improved by numerous +contributors. It is not a finished work and may therefore contain defects or +“bugs” inherent to this type of software development. + +For the above reason, the Work is provided under the Licence on an “as is” basis +and without warranties of any kind concerning the Work, including without +limitation merchantability, fitness for a particular purpose, absence of defects +or errors, accuracy, non-infringement of intellectual property rights other than +copyright as stated in Article 6 of this Licence. + +This disclaimer of warranty is an essential part of the Licence and a condition +for the grant of any rights to the Work. + + + +##8. Disclaimer of Liability + +Except in the cases of wilful misconduct or damages directly caused to natural +persons, the Licensor will in no event be liable for any direct or indirect, +material or moral, damages of any kind, arising out of the Licence or of the use +of the Work, including without limitation, damages for loss of goodwill, work +stoppage, computer failure or malfunction, loss of data or any commercial +damage, even if the Licensor has been advised of the possibility of such +damage. However, the Licensor will be liable under statutory product liability +laws as far such laws apply to the Work. + + + +##9. Additional agreements + +While distributing the Original Work or Derivative Works, You may choose to +conclude an additional agreement to offer, and charge a fee for, acceptance of +support, warranty, indemnity, or other liability obligations and/or services +consistent with this Licence. However, in accepting such obligations, You may +act only on your own behalf and on your sole responsibility, not on behalf of +the original Licensor or any other Contributor, and only if You agree to +indemnify, defend, and hold each Contributor harmless for any liability incurred +by, or claims asserted against such Contributor by the fact You have accepted +any such warranty or additional liability. + + + +##10. Acceptance of the Licence + +The provisions of this Licence can be accepted by clicking on an icon “I agree” +placed under the bottom of a window displaying the text of this Licence or by +affirming consent in any other similar way, in accordance with the rules of +applicable law. Clicking on that icon indicates your clear and irrevocable +acceptance of this Licence and all of its terms and conditions. + +Similarly, you irrevocably accept this Licence and all of its terms and +conditions by exercising any rights granted to You by Article 2 of this Licence, +such as the use of the Work, the creation by You of a Derivative Work or the +Distribution and/or Communication by You of the Work or copies thereof. + + + +##11. Information to the public + +In case of any Distribution and/or Communication of the Work by means of +electronic communication by You (for example, by offering to download the Work +from a remote location) the distribution channel or media (for example, a +website) must at least provide to the public the information requested by the +applicable law regarding the Licensor, the Licence and the way it may be +accessible, concluded, stored and reproduced by the Licensee. + + + +##12. Termination of the Licence + +The Licence and the rights granted hereunder will terminate automatically upon +any breach by the Licensee of the terms of the Licence. + +Such a termination will not terminate the licences of any person who has +received the Work from the Licensee under the Licence, provided such persons +remain in full compliance with the Licence. + + + +##13. Miscellaneous + +Without prejudice of Article 9 above, the Licence represents the complete +agreement between the Parties as to the Work licensed hereunder. + +If any provision of the Licence is invalid or unenforceable under applicable +law, this will not affect the validity or enforceability of the Licence as a +whole. Such provision will be construed and/or reformed so as necessary to make +it valid and enforceable. + +The European Commission may publish other linguistic versions and/or new +versions of this Licence, so far this is required and reasonable, without +reducing the scope of the rights granted by the Licence. New versions of the +Licence will be published with a unique version number. + +All linguistic versions of this Licence, approved by the European Commission, +have identical value. Parties can take advantage of the linguistic version of +their choice. + + + +##14. Jurisdiction + +Any litigation resulting from the interpretation of this License, arising +between the European Commission, as a Licensor, and any Licensee, will be +subject to the jurisdiction of the Court of Justice of the European Communities, +as laid down in article 238 of the Treaty establishing the European Community. + +Any litigation arising between Parties, other than the European Commission, and +resulting from the interpretation of this License, will be subject to the +exclusive jurisdiction of the competent court where the Licensor resides or +conducts its primary business. + + + +##15. Applicable Law + +This Licence shall be governed by the law of the European Union country where +the Licensor resides or has his registered office. + +This licence shall be governed by the Belgian law if: + +- a litigation arises between the European Commission, as a Licensor, and any +- Licensee; the Licensor, other than the European Commission, has no residence +- or registered office inside a European Union country. + + +--- + + +##Appendix + + +**“Compatible Licences”** according to article 5 EUPL are: + + +- GNU General Public License (GNU GPL) v. 2 + +- Open Software License (OSL) v. 2.1, v. 3.0 + +- Common Public License v. 1.0 + +- Eclipse Public License v. 1.0 + +- Cecill v. 2.0 diff --git a/README.md b/README.md new file mode 100644 index 0000000..cec85e9 --- /dev/null +++ b/README.md @@ -0,0 +1,45 @@ +# DetachedREs Library + +DetachedREs is a library for retrieve information relative to Detached Research Entities like Gateways, VOs and VREs from D4Science Infrastructure. + +## Structure of the project + +* The source code is present in the src folder. + +## Built With + +* [OpenJDK](https://openjdk.java.net/) - The JDK used +* [Maven](https://maven.apache.org/) - Dependency Management + +## Documentation + +* Use of this library is described on [Wiki](https://wiki.gcube-system.org/gcube/DetachedREsLibrary). + +## Change log + +See [Releases](https://code-repo.d4science.org/gCubeSystem/detachedres-library/releases). + +## Authors + +* **Giancarlo Panichi** ([ORCID](http://orcid.org/0000-0001-8375-6644)) - [ISTI-CNR Infrascience Group](http://nemis.isti.cnr.it/groups/infrascience) + +## License + +This project is licensed under the EUPL V.1.1 License - see the [LICENSE.md](LICENSE.md) file for details. + + +## About the gCube Framework +This software is part of the [gCubeFramework](https://www.gcube-system.org/ "gCubeFramework"): an +open-source software toolkit used for building and operating Hybrid Data +Infrastructures enabling the dynamic deployment of Virtual Research Environments +by favouring the realisation of reuse oriented policies. + +The projects leading to this software have received funding from a series of European Union programmes including: + +- the Sixth Framework Programme for Research and Technological Development + - DILIGENT (grant no. 004260); +- the Seventh Framework Programme for research, technological development and demonstration + - D4Science (grant no. 212488), D4Science-II (grant no.239019), ENVRI (grant no. 283465), EUBrazilOpenBio (grant no. 288754), iMarine(grant no. 283644); +- the H2020 research and innovation programme + - BlueBRIDGE (grant no. 675680), EGIEngage (grant no. 654142), ENVRIplus (grant no. 654182), Parthenos (grant no. 654119), SoBigData (grant no. 654024),DESIRA (grant no. 818194), ARIADNEplus (grant no. 823914), RISIS2 (grant no. 824091), PerformFish (grant no. 727610), AGINFRAplus (grant no. 731001); + \ No newline at end of file diff --git a/changelog.xml b/changelog.xml new file mode 100644 index 0000000..35e6d84 --- /dev/null +++ b/changelog.xml @@ -0,0 +1,7 @@ + + + First release + + \ No newline at end of file diff --git a/descriptor.xml b/descriptor.xml new file mode 100644 index 0000000..16e0787 --- /dev/null +++ b/descriptor.xml @@ -0,0 +1,31 @@ + + servicearchive + + tar.gz + + / + + + / + true + + README.md + LICENSE.md + changelog.xml + profile.xml + + 755 + true + + + + + target/${build.finalName}.${project.packaging} + /${artifactId} + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..1627a63 --- /dev/null +++ b/pom.xml @@ -0,0 +1,240 @@ + + 4.0.0 + + + maven-parent + org.gcube.tools + 1.1.0 + + + org.gcube.infrastructure.detachedres + detachedres-library + detachedres-library + 1.0.0-SNAPSHOT + Detached Resource Entities Library + + + + scm:git:https://code-repo.d4science.org/gCubeSystem/${project.artifactId}.git + scm:git:https://code-repo.d4science.org/gCubeSystem/${project.artifactId}.git + https://code-repo.d4science.org/gCubeSystem/${project.artifactId} + + + + + + Giancarlo Panichi + g.panichi@isti.cnr.it + CNR Pisa, Istituto di Scienza e Tecnologie dell'Informazione "A. Faedo" + + architect + developer + + + + + + ${project.build.directory}/${project.build.finalName} + distro + config + + + 1.7 + 1.8 + + + 2.6.1 + 3.3.2 + DetachedREs.html + org.gcube.infrastructure.detachedres.detachedreslibrary.detachedreslib + + ${env.KEYS} + + UTF-8 + UTF-8 + 3.1.1 + + + + + + localRun + + + + org.slf4j + slf4j-api + compile + + + org.slf4j + slf4j-log4j12 + runtime + + + + xerces + xerces + 2.4.0 + + + + + + org.gcube.common + common-authorization + runtime + + + org.gcube.common + authorization-client + runtime + + + + + + + + + + + + + org.gcube.common + common-authorization + provided + + + org.gcube.common + authorization-client + provided + + + + + + + org.gcube.resources.discovery + ic-client + + + + + + + org.slf4j + slf4j-api + provided + + + + org.slf4j + slf4j-log4j12 + 1.7.5 + test + + + + + + junit + junit + 4.8.1 + test + + + + + + + + + + + org.gcube.distribution + gcube-bom + 1.4.0 + pom + import + + + + + + + + ${webappDirectory}/WEB-INF/classes + src/main/java + + + + src/main/resources + + **/*.* + + + + + + + + + + + org.codehaus.mojo + gwt-maven-plugin + ${gwt.version} + + true + 180 + htmlunit + **/*GwtTest.java + INFO + ${gwt.runTarget} + ${webappDirectory} + ${gwt.module.name} + true + + + + + resources + + + + + + + + maven-compiler-plugin + + ${maven.compiler.source} + ${maven.compiler.target} + + + + + + org.apache.maven.plugins + maven-assembly-plugin + + + descriptor.xml + + + + + servicearchive + install + + single + + + + + + + + \ No newline at end of file diff --git a/profile.xml b/profile.xml new file mode 100644 index 0000000..fd9933d --- /dev/null +++ b/profile.xml @@ -0,0 +1,29 @@ + + + + Service + + ${project.description} + Infrastructure + ${project.name} + 1.0.0 + + + ${project.description} + ${project.name} + ${version} + + ${project.groupId} + ${project.artifactId} + ${project.version} + + library + + ${project.build.finalName}.${project.packaging} + + + + + + + diff --git a/src/main/java/org/gcube/infrastructure/detachedres/detachedreslibrary/detachedreslib.gwt.xml b/src/main/java/org/gcube/infrastructure/detachedres/detachedreslibrary/detachedreslib.gwt.xml new file mode 100644 index 0000000..7326815 --- /dev/null +++ b/src/main/java/org/gcube/infrastructure/detachedres/detachedreslibrary/detachedreslib.gwt.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + diff --git a/src/main/java/org/gcube/infrastructure/detachedres/detachedreslibrary/server/DetachedREsClient.java b/src/main/java/org/gcube/infrastructure/detachedres/detachedreslibrary/server/DetachedREsClient.java new file mode 100644 index 0000000..d05795e --- /dev/null +++ b/src/main/java/org/gcube/infrastructure/detachedres/detachedreslibrary/server/DetachedREsClient.java @@ -0,0 +1,73 @@ +package org.gcube.infrastructure.detachedres.detachedreslibrary.server; + +import static org.gcube.common.authorization.client.Constants.authorizationService; + +import org.gcube.common.authorization.library.AuthorizationEntry; +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.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + * @author Giancarlo Panichi + * + * + */ +public class DetachedREsClient { + + private Logger logger = LoggerFactory.getLogger(DetachedREsClient.class); + private String token; + private String userName; + private String scope; + + /** + * + */ + public DetachedREsClient() { + + } + + public DetachedREsClient(String token) { + this.token = token; + } + + public DetachedREs getDetachedREs() throws Exception { + retrieveAuthInfo(); + return DetachedREsBuilder.build(scope); + + } + + private void retrieveAuthInfo() throws Exception { + if (Constants.DEBUG_MODE) { + logger.debug("Debug Mode"); + userName = Constants.DEFAULT_USER; + scope = Constants.DEFAULT_SCOPE; + token = Constants.DEFAULT_TOKEN; + + + } else { + logger.debug("Production Mode"); + try { + if (token == null) { + logger.debug("Retrieving token credentials"); + token = SecurityTokenProvider.instance.get(); + } + logger.debug("Use token: " + token); + AuthorizationEntry entry = authorizationService().get(token); + userName = entry.getClientInfo().getId(); + scope = entry.getContext(); + } catch (Exception e) { + logger.error("Error Retrieving token credentials: " + e.getLocalizedMessage(), e); + throw e; + } + + } + + logger.debug("Use: [userName={}, scope={}, token={}]",userName,scope,token); + + } + +} diff --git a/src/main/java/org/gcube/infrastructure/detachedres/detachedreslibrary/server/is/DetachedREsBuilder.java b/src/main/java/org/gcube/infrastructure/detachedres/detachedreslibrary/server/is/DetachedREsBuilder.java new file mode 100644 index 0000000..83e7695 --- /dev/null +++ b/src/main/java/org/gcube/infrastructure/detachedres/detachedreslibrary/server/is/DetachedREsBuilder.java @@ -0,0 +1,142 @@ +package org.gcube.infrastructure.detachedres.detachedreslibrary.server.is; + +import java.util.ArrayList; +import java.util.List; + +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.VOJAXB; +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.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + * @author Giancarlo Panichi + * + * + */ +public class DetachedREsBuilder { + + private static Logger logger = LoggerFactory.getLogger(DetachedREsBuilder.class); + + public static DetachedREs build(String scope) throws Exception { + logger.info("Build DetachedREs"); + DetachedREs detachedREs = null; + + if (Constants.DEBUG_MODE) { + logger.info("DetachedREsBuilder: use debug configuration."); + detachedREs = useDefaultConfiguration(); + } else { + DetachedREsJAXB detachedREsJAXB = null; + try { + detachedREsJAXB = InformationSystemUtils.retrieveDetachedREs(scope); + } catch (Exception e) { + logger.debug(e.getLocalizedMessage(), e); + } + + if (detachedREsJAXB != null) { + logger.info("DetachedREsBuilder: use configuration in scope: " + scope); + + detachedREs = new DetachedREs(); + logger.info("DetachedREsBuilder: configuration enabled: " + detachedREsJAXB.isEnabled()); + detachedREs.setEnabled(detachedREsJAXB.isEnabled()); + + List gatewaysJAXB = detachedREsJAXB.getGateways(); + logger.info("DetachedREsBuilder: Gateways configuration: " + gatewaysJAXB); + if (gatewaysJAXB != null && !gatewaysJAXB.isEmpty()) { + ArrayList gateways = new ArrayList<>(); + for (GatewayJAXB gatewayJAXB : gatewaysJAXB) { + + Gateway gateway = new Gateway(gatewayJAXB.getScope(), gatewayJAXB.getName(), + gatewayJAXB.getDescription()); + if (gatewayJAXB.getVos() != null && !gatewayJAXB.getVos().isEmpty()) { + ArrayList vos = retrieveVOs(gatewayJAXB); + gateway.setVos(vos); + } + gateways.add(gateway); + } + detachedREs.setGateways(gateways); + + } else { + logger.info("DetachedREsBuilder: Gateways are not present in" + " resource for scope: " + scope); + } + + } else { + logger.info("DetachedREsBuilder: DetachedREsData resource is not present in scope: " + scope); + } + } + + logger.debug("DetachedREsBuilder: DetachedREs retrieved: " + detachedREs); + return detachedREs; + } + + private static DetachedREs useDefaultConfiguration() { + Gateway blueBridgeGateway = new Gateway("-1", "BlueBridge Gateway"); + VO gCubeApps = new VO("/d4science.research-infrastructures.eu/gCubeApps", "gCubeApps"); + VRE blueBridgeProject = new VRE("/d4science.research-infrastructures.eu/gCubeApps/BlueBridgeProject", + "BlueBridgeProject"); + + ArrayList vres = new ArrayList<>(); + vres.add(blueBridgeProject); + gCubeApps.setVres(vres); + + ArrayList vos = new ArrayList<>(); + vos.add(gCubeApps); + blueBridgeGateway.setVos(vos); + + ArrayList gateways = new ArrayList<>(); + gateways.add(blueBridgeGateway); + + DetachedREs detachedREs = new DetachedREs(true, gateways); + return detachedREs; + } + + private static ArrayList retrieveVOs(GatewayJAXB gatewayJAXB) throws Exception { + try { + ArrayList vos = new ArrayList<>(); + for (VOJAXB voJAXB : gatewayJAXB.getVos()) { + VO vo = new VO(voJAXB.getScope(), voJAXB.getName(), voJAXB.getDescription()); + if (voJAXB.getVres() != null && !voJAXB.getVres().isEmpty()) { + ArrayList vres = retrieveVREs(voJAXB); + vo.setVres(vres); + } + vos.add(vo); + } + return vos; + + } catch (Exception e) { + throw e; + } catch (Throwable e) { + logger.error("Invalid DetachedREs configuration. Error retrieving VO info: " + e.getLocalizedMessage(), e); + throw new Exception( + "Invalid DetachedREs configuration. Error retrieving VO info: " + e.getLocalizedMessage(), e); + } + + } + + private static ArrayList retrieveVREs(VOJAXB voJAXB) throws Exception { + try { + ArrayList vres = new ArrayList<>(); + for (VREJAXB vreJAXB : voJAXB.getVres()) { + VRE vre = new VRE(vreJAXB.getScope(), vreJAXB.getName(), vreJAXB.getDescription()); + vres.add(vre); + } + return vres; + + } catch (Exception e) { + throw e; + } catch (Throwable e) { + logger.error("Invalid DetachedREs configuration. Error retrieving VRE info: " + e.getLocalizedMessage(), e); + throw new Exception( + "Invalid DetachedREs configuration. Error retrieving VRE info: " + e.getLocalizedMessage(), e); + } + + } + +} diff --git a/src/main/java/org/gcube/infrastructure/detachedres/detachedreslibrary/server/is/InformationSystemUtils.java b/src/main/java/org/gcube/infrastructure/detachedres/detachedreslibrary/server/is/InformationSystemUtils.java new file mode 100644 index 0000000..52e74fd --- /dev/null +++ b/src/main/java/org/gcube/infrastructure/detachedres/detachedreslibrary/server/is/InformationSystemUtils.java @@ -0,0 +1,93 @@ +package org.gcube.infrastructure.detachedres.detachedreslibrary.server.is; + +import java.util.Iterator; +import java.util.List; + +import org.gcube.common.resources.gcore.GenericResource; +import org.gcube.common.resources.gcore.ScopeGroup; +import org.gcube.common.scope.api.ScopeProvider; +import org.gcube.infrastructure.detachedres.detachedreslibrary.server.is.obj.DetachedREsJAXB; +import org.gcube.infrastructure.detachedres.detachedreslibrary.shared.Constants; +import org.gcube.resources.discovery.client.api.DiscoveryClient; +import org.gcube.resources.discovery.client.impl.JAXBParser; +import org.gcube.resources.discovery.client.queries.api.SimpleQuery; +import org.gcube.resources.discovery.icclient.ICFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + * @author Giancarlo Panichi + * + * + */ +public class InformationSystemUtils { + + private static Logger logger = LoggerFactory.getLogger(InformationSystemUtils.class); + + public static DetachedREsJAXB retrieveDetachedREs(String scope) throws Exception { + try { + + if (scope == null || scope.length() == 0) + return null; + + ScopeProvider.instance.set(scope); + logger.debug("Retrieve DetachedREs in scope: " + scope); + + SimpleQuery query = ICFactory.queryFor(GenericResource.class); + query.addCondition("$resource/Profile/SecondaryType/text() eq '" + Constants.DETACHED_RES_CATEGORY + "'") + .addCondition("$resource/Profile/Name/text() eq '" + Constants.DETACHED_RES_NAME + "'") + .setResult("$resource"); + + DiscoveryClient client = ICFactory.clientFor(GenericResource.class); + List detachedREsDataResources = client.submit(query); + logger.debug("Resources: " + detachedREsDataResources); + + DetachedREsJAXB detachedREsJAXB = null; + + for (GenericResource genericResource : detachedREsDataResources) { + if (genericResource.scopes() != null) { + ScopeGroup scopes = genericResource.scopes(); + Iterator iterator = scopes.iterator(); + String scopeFound = null; + boolean found = false; + while (iterator.hasNext() && !found) { + scopeFound = iterator.next(); + if (scopeFound.compareTo(scope) == 0) { + found = true; + } + } + if (found) { + try { + JAXBParser parser = new JAXBParser(DetachedREsJAXB.class); + logger.debug("Body: " + genericResource.profile().bodyAsString()); + detachedREsJAXB = (DetachedREsJAXB) parser.parse(genericResource.profile().bodyAsString()); + logger.debug("DetachedREs: " + detachedREsJAXB); + } catch (Throwable e) { + String error = "Error in discovery DetachedREs in scope " + scope + ". " + + "Resource parsing failed!"; + logger.error(error); + logger.error( + "Error {resource=" + genericResource + ", error=" + e.getLocalizedMessage() + "}"); + logger.error(e.getLocalizedMessage(), e); + throw new Exception(error, e); + } + break; + + } + + } + } + + return detachedREsJAXB; + + } catch (Exception e) { + throw e; + } catch (Throwable e) { + String error = "Error in discovery DetachedREs in scope: " + scope; + logger.error(error, e); + throw new Exception(error, e); + } + } + +} diff --git a/src/main/java/org/gcube/infrastructure/detachedres/detachedreslibrary/server/is/obj/DetachedREsJAXB.java b/src/main/java/org/gcube/infrastructure/detachedres/detachedreslibrary/server/is/obj/DetachedREsJAXB.java new file mode 100644 index 0000000..9885369 --- /dev/null +++ b/src/main/java/org/gcube/infrastructure/detachedres/detachedreslibrary/server/is/obj/DetachedREsJAXB.java @@ -0,0 +1,50 @@ +package org.gcube.infrastructure.detachedres.detachedreslibrary.server.is.obj; + +import java.util.ArrayList; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElementWrapper; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * + * @author Giancarlo Panichi + * + * + */ +@XmlRootElement(name = "detachedres") +@XmlAccessorType(XmlAccessType.FIELD) +public class DetachedREsJAXB { + + @XmlElement(name = "enabled") + private boolean enabled; + + @XmlElementWrapper(name = "gateways", required = false) + @XmlElement(name = "gateway", required = false) + private ArrayList gateways; + + public boolean isEnabled() { + return enabled; + } + + public void setEnabled(boolean enabled) { + this.enabled = enabled; + } + + public ArrayList getGateways() { + return gateways; + } + + public void setGateways(ArrayList gateways) { + this.gateways = gateways; + } + + @Override + public String toString() { + return "DetachedREsJAXB [enabled=" + enabled + ", gateways=" + gateways + "]"; + } + + +} diff --git a/src/main/java/org/gcube/infrastructure/detachedres/detachedreslibrary/server/is/obj/GatewayJAXB.java b/src/main/java/org/gcube/infrastructure/detachedres/detachedreslibrary/server/is/obj/GatewayJAXB.java new file mode 100644 index 0000000..186c778 --- /dev/null +++ b/src/main/java/org/gcube/infrastructure/detachedres/detachedreslibrary/server/is/obj/GatewayJAXB.java @@ -0,0 +1,105 @@ +package org.gcube.infrastructure.detachedres.detachedreslibrary.server.is.obj; + +import java.util.ArrayList; +import java.util.Calendar; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElementWrapper; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * + * @author Giancarlo Panichi + * + * + */ +@XmlRootElement(name = "gateway") +@XmlAccessorType(XmlAccessType.FIELD) +public class GatewayJAXB { + @XmlElement + private String scope; + + @XmlElement + private String name; + + @XmlElement(name = "description", required = false) + private String description; + + @XmlElementWrapper(name = "vos", required = false) + @XmlElement(name = "vo", required = false) + private ArrayList vos; + + @XmlElement(name = "startdate", required = false) + private Calendar startDate; + + @XmlElement(name = "enddate", required = false) + private Calendar endDate; + + @XmlElement(name = "catalogurl", required = false) + private String catalogUrl; + + public String getScope() { + return scope; + } + + public void setScope(String scope) { + this.scope = scope; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public ArrayList getVos() { + return vos; + } + + public void setVos(ArrayList vos) { + this.vos = vos; + } + + public Calendar getStartDate() { + return startDate; + } + + public void setStartDate(Calendar startDate) { + this.startDate = startDate; + } + + public Calendar getEndDate() { + return endDate; + } + + public void setEndDate(Calendar endDate) { + this.endDate = endDate; + } + + public String getCatalogUrl() { + return catalogUrl; + } + + public void setCatalogUrl(String catalogUrl) { + this.catalogUrl = catalogUrl; + } + + @Override + public String toString() { + return "GatewayJAXB [scope=" + scope + ", name=" + name + ", description=" + description + ", vos=" + vos + + ", startDate=" + startDate + ", endDate=" + endDate + ", catalogUrl=" + catalogUrl + "]"; + } + +} diff --git a/src/main/java/org/gcube/infrastructure/detachedres/detachedreslibrary/server/is/obj/VOJAXB.java b/src/main/java/org/gcube/infrastructure/detachedres/detachedreslibrary/server/is/obj/VOJAXB.java new file mode 100644 index 0000000..2e9159f --- /dev/null +++ b/src/main/java/org/gcube/infrastructure/detachedres/detachedreslibrary/server/is/obj/VOJAXB.java @@ -0,0 +1,107 @@ +package org.gcube.infrastructure.detachedres.detachedreslibrary.server.is.obj; + +import java.util.ArrayList; +import java.util.Calendar; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElementWrapper; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * + * @author Giancarlo Panichi + * + * + */ +@XmlRootElement(name = "vo") +@XmlAccessorType(XmlAccessType.FIELD) +public class VOJAXB { + @XmlElement + private String scope; + + @XmlElement + private String name; + + @XmlElement(name = "description", required = false) + private String description; + + @XmlElementWrapper(name = "vres", required = false) + @XmlElement(name = "vre", required = false) + private ArrayList vres; + + @XmlElement(name = "startdate", required = false) + private Calendar startDate; + + @XmlElement(name = "enddate", required = false) + private Calendar endDate; + + @XmlElement(name = "catalogurl", required = false) + private String catalogUrl; + + + public String getScope() { + return scope; + } + + public void setScope(String scope) { + this.scope = scope; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public ArrayList getVres() { + return vres; + } + + public void setVres(ArrayList vres) { + this.vres = vres; + } + + public Calendar getStartDate() { + return startDate; + } + + public void setStartDate(Calendar startDate) { + this.startDate = startDate; + } + + public Calendar getEndDate() { + return endDate; + } + + public void setEndDate(Calendar endDate) { + this.endDate = endDate; + } + + public String getCatalogUrl() { + return catalogUrl; + } + + public void setCatalogUrl(String catalogUrl) { + this.catalogUrl = catalogUrl; + } + + @Override + public String toString() { + return "VOJAXB [scope=" + scope + ", name=" + name + ", description=" + description + ", vres=" + vres + + ", startDate=" + startDate + ", endDate=" + endDate + ", catalogUrl=" + catalogUrl + "]"; + } + + +} diff --git a/src/main/java/org/gcube/infrastructure/detachedres/detachedreslibrary/server/is/obj/VREJAXB.java b/src/main/java/org/gcube/infrastructure/detachedres/detachedreslibrary/server/is/obj/VREJAXB.java new file mode 100644 index 0000000..dd4ddca --- /dev/null +++ b/src/main/java/org/gcube/infrastructure/detachedres/detachedreslibrary/server/is/obj/VREJAXB.java @@ -0,0 +1,105 @@ +package org.gcube.infrastructure.detachedres.detachedreslibrary.server.is.obj; + +import java.util.ArrayList; +import java.util.Calendar; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElementWrapper; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * + * @author Giancarlo Panichi + * + * + */ +@XmlRootElement(name = "vre") +@XmlAccessorType(XmlAccessType.FIELD) +public class VREJAXB { + @XmlElement + private String scope; + + @XmlElement + private String name; + + @XmlElement(name = "description", required = false) + private String description; + + @XmlElementWrapper(name = "managers", required = false) + @XmlElement(name = "manager", required = false) + private ArrayList managers; + + @XmlElement(name = "startdate", required = false) + private Calendar startDate; + + @XmlElement(name = "enddate", required = false) + private Calendar endDate; + + @XmlElement(name = "catalogurl", required = false) + private String catalogUrl; + + public String getScope() { + return scope; + } + + public void setScope(String scope) { + this.scope = scope; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public ArrayList getManagers() { + return managers; + } + + public void setManagers(ArrayList managers) { + this.managers = managers; + } + + public Calendar getStartDate() { + return startDate; + } + + public void setStartDate(Calendar startDate) { + this.startDate = startDate; + } + + public Calendar getEndDate() { + return endDate; + } + + public void setEndDate(Calendar endDate) { + this.endDate = endDate; + } + + public String getCatalogUrl() { + return catalogUrl; + } + + public void setCatalogUrl(String catalogUrl) { + this.catalogUrl = catalogUrl; + } + + @Override + public String toString() { + return "VREJAXB [scope=" + scope + ", name=" + name + ", description=" + description + ", managers=" + managers + + ", startDate=" + startDate + ", endDate=" + endDate + ", catalogUrl=" + catalogUrl + "]"; + } + +} diff --git a/src/main/java/org/gcube/infrastructure/detachedres/detachedreslibrary/shared/Constants.java b/src/main/java/org/gcube/infrastructure/detachedres/detachedreslibrary/shared/Constants.java new file mode 100644 index 0000000..e78658d --- /dev/null +++ b/src/main/java/org/gcube/infrastructure/detachedres/detachedreslibrary/shared/Constants.java @@ -0,0 +1,24 @@ +package org.gcube.infrastructure.detachedres.detachedreslibrary.shared; + +/** + * + * @author Giancarlo Panichi + * + * + */ +public class Constants { + + public static final boolean DEBUG_MODE = false; + public static final boolean TEST_ENABLE = false; + + public static final String DEFAULT_USER = "giancarlo.panichi"; + // public static final String DEFAULT_SCOPE = "/gcube/devNext/NextNext"; + public static final String DEFAULT_SCOPE = "/gcube"; + public static final String DEFAULT_TOKEN = ""; + public static final String DEFAULT_ROLE = "OrganizationMember"; + + // IS Resource + public static final String DETACHED_RES_CATEGORY = "DetachedREs"; + public static final String DETACHED_RES_NAME = "DetachedREsData"; + +} diff --git a/src/main/java/org/gcube/infrastructure/detachedres/detachedreslibrary/shared/re/DetachedREs.java b/src/main/java/org/gcube/infrastructure/detachedres/detachedreslibrary/shared/re/DetachedREs.java new file mode 100644 index 0000000..902e047 --- /dev/null +++ b/src/main/java/org/gcube/infrastructure/detachedres/detachedreslibrary/shared/re/DetachedREs.java @@ -0,0 +1,48 @@ +package org.gcube.infrastructure.detachedres.detachedreslibrary.shared.re; + +import java.io.Serializable; +import java.util.ArrayList; + +/** + * + * @author Giancarlo Panichi + * + */ +public class DetachedREs implements Serializable { + + private static final long serialVersionUID = 2238683459962419017L; + private boolean enabled; + private ArrayList gateways; + + public DetachedREs() { + super(); + } + + public DetachedREs(boolean enabled, ArrayList gateways) { + super(); + this.enabled = enabled; + this.gateways = gateways; + } + + public boolean isEnabled() { + return enabled; + } + + public void setEnabled(boolean enabled) { + this.enabled = enabled; + } + + public ArrayList getGateways() { + return gateways; + } + + public void setGateways(ArrayList gateways) { + this.gateways = gateways; + } + + @Override + public String toString() { + return "DetachedREs [enabled=" + enabled + ", gateways=" + gateways + "]"; + } + +} \ No newline at end of file diff --git a/src/main/java/org/gcube/infrastructure/detachedres/detachedreslibrary/shared/re/Gateway.java b/src/main/java/org/gcube/infrastructure/detachedres/detachedreslibrary/shared/re/Gateway.java new file mode 100644 index 0000000..aab7439 --- /dev/null +++ b/src/main/java/org/gcube/infrastructure/detachedres/detachedreslibrary/shared/re/Gateway.java @@ -0,0 +1,110 @@ +package org.gcube.infrastructure.detachedres.detachedreslibrary.shared.re; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Calendar; + +/** + * + * @author Giancarlo Panichi + * + */ +public class Gateway implements Serializable { + + private static final long serialVersionUID = 2238683459962419017L; + private String scope; + private String name; + private String description; + private ArrayList vos; + private Calendar startDate; + private Calendar endDate; + private String catalogUrl; + + public Gateway() { + super(); + } + + public Gateway(String scope, String name) { + super(); + this.scope = scope; + this.name = name; + } + + public Gateway(String scope, String name, String description) { + super(); + this.scope = scope; + this.name = name; + this.description = description; + } + + public Gateway(String scope, String name, String description, ArrayList vos) { + super(); + this.scope = scope; + this.name = name; + this.description = description; + this.vos = vos; + } + + public String getScope() { + return scope; + } + + public void setScope(String scope) { + this.scope = scope; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public ArrayList getVos() { + return vos; + } + + public void setVos(ArrayList vos) { + this.vos = vos; + } + + public Calendar getStartDate() { + return startDate; + } + + public void setStartDate(Calendar startDate) { + this.startDate = startDate; + } + + public Calendar getEndDate() { + return endDate; + } + + public void setEndDate(Calendar endDate) { + this.endDate = endDate; + } + + public String getCatalogUrl() { + return catalogUrl; + } + + public void setCatalogUrl(String catalogUrl) { + this.catalogUrl = catalogUrl; + } + + @Override + public String toString() { + return "Gateway [scope=" + scope + ", name=" + name + ", description=" + description + ", vos=" + vos + + ", startDate=" + startDate + ", endDate=" + endDate + ", catalogUrl=" + catalogUrl + "]"; + } + +} \ No newline at end of file diff --git a/src/main/java/org/gcube/infrastructure/detachedres/detachedreslibrary/shared/re/VO.java b/src/main/java/org/gcube/infrastructure/detachedres/detachedreslibrary/shared/re/VO.java new file mode 100644 index 0000000..8492a85 --- /dev/null +++ b/src/main/java/org/gcube/infrastructure/detachedres/detachedreslibrary/shared/re/VO.java @@ -0,0 +1,110 @@ +package org.gcube.infrastructure.detachedres.detachedreslibrary.shared.re; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Calendar; + +/** + * + * @author Giancarlo Panichi + * + */ +public class VO implements Serializable { + + private static final long serialVersionUID = 2238683459962419017L; + private String scope; + private String name; + private String description; + private ArrayList vres; + private Calendar startDate; + private Calendar endDate; + private String catalogUrl; + + public VO() { + super(); + } + + public VO(String scope, String name) { + super(); + this.scope = scope; + this.name = name; + } + + public VO(String scope, String name, String description) { + super(); + this.scope = scope; + this.name = name; + this.description = description; + } + + public VO(String scope, String name, String description, ArrayList vres) { + super(); + this.scope = scope; + this.name = name; + this.description = description; + this.vres = vres; + } + + public String getScope() { + return scope; + } + + public void setScope(String scope) { + this.scope = scope; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public ArrayList getVres() { + return vres; + } + + public void setVres(ArrayList vres) { + this.vres = vres; + } + + public Calendar getStartDate() { + return startDate; + } + + public void setStartDate(Calendar startDate) { + this.startDate = startDate; + } + + public Calendar getEndDate() { + return endDate; + } + + public void setEndDate(Calendar endDate) { + this.endDate = endDate; + } + + public String getCatalogUrl() { + return catalogUrl; + } + + public void setCatalogUrl(String catalogUrl) { + this.catalogUrl = catalogUrl; + } + + @Override + public String toString() { + return "VO [scope=" + scope + ", name=" + name + ", description=" + description + ", vres=" + vres + + ", startDate=" + startDate + ", endDate=" + endDate + ", catalogUrl=" + catalogUrl + "]"; + } + +} \ No newline at end of file diff --git a/src/main/java/org/gcube/infrastructure/detachedres/detachedreslibrary/shared/re/VRE.java b/src/main/java/org/gcube/infrastructure/detachedres/detachedreslibrary/shared/re/VRE.java new file mode 100644 index 0000000..705f0c3 --- /dev/null +++ b/src/main/java/org/gcube/infrastructure/detachedres/detachedreslibrary/shared/re/VRE.java @@ -0,0 +1,102 @@ +package org.gcube.infrastructure.detachedres.detachedreslibrary.shared.re; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Calendar; + +/** + * + * @author Giancarlo Panichi + * + */ +public class VRE implements Serializable { + + private static final long serialVersionUID = 2238683459962419017L; + private String scope; + private String name; + private String description; + private ArrayList managers; + private Calendar startDate; + private Calendar endDate; + private String catalogUrl; + + public VRE() { + super(); + } + + public VRE(String scope, String name) { + super(); + this.scope = scope; + this.name = name; + } + + public VRE(String scope, String name, String description) { + super(); + this.scope = scope; + this.name = name; + this.description = description; + } + + public String getScope() { + return scope; + } + + public void setScope(String scope) { + this.scope = scope; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public ArrayList getManagers() { + return managers; + } + + public void setManagers(ArrayList managers) { + this.managers = managers; + } + + public Calendar getStartDate() { + return startDate; + } + + public void setStartDate(Calendar startDate) { + this.startDate = startDate; + } + + public Calendar getEndDate() { + return endDate; + } + + public void setEndDate(Calendar endDate) { + this.endDate = endDate; + } + + public String getCatalogUrl() { + return catalogUrl; + } + + public void setCatalogUrl(String catalogUrl) { + this.catalogUrl = catalogUrl; + } + + @Override + public String toString() { + return "VRE [scope=" + scope + ", name=" + name + ", description=" + description + ", managers=" + managers + + ", startDate=" + startDate + ", endDate=" + endDate + ", catalogUrl=" + catalogUrl + "]"; + } + +} \ No newline at end of file diff --git a/src/main/resources/org/gcube/infrastructure/detachedres/detachedreslibrary/detachedreslib.gwt.xml b/src/main/resources/org/gcube/infrastructure/detachedres/detachedreslibrary/detachedreslib.gwt.xml new file mode 100644 index 0000000..930dab2 --- /dev/null +++ b/src/main/resources/org/gcube/infrastructure/detachedres/detachedreslibrary/detachedreslib.gwt.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + diff --git a/src/test/java/org/gcube/infrastructure/detachedres/detachedreslibrary/DetachedREsTest.java b/src/test/java/org/gcube/infrastructure/detachedres/detachedreslibrary/DetachedREsTest.java new file mode 100644 index 0000000..0a56b71 --- /dev/null +++ b/src/test/java/org/gcube/infrastructure/detachedres/detachedreslibrary/DetachedREsTest.java @@ -0,0 +1,133 @@ +/** + * + */ +package org.gcube.infrastructure.detachedres.detachedreslibrary; + +import java.io.File; +import java.io.StringWriter; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.Marshaller; +import javax.xml.bind.Unmarshaller; + +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; +import org.gcube.infrastructure.detachedres.detachedreslibrary.server.is.obj.VOJAXB; +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.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import junit.framework.TestCase; + +/** + * + * @author Giancarlo Panichi + * + * + */ +public class DetachedREsTest extends TestCase { + + private static Logger logger = LoggerFactory.getLogger(DetachedREsTest.class); + + @Test + public void testDetachedREsResource() { + if (Constants.TEST_ENABLE) { + logger.debug("Test Enabled"); + + try { + DetachedREsClient detachedREsClient=new DetachedREsClient(); + DetachedREs detachedREs= detachedREsClient.getDetachedREs(); + logger.debug("DetachedREs: " + detachedREs); + 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 testDetachedREsMarshaller() { + if (Constants.TEST_ENABLE) { + logger.debug("Test Enabled"); + + try { + logger.info("Check Marshalling"); + + GatewayJAXB blueBridgeGateway = new GatewayJAXB(); + blueBridgeGateway.setScope("-1"); + blueBridgeGateway.setName("BlueBridge Gateway"); + + VOJAXB gCubeApps = new VOJAXB(); + gCubeApps.setScope("/d4science.research-infrastructures.eu/gCubeApps"); + gCubeApps.setName("gCubeApps"); + + VREJAXB blueBridgeProject = new VREJAXB(); + blueBridgeProject.setScope("/d4science.research-infrastructures.eu/gcubeApps/BlueBridgeProject"); + blueBridgeProject.setName("BlueBridgeProject"); + + ArrayList vres=new ArrayList<>(); + vres.add(blueBridgeProject); + gCubeApps.setVres(vres); + + ArrayList vos=new ArrayList<>(); + vos.add(gCubeApps); + blueBridgeGateway.setVos(vos); + + ArrayList gateways=new ArrayList<>(); + gateways.add(blueBridgeGateway); + + DetachedREsJAXB detachedREs = new DetachedREsJAXB(); + detachedREs.setEnabled(true); + detachedREs.setGateways(gateways); + + JAXBContext jaxbContext = JAXBContext.newInstance(DetachedREsJAXB.class); + Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); + jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); + + // Print XML String to Console + StringWriter sw = new StringWriter(); + + // Write XML to StringWriter + jaxbMarshaller.marshal(detachedREs, sw); + + // Verify XML Content + String xmlContent = sw.toString(); + logger.debug(xmlContent); + + logger.info("Check Unmarshalling"); + Path path = Files.createTempFile("DetachedREsData", ".xml"); + File file = path.toFile(); + jaxbMarshaller.marshal(detachedREs, file); + + Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); + DetachedREsJAXB configUnmarshalled = (DetachedREsJAXB) jaxbUnmarshaller + .unmarshal(file); + logger.debug("DetachedREs unmarshallded: " + configUnmarshalled); + file.delete(); + logger.info("Success!"); + assertTrue(true); + + } catch (Throwable e) { + logger.error(e.getLocalizedMessage(), e); + assertTrue("Error in DetachedREs Marshal!", false); + } + } else { + logger.debug("Test Disabled"); + assertTrue(true); + } + } + +} diff --git a/src/test/resources/log4j.properties b/src/test/resources/log4j.properties new file mode 100644 index 0000000..87b68a3 --- /dev/null +++ b/src/test/resources/log4j.properties @@ -0,0 +1,20 @@ +# A default log4j configuration for log4j users. +# +# To use this configuration, deploy it into your application's WEB-INF/classes +# directory. You are also encouraged to edit it as you like. + +log4j.rootLogger=DEBUG, stdout, rollingFile + +# Redirect log messages to console +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.Target=System.out +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n + + +log4j.appender.rollingFile=org.apache.log4j.RollingFileAppender +log4j.appender.rollingFile.File=test.log +log4j.appender.rollingFile.MaxFileSize=20MB +log4j.appender.rollingFile.MaxBackupIndex=2 +log4j.appender.rollingFile.layout = org.apache.log4j.PatternLayout +log4j.appender.rollingFile.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n