Compare commits

...

27 Commits

Author SHA1 Message Date
Luca Frosini 452be51581 Remvoed uneeded import 2024-05-24 10:57:35 +02:00
Luca Frosini cbb351f6b5 Removed uneeded dependency 2024-05-24 10:57:25 +02:00
Luca Frosini 2aa2909e4e Improved code 2024-04-16 16:35:38 +02:00
Luca Frosini 489eed2787 Added the possibility to create any type of resource without gcube-model 2024-04-16 16:11:14 +02:00
Luca Frosini 483826685c improved tests 2024-04-15 11:00:02 +02:00
luca.frosini 179013ec5b Fixed context cache renew 2023-11-09 19:11:59 +01:00
luca.frosini 88ef977959 Added support for paginated results 2023-11-09 18:29:16 +01:00
luca.frosini 3670c234a4 Extended BaseRequestInfo to get new query parameters management for free 2023-09-13 18:43:48 +02:00
luca.frosini dbfa2901c0 Removed -SNAPSHOT for release 2023-07-21 14:28:11 +02:00
luca.frosini 1af4a41fe5 Ignored MacOs File 2023-06-21 11:45:43 +02:00
Luca Frosini caf354617a Fixed tests 2023-05-17 18:04:14 +02:00
Luca Frosini cff16573dd Fixed function 2023-05-17 18:04:08 +02:00
Luca Frosini d8947f2814 Fixed test 2023-05-15 16:50:54 +02:00
Luca Frosini fd7948bd7c Fixed sent parameters 2023-05-15 16:49:19 +02:00
Luca Frosini 64ec6c94d5 Added missing query parameters to requests 2023-05-05 12:20:57 +02:00
Luca Frosini 6b8b2e780a Using RequestInfo 2023-05-02 17:24:11 +02:00
Luca Frosini 22a6538683 Fixed code to comply with uuid property rename to id 2023-04-28 11:49:11 +02:00
Luca Frosini b8c80b122d Fixed code to comply with uuid property rename to id 2023-04-28 11:47:50 +02:00
Luca Frosini af2ef0ccb5 Refactored to use Element getTypeName() function 2023-04-27 11:13:35 +02:00
Luca Frosini 83deeb649b Refactored due to is-model constant name change 2023-04-27 10:42:34 +02:00
Luca Frosini 05279d72fa Getting type indication property from constant 2023-04-26 21:45:37 +02:00
Luca Frosini c9c6c59c5c Migrate code to reorganized E/R format ref. #24992 2023-04-26 10:46:08 +02:00
Luca Frosini b8d3fac55f Reorganized utilities and their usage 2023-04-21 15:57:26 +02:00
Luca Frosini 02abe7e89f Redesigning E/R instance definition 2023-04-20 12:09:25 +02:00
Luca Frosini 1011c5a68d Porting code to redesigned E/R format 2023-04-19 13:14:29 +02:00
Luca Frosini 9a465edb19 Porting code to redesigned E/R format 2023-04-19 11:38:22 +02:00
Luca Frosini bef7068964 Redesigning E/R instance definition 2023-04-18 17:52:40 +02:00
16 changed files with 586 additions and 1023 deletions

2
.gitignore vendored
View File

@ -1,3 +1,5 @@
target target
.classpath .classpath
.project .project
/.DS_Store
/bin/

View File

@ -2,6 +2,16 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
# Changelog for Resource Registry Publisher # Changelog for Resource Registry Publisher
## [v4.5.0-SNAPSHOT]
- Added support for paginated results [#24648]
## [v4.4.0]
- Migrated code to reorganized E/R format [#24992]
## [v4.3.0] ## [v4.3.0]
- Enhanced gcube-bom version - Enhanced gcube-bom version

10
pom.xml
View File

@ -9,7 +9,7 @@
<groupId>org.gcube.information-system</groupId> <groupId>org.gcube.information-system</groupId>
<artifactId>resource-registry-publisher</artifactId> <artifactId>resource-registry-publisher</artifactId>
<version>4.3.0</version> <version>4.5.0-SNAPSHOT</version>
<name>Resource Registry Publisher</name> <name>Resource Registry Publisher</name>
<description>Resource Registry Publisher is a library designed to interact with Resource Registry Instances APIs</description> <description>Resource Registry Publisher is a library designed to interact with Resource Registry Instances APIs</description>
@ -29,7 +29,7 @@
<dependency> <dependency>
<groupId>org.gcube.distribution</groupId> <groupId>org.gcube.distribution</groupId>
<artifactId>gcube-bom</artifactId> <artifactId>gcube-bom</artifactId>
<version>2.2.0</version> <version>2.4.0</version>
<type>pom</type> <type>pom</type>
<scope>import</scope> <scope>import</scope>
</dependency> </dependency>
@ -49,10 +49,6 @@
<groupId>org.gcube.common</groupId> <groupId>org.gcube.common</groupId>
<artifactId>gxHTTP</artifactId> <artifactId>gxHTTP</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>common-utility-sg3</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.slf4j</groupId> <groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId> <artifactId>slf4j-api</artifactId>
@ -87,7 +83,7 @@
<dependency> <dependency>
<groupId>org.gcube.common</groupId> <groupId>org.gcube.common</groupId>
<artifactId>authorization-utils</artifactId> <artifactId>authorization-utils</artifactId>
<version>[2.1.0, 3.0.0-SNAPSHOT)</version> <version>[2.2.0, 3.0.0-SNAPSHOT)</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -10,6 +10,7 @@ import org.gcube.informationsystem.model.reference.entities.Facet;
import org.gcube.informationsystem.model.reference.entities.Resource; import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.model.reference.relations.ConsistsOf; import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
import org.gcube.informationsystem.model.reference.relations.IsRelatedTo; import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
import org.gcube.informationsystem.resourceregistry.api.contexts.ContextCache;
import org.gcube.informationsystem.resourceregistry.api.exceptions.AlreadyPresentException; import org.gcube.informationsystem.resourceregistry.api.exceptions.AlreadyPresentException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.AvailableInAnotherContextException; import org.gcube.informationsystem.resourceregistry.api.exceptions.AvailableInAnotherContextException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException; import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
@ -28,25 +29,45 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.relations.isr
import org.gcube.informationsystem.resourceregistry.api.exceptions.relations.isrelatedto.IsRelatedToAvailableInAnotherContextException; import org.gcube.informationsystem.resourceregistry.api.exceptions.relations.isrelatedto.IsRelatedToAvailableInAnotherContextException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.relations.isrelatedto.IsRelatedToNotFoundException; import org.gcube.informationsystem.resourceregistry.api.exceptions.relations.isrelatedto.IsRelatedToNotFoundException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaViolationException; import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaViolationException;
import org.gcube.informationsystem.resourceregistry.api.request.RequestInfo;
/** /**
* @author Luca Frosini (ISTI - CNR) * @author Luca Frosini (ISTI - CNR)
*/ */
public interface ResourceRegistryPublisher { public interface ResourceRegistryPublisher extends RequestInfo {
public boolean isHierarchicalMode(); /**
* Use {@link #includeContexts()} instead
public void setHierarchicalMode(boolean hierarchicalMode); * @return
*/
@Deprecated
public boolean isIncludeContextsInHeader(); public boolean isIncludeContextsInHeader();
public void setIncludeContextsInHeader(boolean includeContextsInHeader); /**
* Use {@link #includeContexts(boolean)} instead
* @param includeContextsInHeader
*/
@Deprecated
public void setIncludeContextsInHeader(boolean includeContexts);
public void addHeader(String name, String value); public void addHeader(String name, String value);
public ContextCache getContextCache();
/**
* Use {@link #getContexts()} instead
* @return an array containing all contexts definition
* @throws ResourceRegistryException if fails
*/
@Deprecated
public List<Context> getAllContext() throws ResourceRegistryException; public List<Context> getAllContext() throws ResourceRegistryException;
/**
* @return an array containing all contexts definition
* @throws ResourceRegistryException if fails
*/
public List<Context> getContexts() throws ResourceRegistryException;
public Context getContext(UUID uuid) throws ContextNotFoundException, ResourceRegistryException; public Context getContext(UUID uuid) throws ContextNotFoundException, ResourceRegistryException;
public Context getCurrentContext() throws ContextNotFoundException, ResourceRegistryException; public Context getCurrentContext() throws ContextNotFoundException, ResourceRegistryException;

View File

@ -7,15 +7,16 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode;
import org.gcube.common.gxhttp.reference.GXConnection; import org.gcube.common.gxhttp.reference.GXConnection;
import org.gcube.common.gxhttp.request.GXHTTPStringRequest; import org.gcube.common.gxhttp.request.GXHTTPStringRequest;
import org.gcube.common.http.GXHTTPUtility; import org.gcube.common.http.GXHTTPUtility;
import org.gcube.informationsystem.contexts.reference.entities.Context; import org.gcube.informationsystem.contexts.reference.entities.Context;
import org.gcube.informationsystem.model.impl.properties.HeaderImpl;
import org.gcube.informationsystem.model.reference.ERElement; import org.gcube.informationsystem.model.reference.ERElement;
import org.gcube.informationsystem.model.reference.entities.Facet; import org.gcube.informationsystem.model.reference.entities.Facet;
import org.gcube.informationsystem.model.reference.entities.Resource; import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.model.reference.properties.Header;
import org.gcube.informationsystem.model.reference.relations.ConsistsOf; import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
import org.gcube.informationsystem.model.reference.relations.IsRelatedTo; import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
import org.gcube.informationsystem.resourceregistry.api.contexts.ContextCache; import org.gcube.informationsystem.resourceregistry.api.contexts.ContextCache;
@ -39,18 +40,20 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.relations.isr
import org.gcube.informationsystem.resourceregistry.api.exceptions.relations.isrelatedto.IsRelatedToAvailableInAnotherContextException; import org.gcube.informationsystem.resourceregistry.api.exceptions.relations.isrelatedto.IsRelatedToAvailableInAnotherContextException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.relations.isrelatedto.IsRelatedToNotFoundException; import org.gcube.informationsystem.resourceregistry.api.exceptions.relations.isrelatedto.IsRelatedToNotFoundException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaViolationException; import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaViolationException;
import org.gcube.informationsystem.resourceregistry.api.request.BaseRequestInfo;
import org.gcube.informationsystem.resourceregistry.api.rest.AccessPath; import org.gcube.informationsystem.resourceregistry.api.rest.AccessPath;
import org.gcube.informationsystem.resourceregistry.api.rest.InstancePath; import org.gcube.informationsystem.resourceregistry.api.rest.InstancePath;
import org.gcube.informationsystem.resourceregistry.api.rest.SharingPath; import org.gcube.informationsystem.resourceregistry.api.rest.SharingPath;
import org.gcube.informationsystem.resourceregistry.api.rest.SharingPath.SharingOperation; import org.gcube.informationsystem.resourceregistry.api.rest.SharingPath.SharingOperation;
import org.gcube.informationsystem.resourceregistry.api.rest.httputils.HTTPUtility; import org.gcube.informationsystem.resourceregistry.api.rest.httputils.HTTPUtility;
import org.gcube.informationsystem.serialization.ElementMapper; import org.gcube.informationsystem.serialization.ElementMapper;
import org.gcube.informationsystem.utils.TypeUtility;
import org.gcube.informationsystem.utils.UUIDManager; import org.gcube.informationsystem.utils.UUIDManager;
import org.gcube.informationsystem.utils.Utility; import org.gcube.informationsystem.utils.UUIDUtility;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher { public class ResourceRegistryPublisherImpl extends BaseRequestInfo implements ResourceRegistryPublisher {
private static final Logger logger = LoggerFactory.getLogger(ResourceRegistryPublisherImpl.class); private static final Logger logger = LoggerFactory.getLogger(ResourceRegistryPublisherImpl.class);
@ -60,9 +63,6 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
protected final String address; protected final String address;
protected Map<String, String> headers; protected Map<String, String> headers;
protected boolean hierarchicalMode;
protected boolean includeContextsInHeader;
protected ContextCache contextCache; protected ContextCache contextCache;
@ -76,57 +76,93 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
this.hierarchicalMode = hierarchicalMode; this.hierarchicalMode = hierarchicalMode;
} }
@Deprecated
@Override @Override
public boolean isIncludeContextsInHeader() { public boolean isIncludeContextsInHeader() {
return includeContextsInHeader; return includeContexts();
} }
@Deprecated
@Override @Override
public void setIncludeContextsInHeader(boolean includeContextsInHeader) { public void setIncludeContextsInHeader(boolean includeContexts) {
this.includeContextsInHeader = includeContextsInHeader; setIncludeContexts(includeContexts);
} }
private GXHTTPStringRequest includeAdditionalQueryParameters(GXHTTPStringRequest gxHTTPStringRequest) private void addOptionalQueryParameters(Map<String,String> queryParams) throws UnsupportedEncodingException {
throws UnsupportedEncodingException { addHierarchicalMode(queryParams);
return includeAdditionalQueryParameters(gxHTTPStringRequest, null); addIncludeContexts(queryParams);
addIncludeMeta(queryParams);
addIncludeAllMeta(queryParams);
} }
private GXHTTPStringRequest includeAdditionalQueryParameters(GXHTTPStringRequest gxHTTPStringRequest, private GXHTTPStringRequest includeAdditionalQueryParameters(GXHTTPStringRequest gxHTTPStringRequest) throws UnsupportedEncodingException{
Map<String, String> queryParams) throws UnsupportedEncodingException { Map<String,String> queryParams = new HashMap<>();
gxHTTPStringRequest = checkHierarchicalMode(gxHTTPStringRequest, queryParams); return includeAdditionalQueryParameters(gxHTTPStringRequest, queryParams);
return checkIncludeContextsInInstanceHeader(gxHTTPStringRequest, queryParams);
} }
private GXHTTPStringRequest checkHierarchicalMode(GXHTTPStringRequest gxHTTPStringRequest, private GXHTTPStringRequest includeAdditionalQueryParameters(GXHTTPStringRequest gxHTTPStringRequest, Map<String,String> queryParams) throws UnsupportedEncodingException{
Map<String, String> queryParams) throws UnsupportedEncodingException { if(queryParams==null) {
queryParams = new HashMap<>();
}
addOptionalQueryParameters(queryParams);
return gxHTTPStringRequest.queryParams(queryParams);
}
private void addHierarchicalMode(Map<String,String> queryParams) throws UnsupportedEncodingException{
if(hierarchicalMode) { if(hierarchicalMode) {
if(queryParams==null) { queryParams.put(InstancePath.HIERARCHICAL_MODE_QUERY_PARAMETER, Boolean.toString(hierarchicalMode));
queryParams = new HashMap<>();
}
queryParams.put(AccessPath.HIERARCHICAL_MODE_QUERY_PARAMETER, Boolean.toString(hierarchicalMode));
} }
return gxHTTPStringRequest.queryParams(queryParams);
} }
private GXHTTPStringRequest checkIncludeContextsInInstanceHeader(GXHTTPStringRequest gxHTTPStringRequest, private void addIncludeContexts(Map<String,String> queryParams) throws UnsupportedEncodingException{
Map<String, String> queryParams) throws UnsupportedEncodingException { if(includeContexts) {
if(includeContextsInHeader) { queryParams.put(InstancePath.INCLUDE_CONTEXTS_QUERY_PARAMETER, Boolean.toString(includeContexts));
if(queryParams==null) { }
queryParams = new HashMap<>(); }
}
queryParams.put(AccessPath.INCLUDE_CONTEXTS_IN_HEADER_QUERY_PARAMETER, Boolean.toString(includeContextsInHeader)); private void addIncludeMeta(Map<String,String> queryParams) throws UnsupportedEncodingException{
addIncludeMeta(queryParams, includeMeta);
}
private void addIncludeMeta(Map<String,String> queryParams, boolean includeMeta) throws UnsupportedEncodingException{
if(includeMeta) {
queryParams.put(InstancePath.INCLUDE_META_QUERY_PARAMETER, Boolean.toString(includeMeta));
}
}
private void addIncludeAllMeta(Map<String,String> queryParams) throws UnsupportedEncodingException{
if(allMeta) {
queryParams.put(InstancePath.INCLUDE_META_IN_ALL_INSTANCES_QUERY_PARAMETER, Boolean.toString(allMeta));
}
}
private void addOffset(Map<String,String> queryParams) throws UnsupportedEncodingException{
addOffset(queryParams, offset);
}
private void addOffset(Map<String,String> queryParams, Integer offset) throws UnsupportedEncodingException{
if(offset!=null) {
queryParams.put(InstancePath.OFFSET_QUERY_PARAMETER, offset.toString());
}
}
private void addLimit(Map<String,String> queryParams) throws UnsupportedEncodingException{
addLimit(queryParams, limit);
}
private void addLimit(Map<String,String> queryParams, Integer limit) throws UnsupportedEncodingException{
if(limit!=null) {
queryParams.put(InstancePath.LIMIT_QUERY_PARAMETER, limit.toString());
} }
return gxHTTPStringRequest.queryParams(queryParams);
} }
protected ContextCacheRenewal contextCacheRenewal = new ContextCacheRenewal() { protected ContextCacheRenewal contextCacheRenewal = new ContextCacheRenewal() {
@Override @Override
public List<Context> renew() throws ResourceRegistryException { public List<Context> renew() throws ResourceRegistryException {
return getAllContextFromServer(); return getAllContextFromServer(true, 0, BaseRequestInfo.UNBOUNDED_LIMIT);
} }
}; };
@Override @Override
@ -148,6 +184,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
} }
public ResourceRegistryPublisherImpl(String address, boolean sharedContextCache) { public ResourceRegistryPublisherImpl(String address, boolean sharedContextCache) {
super();
this.address = address; this.address = address;
this.headers = new HashMap<>(); this.headers = new HashMap<>();
if(sharedContextCache) { if(sharedContextCache) {
@ -158,14 +195,30 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
contextCache.setContextCacheRenewal(contextCacheRenewal); contextCache.setContextCacheRenewal(contextCacheRenewal);
} }
/**
* It reads all the contexts from server.
* The cache used for contexts is bypassed and not updated.
* @return All Contexts read from server
* @throws ResourceRegistryException
*/
public List<Context> getAllContextFromServer() throws ResourceRegistryException { public List<Context> getAllContextFromServer() throws ResourceRegistryException {
return getAllContextFromServer(includeMeta, offset, limit);
}
protected List<Context> getAllContextFromServer(boolean includeMeta, Integer offset, Integer limit) throws ResourceRegistryException {
try { try {
logger.info("Going to read all {}s", Context.NAME); logger.info("Going to read all {}s", Context.NAME);
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest(); GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest();
gxHTTPStringRequest.header(ACCEPT_HTTP_HEADER_KEY, GXConnection.APPLICATION_JSON_CHARSET_UTF_8); gxHTTPStringRequest.header(ACCEPT_HTTP_HEADER_KEY, GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
gxHTTPStringRequest.path(AccessPath.ACCESS_PATH_PART); gxHTTPStringRequest.path(AccessPath.ACCESS_PATH_PART);
gxHTTPStringRequest.path(AccessPath.CONTEXTS_PATH_PART); gxHTTPStringRequest.path(AccessPath.CONTEXTS_PATH_PART);
Map<String,String> parameters = new HashMap<>();
addIncludeMeta(parameters, includeMeta);
addOffset(parameters, offset);
addLimit(parameters, limit);
gxHTTPStringRequest.queryParams(parameters);
HttpURLConnection httpURLConnection = gxHTTPStringRequest.get(); HttpURLConnection httpURLConnection = gxHTTPStringRequest.get();
String ret = HTTPUtility.getResponse(String.class, httpURLConnection); String ret = HTTPUtility.getResponse(String.class, httpURLConnection);
@ -184,21 +237,48 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
@Deprecated
@Override @Override
public List<Context> getAllContext() throws ResourceRegistryException { public List<Context> getAllContext() throws ResourceRegistryException {
return contextCache.getContexts(); return getContexts();
} }
protected Context getContextFromServer(String id) throws ContextNotFoundException, ResourceRegistryException { @Override
public List<Context> getContexts() throws ResourceRegistryException {
return contextCache.getContexts();
}
@Override
public ContextCache getContextCache() {
return contextCache;
}
/**
* It reads the context from server.
* The cache used for contexts is bypassed and not updated.
* @param uuid
* @return the Contexts read from server
* @throws ContextNotFoundException
* @throws ResourceRegistryException
*/
public Context getContextFromServer(UUID uuid) throws ContextNotFoundException, ResourceRegistryException {
return getContextFromServer(uuid.toString());
}
protected Context getContextFromServer(String uuid) throws ContextNotFoundException, ResourceRegistryException {
try { try {
logger.info("Going to get current {} ", Context.NAME); logger.info("Going to get current {} ", Context.NAME);
GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest(); GXHTTPStringRequest gxHTTPStringRequest = getGXHTTPStringRequest();
gxHTTPStringRequest.header(ACCEPT_HTTP_HEADER_KEY, GXConnection.APPLICATION_JSON_CHARSET_UTF_8); gxHTTPStringRequest.header(ACCEPT_HTTP_HEADER_KEY, GXConnection.APPLICATION_JSON_CHARSET_UTF_8);
gxHTTPStringRequest.path(AccessPath.ACCESS_PATH_PART); gxHTTPStringRequest.path(AccessPath.ACCESS_PATH_PART);
gxHTTPStringRequest.path(AccessPath.CONTEXTS_PATH_PART); gxHTTPStringRequest.path(AccessPath.CONTEXTS_PATH_PART);
gxHTTPStringRequest.path(id); gxHTTPStringRequest.path(uuid);
Map<String,String> parameters = new HashMap<>();
addIncludeMeta(parameters);
gxHTTPStringRequest.queryParams(parameters);
HttpURLConnection httpURLConnection = gxHTTPStringRequest.get(); HttpURLConnection httpURLConnection = gxHTTPStringRequest.get();
Context context = HTTPUtility.getResponse(Context.class, httpURLConnection); Context context = HTTPUtility.getResponse(Context.class, httpURLConnection);
@ -224,7 +304,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
context = getContextFromServer(uuid.toString()); context = getContextFromServer(uuid.toString());
contextCache.cleanCache(); contextCache.cleanCache();
contextCache.refreshContextsIfNeeded(); contextCache.refreshContextsIfNeeded();
Context c = contextCache.getContextByUUID(context.getHeader().getUUID()); Context c = contextCache.getContextByUUID(uuid);
if (c != null) { if (c != null) {
context = c; context = c;
} else { } else {
@ -244,14 +324,14 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
} }
private UUID getCurrentContextUUID() throws ResourceRegistryException { private UUID getCurrentContextUUID() throws ResourceRegistryException {
return getCurrentContext().getHeader().getUUID(); return getCurrentContext().getID();
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public <ERElem extends ERElement> List<ERElem> list(Class<ERElem> clazz, Boolean polymorphic) public <ERElem extends ERElement> List<ERElem> list(Class<ERElem> clazz, Boolean polymorphic)
throws ResourceRegistryException { throws ResourceRegistryException {
String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getTypeName(clazz); String type = TypeUtility.getTypeName(clazz);
String ret = list(type, polymorphic); String ret = list(type, polymorphic);
try { try {
return (List<ERElem>) ElementMapper.unmarshalList(ERElement.class, ret); return (List<ERElem>) ElementMapper.unmarshalList(ERElement.class, ret);
@ -270,6 +350,8 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
gxHTTPStringRequest.path(type); gxHTTPStringRequest.path(type);
Map<String,String> parameters = new HashMap<>(); Map<String,String> parameters = new HashMap<>();
addOffset(parameters);
addLimit(parameters);
parameters.put(InstancePath.POLYMORPHIC_QUERY_PARAMETER, polymorphic.toString()); parameters.put(InstancePath.POLYMORPHIC_QUERY_PARAMETER, polymorphic.toString());
includeAdditionalQueryParameters(gxHTTPStringRequest, parameters); includeAdditionalQueryParameters(gxHTTPStringRequest, parameters);
@ -299,6 +381,13 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
gxHTTPStringRequest.path(type); gxHTTPStringRequest.path(type);
gxHTTPStringRequest.path(uuid.toString()); gxHTTPStringRequest.path(uuid.toString());
Map<String,String> parameters = new HashMap<>();
addIncludeContexts(parameters);
addIncludeMeta(parameters);
addIncludeAllMeta(parameters);
gxHTTPStringRequest.queryParams(parameters);
HttpURLConnection httpURLConnection = gxHTTPStringRequest.put(json); HttpURLConnection httpURLConnection = gxHTTPStringRequest.put(json);
String ret = HTTPUtility.getResponse(String.class, httpURLConnection); String ret = HTTPUtility.getResponse(String.class, httpURLConnection);
@ -317,16 +406,13 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
protected <ERElem extends ERElement> String internalCreate(ERElem er) protected <ERElem extends ERElement> String internalCreate(ERElem er)
throws SchemaViolationException, AlreadyPresentException, ResourceRegistryException { throws SchemaViolationException, AlreadyPresentException, ResourceRegistryException {
try { try {
String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility String type = er.getTypeName();
.getTypeName(er); UUID uuid = er.getID();
String json = ElementMapper.marshal(er); if (uuid == null) {
Header header = er.getHeader(); uuid = UUIDManager.getInstance().generateValidUUID();
if (header == null) { er.setID(uuid);
UUID randomUUID = UUIDManager.generateValidRandomUUID();
header = new HeaderImpl(randomUUID);
er.setHeader(header);
} }
UUID uuid = er.getHeader().getUUID(); String json = ElementMapper.marshal(er);
return create(type, json, uuid); return create(type, json, uuid);
} catch (ResourceRegistryException e) { } catch (ResourceRegistryException e) {
// logger.trace("Error Creating {}", facet, e); // logger.trace("Error Creating {}", facet, e);
@ -357,8 +443,16 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
public String create(String json) public String create(String json)
throws SchemaViolationException, AlreadyPresentException, ResourceRegistryException { throws SchemaViolationException, AlreadyPresentException, ResourceRegistryException {
try { try {
ERElement e = ElementMapper.unmarshal(ERElement.class, json); ObjectMapper mapper = new ObjectMapper();
return internalCreate(e); JsonNode jsonNode = mapper.readTree(json);
String type = TypeUtility.getTypeName(jsonNode);
UUID uuid = UUIDUtility.getUUID(jsonNode);
if(uuid==null) {
uuid = UUIDManager.getInstance().generateValidUUID();
((ObjectNode) jsonNode).put(ERElement.ID_PROPERTY, uuid.toString());
json = mapper.writeValueAsString(jsonNode);
}
return create(type, json, uuid);
} catch (ResourceRegistryException e) { } catch (ResourceRegistryException e) {
// logger.trace("Error Creating {}", facet, e); // logger.trace("Error Creating {}", facet, e);
throw e; throw e;
@ -371,15 +465,15 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
@Override @Override
public <ERElem extends ERElement> boolean exist(ERElem er) public <ERElem extends ERElement> boolean exist(ERElem er)
throws AvailableInAnotherContextException, ResourceRegistryException { throws AvailableInAnotherContextException, ResourceRegistryException {
String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getTypeName(er); String type = er.getTypeName();
UUID uuid = er.getHeader().getUUID(); UUID uuid = er.getID();
return exist(type, uuid); return exist(type, uuid);
} }
@Override @Override
public <ERElem extends ERElement> boolean exist(Class<ERElem> clazz, UUID uuid) public <ERElem extends ERElement> boolean exist(Class<ERElem> clazz, UUID uuid)
throws AvailableInAnotherContextException, ResourceRegistryException { throws AvailableInAnotherContextException, ResourceRegistryException {
String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getTypeName(clazz); String type = TypeUtility.getTypeName(clazz);
return exist(type, uuid); return exist(type, uuid);
} }
@ -395,7 +489,9 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
gxHTTPStringRequest.path(type); gxHTTPStringRequest.path(type);
gxHTTPStringRequest.path(uuid.toString()); gxHTTPStringRequest.path(uuid.toString());
includeAdditionalQueryParameters(gxHTTPStringRequest); Map<String,String> queryParams = new HashMap<>();
addHierarchicalMode(queryParams);
gxHTTPStringRequest.queryParams(queryParams);
HttpURLConnection httpURLConnection = gxHTTPStringRequest.head(); HttpURLConnection httpURLConnection = gxHTTPStringRequest.head();
HTTPUtility.getResponse(String.class, httpURLConnection); HTTPUtility.getResponse(String.class, httpURLConnection);
@ -420,9 +516,8 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
public <ERElem extends ERElement> ERElem read(ERElem er) public <ERElem extends ERElement> ERElem read(ERElem er)
throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException { throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
try { try {
String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility String type = er.getTypeName();
.getTypeName(er); UUID uuid = er.getID();
UUID uuid = er.getHeader().getUUID();
String ret = read(type, uuid); String ret = read(type, uuid);
return (ERElem) ElementMapper.unmarshal(ERElement.class, ret); return (ERElem) ElementMapper.unmarshal(ERElement.class, ret);
} catch (ResourceRegistryException e) { } catch (ResourceRegistryException e) {
@ -437,7 +532,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
public <ERElem extends ERElement> ERElem read(Class<ERElem> clazz, UUID uuid) public <ERElem extends ERElement> ERElem read(Class<ERElem> clazz, UUID uuid)
throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException { throws NotFoundException, AvailableInAnotherContextException, ResourceRegistryException {
try { try {
String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getTypeName(clazz); String type = TypeUtility.getTypeName(clazz);
String ret = read(type, uuid); String ret = read(type, uuid);
return (ERElem) ElementMapper.unmarshal(ERElement.class, ret); return (ERElem) ElementMapper.unmarshal(ERElement.class, ret);
} catch (ResourceRegistryException e) { } catch (ResourceRegistryException e) {
@ -481,10 +576,9 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
public <ERElem extends ERElement> ERElem update(ERElem er) public <ERElem extends ERElement> ERElem update(ERElem er)
throws SchemaViolationException, NotFoundException, ResourceRegistryException { throws SchemaViolationException, NotFoundException, ResourceRegistryException {
try { try {
String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility String type = er.getTypeName();
.getTypeName(er);
String json = ElementMapper.marshal(er); String json = ElementMapper.marshal(er);
UUID uuid = er.getHeader().getUUID(); UUID uuid = er.getID();
String ret = update(type, json, uuid); String ret = update(type, json, uuid);
return (ERElem) ElementMapper.unmarshal(ERElement.class, ret); return (ERElem) ElementMapper.unmarshal(ERElement.class, ret);
} catch (ResourceRegistryException e) { } catch (ResourceRegistryException e) {
@ -500,7 +594,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
public String update(String json) public String update(String json)
throws SchemaViolationException, NotFoundException, ResourceRegistryException { throws SchemaViolationException, NotFoundException, ResourceRegistryException {
try { try {
String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getClassFromJsonString(json); String type = TypeUtility.getTypeName(json);
return update(type, json); return update(type, json);
} catch (ResourceRegistryException e) { } catch (ResourceRegistryException e) {
// logger.trace("Error Creating {}", facet, e); // logger.trace("Error Creating {}", facet, e);
@ -515,7 +609,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
public String update(String type, String json) public String update(String type, String json)
throws SchemaViolationException, NotFoundException, ResourceRegistryException { throws SchemaViolationException, NotFoundException, ResourceRegistryException {
try { try {
UUID uuid = Utility.getUUIDFromJSONString(json); UUID uuid = UUIDUtility.getUUID(json);
return update(type, json, uuid); return update(type, json, uuid);
} catch (ResourceRegistryException e) { } catch (ResourceRegistryException e) {
// logger.trace("Error Creating {}", facet, e); // logger.trace("Error Creating {}", facet, e);
@ -537,6 +631,12 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
gxHTTPStringRequest.path(InstancePath.INSTANCES_PATH_PART); gxHTTPStringRequest.path(InstancePath.INSTANCES_PATH_PART);
gxHTTPStringRequest.path(type); gxHTTPStringRequest.path(type);
gxHTTPStringRequest.path(uuid.toString()); gxHTTPStringRequest.path(uuid.toString());
Map<String,String> parameters = new HashMap<>();
addIncludeContexts(parameters);
addIncludeMeta(parameters);
addIncludeAllMeta(parameters);
gxHTTPStringRequest.queryParams(parameters);
HttpURLConnection httpURLConnection = gxHTTPStringRequest.put(json); HttpURLConnection httpURLConnection = gxHTTPStringRequest.put(json);
String ret = HTTPUtility.getResponse(String.class, httpURLConnection); String ret = HTTPUtility.getResponse(String.class, httpURLConnection);
@ -558,9 +658,8 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
public <ERElem extends ERElement> boolean delete(ERElem er) public <ERElem extends ERElement> boolean delete(ERElem er)
throws SchemaViolationException, NotFoundException, ResourceRegistryException { throws SchemaViolationException, NotFoundException, ResourceRegistryException {
try { try {
String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility String type = er.getTypeName();
.getTypeName(er); UUID uuid = er.getID();
UUID uuid = er.getHeader().getUUID();
return delete(type, uuid); return delete(type, uuid);
} catch (ResourceRegistryException e) { } catch (ResourceRegistryException e) {
// logger.trace("Error Creating {}", facet, e); // logger.trace("Error Creating {}", facet, e);
@ -812,7 +911,10 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
Boolean forceAddToContext = getCurrentContextUUID().compareTo(contextUUID)==0; Boolean forceAddToContext = getCurrentContextUUID().compareTo(contextUUID)==0;
queryParams.put(SharingPath.FORCE_ADD_TO_CONTEXT_QUERY_PARAMETER, forceAddToContext.toString()); queryParams.put(SharingPath.FORCE_ADD_TO_CONTEXT_QUERY_PARAMETER, forceAddToContext.toString());
includeAdditionalQueryParameters(gxHTTPStringRequest, queryParams); addIncludeMeta(queryParams);
addIncludeAllMeta(queryParams);
addIncludeContexts(queryParams);
gxHTTPStringRequest.queryParams(queryParams);
HttpURLConnection httpURLConnection = gxHTTPStringRequest.post(); HttpURLConnection httpURLConnection = gxHTTPStringRequest.post();
String jsonArray = HTTPUtility.getResponse(String.class, httpURLConnection); String jsonArray = HTTPUtility.getResponse(String.class, httpURLConnection);
@ -835,9 +937,8 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
public List<ERElement> addToContext(ERElement er, UUID contextUUID, Boolean dryRun) public List<ERElement> addToContext(ERElement er, UUID contextUUID, Boolean dryRun)
throws SchemaViolationException, NotFoundException, ContextNotFoundException, ResourceRegistryException { throws SchemaViolationException, NotFoundException, ContextNotFoundException, ResourceRegistryException {
try { try {
String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility String type = er.getTypeName();
.getTypeName(er); UUID instanceUUID = er.getID();
UUID instanceUUID = er.getHeader().getUUID();
return addToContext(type, instanceUUID, contextUUID, dryRun); return addToContext(type, instanceUUID, contextUUID, dryRun);
} catch (ResourceRegistryException e) { } catch (ResourceRegistryException e) {
// logger.trace("Error Creating {}", facet, e); // logger.trace("Error Creating {}", facet, e);
@ -879,7 +980,10 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
queryParams.put(SharingPath.OPERATION_QUERY_PARAMETER, SharingOperation.REMOVE.name()); queryParams.put(SharingPath.OPERATION_QUERY_PARAMETER, SharingOperation.REMOVE.name());
queryParams.put(SharingPath.DRY_RUN_QUERY_QUERY_PARAMETER, dryRun.toString()); queryParams.put(SharingPath.DRY_RUN_QUERY_QUERY_PARAMETER, dryRun.toString());
includeAdditionalQueryParameters(gxHTTPStringRequest, queryParams); addIncludeMeta(queryParams);
addIncludeAllMeta(queryParams);
addIncludeContexts(queryParams);
gxHTTPStringRequest.queryParams(queryParams);
HttpURLConnection httpURLConnection = gxHTTPStringRequest.post(); HttpURLConnection httpURLConnection = gxHTTPStringRequest.post();
@ -903,9 +1007,8 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
public List<ERElement> removeFromContext(ERElement er, UUID contextUUID, Boolean dryRun) public List<ERElement> removeFromContext(ERElement er, UUID contextUUID, Boolean dryRun)
throws SchemaViolationException, NotFoundException, ContextNotFoundException, ResourceRegistryException { throws SchemaViolationException, NotFoundException, ContextNotFoundException, ResourceRegistryException {
try { try {
String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility String type = er.getTypeName();
.getTypeName(er); UUID instanceUUID = er.getID();
UUID instanceUUID = er.getHeader().getUUID();
return removeFromContext(type, instanceUUID, contextUUID, dryRun); return removeFromContext(type, instanceUUID, contextUUID, dryRun);
} catch (ResourceRegistryException e) { } catch (ResourceRegistryException e) {
// logger.trace("Error Creating {}", facet, e); // logger.trace("Error Creating {}", facet, e);
@ -963,8 +1066,8 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
@Override @Override
public <ERElem extends ERElement> Map<UUID, String> getElementContexts(ERElem er) public <ERElem extends ERElement> Map<UUID, String> getElementContexts(ERElem er)
throws NotFoundException, ResourceRegistryException { throws NotFoundException, ResourceRegistryException {
String type = org.gcube.informationsystem.resourceregistry.api.utils.Utility.getTypeName(er); String type = er.getTypeName();
UUID instanceUUID = er.getHeader().getUUID(); UUID instanceUUID = er.getID();
return getElementContexts(type, instanceUUID); return getElementContexts(type, instanceUUID);
} }

View File

@ -13,9 +13,8 @@ import org.gcube.common.authorization.utils.secret.JWTSecret;
import org.gcube.common.authorization.utils.secret.Secret; import org.gcube.common.authorization.utils.secret.Secret;
import org.gcube.common.authorization.utils.secret.SecretUtility; import org.gcube.common.authorization.utils.secret.SecretUtility;
import org.gcube.common.keycloak.KeycloakClientFactory; import org.gcube.common.keycloak.KeycloakClientFactory;
import org.gcube.common.keycloak.KeycloakClientHelper;
import org.gcube.common.keycloak.model.TokenResponse; import org.gcube.common.keycloak.model.TokenResponse;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.informationsystem.model.reference.properties.Header;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -24,7 +23,6 @@ import org.slf4j.LoggerFactory;
/** /**
* @author Luca Frosini (ISTI - CNR) * @author Luca Frosini (ISTI - CNR)
*/ */
@SuppressWarnings("deprecation")
public class ContextTest { public class ContextTest {
private static final Logger logger = LoggerFactory.getLogger(ContextTest.class); private static final Logger logger = LoggerFactory.getLogger(ContextTest.class);
@ -40,17 +38,15 @@ public class ContextTest {
public static final String NEXTNEXT; public static final String NEXTNEXT;
public static final String DEVSEC; public static final String DEVSEC;
public static final String DEVVRE; public static final String DEVVRE;
protected static final Properties properties; protected static final Properties properties;
protected static final String CLIENT_ID_PROPERTY_KEY = "client_id"; public static final String TYPE_PROPERTY_KEY = "type";
protected static final String CLIENT_SECRET_PROPERTY_KEY = "client_secret"; public static final String USERNAME_PROPERTY_KEY = "username";
public static final String PASSWORD_PROPERTY_KEY = "password";
protected static final String clientID; public static final String CLIENT_ID_PROPERTY_KEY = "clientId";
protected static final String clientSecret;
public static final String RESOURCE_REGISTRY_URL_PROPERTY = "RESOURCE_REGISTRY_URL"; public static final String RESOURCE_REGISTRY_URL_PROPERTY = "RESOURCE_REGISTRY_URL";
public static final String RESOURCE_REGISTRY_URL;
static { static {
GCUBE = "/gcube"; GCUBE = "/gcube";
@ -59,7 +55,7 @@ public class ContextTest {
DEVSEC = GCUBE + "/devsec"; DEVSEC = GCUBE + "/devsec";
DEVVRE = DEVSEC + "/devVRE"; DEVVRE = DEVSEC + "/devVRE";
PARENT_DEFAULT_TEST_SCOPE = "/gcube"; PARENT_DEFAULT_TEST_SCOPE = GCUBE;
DEFAULT_TEST_SCOPE = DEVNEXT; DEFAULT_TEST_SCOPE = DEVNEXT;
ALTERNATIVE_TEST_SCOPE = NEXTNEXT; ALTERNATIVE_TEST_SCOPE = NEXTNEXT;
@ -68,18 +64,16 @@ public class ContextTest {
try { try {
// load the properties file // load the properties file
properties.load(input); properties.load(input);
clientID = properties.getProperty(CLIENT_ID_PROPERTY_KEY);
clientSecret = properties.getProperty(CLIENT_SECRET_PROPERTY_KEY);
RESOURCE_REGISTRY_URL = properties.getProperty(RESOURCE_REGISTRY_URL_PROPERTY);
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
private enum Type{
USER, CLIENT_ID
};
public static void set(Secret secret) throws Exception { public static void set(Secret secret) throws Exception {
SecretManagerProvider.instance.reset(); SecretManagerProvider.instance.reset();
SecretManager secretManager = new SecretManager(); SecretManager secretManager = new SecretManager();
@ -89,15 +83,56 @@ public class ContextTest {
} }
public static void setContextByName(String fullContextName) throws Exception { public static void setContextByName(String fullContextName) throws Exception {
logger.debug("Going to set credentials for context {}", fullContextName);
Secret secret = getSecretByContextName(fullContextName); Secret secret = getSecretByContextName(fullContextName);
set(secret); set(secret);
} }
private static TokenResponse getJWTAccessToken(String context) throws Exception { private static TokenResponse getJWTAccessToken(String context) throws Exception {
ScopeProvider.instance.set(context); Type type = Type.valueOf(properties.get(TYPE_PROPERTY_KEY).toString());
TokenResponse tr = KeycloakClientFactory.newInstance().queryUMAToken(clientID, clientSecret, context, null);
return tr; TokenResponse tr = null;
int index = context.indexOf('/', 1);
String root = context.substring(0, index == -1 ? context.length() : index);
switch (type) {
case CLIENT_ID:
String clientId = properties.getProperty(CLIENT_ID_PROPERTY_KEY);
String clientSecret = properties.getProperty(root);
tr = KeycloakClientFactory.newInstance().queryUMAToken(context, clientId, clientSecret, context, null);
break;
case USER:
default:
String username = properties.getProperty(USERNAME_PROPERTY_KEY);
String password = properties.getProperty(PASSWORD_PROPERTY_KEY);
switch (root) {
case "/gcube":
default:
clientId = "next.d4science.org";
break;
case "/pred4s":
clientId = "pre.d4science.org";
break;
case "/d4science.research-infrastructures.eu":
clientId = "services.d4science.org";
break;
}
clientSecret = null;
tr = KeycloakClientHelper.getTokenForUser(context, username, password);
break;
}
return tr;
} }
public static Secret getSecretByContextName(String context) throws Exception { public static Secret getSecretByContextName(String context) throws Exception {
@ -117,7 +152,7 @@ public class ContextTest {
} }
public static String getUser() { public static String getUser() {
String user = Header.UNKNOWN_USER; String user = "UNKNOWN";
try { try {
user = SecretManagerProvider.instance.get().getUser().getUsername(); user = SecretManagerProvider.instance.get().getUser().getUsername();
} catch(Exception e) { } catch(Exception e) {

View File

@ -13,18 +13,18 @@ import java.util.Map;
import java.util.UUID; import java.util.UUID;
import org.gcube.common.encryption.encrypter.StringEncrypter; import org.gcube.common.encryption.encrypter.StringEncrypter;
import org.gcube.informationsystem.base.reference.Element;
import org.gcube.informationsystem.base.reference.IdentifiableElement; import org.gcube.informationsystem.base.reference.IdentifiableElement;
import org.gcube.informationsystem.model.impl.properties.EncryptedImpl;
import org.gcube.informationsystem.model.impl.properties.PropagationConstraintImpl; import org.gcube.informationsystem.model.impl.properties.PropagationConstraintImpl;
import org.gcube.informationsystem.model.impl.properties.VaultImpl;
import org.gcube.informationsystem.model.impl.relations.ConsistsOfImpl; import org.gcube.informationsystem.model.impl.relations.ConsistsOfImpl;
import org.gcube.informationsystem.model.reference.ModelElement;
import org.gcube.informationsystem.model.reference.entities.Facet; import org.gcube.informationsystem.model.reference.entities.Facet;
import org.gcube.informationsystem.model.reference.entities.Resource; import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.model.reference.properties.Header; import org.gcube.informationsystem.model.reference.properties.Encrypted;
import org.gcube.informationsystem.model.reference.properties.Metadata;
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint; import org.gcube.informationsystem.model.reference.properties.PropagationConstraint;
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.AddConstraint; import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.AddConstraint;
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.RemoveConstraint; import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.RemoveConstraint;
import org.gcube.informationsystem.model.reference.properties.Vault;
import org.gcube.informationsystem.model.reference.relations.ConsistsOf; import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
import org.gcube.informationsystem.resourceregistry.api.exceptions.entities.resource.ResourceNotFoundException; import org.gcube.informationsystem.resourceregistry.api.exceptions.entities.resource.ResourceNotFoundException;
import org.gcube.informationsystem.serialization.ElementMapper; import org.gcube.informationsystem.serialization.ElementMapper;
@ -86,11 +86,14 @@ public class ERManagementTest extends ContextTest {
protected ResourceRegistryPublisher resourceRegistryPublisher; protected ResourceRegistryPublisher resourceRegistryPublisher;
public ERManagementTest() { public ERManagementTest() {
if(ContextTest.RESOURCE_REGISTRY_URL !=null && !ContextTest.RESOURCE_REGISTRY_URL.isEmpty()) { Object rrURLOBj = ContextTest.properties.get(RESOURCE_REGISTRY_URL_PROPERTY);
resourceRegistryPublisher = new ResourceRegistryPublisherImpl(ContextTest.RESOURCE_REGISTRY_URL); if(rrURLOBj!=null && !rrURLOBj.toString().isEmpty()) {
resourceRegistryPublisher = new ResourceRegistryPublisherImpl(rrURLOBj.toString());
}else { }else {
resourceRegistryPublisher = ResourceRegistryPublisherFactory.create(); resourceRegistryPublisher = ResourceRegistryPublisherFactory.create();
} }
resourceRegistryPublisher.setIncludeMeta(true);
resourceRegistryPublisher.setAllMeta(true);
} }
@ -127,7 +130,7 @@ public class ERManagementTest extends ContextTest {
Configuration configuration = new ConfigurationImpl(); Configuration configuration = new ConfigurationImpl();
IdentifierFacet identifierFacet = new IdentifierFacetImpl(); IdentifierFacet identifierFacet = new IdentifierFacetImpl();
identifierFacet.setType(IdentificationType.STRING); identifierFacet.setIdentificationType(IdentificationType.STRING);
identifierFacet.setValue("MyID"); identifierFacet.setValue("MyID");
identifierFacet.setPersistent(false); identifierFacet.setPersistent(false);
@ -218,46 +221,46 @@ public class ERManagementTest extends ContextTest {
return hostingNode; return hostingNode;
} }
public static void checkHeader(IdentifiableElement identifiableElement, IdentifiableElement createdIdentifiableElement) { public static void checkUUIDAndMetadata(IdentifiableElement identifiableElement, IdentifiableElement createdIdentifiableElement) {
Header createdHeader = createdIdentifiableElement.getHeader(); UUID createdUUID = createdIdentifiableElement.getID();
Assert.assertTrue(createdHeader!=null);
UUID createdUUID = createdHeader.getUUID();
Assert.assertTrue(createdUUID!=null); Assert.assertTrue(createdUUID!=null);
String createdBy = createdHeader.getCreatedBy(); if(identifiableElement.getID()!=null) {
Assert.assertTrue(createdUUID.compareTo(identifiableElement.getID())==0);
}
Metadata createdMetadata = createdIdentifiableElement.getMetadata();
Assert.assertTrue(createdMetadata!=null);
String createdBy = createdMetadata.getCreatedBy();
Assert.assertTrue(createdBy!=null); Assert.assertTrue(createdBy!=null);
String lastUpdateBy = createdHeader.getLastUpdateBy(); String lastUpdateBy = createdMetadata.getLastUpdateBy();
Assert.assertTrue(lastUpdateBy!=null); Assert.assertTrue(lastUpdateBy!=null);
Date creationTime = createdHeader.getCreationTime(); Date creationTime = createdMetadata.getCreationTime();
Assert.assertTrue(creationTime!=null); Assert.assertTrue(creationTime!=null);
Date lastUpdateTime = createdHeader.getLastUpdateTime(); Date lastUpdateTime = createdMetadata.getLastUpdateTime();
Assert.assertTrue(lastUpdateTime!=null); Assert.assertTrue(lastUpdateTime!=null);
Assert.assertTrue(lastUpdateTime.equals(creationTime) || lastUpdateTime.equals(lastUpdateTime)); Assert.assertTrue(lastUpdateTime.equals(creationTime) || lastUpdateTime.equals(lastUpdateTime));
Header header = identifiableElement.getHeader(); Metadata metadata = identifiableElement.getMetadata();
if(header!=null) { if(metadata!=null) {
if(header.getUUID()!=null) { if(metadata.getCreatedBy()!=null) {
Assert.assertTrue(createdUUID.compareTo(header.getUUID())==0); Assert.assertTrue(createdBy.compareTo(metadata.getCreatedBy())==0);
}
if(header.getCreatedBy()!=null) {
Assert.assertTrue(createdBy.compareTo(header.getCreatedBy())==0);
}else { }else {
Assert.assertTrue(createdBy.compareTo(ContextTest.getUser())==0); Assert.assertTrue(createdBy.compareTo(ContextTest.getUser())==0);
} }
if(header.getLastUpdateBy()!=null) { if(metadata.getLastUpdateBy()!=null) {
Assert.assertTrue(lastUpdateBy.compareTo(header.getLastUpdateBy())==0); Assert.assertTrue(lastUpdateBy.compareTo(metadata.getLastUpdateBy())==0);
}else { }else {
Assert.assertTrue(lastUpdateBy.compareTo(ContextTest.getUser())==0); Assert.assertTrue(lastUpdateBy.compareTo(ContextTest.getUser())==0);
} }
if(header.getLastUpdateTime()!=null) { if(metadata.getLastUpdateTime()!=null) {
Assert.assertTrue(lastUpdateTime.after(header.getLastUpdateTime())); Assert.assertTrue(lastUpdateTime.after(metadata.getLastUpdateTime()));
} }
} }
@ -269,7 +272,7 @@ public class ERManagementTest extends ContextTest {
} }
public static void checkConsistOf(ConsistsOf<? extends Resource, ? extends Facet> consistsOf, ConsistsOf<? extends Resource, ? extends Facet> gotConsistsOf) { public static void checkConsistOf(ConsistsOf<? extends Resource, ? extends Facet> consistsOf, ConsistsOf<? extends Resource, ? extends Facet> gotConsistsOf) {
checkHeader(consistsOf, gotConsistsOf); checkUUIDAndMetadata(consistsOf, gotConsistsOf);
if(consistsOf.getPropagationConstraint()==null) { if(consistsOf.getPropagationConstraint()==null) {
PropagationConstraint propagationConstraint = gotConsistsOf.getPropagationConstraint(); PropagationConstraint propagationConstraint = gotConsistsOf.getPropagationConstraint();
@ -281,9 +284,9 @@ public class ERManagementTest extends ContextTest {
} }
Map<String, Object> additionalProperties = new HashMap<>(consistsOf.getAdditionalProperties()); Map<String, Object> additionalProperties = new HashMap<>(consistsOf.getAdditionalProperties());
additionalProperties.remove(Element.SUPERCLASSES_PROPERTY); additionalProperties.remove(ModelElement.SUPERTYPES_PROPERTY);
Map<String, Object> gotAdditionalProperties = new HashMap<>(gotConsistsOf.getAdditionalProperties()); Map<String, Object> gotAdditionalProperties = new HashMap<>(gotConsistsOf.getAdditionalProperties());
gotAdditionalProperties.remove(Element.SUPERCLASSES_PROPERTY); gotAdditionalProperties.remove(ModelElement.SUPERTYPES_PROPERTY);
Assert.assertTrue(additionalProperties.size()==gotAdditionalProperties.size()); Assert.assertTrue(additionalProperties.size()==gotAdditionalProperties.size());
for(String key : additionalProperties.keySet()) { for(String key : additionalProperties.keySet()) {
Assert.assertTrue(gotAdditionalProperties.containsKey(key)); Assert.assertTrue(gotAdditionalProperties.containsKey(key));
@ -295,7 +298,7 @@ public class ERManagementTest extends ContextTest {
} }
public static void checkFacet(Facet facet, Facet gotFacet) throws Exception { public static void checkFacet(Facet facet, Facet gotFacet) throws Exception {
checkHeader(facet, gotFacet); checkUUIDAndMetadata(facet, gotFacet);
Class<? extends Facet> clz = facet.getClass(); Class<? extends Facet> clz = facet.getClass();
Class<? extends Facet> gotClz = gotFacet.getClass(); Class<? extends Facet> gotClz = gotFacet.getClass();
Assert.assertTrue(clz==gotClz); Assert.assertTrue(clz==gotClz);
@ -307,7 +310,7 @@ public class ERManagementTest extends ContextTest {
protected static <R extends Resource> void checkResource(R resource, R gotResource) throws Exception { protected static <R extends Resource> void checkResource(R resource, R gotResource) throws Exception {
Assert.assertTrue(resource.getClass() == gotResource.getClass()); Assert.assertTrue(resource.getClass() == gotResource.getClass());
checkHeader(resource, gotResource); checkUUIDAndMetadata(resource, gotResource);
List<ConsistsOf<? extends Resource, ? extends Facet>> resourceConsistsOf = resource.getConsistsOf(); List<ConsistsOf<? extends Resource, ? extends Facet>> resourceConsistsOf = resource.getConsistsOf();
List<ConsistsOf<? extends Resource, ? extends Facet>> gotResourceConsistsOf = gotResource.getConsistsOf(); List<ConsistsOf<? extends Resource, ? extends Facet>> gotResourceConsistsOf = gotResource.getConsistsOf();
@ -396,7 +399,7 @@ public class ERManagementTest extends ContextTest {
@Test @Test
public void testReadResource() throws Exception { public void testReadResource() throws Exception {
ResourceManagement resourceManagement = new ResourceManagement(); ResourceManagement resourceManagement = new ResourceManagement();
resourceManagement.setUUID(UUID.fromString("26da57ee-33bd-4c4b-8aef-9206b61c329e")); resourceManagement.setUUID(UUIDUtility.fromString("26da57ee-33bd-4c4b-8aef-9206b61c329e"));
String read = resourceManagement.read().toString(); String read = resourceManagement.read().toString();
logger.debug(read); logger.debug(read);
} }
@ -406,7 +409,7 @@ public class ERManagementTest extends ContextTest {
@Test @Test
public void testDeleteResource() throws Exception { public void testDeleteResource() throws Exception {
ResourceManagement resourceManagement = new ResourceManagement(); ResourceManagement resourceManagement = new ResourceManagement();
resourceManagement.setUUID(UUID.fromString("64635295-7ced-4931-a55f-40fc8199b280")); resourceManagement.setUUID(UUIDUtility.fromString("64635295-7ced-4931-a55f-40fc8199b280"));
boolean deleted = resourceManagement.delete(); boolean deleted = resourceManagement.delete();
Assert.assertTrue(deleted); Assert.assertTrue(deleted);
} }
@ -450,13 +453,13 @@ public class ERManagementTest extends ContextTest {
Assert.assertTrue(cpuFacet.getModel().compareTo(createdCpuFacet.getModel()) == 0); Assert.assertTrue(cpuFacet.getModel().compareTo(createdCpuFacet.getModel()) == 0);
Assert.assertTrue(cpuFacet.getVendor().compareTo(createdCpuFacet.getVendor()) == 0); Assert.assertTrue(cpuFacet.getVendor().compareTo(createdCpuFacet.getVendor()) == 0);
UUID uuid = createdCpuFacet.getHeader().getUUID(); UUID uuid = createdCpuFacet.getID();
CPUFacet readCpuFacet = resourceRegistryPublisher.read(createdCpuFacet.getClass(), uuid); CPUFacet readCpuFacet = resourceRegistryPublisher.read(createdCpuFacet.getClass(), uuid);
Assert.assertTrue(cpuFacet.getClockSpeed().compareTo(readCpuFacet.getClockSpeed()) == 0); Assert.assertTrue(cpuFacet.getClockSpeed().compareTo(readCpuFacet.getClockSpeed()) == 0);
Assert.assertTrue(cpuFacet.getModel().compareTo(readCpuFacet.getModel()) == 0); Assert.assertTrue(cpuFacet.getModel().compareTo(readCpuFacet.getModel()) == 0);
Assert.assertTrue(cpuFacet.getVendor().compareTo(readCpuFacet.getVendor()) == 0); Assert.assertTrue(cpuFacet.getVendor().compareTo(readCpuFacet.getVendor()) == 0);
Assert.assertTrue(uuid.compareTo(readCpuFacet.getHeader().getUUID()) == 0); Assert.assertTrue(uuid.compareTo(readCpuFacet.getID()) == 0);
String newVendor = "Intel"; String newVendor = "Intel";
String newClockSpeed = "2 GHz"; String newClockSpeed = "2 GHz";
@ -473,9 +476,9 @@ public class ERManagementTest extends ContextTest {
Assert.assertTrue(updatedCpuFacet.getVendor().compareTo(newVendor) == 0); Assert.assertTrue(updatedCpuFacet.getVendor().compareTo(newVendor) == 0);
Assert.assertTrue(((String) updatedCpuFacet.getAdditionalProperty(additionPropertyKey)) Assert.assertTrue(((String) updatedCpuFacet.getAdditionalProperty(additionPropertyKey))
.compareTo((String) readCpuFacet.getAdditionalProperty(additionPropertyKey)) == 0); .compareTo((String) readCpuFacet.getAdditionalProperty(additionPropertyKey)) == 0);
Assert.assertTrue(uuid.compareTo(updatedCpuFacet.getHeader().getUUID()) == 0); Assert.assertTrue(uuid.compareTo(updatedCpuFacet.getID()) == 0);
String user = ContextTest.getUser(); String user = ContextTest.getUser();
Assert.assertTrue(updatedCpuFacet.getHeader().getLastUpdateBy().compareTo(user) == 0); Assert.assertTrue(updatedCpuFacet.getMetadata().getLastUpdateBy().compareTo(user) == 0);
CPUFacet readUpdatedCpuFacet = resourceRegistryPublisher.read(updatedCpuFacet); CPUFacet readUpdatedCpuFacet = resourceRegistryPublisher.read(updatedCpuFacet);
@ -484,7 +487,7 @@ public class ERManagementTest extends ContextTest {
Assert.assertTrue(updatedCpuFacet.getVendor().compareTo(readUpdatedCpuFacet.getVendor()) == 0); Assert.assertTrue(updatedCpuFacet.getVendor().compareTo(readUpdatedCpuFacet.getVendor()) == 0);
Assert.assertTrue(((String) updatedCpuFacet.getAdditionalProperty(additionPropertyKey)) Assert.assertTrue(((String) updatedCpuFacet.getAdditionalProperty(additionPropertyKey))
.compareTo((String) readUpdatedCpuFacet.getAdditionalProperty(additionPropertyKey)) == 0); .compareTo((String) readUpdatedCpuFacet.getAdditionalProperty(additionPropertyKey)) == 0);
Assert.assertTrue(uuid.compareTo(updatedCpuFacet.getHeader().getUUID()) == 0); Assert.assertTrue(uuid.compareTo(updatedCpuFacet.getID()) == 0);
resourceRegistryPublisher.delete(readCpuFacet); resourceRegistryPublisher.delete(readCpuFacet);
} finally { } finally {
@ -514,12 +517,12 @@ public class ERManagementTest extends ContextTest {
String additionlaPropertyValue = "MyTest"; String additionlaPropertyValue = "MyTest";
accessPointFacet.setAdditionalProperty(additionlaPropertyKey, additionlaPropertyValue); accessPointFacet.setAdditionalProperty(additionlaPropertyKey, additionlaPropertyValue);
Vault vault = new VaultImpl(); Encrypted encrypted = new EncryptedImpl();
String plainValue = "my plain value"; String plainValue = "my plain value";
String encryptedValue = StringEncrypter.getEncrypter().encrypt(plainValue); String encryptedValue = StringEncrypter.getEncrypter().encrypt(plainValue);
vault.setValue(encryptedValue); encrypted.setValue(encryptedValue);
String encryptedKey = "Enc"; String encryptedKey = "Enc";
accessPointFacet.setAdditionalProperty(encryptedKey, vault); accessPointFacet.setAdditionalProperty(encryptedKey, encrypted);
configuration.addFacet(accessPointFacet); configuration.addFacet(accessPointFacet);
@ -531,8 +534,8 @@ public class ERManagementTest extends ContextTest {
AccessPointFacet apf = configuration.getFacets(AccessPointFacet.class).get(0); AccessPointFacet apf = configuration.getFacets(AccessPointFacet.class).get(0);
Assert.assertTrue(apf.getAuthorization() instanceof ValueSchema); Assert.assertTrue(apf.getAuthorization() instanceof ValueSchema);
Assert.assertTrue(apf.getAdditionalProperty(encryptedKey) instanceof Vault); Assert.assertTrue(apf.getAdditionalProperty(encryptedKey) instanceof Encrypted);
Vault enc = (Vault) apf.getAdditionalProperty(encryptedKey); Encrypted enc = (Encrypted) apf.getAdditionalProperty(encryptedKey);
String encValue = enc.getValue(); String encValue = enc.getValue();
Assert.assertTrue(encValue.compareTo(encryptedValue) == 0); Assert.assertTrue(encValue.compareTo(encryptedValue) == 0);
String decryptedValue = StringEncrypter.getEncrypter().decrypt(encValue); String decryptedValue = StringEncrypter.getEncrypter().decrypt(encValue);
@ -577,11 +580,17 @@ public class ERManagementTest extends ContextTest {
// EService eService = ElementMapper.unmarshal(EService.class, fileInputStream); // EService eService = ElementMapper.unmarshal(EService.class, fileInputStream);
// //
// ResourceManagement resourceManagement = new ResourceManagement(); // ResourceManagement resourceManagement = new ResourceManagement();
// resourceManagement.setUUID(eService.getHeader().getUUID()); // resourceManagement.setUUID(eService.getUUID());
// resourceManagement.setJson(ElementMapper.marshal(eService)); // resourceManagement.setJson(ElementMapper.marshal(eService));
// //
// resourceManagement.update(); // resourceManagement.update();
// //
// } // }
// @Test
// public void testCreateResourceFromJson() throws Exception {
// String json = "{\"type\":\"VirtualService\",\"consistsOf\":[{\"type\":\"IsIdentifiedBy\",\"target\":{\"name\":\"aaaaaa\",\"optional\":\"true\",\"group\":\"xxxxx\",\"description\":\"\",\"version\":\"cvcvvv\",\"qualifier\":\"\",\"type\":\"SoftwareFacet\",\"aaaa\":\"dddddd\"}}]}";
// String ret = resourceRegistryPublisher.create(json);
// }
} }

View File

@ -3,15 +3,15 @@ package org.gcube.informationsystem.resourceregistry.publisher;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import org.gcube.informationsystem.model.impl.properties.HeaderImpl; import org.gcube.informationsystem.base.reference.Element;
import org.gcube.informationsystem.base.reference.IdentifiableElement;
import org.gcube.informationsystem.model.impl.relations.ConsistsOfImpl; import org.gcube.informationsystem.model.impl.relations.ConsistsOfImpl;
import org.gcube.informationsystem.model.reference.entities.Facet; import org.gcube.informationsystem.model.reference.entities.Facet;
import org.gcube.informationsystem.model.reference.entities.Resource; import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.model.reference.relations.ConsistsOf; import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.entities.resource.ResourceAlreadyPresentException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaViolationException; import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaViolationException;
import org.gcube.informationsystem.serialization.ElementMapper; import org.gcube.informationsystem.serialization.ElementMapper;
import org.gcube.informationsystem.utils.UUIDManager;
import org.gcube.resourcemanagement.model.impl.entities.facets.CPUFacetImpl; import org.gcube.resourcemanagement.model.impl.entities.facets.CPUFacetImpl;
import org.gcube.resourcemanagement.model.impl.entities.facets.SimpleFacetImpl; import org.gcube.resourcemanagement.model.impl.entities.facets.SimpleFacetImpl;
import org.gcube.resourcemanagement.model.impl.entities.facets.SoftwareFacetImpl; import org.gcube.resourcemanagement.model.impl.entities.facets.SoftwareFacetImpl;
@ -21,11 +21,13 @@ import org.gcube.resourcemanagement.model.impl.relations.consistsof.IsIdentified
import org.gcube.resourcemanagement.model.reference.entities.facets.CPUFacet; import org.gcube.resourcemanagement.model.reference.entities.facets.CPUFacet;
import org.gcube.resourcemanagement.model.reference.entities.facets.SimpleFacet; import org.gcube.resourcemanagement.model.reference.entities.facets.SimpleFacet;
import org.gcube.resourcemanagement.model.reference.entities.facets.SoftwareFacet; import org.gcube.resourcemanagement.model.reference.entities.facets.SoftwareFacet;
import org.gcube.resourcemanagement.model.reference.entities.resources.Actor;
import org.gcube.resourcemanagement.model.reference.entities.resources.Configuration; import org.gcube.resourcemanagement.model.reference.entities.resources.Configuration;
import org.gcube.resourcemanagement.model.reference.entities.resources.EService; import org.gcube.resourcemanagement.model.reference.entities.resources.EService;
import org.gcube.resourcemanagement.model.reference.entities.resources.HostingNode; import org.gcube.resourcemanagement.model.reference.entities.resources.HostingNode;
import org.gcube.resourcemanagement.model.reference.entities.resources.RunningPlugin; import org.gcube.resourcemanagement.model.reference.entities.resources.RunningPlugin;
import org.gcube.resourcemanagement.model.reference.relations.consistsof.IsIdentifiedBy; import org.gcube.resourcemanagement.model.reference.relations.consistsof.IsIdentifiedBy;
import org.gcube.resourcemanagement.model.reference.relations.isrelatedto.Activates;
import org.junit.Test; import org.junit.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -34,8 +36,8 @@ public class InvalidOperationTest extends ERManagementTest {
private static Logger logger = LoggerFactory.getLogger(InvalidOperationTest.class); private static Logger logger = LoggerFactory.getLogger(InvalidOperationTest.class);
public static final String ACTIVATES = "{\"propagationConstraint\":{\"@class\":\"PropagationConstraint\",\"add\":\"propagate\",\"remove\":\"cascade\"},\"@class\":\"Activates\",\"source\":{\"header\":{\"@class\":\"Header\",\"uuid\":\"CONFIGURATION_UUID\"},\"@class\":\"Configuration\"},\"target\":{\"header\":{\"@class\":\"Header\",\"uuid\":\"ESERVICE_UUID\"},\"@class\":\"EService\"}}"; public static final String ACTIVATES = "{\"propagationConstraint\":{\"" + Element.TYPE_PROPERTY + "\":\"PropagationConstraint\",\"add\":\"propagate\",\"remove\":\"cascade\",\"delete\":\"cascade\"},\"" + Element.TYPE_PROPERTY + "\":\"Activates\",\"source\":{\"" + Element.TYPE_PROPERTY + "\":\"Configuration\",\"" + IdentifiableElement.ID_PROPERTY + "\":\"CONFIGURATION_UUID\"},\"target\":{\"" + IdentifiableElement.ID_PROPERTY + "\":\"ESERVICE_UUID\",\"" + Element.TYPE_PROPERTY + "\":\"EService\"}}";
public static final String ACTOR = "{\"@class\":\"Actor\",\"header\":null,\"consistsOf\":[{\"@class\":\"IsIdentifiedBy\",\"header\":null,\"propagationConstraint\":{\"@class\":\"PropagationConstraint\",\"remove\":\"cascadeWhenOrphan\",\"add\":\"propagate\"},\"source\":{\"@class\":\"Actor\",\"header\":null},\"target\":{\"@class\":\"ContactFacet\",\"header\":null,\"title\":\"Dr.\",\"name\":\"Frosini\",\"middleName\":null,\"surname\":null,\"eMail\":\"luca.frosini@isti.cnr.it\"}}],\"isRelatedTo\":[]}"; public static final String ACTOR = "{\"" + Element.TYPE_PROPERTY + "\":\"Actor\",\"metadata\":null,\"consistsOf\":[{\"" + Element.TYPE_PROPERTY + "\":\"IsIdentifiedBy\",\"metadata\":null,\"propagationConstraint\":{\"" + Element.TYPE_PROPERTY + "\":\"PropagationConstraint\",\"remove\":\"cascade\",\"delete\":\"cascade\",\"add\":\"propagate\"},\"source\":{\"" + Element.TYPE_PROPERTY + "\":\"Actor\",\"metadata\":null},\"target\":{\"" + Element.TYPE_PROPERTY + "\":\"ContactFacet\",\"metadata\":null,\"title\":\"Dr.\",\"name\":\"Frosini\",\"middleName\":null,\"surname\":null,\"eMail\":\"luca.frosini@isti.cnr.it\"}}],\"isRelatedTo\":[]}";
@Test(expected = SchemaViolationException.class) @Test(expected = SchemaViolationException.class)
public void createInvalidIsRealtedTo() throws Exception { public void createInvalidIsRealtedTo() throws Exception {
@ -54,10 +56,10 @@ public class InvalidOperationTest extends ERManagementTest {
* Here we want to test how the service behave if a client does not behave properly * Here we want to test how the service behave if a client does not behave properly
*/ */
String json = ACTIVATES.replace("CONFIGURATION_UUID", configuration.getHeader().getUUID().toString()); String json = ACTIVATES.replace("CONFIGURATION_UUID", configuration.getID().toString());
json = json.replace("ESERVICE_UUID", eService.getHeader().getUUID().toString()); json = json.replace("ESERVICE_UUID", eService.getID().toString());
resourceRegistryPublisher.create(json); ((ResourceRegistryPublisherImpl)resourceRegistryPublisher).create(Activates.NAME, json, UUIDManager.getInstance().generateValidUUID());
}finally { }finally {
resourceRegistryPublisher.delete(configuration); resourceRegistryPublisher.delete(configuration);
@ -65,17 +67,6 @@ public class InvalidOperationTest extends ERManagementTest {
} }
} }
@Test(expected = ResourceAlreadyPresentException.class)
public void testRecreate() throws Exception {
EService eService = createEService();
try {
resourceRegistryPublisher.create(eService);
}finally {
resourceRegistryPublisher.delete(eService);
}
}
@Test(expected = SchemaViolationException.class) @Test(expected = SchemaViolationException.class)
public void testCreateStandAloneFacet() throws Exception { public void testCreateStandAloneFacet() throws Exception {
CPUFacet cpuFacet = new CPUFacetImpl(); CPUFacet cpuFacet = new CPUFacetImpl();
@ -101,15 +92,9 @@ public class InvalidOperationTest extends ERManagementTest {
resourceRegistryPublisher.create(runningPlugin); resourceRegistryPublisher.create(runningPlugin);
} }
@Test(expected = ResourceRegistryException.class)
public void testCreateAnEntityDifferentFromDeclared() throws Exception {
EService eService = ERManagementTest.instantiateValidEService();
resourceRegistryPublisher.create(eService);
}
@Test(expected = SchemaViolationException.class) @Test(expected = SchemaViolationException.class)
public void testCreateAbstractEntity() throws Exception { public void testCreateAbstractEntity() throws Exception {
resourceRegistryPublisher.create(ACTOR); ((ResourceRegistryPublisherImpl)resourceRegistryPublisher).create(Actor.NAME, ACTOR, UUIDManager.getInstance().generateValidUUID());
} }
@Test(expected = SchemaViolationException.class) @Test(expected = SchemaViolationException.class)
@ -168,14 +153,14 @@ public class InvalidOperationTest extends ERManagementTest {
ERManagementTest erManagementTest = new ERManagementTest(); ERManagementTest erManagementTest = new ERManagementTest();
Map<String, Resource> map = erManagementTest.createHostingNodeAndEService(); Map<String, Resource> map = erManagementTest.createHostingNodeAndEService();
UUID hostingNodeUUID = map.get(HostingNode.NAME).getHeader().getUUID(); UUID hostingNodeUUID = map.get(HostingNode.NAME).getID();
UUID eServiceUUID = map.get(EService.NAME).getHeader().getUUID(); UUID eServiceUUID = map.get(EService.NAME).getID();
HostingNode hostingNode = new HostingNodeImpl(); HostingNode hostingNode = new HostingNodeImpl();
hostingNode.setHeader(new HeaderImpl(hostingNodeUUID)); hostingNode.setID(hostingNodeUUID);
SimpleFacet fakeEServiceAsSimpleFacet = new SimpleFacetImpl(); SimpleFacet fakeEServiceAsSimpleFacet = new SimpleFacetImpl();
fakeEServiceAsSimpleFacet.setHeader(new HeaderImpl(eServiceUUID)); fakeEServiceAsSimpleFacet.setID(eServiceUUID);
ConsistsOf<HostingNode, SimpleFacet> consistsOf = new ConsistsOfImpl<HostingNode, SimpleFacet>(hostingNode, fakeEServiceAsSimpleFacet); ConsistsOf<HostingNode, SimpleFacet> consistsOf = new ConsistsOfImpl<HostingNode, SimpleFacet>(hostingNode, fakeEServiceAsSimpleFacet);
@ -183,7 +168,7 @@ public class InvalidOperationTest extends ERManagementTest {
String json = ElementMapper.marshal(consistsOf); String json = ElementMapper.marshal(consistsOf);
json = json.replaceAll(SimpleFacet.NAME, EService.NAME); json = json.replaceAll(SimpleFacet.NAME, EService.NAME);
resourceRegistryPublisher.create(json); ((ResourceRegistryPublisherImpl)resourceRegistryPublisher).create(ConsistsOf.NAME, json, UUIDManager.getInstance().generateValidUUID());
throw new Exception("A ConsistsOf has been created between two resoures. This should not happen"); throw new Exception("A ConsistsOf has been created between two resoures. This should not happen");
} finally { } finally {
resourceRegistryPublisher.delete(map.get(EService.NAME)); resourceRegistryPublisher.delete(map.get(EService.NAME));

View File

@ -0,0 +1,46 @@
/**
*
*/
package org.gcube.informationsystem.resourceregistry.publisher;
import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* To properly use thois test you must comment
* gcube-model dependency
* @author Luca Frosini (ISTI - CNR)
*/
public class NoGcubeModelTest extends ContextTest {
private static Logger logger = LoggerFactory.getLogger(NoGcubeModelTest.class);
public static final String GROUP = "InformationSystem";
public static final String NAME = "resource-registry";
public static final String VERSION = "1.0.0";
public static final String NEW_VERSION = "2.0.0";
protected ResourceRegistryPublisher resourceRegistryPublisher;
public NoGcubeModelTest() {
Object rrURLOBj = ContextTest.properties.get(RESOURCE_REGISTRY_URL_PROPERTY);
if(rrURLOBj!=null && !rrURLOBj.toString().isEmpty()) {
resourceRegistryPublisher = new ResourceRegistryPublisherImpl(rrURLOBj.toString());
}else {
resourceRegistryPublisher = ResourceRegistryPublisherFactory.create();
}
resourceRegistryPublisher.setIncludeMeta(true);
resourceRegistryPublisher.setAllMeta(true);
}
@Ignore
@Test
public void testCreateResourceFromJson() throws Exception {
String json = "{\"type\":\"VirtualService\",\"consistsOf\":[{\"type\":\"IsIdentifiedBy\",\"target\":{\"name\":\"aaaaaa\",\"optional\":\"true\",\"group\":\"xxxxx\",\"description\":\"\",\"version\":\"cvcvvv\",\"qualifier\":\"\",\"type\":\"SoftwareFacet\",\"aaaa\":\"dddddd\"}}]}";
String ret = resourceRegistryPublisher.createResource(json);
logger.info(ret);
}
}

View File

@ -32,16 +32,15 @@ import javax.management.MalformedObjectNameException;
import javax.management.ObjectName; import javax.management.ObjectName;
import javax.management.ReflectionException; import javax.management.ReflectionException;
import org.gcube.informationsystem.model.impl.properties.HeaderImpl;
import org.gcube.informationsystem.model.impl.properties.PropagationConstraintImpl; import org.gcube.informationsystem.model.impl.properties.PropagationConstraintImpl;
import org.gcube.informationsystem.model.impl.relations.ConsistsOfImpl; import org.gcube.informationsystem.model.impl.relations.ConsistsOfImpl;
import org.gcube.informationsystem.model.reference.entities.Facet; import org.gcube.informationsystem.model.reference.entities.Facet;
import org.gcube.informationsystem.model.reference.entities.Resource; import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.model.reference.properties.Header;
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint; import org.gcube.informationsystem.model.reference.properties.PropagationConstraint;
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.RemoveConstraint; import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.RemoveConstraint;
import org.gcube.informationsystem.model.reference.relations.ConsistsOf; import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
import org.gcube.informationsystem.utils.UUIDManager;
import org.gcube.resourcemanagement.model.impl.entities.facets.CPUFacetImpl; import org.gcube.resourcemanagement.model.impl.entities.facets.CPUFacetImpl;
import org.gcube.resourcemanagement.model.impl.entities.facets.EventFacetImpl; import org.gcube.resourcemanagement.model.impl.entities.facets.EventFacetImpl;
import org.gcube.resourcemanagement.model.impl.entities.facets.MemoryFacetImpl; import org.gcube.resourcemanagement.model.impl.entities.facets.MemoryFacetImpl;
@ -86,8 +85,9 @@ public class SmartgearResourcesTest extends ERManagementTest {
protected ResourceRegistryPublisher resourceRegistryPublisher; protected ResourceRegistryPublisher resourceRegistryPublisher;
public SmartgearResourcesTest() { public SmartgearResourcesTest() {
if(ContextTest.RESOURCE_REGISTRY_URL !=null && !ContextTest.RESOURCE_REGISTRY_URL.isEmpty()) { Object rrURLOBj = ContextTest.properties.get(RESOURCE_REGISTRY_URL_PROPERTY);
resourceRegistryPublisher = new ResourceRegistryPublisherImpl(ContextTest.RESOURCE_REGISTRY_URL); if(rrURLOBj!=null && !rrURLOBj.toString().isEmpty()) {
resourceRegistryPublisher = new ResourceRegistryPublisherImpl(rrURLOBj.toString());
}else { }else {
resourceRegistryPublisher = ResourceRegistryPublisherFactory.create(); resourceRegistryPublisher = ResourceRegistryPublisherFactory.create();
} }
@ -96,11 +96,10 @@ public class SmartgearResourcesTest extends ERManagementTest {
@Test @Test
public void testHostingNodeOperations() throws ResourceRegistryException, public void testHostingNodeOperations() throws ResourceRegistryException,
IOException, URISyntaxException { IOException, URISyntaxException {
UUID uuid = UUID.randomUUID(); UUID uuid = UUIDManager.getInstance().generateValidUUID();
HostingNode hostingNode = new HostingNodeImpl(); HostingNode hostingNode = new HostingNodeImpl();
Header header = new HeaderImpl(uuid); hostingNode.setID(uuid);
hostingNode.setHeader(header);
NetworkingFacet networkingFacet = new NetworkingFacetImpl(); NetworkingFacet networkingFacet = new NetworkingFacetImpl();
try { try {

View File

@ -14,20 +14,20 @@ import java.util.UUID;
import org.gcube.common.encryption.encrypter.StringEncrypter; import org.gcube.common.encryption.encrypter.StringEncrypter;
import org.gcube.informationsystem.base.reference.Direction; import org.gcube.informationsystem.base.reference.Direction;
import org.gcube.informationsystem.model.impl.properties.EncryptedImpl;
import org.gcube.informationsystem.model.impl.properties.PropagationConstraintImpl; import org.gcube.informationsystem.model.impl.properties.PropagationConstraintImpl;
import org.gcube.informationsystem.model.impl.properties.VaultImpl;
import org.gcube.informationsystem.model.impl.relations.ConsistsOfImpl; import org.gcube.informationsystem.model.impl.relations.ConsistsOfImpl;
import org.gcube.informationsystem.model.reference.entities.Facet; import org.gcube.informationsystem.model.reference.entities.Facet;
import org.gcube.informationsystem.model.reference.entities.Resource; import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.model.reference.properties.Encrypted;
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint; import org.gcube.informationsystem.model.reference.properties.PropagationConstraint;
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.AddConstraint; import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.AddConstraint;
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.DeleteConstraint; import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.DeleteConstraint;
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.RemoveConstraint; import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.RemoveConstraint;
import org.gcube.informationsystem.model.reference.properties.Vault;
import org.gcube.informationsystem.model.reference.relations.ConsistsOf; import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
import org.gcube.informationsystem.model.reference.relations.IsRelatedTo; import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
import org.gcube.informationsystem.model.reference.relations.Relation;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaViolationException;
import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClient; import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClient;
import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClientFactory; import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClientFactory;
import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClientImpl; import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClientImpl;
@ -40,23 +40,30 @@ import org.gcube.resourcemanagement.model.impl.entities.facets.AccessPointFacetI
import org.gcube.resourcemanagement.model.impl.entities.facets.CPUFacetImpl; import org.gcube.resourcemanagement.model.impl.entities.facets.CPUFacetImpl;
import org.gcube.resourcemanagement.model.impl.entities.facets.EventFacetImpl; import org.gcube.resourcemanagement.model.impl.entities.facets.EventFacetImpl;
import org.gcube.resourcemanagement.model.impl.entities.facets.LicenseFacetImpl; import org.gcube.resourcemanagement.model.impl.entities.facets.LicenseFacetImpl;
import org.gcube.resourcemanagement.model.impl.entities.facets.MemoryFacetImpl;
import org.gcube.resourcemanagement.model.impl.entities.facets.NetworkingFacetImpl; import org.gcube.resourcemanagement.model.impl.entities.facets.NetworkingFacetImpl;
import org.gcube.resourcemanagement.model.impl.entities.facets.SoftwareFacetImpl; import org.gcube.resourcemanagement.model.impl.entities.facets.SoftwareFacetImpl;
import org.gcube.resourcemanagement.model.impl.entities.facets.StateFacetImpl; import org.gcube.resourcemanagement.model.impl.entities.facets.StateFacetImpl;
import org.gcube.resourcemanagement.model.impl.entities.resources.EServiceImpl; import org.gcube.resourcemanagement.model.impl.entities.resources.EServiceImpl;
import org.gcube.resourcemanagement.model.impl.entities.resources.HostingNodeImpl; import org.gcube.resourcemanagement.model.impl.entities.resources.HostingNodeImpl;
import org.gcube.resourcemanagement.model.impl.relations.consistsof.HasPersistentMemoryImpl;
import org.gcube.resourcemanagement.model.impl.relations.consistsof.HasVolatileMemoryImpl;
import org.gcube.resourcemanagement.model.impl.relations.consistsof.IsIdentifiedByImpl; import org.gcube.resourcemanagement.model.impl.relations.consistsof.IsIdentifiedByImpl;
import org.gcube.resourcemanagement.model.impl.relations.isrelatedto.ActivatesImpl; import org.gcube.resourcemanagement.model.impl.relations.isrelatedto.ActivatesImpl;
import org.gcube.resourcemanagement.model.reference.entities.facets.AccessPointFacet; import org.gcube.resourcemanagement.model.reference.entities.facets.AccessPointFacet;
import org.gcube.resourcemanagement.model.reference.entities.facets.CPUFacet; import org.gcube.resourcemanagement.model.reference.entities.facets.CPUFacet;
import org.gcube.resourcemanagement.model.reference.entities.facets.EventFacet; import org.gcube.resourcemanagement.model.reference.entities.facets.EventFacet;
import org.gcube.resourcemanagement.model.reference.entities.facets.LicenseFacet; import org.gcube.resourcemanagement.model.reference.entities.facets.LicenseFacet;
import org.gcube.resourcemanagement.model.reference.entities.facets.MemoryFacet;
import org.gcube.resourcemanagement.model.reference.entities.facets.MemoryFacet.MemoryUnit;
import org.gcube.resourcemanagement.model.reference.entities.facets.NetworkingFacet; import org.gcube.resourcemanagement.model.reference.entities.facets.NetworkingFacet;
import org.gcube.resourcemanagement.model.reference.entities.facets.SoftwareFacet; import org.gcube.resourcemanagement.model.reference.entities.facets.SoftwareFacet;
import org.gcube.resourcemanagement.model.reference.entities.facets.StateFacet; import org.gcube.resourcemanagement.model.reference.entities.facets.StateFacet;
import org.gcube.resourcemanagement.model.reference.entities.resources.EService; import org.gcube.resourcemanagement.model.reference.entities.resources.EService;
import org.gcube.resourcemanagement.model.reference.entities.resources.GCubeResource; import org.gcube.resourcemanagement.model.reference.entities.resources.GCubeResource;
import org.gcube.resourcemanagement.model.reference.entities.resources.HostingNode; import org.gcube.resourcemanagement.model.reference.entities.resources.HostingNode;
import org.gcube.resourcemanagement.model.reference.relations.consistsof.HasPersistentMemory;
import org.gcube.resourcemanagement.model.reference.relations.consistsof.HasVolatileMemory;
import org.gcube.resourcemanagement.model.reference.relations.consistsof.IsIdentifiedBy; import org.gcube.resourcemanagement.model.reference.relations.consistsof.IsIdentifiedBy;
import org.gcube.resourcemanagement.model.reference.relations.isrelatedto.Activates; import org.gcube.resourcemanagement.model.reference.relations.isrelatedto.Activates;
import org.junit.Assert; import org.junit.Assert;
@ -77,9 +84,10 @@ public class ERManagementTest extends ContextTest {
protected ResourceRegistryClient resourceRegistryClient; protected ResourceRegistryClient resourceRegistryClient;
public ERManagementTest() { public ERManagementTest() {
if(ContextTest.RESOURCE_REGISTRY_URL !=null && !ContextTest.RESOURCE_REGISTRY_URL.isEmpty()) { Object rrURLOBj = ContextTest.properties.get(RESOURCE_REGISTRY_URL_PROPERTY);
resourceRegistryPublisher = new ResourceRegistryPublisherImpl(ContextTest.RESOURCE_REGISTRY_URL); if(rrURLOBj!=null && !rrURLOBj.toString().isEmpty()) {
resourceRegistryClient = new ResourceRegistryClientImpl(ContextTest.RESOURCE_REGISTRY_URL); resourceRegistryPublisher = new ResourceRegistryPublisherImpl(rrURLOBj.toString());
resourceRegistryClient = new ResourceRegistryClientImpl(rrURLOBj.toString());
}else { }else {
resourceRegistryPublisher = ResourceRegistryPublisherFactory.create(); resourceRegistryPublisher = ResourceRegistryPublisherFactory.create();
resourceRegistryClient = ResourceRegistryClientFactory.create(); resourceRegistryClient = ResourceRegistryClientFactory.create();
@ -89,19 +97,39 @@ public class ERManagementTest extends ContextTest {
@Test @Test
public void testEncrypted() throws Exception { public void testEncrypted() throws Exception {
EService eService = new EServiceImpl(); EService eService = new EServiceImpl();
AccessPointFacet accessPointFacet = new AccessPointFacetImpl(); AccessPointFacet accessPointFacet = new AccessPointFacetImpl();
URL endpoint = new URL("https://d4science.org:443"); URL endpoint = new URL("https://d4science.org:443");
accessPointFacet.setEndpoint(endpoint.toURI()); accessPointFacet.setEndpoint(endpoint.toURI());
Vault encrypted = new VaultImpl(); Encrypted encrypted = new EncryptedImpl();
encrypted.setValue(StringEncrypter.getEncrypter().encrypt("1")); encrypted.setValue(StringEncrypter.getEncrypter().encrypt("1"));
accessPointFacet.setAdditionalProperty(PASSWORD, encrypted); accessPointFacet.setAdditionalProperty(PASSWORD, encrypted);
eService.addFacet(accessPointFacet); eService.addFacet(accessPointFacet);
SoftwareFacet softwareFacet = new SoftwareFacetImpl();
softwareFacet.setGroup("InformationSystem");
softwareFacet.setName("resource-registry");
softwareFacet.setVersion("1.1.0");
IsIdentifiedBy<Resource,Facet> isIdentifiedBy = new IsIdentifiedByImpl<Resource,Facet>(eService, softwareFacet,
null);
eService.addFacet(isIdentifiedBy);
EventFacet eventFacet = new EventFacetImpl();
eventFacet.setDate(Calendar.getInstance().getTime());
eventFacet.setEvent("Created");
eService.addFacet(eventFacet);
StateFacet stateFacet = new StateFacetImpl();
stateFacet.setValue("ready");
eService.addFacet(stateFacet);
ResourceRegistryPublisher resourceRegistryPublisher = ResourceRegistryPublisherFactory.create(); ResourceRegistryPublisher resourceRegistryPublisher = ResourceRegistryPublisherFactory.create();
EService receivedEservice = resourceRegistryPublisher.create(eService); EService receivedEservice = resourceRegistryPublisher.create(eService);
AccessPointFacet receivedFacet = (AccessPointFacet) receivedEservice.getFacets().get(0);
UUID eServiceUUID = receivedEservice.getHeader().getUUID(); AccessPointFacet receivedFacet = (AccessPointFacet) receivedEservice.getFacets(AccessPointFacet.class).get(0);
UUID facetUUID = receivedFacet.getHeader().getUUID(); UUID eServiceUUID = receivedEservice.getID();
UUID facetUUID = receivedFacet.getID();
logger.debug("Created {} : {}", EService.NAME, ElementMapper.marshal(receivedEservice)); logger.debug("Created {} : {}", EService.NAME, ElementMapper.marshal(receivedEservice));
@ -114,14 +142,14 @@ public class ERManagementTest extends ContextTest {
receivedEservice = resourceRegistryPublisher.read(receivedEservice); receivedEservice = resourceRegistryPublisher.read(receivedEservice);
logger.debug("Read {} : {}", EService.NAME, ElementMapper.marshal(receivedEservice)); logger.debug("Read {} : {}", EService.NAME, ElementMapper.marshal(receivedEservice));
} }
UUID receivedEServiceUUID = receivedEservice.getHeader().getUUID(); UUID receivedEServiceUUID = receivedEservice.getID();
Assert.assertTrue(eServiceUUID.compareTo(receivedEServiceUUID)==0); Assert.assertTrue(eServiceUUID.compareTo(receivedEServiceUUID)==0);
receivedFacet = (AccessPointFacet) receivedEservice.getFacets().get(0); receivedFacet = (AccessPointFacet) receivedEservice.getFacets(AccessPointFacet.class).get(0);
UUID receivedFacetUUID = receivedFacet.getHeader().getUUID(); UUID receivedFacetUUID = receivedFacet.getID();
Assert.assertTrue(facetUUID.compareTo(receivedFacetUUID)==0); Assert.assertTrue(facetUUID.compareTo(receivedFacetUUID)==0);
Vault receivedEncrypted = (Vault) receivedFacet.getAdditionalProperty(PASSWORD); Encrypted receivedEncrypted = (Encrypted) receivedFacet.getAdditionalProperty(PASSWORD);
Assert.assertTrue(encrypted.getValue().compareTo(receivedEncrypted.getValue())==0); Assert.assertTrue(encrypted.getValue().compareTo(receivedEncrypted.getValue())==0);
} catch(ResourceRegistryException e) { } catch(ResourceRegistryException e) {
logger.error("", e); logger.error("", e);
@ -300,56 +328,6 @@ public class ERManagementTest extends ContextTest {
Assert.assertTrue(deleted); Assert.assertTrue(deleted);
} }
@Test
public void testCreateReadDeleteFacet() throws Exception {
CPUFacet cpuFacet = new CPUFacetImpl();
cpuFacet.setClockSpeed("1 GHz");
cpuFacet.setModel("Opteron");
cpuFacet.setVendor("AMD");
CPUFacet createdCpuFacet = resourceRegistryPublisher.createFacet(cpuFacet);
Assert.assertTrue(cpuFacet.getClockSpeed().compareTo(createdCpuFacet.getClockSpeed()) == 0);
Assert.assertTrue(cpuFacet.getModel().compareTo(createdCpuFacet.getModel()) == 0);
Assert.assertTrue(cpuFacet.getVendor().compareTo(createdCpuFacet.getVendor()) == 0);
UUID uuid = createdCpuFacet.getHeader().getUUID();
CPUFacet readCpuFacet = resourceRegistryClient.getInstance(CPUFacet.class, uuid);
Assert.assertTrue(cpuFacet.getClockSpeed().compareTo(readCpuFacet.getClockSpeed()) == 0);
Assert.assertTrue(cpuFacet.getModel().compareTo(readCpuFacet.getModel()) == 0);
Assert.assertTrue(cpuFacet.getVendor().compareTo(readCpuFacet.getVendor()) == 0);
Assert.assertTrue(uuid.compareTo(readCpuFacet.getHeader().getUUID()) == 0);
String newVendor = "Intel";
String newClockSpeed = "2 GHz";
readCpuFacet.setVendor(newVendor);
readCpuFacet.setClockSpeed(newClockSpeed);
String additionPropertyKey = "My";
String additionPropertyValue = "Test";
readCpuFacet.setAdditionalProperty(additionPropertyKey, additionPropertyValue);
CPUFacet updatedCpuFacet = resourceRegistryPublisher.updateFacet(readCpuFacet);
Assert.assertTrue(readCpuFacet.getClockSpeed().compareTo(updatedCpuFacet.getClockSpeed()) == 0);
Assert.assertTrue(readCpuFacet.getModel().compareTo(updatedCpuFacet.getModel()) == 0);
Assert.assertTrue(readCpuFacet.getVendor().compareTo(updatedCpuFacet.getVendor()) == 0);
Assert.assertTrue(((String) updatedCpuFacet.getAdditionalProperty(additionPropertyKey))
.compareTo((String) readCpuFacet.getAdditionalProperty(additionPropertyKey)) == 0);
Assert.assertTrue(uuid.compareTo(updatedCpuFacet.getHeader().getUUID()) == 0);
CPUFacet readUpdatedCpuFacet = resourceRegistryClient.getInstance(CPUFacet.class, uuid);
Assert.assertTrue(updatedCpuFacet.getClockSpeed().compareTo(readUpdatedCpuFacet.getClockSpeed()) == 0);
Assert.assertTrue(updatedCpuFacet.getModel().compareTo(readUpdatedCpuFacet.getModel()) == 0);
Assert.assertTrue(updatedCpuFacet.getVendor().compareTo(readUpdatedCpuFacet.getVendor()) == 0);
Assert.assertTrue(((String) updatedCpuFacet.getAdditionalProperty(additionPropertyKey))
.compareTo((String) readUpdatedCpuFacet.getAdditionalProperty(additionPropertyKey)) == 0);
Assert.assertTrue(uuid.compareTo(updatedCpuFacet.getHeader().getUUID()) == 0);
boolean deleted = resourceRegistryPublisher.deleteFacet(readUpdatedCpuFacet);
Assert.assertTrue(deleted);
}
public Map<String,Resource> createHostingNodeAndEService() throws Exception { public Map<String,Resource> createHostingNodeAndEService() throws Exception {
Map<String,Resource> map = new HashMap<>(); Map<String,Resource> map = new HashMap<>();
@ -364,29 +342,71 @@ public class ERManagementTest extends ContextTest {
null); null);
eService.addFacet(isIdentifiedBy); eService.addFacet(isIdentifiedBy);
AccessPointFacet accessPointFacet = new AccessPointFacetImpl();
accessPointFacet.setEndpoint(new URI("https://localhost"));
accessPointFacet.setEntryName("port1");
eService.addFacet(accessPointFacet);
EventFacet eventFacet = new EventFacetImpl();
eventFacet.setDate(Calendar.getInstance().getTime());
eventFacet.setEvent("Created");
eService.addFacet(eventFacet);
StateFacet stateFacet = new StateFacetImpl();
stateFacet.setValue("ready");
eService.addFacet(stateFacet);
eService = resourceRegistryPublisher.createResource(eService); eService = resourceRegistryPublisher.createResource(eService);
map.put(EService.NAME, eService); map.put(EService.NAME, eService);
// networkingFacet = resourceRegistryPublisher.createFacet(networkingFacet);
// logger.debug("Unmarshalled {} {}", NetworkingFacet.NAME, networkingFacet);
HostingNode hostingNode = new HostingNodeImpl();
NetworkingFacet networkingFacet = new NetworkingFacetImpl(); NetworkingFacet networkingFacet = new NetworkingFacetImpl();
networkingFacet.setIPAddress("146.48.87.183"); networkingFacet.setIPAddress("146.48.87.183");
networkingFacet.setHostName("pc-frosini.isti.cnr.it"); networkingFacet.setHostName("pc-frosini.isti.cnr.it");
networkingFacet.setDomainName("isti.cnr.it"); networkingFacet.setDomainName("isti.cnr.it");
networkingFacet.setMask("255.255.248.0"); networkingFacet.setMask("255.255.248.0");
networkingFacet.setBroadcastAddress("146.48.87.255"); networkingFacet.setBroadcastAddress("146.48.87.255");
networkingFacet = resourceRegistryPublisher.createFacet(networkingFacet); isIdentifiedBy = new IsIdentifiedByImpl<Resource,Facet>(hostingNode, networkingFacet, null);
logger.debug("Unmarshalled {} {}", NetworkingFacet.NAME, networkingFacet); hostingNode.addFacet(isIdentifiedBy);
HostingNode hostingNode = new HostingNodeImpl();
CPUFacet cpuFacet = new CPUFacetImpl(); CPUFacet cpuFacet = new CPUFacetImpl();
cpuFacet.setClockSpeed("1 GHz"); cpuFacet.setClockSpeed("1 GHz");
cpuFacet.setModel("Opteron"); cpuFacet.setModel("Opteron");
cpuFacet.setVendor("AMD"); cpuFacet.setVendor("AMD");
hostingNode.addFacet(cpuFacet); hostingNode.addFacet(cpuFacet);
isIdentifiedBy = new IsIdentifiedByImpl<Resource,Facet>(hostingNode, networkingFacet, null); MemoryFacet ram = new MemoryFacetImpl();
hostingNode.addFacet(isIdentifiedBy); ram.setSize(8);
ram.setUnit(MemoryUnit.GB);
ram.setUsed(2);
HasVolatileMemory<HostingNode, MemoryFacet> hasVolatileMemory =
new HasVolatileMemoryImpl<HostingNode, MemoryFacet>(hostingNode, ram, null);
hostingNode.addFacet(hasVolatileMemory);
MemoryFacet disk = new MemoryFacetImpl();
disk.setSize(256);
disk.setUnit(MemoryUnit.GB);
disk.setUsed(120);
HasPersistentMemory<HostingNode, MemoryFacet> hasPersistentMemory =
new HasPersistentMemoryImpl<HostingNode, MemoryFacet>(hostingNode, disk, null);
hostingNode.addFacet(hasPersistentMemory);
StateFacet hnStateFacet = new StateFacetImpl();
hnStateFacet.setValue("certified");
hostingNode.addFacet(hnStateFacet);
EventFacet hnEventFacet = new EventFacetImpl();
hnEventFacet.setDate(Calendar.getInstance().getTime());
hnEventFacet.setEvent("Created");
hostingNode.addFacet(hnEventFacet);
PropagationConstraint propagationConstraint = new PropagationConstraintImpl(); PropagationConstraint propagationConstraint = new PropagationConstraintImpl();
propagationConstraint.setDeleteConstraint(DeleteConstraint.cascade); propagationConstraint.setDeleteConstraint(DeleteConstraint.cascade);
@ -423,57 +443,27 @@ public class ERManagementTest extends ContextTest {
HostingNode hostingNode = (HostingNode) map.get(HostingNode.NAME); HostingNode hostingNode = (HostingNode) map.get(HostingNode.NAME);
Facet shared = hostingNode.getConsistsOf().get(0).getTarget(); Facet shared = hostingNode.getConsistsOf().get(0).getTarget();
UUID sharedFacetUUID = shared.getHeader().getUUID(); UUID sharedFacetUUID = shared.getID();
ConsistsOf<EService,Facet> consistsOf = new ConsistsOfImpl<EService,Facet>(eService, shared, null);
consistsOf = resourceRegistryPublisher.createConsistsOf(consistsOf);
boolean deleted = resourceRegistryPublisher.deleteResource(map.get(EService.NAME));
Assert.assertTrue(deleted);
deleted = resourceRegistryPublisher.deleteResource(map.get(HostingNode.NAME));
Assert.assertTrue(deleted);
try { try {
resourceRegistryClient.getInstance(Facet.class, sharedFacetUUID); ConsistsOf<EService,Facet> consistsOf = new ConsistsOfImpl<EService,Facet>(eService, shared, null);
throw new Exception(String.format("Shared Facet %s was not deleted", shared)); consistsOf = resourceRegistryPublisher.createConsistsOf(consistsOf);
} catch(ResourceRegistryException e) { } catch (SchemaViolationException e) {
logger.debug("Shared Facet was not foud as expected"); logger.debug("As expected ", e);
} finally {
boolean deleted = resourceRegistryPublisher.deleteResource(map.get(EService.NAME));
Assert.assertTrue(deleted);
deleted = resourceRegistryPublisher.deleteResource(map.get(HostingNode.NAME));
Assert.assertTrue(deleted);
try {
resourceRegistryClient.getInstance(Facet.class, sharedFacetUUID);
throw new Exception(String.format("Shared Facet %s was not deleted", shared));
} catch(ResourceRegistryException e) {
logger.debug("Shared Facet was not found as expected");
}
} }
}
@Test
public void testCreateResourceAndFacet() throws Exception {
HostingNode hostingNode = new HostingNodeImpl();
hostingNode = resourceRegistryPublisher.createResource(hostingNode);
CPUFacet cpuFacet = new CPUFacetImpl();
cpuFacet.setClockSpeed("1 GHz");
cpuFacet.setModel("Opteron");
cpuFacet.setVendor("AMD");
CPUFacet createdCpuFacet = resourceRegistryPublisher.createFacet(cpuFacet);
ConsistsOf<HostingNode,Facet> consistsOf = new ConsistsOfImpl<HostingNode,Facet>(hostingNode, createdCpuFacet,
null);
consistsOf = resourceRegistryPublisher.createConsistsOf(consistsOf);
UUID consistOfUUID = consistsOf.getHeader().getUUID();
boolean detached = resourceRegistryPublisher.deleteConsistsOf(consistsOf);
if(detached) {
logger.trace("{} {} with uuid {} removed successfully", ConsistsOf.NAME, Relation.NAME, consistOfUUID);
} else {
String error = String.format("Unable to remove %s %s with uuid %s", ConsistsOf.NAME, Relation.NAME,
consistOfUUID);
logger.error(error);
throw new Exception(error);
}
boolean deleted = resourceRegistryPublisher.deleteResource(hostingNode);
Assert.assertTrue(deleted);
} }
@ -550,23 +540,23 @@ public class ERManagementTest extends ContextTest {
Map<String,Resource> map = createHostingNodeAndEService(); Map<String,Resource> map = createHostingNodeAndEService();
EService eService = (EService) map.get(EService.NAME); EService eService = (EService) map.get(EService.NAME);
UUID eServiceUUID = eService.getHeader().getUUID(); UUID eServiceUUID = eService.getID();
HostingNode hostingNode = (HostingNode) map.get(HostingNode.NAME); HostingNode hostingNode = (HostingNode) map.get(HostingNode.NAME);
UUID hostingNodeUUID = hostingNode.getHeader().getUUID(); UUID hostingNodeUUID = hostingNode.getID();
/* EService */ /* EService */
List<Resource> resourceList = resourceRegistryClient.getRelatedResourcesFromReferenceResource(Resource.class, List<Resource> resourceList = resourceRegistryClient.getRelatedResourcesFromReferenceResource(Resource.class,
IsRelatedTo.class, EService.class, eServiceUUID, Direction.BOTH, true); IsRelatedTo.class, EService.class, eServiceUUID, Direction.BOTH, true);
Assert.assertTrue(resourceList.size() == 1); Assert.assertTrue(resourceList.size() == 1);
Resource resource = resourceList.get(0); Resource resource = resourceList.get(0);
Assert.assertTrue(resource.getHeader().getUUID().compareTo(hostingNodeUUID) == 0); Assert.assertTrue(resource.getID().compareTo(hostingNodeUUID) == 0);
resourceList = resourceRegistryClient.getRelatedResourcesFromReferenceResource(Resource.class, resourceList = resourceRegistryClient.getRelatedResourcesFromReferenceResource(Resource.class,
IsRelatedTo.class, EService.class, eServiceUUID, Direction.OUT, true); IsRelatedTo.class, EService.class, eServiceUUID, Direction.OUT, true);
Assert.assertTrue(resourceList.size() == 1); Assert.assertTrue(resourceList.size() == 1);
resource = resourceList.get(0); resource = resourceList.get(0);
Assert.assertTrue(resource.getHeader().getUUID().compareTo(hostingNodeUUID) == 0); Assert.assertTrue(resource.getID().compareTo(hostingNodeUUID) == 0);
resourceList = resourceRegistryClient.getRelatedResourcesFromReferenceResource(Resource.class, resourceList = resourceRegistryClient.getRelatedResourcesFromReferenceResource(Resource.class,
IsRelatedTo.class, EService.class, eServiceUUID, Direction.IN, true); IsRelatedTo.class, EService.class, eServiceUUID, Direction.IN, true);
@ -590,7 +580,7 @@ public class ERManagementTest extends ContextTest {
IsRelatedTo.class, HostingNode.class, hostingNodeUUID, Direction.BOTH, true); IsRelatedTo.class, HostingNode.class, hostingNodeUUID, Direction.BOTH, true);
Assert.assertTrue(resourceList.size() == 1); Assert.assertTrue(resourceList.size() == 1);
resource = resourceList.get(0); resource = resourceList.get(0);
Assert.assertTrue(resource.getHeader().getUUID().compareTo(eServiceUUID) == 0); Assert.assertTrue(resource.getID().compareTo(eServiceUUID) == 0);
resourceList = resourceRegistryClient.getRelatedResourcesFromReferenceResource(Resource.class, resourceList = resourceRegistryClient.getRelatedResourcesFromReferenceResource(Resource.class,
IsRelatedTo.class, HostingNode.class, hostingNodeUUID, Direction.OUT, true); IsRelatedTo.class, HostingNode.class, hostingNodeUUID, Direction.OUT, true);
@ -600,7 +590,7 @@ public class ERManagementTest extends ContextTest {
IsRelatedTo.class, HostingNode.class, hostingNodeUUID, Direction.IN, true); IsRelatedTo.class, HostingNode.class, hostingNodeUUID, Direction.IN, true);
Assert.assertTrue(resourceList.size() == 1); Assert.assertTrue(resourceList.size() == 1);
resource = resourceList.get(0); resource = resourceList.get(0);
Assert.assertTrue(resource.getHeader().getUUID().compareTo(eServiceUUID) == 0); Assert.assertTrue(resource.getID().compareTo(eServiceUUID) == 0);
resourceList = resourceRegistryClient.getRelatedResourcesFromReferenceResource(Resource.class, resourceList = resourceRegistryClient.getRelatedResourcesFromReferenceResource(Resource.class,
IsRelatedTo.class, HostingNode.class, hostingNodeUUID, Direction.BOTH, false); IsRelatedTo.class, HostingNode.class, hostingNodeUUID, Direction.BOTH, false);
@ -616,8 +606,7 @@ public class ERManagementTest extends ContextTest {
/* END HostingNode */ /* END HostingNode */
Facet identificationFacet = eService.getIdentificationFacets().get(0); Facet identificationFacet = eService.getIdentificationFacets().get(0);
UUID identificationFacetUUID = identificationFacet.getHeader().getUUID(); UUID identificationFacetUUID = identificationFacet.getID();
/* Eservice with Software Facet as Identification Facet */ /* Eservice with Software Facet as Identification Facet */
@ -625,8 +614,8 @@ public class ERManagementTest extends ContextTest {
Assert.assertTrue(resourceList.size() == 1); Assert.assertTrue(resourceList.size() == 1);
resource = resourceList.get(0); resource = resourceList.get(0);
Facet targetIdentificationFacet = ((GCubeResource) resource).getIdentificationFacets().get(0); Facet targetIdentificationFacet = ((GCubeResource) resource).getIdentificationFacets().get(0);
Assert.assertTrue(resource.getHeader().getUUID().compareTo(eServiceUUID) == 0); Assert.assertTrue(resource.getID().compareTo(eServiceUUID) == 0);
Assert.assertTrue(targetIdentificationFacet.getHeader().getUUID().compareTo(identificationFacetUUID) == 0); Assert.assertTrue(targetIdentificationFacet.getID().compareTo(identificationFacetUUID) == 0);
resourceList = resourceRegistryClient.getResourcesFromReferenceFacet(Resource.class, ConsistsOf.class, SoftwareFacet.class, identificationFacetUUID, false); resourceList = resourceRegistryClient.getResourcesFromReferenceFacet(Resource.class, ConsistsOf.class, SoftwareFacet.class, identificationFacetUUID, false);
Assert.assertTrue(resourceList.size() == 0); Assert.assertTrue(resourceList.size() == 0);
@ -639,7 +628,7 @@ public class ERManagementTest extends ContextTest {
List<Facet> facets = resourceRegistryClient.getRelated(Facet.class, ConsistsOf.class, EService.class, eServiceUUID, Direction.in, true); List<Facet> facets = resourceRegistryClient.getRelated(Facet.class, ConsistsOf.class, EService.class, eServiceUUID, Direction.in, true);
Assert.assertTrue(resourceList.size() == 1); Assert.assertTrue(resourceList.size() == 1);
Facet facet = facets.get(0); Facet facet = facets.get(0);
Assert.assertTrue(facet.getHeader().getUUID().compareTo(identificationFacetUUID) == 0); Assert.assertTrue(facet.getUUID().compareTo(identificationFacetUUID) == 0);
facets = resourceRegistryClient.getRelated(Facet.class, ConsistsOf.class, EService.class, eServiceUUID, Direction.in, false); facets = resourceRegistryClient.getRelated(Facet.class, ConsistsOf.class, EService.class, eServiceUUID, Direction.in, false);
Assert.assertTrue(resourceList.size() == 0); Assert.assertTrue(resourceList.size() == 0);
@ -654,39 +643,13 @@ public class ERManagementTest extends ContextTest {
@Test @Test
public void testCreateHostingNodeThenActivatesWithEService() throws Exception { public void testCreateHostingNodeThenActivatesWithEService() throws Exception {
HostingNode hostingNode = new HostingNodeImpl(); HostingNode hostingNode = org.gcube.informationsystem.resourceregistry.publisher.ERManagementTest.instantiateValidHostingNode();
CPUFacet cpuFacet = new CPUFacetImpl();
cpuFacet.setClockSpeed("1 GHz");
cpuFacet.setModel("Opteron");
cpuFacet.setVendor("AMD");
hostingNode.addFacet(cpuFacet);
NetworkingFacet networkingFacet = new NetworkingFacetImpl();
networkingFacet.setIPAddress("146.48.87.183");
networkingFacet.setHostName("pc-frosini.isti.cnr.it");
networkingFacet.setDomainName("isti.cnr.it");
networkingFacet.setMask("255.255.248.0");
networkingFacet.setBroadcastAddress("146.48.87.255");
IsIdentifiedBy<HostingNode,NetworkingFacet> hnIsIdentifiedBy = new IsIdentifiedByImpl<HostingNode,NetworkingFacet>(
hostingNode, networkingFacet, null);
hostingNode.addFacet(hnIsIdentifiedBy);
hostingNode = resourceRegistryPublisher.createResource(hostingNode); hostingNode = resourceRegistryPublisher.createResource(hostingNode);
/* -------- */ /* -------- */
EService eService = new EServiceImpl(); EService eService = org.gcube.informationsystem.resourceregistry.publisher.ERManagementTest.instantiateValidEService();
SoftwareFacet softwareFacet = new SoftwareFacetImpl();
softwareFacet.setGroup("InformationSystem");
softwareFacet.setName("resource-registry");
softwareFacet.setVersion("1.1.0");
IsIdentifiedBy<Resource,Facet> isIdentifiedBy = new IsIdentifiedByImpl<Resource,Facet>(eService, softwareFacet,
null);
eService.addFacet(isIdentifiedBy);
PropagationConstraint propagationConstraint = new PropagationConstraintImpl(); PropagationConstraint propagationConstraint = new PropagationConstraintImpl();
propagationConstraint.setDeleteConstraint(DeleteConstraint.cascade); propagationConstraint.setDeleteConstraint(DeleteConstraint.cascade);

View File

@ -42,8 +42,9 @@ public class EntityManagementTest extends ContextTest {
protected ResourceRegistryPublisher resourceRegistryPublisher; protected ResourceRegistryPublisher resourceRegistryPublisher;
public EntityManagementTest(){ public EntityManagementTest(){
if(ContextTest.RESOURCE_REGISTRY_URL !=null && !ContextTest.RESOURCE_REGISTRY_URL.isEmpty()) { Object rrURLOBj = ContextTest.properties.get(RESOURCE_REGISTRY_URL_PROPERTY);
resourceRegistryPublisher = new ResourceRegistryPublisherImpl(ContextTest.RESOURCE_REGISTRY_URL); if(rrURLOBj!=null && !rrURLOBj.toString().isEmpty()) {
resourceRegistryPublisher = new ResourceRegistryPublisherImpl(rrURLOBj.toString());
}else { }else {
resourceRegistryPublisher = ResourceRegistryPublisherFactory.create(); resourceRegistryPublisher = ResourceRegistryPublisherFactory.create();
} }
@ -62,7 +63,7 @@ public class EntityManagementTest extends ContextTest {
Assert.assertTrue(cpuFacet.getModel().compareTo(createdCpuFacet.getModel())==0); Assert.assertTrue(cpuFacet.getModel().compareTo(createdCpuFacet.getModel())==0);
Assert.assertTrue(cpuFacet.getVendor().compareTo(createdCpuFacet.getVendor())==0); Assert.assertTrue(cpuFacet.getVendor().compareTo(createdCpuFacet.getVendor())==0);
UUID uuid = createdCpuFacet.getHeader().getUUID(); UUID uuid = createdCpuFacet.getID();
String newVendor = "Intel"; String newVendor = "Intel";
String newClockSpeed = "2 GHz"; String newClockSpeed = "2 GHz";
@ -78,7 +79,7 @@ public class EntityManagementTest extends ContextTest {
Assert.assertTrue(createdCpuFacet.getModel().compareTo(updatedCpuFacet.getModel())==0); Assert.assertTrue(createdCpuFacet.getModel().compareTo(updatedCpuFacet.getModel())==0);
Assert.assertTrue(createdCpuFacet.getVendor().compareTo(updatedCpuFacet.getVendor())==0); Assert.assertTrue(createdCpuFacet.getVendor().compareTo(updatedCpuFacet.getVendor())==0);
Assert.assertTrue(((String) updatedCpuFacet.getAdditionalProperty(additionPropertyKey)).compareTo((String) createdCpuFacet.getAdditionalProperty(additionPropertyKey))==0); Assert.assertTrue(((String) updatedCpuFacet.getAdditionalProperty(additionPropertyKey)).compareTo((String) createdCpuFacet.getAdditionalProperty(additionPropertyKey))==0);
Assert.assertTrue(uuid.compareTo(updatedCpuFacet.getHeader().getUUID())==0); Assert.assertTrue(uuid.compareTo(updatedCpuFacet.getID())==0);
boolean deleted = resourceRegistryPublisher.deleteFacet(updatedCpuFacet); boolean deleted = resourceRegistryPublisher.deleteFacet(updatedCpuFacet);
Assert.assertTrue(deleted); Assert.assertTrue(deleted);
@ -99,7 +100,7 @@ public class EntityManagementTest extends ContextTest {
Assert.assertTrue(cpuFacet.getModel().compareTo(createdCpuFacet.getModel())==0); Assert.assertTrue(cpuFacet.getModel().compareTo(createdCpuFacet.getModel())==0);
Assert.assertTrue(cpuFacet.getVendor().compareTo(createdCpuFacet.getVendor())==0); Assert.assertTrue(cpuFacet.getVendor().compareTo(createdCpuFacet.getVendor())==0);
UUID uuid = createdCpuFacet.getHeader().getUUID(); UUID uuid = createdCpuFacet.getID();
String newVendor = "Intel"; String newVendor = "Intel";
String newClockSpeed = "2 GHz"; String newClockSpeed = "2 GHz";
@ -117,7 +118,7 @@ public class EntityManagementTest extends ContextTest {
Assert.assertTrue(createdCpuFacet.getModel().compareTo(updatedCpuFacet.getModel())==0); Assert.assertTrue(createdCpuFacet.getModel().compareTo(updatedCpuFacet.getModel())==0);
Assert.assertTrue(createdCpuFacet.getVendor().compareTo(updatedCpuFacet.getVendor())==0); Assert.assertTrue(createdCpuFacet.getVendor().compareTo(updatedCpuFacet.getVendor())==0);
Assert.assertTrue(((String) updatedCpuFacet.getAdditionalProperty(additionPropertyKey)).compareTo((String) createdCpuFacet.getAdditionalProperty(additionPropertyKey))==0); Assert.assertTrue(((String) updatedCpuFacet.getAdditionalProperty(additionPropertyKey)).compareTo((String) createdCpuFacet.getAdditionalProperty(additionPropertyKey))==0);
Assert.assertTrue(uuid.compareTo(updatedCpuFacet.getHeader().getUUID())==0); Assert.assertTrue(uuid.compareTo(updatedCpuFacet.getID())==0);
boolean deleted = resourceRegistryPublisher.deleteFacet(updatedCpuFacet); boolean deleted = resourceRegistryPublisher.deleteFacet(updatedCpuFacet);
Assert.assertTrue(deleted); Assert.assertTrue(deleted);

View File

@ -72,10 +72,10 @@ public class MultiContextTest extends ContextTest {
protected ResourceRegistryClient resourceRegistryClient; protected ResourceRegistryClient resourceRegistryClient;
public MultiContextTest() throws Exception { public MultiContextTest() throws Exception {
ContextTest.setContextByName(PARENT_DEFAULT_TEST_SCOPE); Object rrURLOBj = ContextTest.properties.get(RESOURCE_REGISTRY_URL_PROPERTY);
if(ContextTest.RESOURCE_REGISTRY_URL !=null && !ContextTest.RESOURCE_REGISTRY_URL.isEmpty()) { if(rrURLOBj!=null && !rrURLOBj.toString().isEmpty()) {
resourceRegistryPublisher = new ResourceRegistryPublisherImpl(ContextTest.RESOURCE_REGISTRY_URL); resourceRegistryPublisher = new ResourceRegistryPublisherImpl(rrURLOBj.toString());
resourceRegistryClient = new ResourceRegistryClientImpl(ContextTest.RESOURCE_REGISTRY_URL); resourceRegistryClient = new ResourceRegistryClientImpl(rrURLOBj.toString());
}else { }else {
resourceRegistryPublisher = ResourceRegistryPublisherFactory.create(); resourceRegistryPublisher = ResourceRegistryPublisherFactory.create();
resourceRegistryClient = ResourceRegistryClientFactory.create(); resourceRegistryClient = ResourceRegistryClientFactory.create();
@ -127,7 +127,6 @@ public class MultiContextTest extends ContextTest {
IsIdentifiedBy<HostingNode, NetworkingFacet> isIdentifiedByHNNF = new IsIdentifiedByImpl<HostingNode, NetworkingFacet>(hostingNode, networkingFacet, null); IsIdentifiedBy<HostingNode, NetworkingFacet> isIdentifiedByHNNF = new IsIdentifiedByImpl<HostingNode, NetworkingFacet>(hostingNode, networkingFacet, null);
hostingNode.addFacet(isIdentifiedByHNNF); hostingNode.addFacet(isIdentifiedByHNNF);
CPUFacet cpuFacet = new CPUFacetImpl(); CPUFacet cpuFacet = new CPUFacetImpl();
cpuFacet.setClockSpeed("1 GHz"); cpuFacet.setClockSpeed("1 GHz");
cpuFacet.setModel("Opteron"); cpuFacet.setModel("Opteron");
@ -154,22 +153,28 @@ public class MultiContextTest extends ContextTest {
new HasPersistentMemoryImpl<HostingNode, MemoryFacet>(hostingNode, disk, null); new HasPersistentMemoryImpl<HostingNode, MemoryFacet>(hostingNode, disk, null);
hostingNode.addFacet(hasPersistentMemory); hostingNode.addFacet(hasPersistentMemory);
StateFacet hnStateFacet = new StateFacetImpl();
hnStateFacet.setValue("certified");
hostingNode.addFacet(hnStateFacet);
EventFacet hnEventFacet = new EventFacetImpl();
hnEventFacet.setDate(Calendar.getInstance().getTime());
hnEventFacet.setEvent("Created");
hostingNode.addFacet(hnEventFacet);
Activates<HostingNode, EService> activates = new ActivatesImpl<HostingNode, EService>(hostingNode, createdEService, null); Activates<HostingNode, EService> activates = new ActivatesImpl<HostingNode, EService>(hostingNode, createdEService, null);
hostingNode.attachResource(activates); hostingNode.attachResource(activates);
HostingNode createdHN = resourceRegistryPublisher.createResource(hostingNode); HostingNode createdHN = resourceRegistryPublisher.createResource(hostingNode);
logger.debug("Created : {}", createdHN); logger.debug("Created : {}", createdHN);
UUID hostingNodeUUID = createdHN.getID();
UUID eServiceUUID = createdEService.getID();
UUID alternativeContextUUID = ContextCache.getInstance().getUUIDByFullName(ALTERNATIVE_TEST_SCOPE);
resourceRegistryPublisher.addResourceToContext(createdHN, alternativeContextUUID, false);
logger.debug("Changing token to test add to scope");
ContextTest.setContextByName(ContextTest.ALTERNATIVE_TEST_SCOPE);
UUID hostingNodeUUID = createdHN.getHeader().getUUID();
UUID eServiceUUID = createdEService.getHeader().getUUID();
logger.debug("Changing token to test add to scope"); logger.debug("Changing token to test add to scope");
ContextTest.setContextByName(ContextTest.ALTERNATIVE_TEST_SCOPE); ContextTest.setContextByName(ContextTest.ALTERNATIVE_TEST_SCOPE);
@ -219,8 +224,8 @@ public class MultiContextTest extends ContextTest {
} }
@Test @Test
public void testGetAllContexts() throws Exception { public void testGetContexts() throws Exception {
List<Context> contexts = resourceRegistryPublisher.getAllContext(); List<Context> contexts = resourceRegistryPublisher.getContexts();
logger.debug("{}", contexts); logger.debug("{}", contexts);
ContextCache contextCache = ContextCache.getInstance(); ContextCache contextCache = ContextCache.getInstance();
@ -229,11 +234,11 @@ public class MultiContextTest extends ContextTest {
for(Context c : contexts) { for(Context c : contexts) {
UUID uuid = c.getHeader().getUUID(); UUID uuid = c.getID();
if(c.getParent()!=null) { if(c.getParent()!=null) {
IsParentOf isParentOf = c.getParent(); IsParentOf isParentOf = c.getParent();
Context parentContext = isParentOf.getSource(); Context parentContext = isParentOf.getSource();
UUID parentUUID = parentContext.getHeader().getUUID(); UUID parentUUID = parentContext.getID();
Assert.assertEquals(parentContext, contextCache.getContextByUUID(parentUUID)); Assert.assertEquals(parentContext, contextCache.getContextByUUID(parentUUID));
List<IsParentOf> children = parentContext.getChildren(); List<IsParentOf> children = parentContext.getChildren();
boolean found = false; boolean found = false;
@ -244,9 +249,9 @@ public class MultiContextTest extends ContextTest {
} }
} }
Assert.assertTrue(found); Assert.assertTrue(found);
logger.debug("{} : {} (parent {} : {})", c.getHeader().getUUID(), contextCache.getContextFullNameByUUID(uuid), parentUUID, contextCache.getContextFullNameByUUID(parentUUID)); logger.debug("{} : {} (parent {} : {})", c.getID(), contextCache.getContextFullNameByUUID(uuid), parentUUID, contextCache.getContextFullNameByUUID(parentUUID));
}else { }else {
logger.debug("{} : {}", c.getHeader().getUUID(), contextCache.getContextFullNameByUUID(uuid)); logger.debug("{} : {}", c.getID(), contextCache.getContextFullNameByUUID(uuid));
} }
} }
@ -254,7 +259,7 @@ public class MultiContextTest extends ContextTest {
logger.debug("Current context : {}", currentContext); logger.debug("Current context : {}", currentContext);
for(Context c : contexts) { for(Context c : contexts) {
UUID uuid = c.getHeader().getUUID(); UUID uuid = c.getID();
Context context = resourceRegistryPublisher.getContext(uuid); Context context = resourceRegistryPublisher.getContext(uuid);
String fullName = ContextCache.getInstance().getContextFullNameByUUID(uuid); String fullName = ContextCache.getInstance().getContextFullNameByUUID(uuid);
logger.debug("{} - {} : {}", uuid, fullName, context); logger.debug("{} - {} : {}", uuid, fullName, context);

View File

@ -1,142 +0,0 @@
/**
*
*/
package org.gcube.informationsystem.resourceregistry.publisher.old;
import java.util.List;
import java.util.UUID;
import org.gcube.informationsystem.model.reference.entities.Facet;
import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.entities.facet.FacetNotFoundException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.entities.resource.ResourceNotFoundException;
import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClient;
import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClientFactory;
import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClientImpl;
import org.gcube.informationsystem.resourceregistry.publisher.ContextTest;
import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPublisher;
import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPublisherFactory;
import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPublisherImpl;
import org.gcube.resourcemanagement.model.impl.entities.facets.CPUFacetImpl;
import org.gcube.resourcemanagement.model.impl.entities.facets.SoftwareFacetImpl;
import org.gcube.resourcemanagement.model.impl.entities.resources.EServiceImpl;
import org.gcube.resourcemanagement.model.impl.relations.consistsof.IsIdentifiedByImpl;
import org.gcube.resourcemanagement.model.reference.entities.facets.CPUFacet;
import org.gcube.resourcemanagement.model.reference.entities.facets.SoftwareFacet;
import org.gcube.resourcemanagement.model.reference.entities.resources.EService;
import org.gcube.resourcemanagement.model.reference.relations.consistsof.IsIdentifiedBy;
import org.junit.Assert;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR)
*
*/
public class RRClientTest extends ContextTest {
private static final Logger logger = LoggerFactory.getLogger(EntityManagementTest.class);
protected ResourceRegistryPublisher resourceRegistryPublisher;
protected ResourceRegistryClient resourceRegistryClient;
public RRClientTest(){
if(ContextTest.RESOURCE_REGISTRY_URL !=null && !ContextTest.RESOURCE_REGISTRY_URL.isEmpty()) {
resourceRegistryPublisher = new ResourceRegistryPublisherImpl(ContextTest.RESOURCE_REGISTRY_URL);
resourceRegistryClient = new ResourceRegistryClientImpl(ContextTest.RESOURCE_REGISTRY_URL);
}else {
resourceRegistryPublisher = ResourceRegistryPublisherFactory.create();
resourceRegistryClient = ResourceRegistryClientFactory.create();
}
logger.trace("{} and {} created",
ResourceRegistryPublisher.class.getSimpleName(),
ResourceRegistryClient.class.getSimpleName());
}
@Test
public void testGetFacet() throws FacetNotFoundException, ResourceRegistryException{
CPUFacet cpuFacet = new CPUFacetImpl();
cpuFacet.setClockSpeed("1 GHz");
cpuFacet.setModel("Opteron");
cpuFacet.setVendor("AMD");
CPUFacet createdCpuFacet = resourceRegistryPublisher.createFacet(cpuFacet);
Assert.assertTrue(cpuFacet.getClockSpeed().compareTo(createdCpuFacet.getClockSpeed())==0);
Assert.assertTrue(cpuFacet.getModel().compareTo(createdCpuFacet.getModel())==0);
Assert.assertTrue(cpuFacet.getVendor().compareTo(createdCpuFacet.getVendor())==0);
UUID uuid = createdCpuFacet.getHeader().getUUID();
Facet f = resourceRegistryClient.getInstance(Facet.class, uuid);
Assert.assertTrue(f instanceof CPUFacet);
CPUFacet readCpuFacet = (CPUFacet) f;
Assert.assertTrue(readCpuFacet.getClockSpeed().compareTo(createdCpuFacet.getClockSpeed())==0);
Assert.assertTrue(readCpuFacet.getModel().compareTo(createdCpuFacet.getModel())==0);
Assert.assertTrue(readCpuFacet.getVendor().compareTo(createdCpuFacet.getVendor())==0);
readCpuFacet = resourceRegistryClient.getInstance(CPUFacet.class, uuid);
Assert.assertTrue(readCpuFacet.getClockSpeed().compareTo(createdCpuFacet.getClockSpeed())==0);
Assert.assertTrue(readCpuFacet.getModel().compareTo(createdCpuFacet.getModel())==0);
Assert.assertTrue(readCpuFacet.getVendor().compareTo(createdCpuFacet.getVendor())==0);
boolean deleted = resourceRegistryPublisher.deleteFacet(createdCpuFacet);
Assert.assertTrue(deleted);
}
@Test
public void testGetResource() throws ResourceNotFoundException, ResourceRegistryException{
EService eService = new EServiceImpl();
SoftwareFacet softwareFacet = new SoftwareFacetImpl();
softwareFacet.setGroup("InformationSystem");
softwareFacet.setName("resource-registry");
softwareFacet.setVersion("1.1.0");
IsIdentifiedBy<EService, SoftwareFacet> isIdentifiedByESSF = new IsIdentifiedByImpl<>(eService, softwareFacet, null);
eService.addFacet(isIdentifiedByESSF);
EService createdEService = resourceRegistryPublisher.createResource(eService);
List<? extends Facet> idenficationFacets = createdEService.getIdentificationFacets();
Assert.assertTrue(idenficationFacets!=null);
Assert.assertTrue(idenficationFacets.size()==1);
Facet f = idenficationFacets.get(0);
Assert.assertTrue(f!=null);
Assert.assertTrue(f instanceof SoftwareFacet);
SoftwareFacet createdSoftwareFacet = (SoftwareFacet) f;
Assert.assertTrue(createdSoftwareFacet.getGroup().compareTo(softwareFacet.getGroup())==0);
Assert.assertTrue(createdSoftwareFacet.getName().compareTo(softwareFacet.getName())==0);
Assert.assertTrue(createdSoftwareFacet.getVersion().compareTo(softwareFacet.getVersion())==0);
Resource resource = resourceRegistryClient.getInstance(Resource.class, createdEService.getHeader().getUUID());
Assert.assertTrue(resource.getHeader().getUUID().compareTo(createdEService.getHeader().getUUID())==0);
Assert.assertTrue(resource instanceof EService);
EService readEService = resourceRegistryClient.getInstance(EService.class, createdEService.getHeader().getUUID());
Assert.assertTrue(readEService.getHeader().getUUID().compareTo(createdEService.getHeader().getUUID())==0);
List<? extends Facet> idFacets = readEService.getIdentificationFacets();
Assert.assertTrue(idFacets!=null);
Assert.assertTrue(idFacets.size()==1);
f = idFacets.get(0);
Assert.assertTrue(f!=null);
Assert.assertTrue(f instanceof SoftwareFacet);
SoftwareFacet readSoftwareFacet = (SoftwareFacet) f;
Assert.assertTrue(readSoftwareFacet.getGroup().compareTo(softwareFacet.getGroup())==0);
Assert.assertTrue(readSoftwareFacet.getName().compareTo(softwareFacet.getName())==0);
Assert.assertTrue(readSoftwareFacet.getVersion().compareTo(softwareFacet.getVersion())==0);
Assert.assertTrue(readSoftwareFacet.getHeader().getUUID().compareTo(createdSoftwareFacet.getHeader().getUUID())==0);
boolean deleted = resourceRegistryPublisher.deleteResource(createdEService);
Assert.assertTrue(deleted);
}
}

View File

@ -1,7 +1,22 @@
client_id=junit.tests.luca.frosini type=USER
client_secret=6b0d0222-3130-41f1-a86d-6b23993547be #type=CLIENT_ID
#RESOURCE_REGISTRY_URL=http://localhost:8080/resource-registry
#RESOURCE_REGISTRY_URL=http://pc-frosini.isti.cnr.it:8080/resource-registry username=luca.frosini
#RESOURCE_REGISTRY_URL=http://resourceregistry1-d-d4s.d4science.org/resource-registry password=Pupp4M3l0
#RESOURCE_REGISTRY_URL=https://resource-registry.dev.d4science.org/resource-registry
#RESOURCE_REGISTRY_URL=http://url.gcube.d4science.org/resource-registry #username=grsf.publisher
#password=grsfcambiami
#clientId=grsf-publisher
#/gcube=54cc7454-1a84-11ee-be56-0242ac120002
#/pred4s=de293f60-e004-45ce-b64f-20de77fad888
#/d4science.research-infrastructures.eu=
#client_id=junit.tests.luca.frosini
#/gcube=6b0d0222-3130-41f1-a86d-6b23993547be
#clientId=gcat
#/gcube=712add63-c642-4a6a-8ddc-283dc978120a
#/pred4s=4e35a122-8f25-48f9-9788-8588ee86633f
#/d4science.research-infrastructures.eu=