Get Configuration fixes

#22461
Fabio Sinibaldi 2 years ago
parent 93abb135d5
commit c8ad2a1004

@ -17,6 +17,7 @@ import org.gcube.application.cms.serialization.Serialization;
import org.gcube.application.cms.custom.gna.concessioni.model.ProfiledConcessione;
import org.gcube.application.cms.plugins.LifecycleManager;
import org.gcube.application.cms.plugins.model.PluginDescriptor;
import org.gcube.application.geoportal.common.model.configuration.Index;
import org.gcube.application.geoportal.common.model.document.*;
import org.gcube.application.geoportal.common.model.document.access.Access;
import org.gcube.application.geoportal.common.model.document.access.AccessPolicy;
@ -258,14 +259,26 @@ public class ConcessioniLifeCycleManager implements LifecycleManager {
indexerPlugin = (IndexerPluginInterface) pluginManager.getById("SDI-Indexer-Plugin");
BaseRequest indexRequest = new BaseRequest(req.getUseCaseDescriptor(),req.getCaller(),req.getContext());
// Info on Public index
indexRequest.setCallParameters(getPublicIndexParams(req));
toReturn.getIndexes().add(indexerPlugin.getIndex(indexRequest));
// Info on Public index
try {
indexRequest.setCallParameters(getPublicIndexParams(req));
Index publicIndex = indexerPlugin.getIndex(indexRequest);
publicIndex.put("flag", "public");
toReturn.getIndexes().add(publicIndex);
}catch(ConfigurationException e){
toReturn.addErrorMessage("Unable to gather information on public GIS Centroids Index : "+e.getMessage());
log.error("Unable to gather information on public GIS Centroids Index",e);
}
// Info on internal_index
indexRequest.setCallParameters(getInternalIndexParams(req));
toReturn.getIndexes().add(indexerPlugin.getIndex(indexRequest));
try {
indexRequest.setCallParameters(getInternalIndexParams(req));
Index internalIndex = indexerPlugin.getIndex(indexRequest);
internalIndex.put("flag", "internal");
toReturn.getIndexes().add(internalIndex);
}catch(ConfigurationException e){
toReturn.addErrorMessage("Unable to gather information on internal GIS Centroids Index : "+e.getMessage());
log.error("Unable to gather information on internal GIS Centroids Index",e);
}
return toReturn;
}

@ -1,12 +1,16 @@
package org.gcube.application.geoportal.common.model.configuration;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import jdk.nashorn.internal.runtime.regexp.joni.Config;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.gcube.application.geoportal.common.model.document.lifecycle.LifecycleInformation;
import javax.xml.bind.annotation.XmlRootElement;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
@XmlRootElement
@ -19,9 +23,19 @@ public class Configuration{
public static final String CONTEXT = "context";
public static final String LAST_UPDATED_TIME = "last_updated_time";
public static final String ERROR_MESSAGES="errorMessages";
public static final String WARNING_MESSAGES="warningMessages";
public static final String STATUS="status";
public static final String INDEXES = "indexes";
public static final String ARCHIVES = "archives";
public static enum Status{
OK,ERROR,WARNING
}
@JsonProperty(PROFILE_ID)
private String profileId;
@JsonProperty(CONTEXT)
@ -34,4 +48,30 @@ public class Configuration{
@JsonProperty(ARCHIVES)
private List<Archive> archives;
@JsonProperty(ERROR_MESSAGES)
private List<String> errorMessages;
@JsonProperty(WARNING_MESSAGES)
private List<String> warningMessages;
@JsonProperty(STATUS)
private Status status=Status.OK;
@JsonIgnore
public Configuration addErrorMessage(String msg){
status = Status.ERROR;
if(errorMessages==null)
errorMessages=new ArrayList<>();
errorMessages.add(msg);
return this;
}
@JsonIgnore
public Configuration addWarningMessage(String msg){
if(status == null || status.equals(Status.OK))
status = Status.WARNING;
if(warningMessages==null)
warningMessages=new ArrayList<>();
warningMessages.add(msg);
return this;
}
}

@ -12,7 +12,7 @@ public class GCubeTest {
//testContext = "/pred4s/preprod/preVRE";
// testContext = "/gcube/devsec/devVRE";
testContext = "/gcube/devsec/devVRE";
System.out.println("TEST CONTEXT = "+testContext);

@ -387,18 +387,18 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
}
@Override
public Configuration getConfiguration() throws ConfigurationException {
public Configuration getConfiguration() throws ConfigurationException{
log.debug("Asking configuration for {} in {} ", useCaseDescriptor.getId(), UserUtils.getCurrent().getContext());
Configuration toReturn= new Configuration();
List<Archive> archives = new ArrayList<>();
toReturn.setArchives(archives);
List<Index> indexes=new ArrayList<>();
toReturn.setIndexes(indexes);
// Set Basic Info
toReturn.setArchives(archives);
toReturn.setProfileId(this.getUseCaseDescriptor().getId());
toReturn.setContext(ContextUtils.getCurrentScope());
toReturn.setLastUpdatedTime(LocalDateTime.now());
// Add Mongo Info
Archive mongoArchive = new Archive("DOCUMENT-STORE-COLLECTION");
MongoCollection coll=getCollection();
@ -411,19 +411,26 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
// Set WS Info
try {
archives.add(new WorkspaceManager().getConfiguration());
}catch (StorageHubException e) {
throw new ConfigurationException("Unable to get WS Configuration",e);
}catch (Exception e) {
toReturn.addErrorMessage("Unable to get WS info "+e.getMessage());
log.error("Unable to get WS Configuration",e);
}
// ADD LC Infos
AccountingInfo user = UserUtils.getCurrent().asInfo();
Configuration lcConfig = getLCManager().getCurrentConfiguration(new BaseRequest(useCaseDescriptor,user.getUser(),user.getContext()));
try{
Configuration lcConfig = getLCManager().getCurrentConfiguration(new BaseRequest(useCaseDescriptor,user.getUser(),user.getContext()));
log.info("Configuration is {} ",lcConfig);
if(lcConfig.getArchives()!=null)
archives.addAll(lcConfig.getArchives());
if(lcConfig.getIndexes()!=null)
indexes.addAll(lcConfig.getIndexes());
}catch(ConfigurationException e){
toReturn.addErrorMessage("Unable to get Lifecycle info "+e.getMessage());
log.error("Unable to get Lifecycle info ",e);
}
log.debug("Returning current configuration {}",toReturn);
return toReturn;

@ -13,6 +13,8 @@ import org.gcube.application.geoportal.service.engine.mongo.ProfiledMongoManager
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
import org.gcube.application.cms.serialization.Serialization;
import org.gcube.application.geoportal.service.engine.providers.ConfigurationCache;
import org.gcube.application.geoportal.service.engine.providers.UCDManager;
import org.gcube.application.geoportal.service.model.internal.faults.RegistrationException;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
@ -28,7 +30,7 @@ public class ProfiledDocuments {
manager=new GuardedMethod<ProfiledMongoManager>(){
@Override
protected ProfiledMongoManager run() throws Exception {
return new ProfiledMongoManager(profileID);
return new ProfiledMongoManager(profileID);
}
}.execute().getResult();
}

@ -76,7 +76,7 @@ public class PostgisIndexer {
dbManager.create(table);
log.debug("Checking/ registering index layer in GS ");
indexName = indexName;
this.indexName = indexName;
indexLayer = manager.configureCentroidLayer(indexName,workspace,storeName,table,connectionParameters);
// TODO Additional layers

@ -4,13 +4,11 @@ import freemarker.core.PlainTextOutputFormat;
import lombok.Getter;
import org.bson.Document;
import org.gcube.application.geoportal.common.model.document.filesets.GCubeSDILayer;
import org.gcube.application.geoportal.common.model.document.filesets.Materialization;
import sun.misc.GC;
import javax.print.Doc;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
public class GCubeSDILayerBuilder {
@ -32,7 +30,7 @@ public class GCubeSDILayerBuilder {
GCubeSDILayer theObject = new GCubeSDILayer();
@Getter
Document platformInfo= new Document(GCubeSDILayer.PLATFORM_INFO,GS_PLATFORM);
Document platformInfo= new Document(Materialization.TYPE,GS_PLATFORM);
@Getter
GCubeSDILayer.BBOX bbox = GCubeSDILayer.BBOX.WORLD;
@ -41,12 +39,11 @@ public class GCubeSDILayerBuilder {
Map<OGC_TYPE,Document> ogcLinks = new HashMap<>();
public GCubeSDILayerBuilder(){
}
public GCubeSDILayer getLayer(){
theObject.put(GCubeSDILayer.PLATFORM_INFO,platformInfo);
theObject.put(GCubeSDILayer.PLATFORM_INFO, Collections.singleton(platformInfo));
theObject.put(GCubeSDILayer.B_BOX,bbox);
prepareOGCLinks();

@ -9,6 +9,7 @@ import org.gcube.application.cms.plugins.reports.Report;
import org.gcube.application.cms.plugins.requests.BaseRequest;
import org.gcube.application.cms.plugins.requests.IndexDocumentRequest;
import org.gcube.application.cms.sdi.engine.PostgisIndexer;
import org.gcube.application.cms.sdi.model.GCubeSDILayerBuilder;
import org.gcube.application.cms.sdi.plugins.SDIIndexerPlugin;
import org.gcube.application.cms.serialization.Serialization;
import org.gcube.application.cms.tests.BasicPluginTest;
@ -18,6 +19,8 @@ import org.gcube.application.geoportal.common.model.configuration.Index;
import org.gcube.application.geoportal.common.model.document.Project;
import org.gcube.application.geoportal.common.model.document.accounting.Context;
import org.gcube.application.geoportal.common.model.document.accounting.User;
import org.gcube.application.geoportal.common.model.document.filesets.GCubeSDILayer;
import org.gcube.application.geoportal.common.model.document.filesets.Materialization;
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor;
import org.gcube.application.geoportal.common.utils.Files;
@ -26,8 +29,7 @@ import org.gcube.spatial.data.geonetwork.utils.UserUtils;
import org.junit.Test;
import ucar.units.Base;
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertTrue;
import static junit.framework.TestCase.*;
import static org.junit.Assume.assumeTrue;
public class IndexerTest extends BasicPluginTest {
@ -58,7 +60,7 @@ public class IndexerTest extends BasicPluginTest {
@Test
public void getIndex() throws ConfigurationException {
public void getIndex() throws ConfigurationException, JsonProcessingException {
assumeTrue(GCubeTest.isTestInfrastructureEnabled());
IndexerPluginInterface plugin = (IndexerPluginInterface) plugins.get(SDIIndexerPlugin.DESCRIPTOR.getId());
UseCaseDescriptor descriptor=TestProfiles.profiles.get("profiledConcessioni");
@ -68,6 +70,17 @@ public class IndexerTest extends BasicPluginTest {
.setParameter("indexName",Files.fixFilename(GCubeTest.getContext()+"test_index")));
System.out.println("Test Index Is "+index);
assertEquals(index.getType(), PostgisIndexer.INDEX_TYPE);
assertNotNull(index.get("layer"));
assertNotNull(index.get("indexName"));
GCubeSDILayer layer = Serialization.convert(index.get("layer"),GCubeSDILayer.class);
assertEquals(GCubeSDILayer.GCUBE_SDY_LAYER_TYPE,layer.getType());
for (Object pIObj : layer.getPlatformInfo()){
Document platformDoc = Serialization.asDocument(pIObj);
assertEquals(GCubeSDILayerBuilder.GS_PLATFORM,platformDoc.get(Materialization.TYPE));
}
}
}

Loading…
Cancel
Save