Added the possibility to create any type of resource without gcube-model

This commit is contained in:
Luca Frosini 2024-04-16 16:11:14 +02:00
parent 483826685c
commit 489eed2787
2 changed files with 57 additions and 2 deletions

View File

@ -7,6 +7,8 @@ import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode;
import org.gcube.common.gxhttp.reference.GXConnection;
import org.gcube.common.gxhttp.request.GXHTTPStringRequest;
import org.gcube.common.http.GXHTTPUtility;
@ -44,6 +46,7 @@ import org.gcube.informationsystem.resourceregistry.api.rest.SharingPath;
import org.gcube.informationsystem.resourceregistry.api.rest.SharingPath.SharingOperation;
import org.gcube.informationsystem.resourceregistry.api.rest.httputils.HTTPUtility;
import org.gcube.informationsystem.serialization.ElementMapper;
import org.gcube.informationsystem.utils.JsonUtility;
import org.gcube.informationsystem.utils.TypeUtility;
import org.gcube.informationsystem.utils.UUIDManager;
import org.gcube.informationsystem.utils.UUIDUtility;
@ -440,8 +443,14 @@ public class ResourceRegistryPublisherImpl extends BaseRequestInfo implements Re
public String create(String json)
throws SchemaViolationException, AlreadyPresentException, ResourceRegistryException {
try {
ERElement e = ElementMapper.unmarshal(ERElement.class, json);
return internalCreate(e);
JsonNode jsonNode = JsonUtility.getJsonNode(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());
}
return create(type, json, uuid);
} catch (ResourceRegistryException e) {
// logger.trace("Error Creating {}", facet, e);
throw e;

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);
}
}