in progress on migration to UCD and Profiled Document

This commit is contained in:
Francesco Mangiacrapa 2022-03-17 18:08:58 +01:00
parent 3c1008eaf8
commit 0cb588a881
25 changed files with 1455 additions and 959 deletions

View File

@ -1,5 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
@ -31,7 +36,12 @@
<wb-module deploy-name="geoportal-data-entry-app-3.0.0-SNAPSHOT">
@ -63,7 +73,12 @@
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
@ -95,7 +110,12 @@
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
@ -136,7 +156,12 @@
<dependent-module archiveName="geoportal-data-common-2.0.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/geoportal-data-common/geoportal-data-common">
<dependency-type>uses</dependency-type>
</dependent-module>
@ -168,7 +193,12 @@
<property name="context-root" value="geoportal-data-entry-app"/>
@ -200,7 +230,12 @@
<property name="java-output-path" value="/geoportal-data-entry-app/target/geoportal-data-entry-app-2.0.0-SNAPSHOT/WEB-INF/classes"/>
@ -232,7 +267,12 @@
</wb-module>

View File

@ -10,6 +10,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
#### Enhancements
- [#22684] Porting to Profiled Document
- Moved to maven-portal-bom v3.7.0[-SNAPSHOT]
## [v2.1.0] - 2021-11-24

20
pom.xml
View File

@ -51,7 +51,7 @@
<dependency>
<groupId>org.gcube.distribution</groupId>
<artifactId>maven-portal-bom</artifactId>
<version>3.6.3</version>
<version>3.7.0-SNAPSHOT</version>
<type>pom</type>
<scope>import</scope>
</dependency>
@ -68,7 +68,7 @@
<scope>provided</scope>
</dependency>
<!-- ASM required for GWT 2.9-->
<!-- ASM required for GWT 2.9 -->
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
@ -111,6 +111,22 @@
<artifactId>metadata-profile-form-builder-widget</artifactId>
<version>[2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
<scope>compile</scope>
<!-- does not remove these exclusions, there are conflict with jackson
2.7 used by geo-json dependency -->
<exclusions>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</exclusion>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</exclusion>
<exclusion>
<groupId>de.grundid.opendatalab</groupId>
<artifactId>geojson-jackson</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.gcube.portlets.widgets</groupId>

View File

@ -8,16 +8,16 @@ import java.util.List;
import java.util.TreeMap;
import org.gcube.application.geoportalcommon.shared.GeoNaItemRef;
import org.gcube.application.geoportalcommon.shared.ItemField;
import org.gcube.application.geoportalcommon.shared.SearchingFilter;
import org.gcube.application.geoportalcommon.shared.SearchingFilter.ORDER;
import org.gcube.application.geoportalcommon.shared.config.ACTION_ON_ITEM;
import org.gcube.application.geoportalcommon.shared.config.GcubeUserRole;
import org.gcube.application.geoportalcommon.shared.config.RoleRights;
import org.gcube.application.geoportalcommon.shared.config.RoleRights.OPERATION_TYPE;
import org.gcube.application.geoportalcommon.shared.geoportalconfig.ConfigurationDV;
import org.gcube.application.geoportalcommon.shared.geoportalconfig.DocumentConfigDV;
import org.gcube.application.geoportalcommon.shared.geoportalconfig.GcubeProfileDV;
import org.gcube.application.geoportalcommon.shared.geoportal.HandlerDeclarationDV;
import org.gcube.application.geoportalcommon.shared.geoportal.UseCaseDescriptorDV;
import org.gcube.application.geoportalcommon.shared.geoportal.config.GcubeProfileDV;
import org.gcube.application.geoportalcommon.shared.geoportal.config.ItemFieldDV;
import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV;
import org.gcube.application.geoportalcommon.shared.products.model.RecordDV;
import org.gcube.application.geoportalcommon.shared.products.model.ValidationReportDV;
@ -43,6 +43,7 @@ import org.gcube.portlets.user.geoportaldataentry.client.ui.form.GeonaDataEntryM
import org.gcube.portlets.user.geoportaldataentry.client.ui.report.BuildValidationReport;
import org.gcube.portlets.user.geoportaldataentry.client.ui.report.ReportTemplateToHTML;
import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.DialogConfirm;
import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.DialogInform;
import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.HTMLUtil;
import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.HTMLUtil.HTML_TAG;
import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.LoaderIcon;
@ -113,9 +114,9 @@ public class GeoPortalDataEntryApp implements EntryPoint {
private LoaderIcon loader = new LoaderIcon("Loading Application... please wait");
private List<ItemField> displayFields = new ArrayList<ItemField>();
private List<ItemField> sortByFields = new ArrayList<ItemField>();
private List<ItemField> searchByFields = new ArrayList<ItemField>();
private List<ItemFieldDV> displayFields = new ArrayList<ItemFieldDV>();
private List<ItemFieldDV> sortByFields = new ArrayList<ItemFieldDV>();
private List<ItemFieldDV> searchByFields = new ArrayList<ItemFieldDV>();
private GeonaISConfig geonaISConfig;
@ -133,7 +134,7 @@ public class GeoPortalDataEntryApp implements EntryPoint {
return numberOfCards;
}
private List<DocumentConfigDV> listDocumentConfigs;
private List<UseCaseDescriptorDV> listUCDescriptors;
private boolean dataEntryProjectCreated = false;
@ -200,9 +201,9 @@ public class GeoPortalDataEntryApp implements EntryPoint {
}
List<ItemField> itemFields = gNADataEntryConfig.getListItemFields();
List<ItemFieldDV> itemFields = gNADataEntryConfig.getListItemFields();
for (ItemField itemField : itemFields) {
for (ItemFieldDV itemField : itemFields) {
if (itemField.isDisplayAsResult()) {
displayFields.add(itemField);
}
@ -220,14 +221,14 @@ public class GeoPortalDataEntryApp implements EntryPoint {
SearchingFilter initialSortFilter = new SearchingFilter();
initialSortFilter.setOrder(ORDER.ASC);
initialSortFilter.setOrderByFields(
Arrays.asList(new ItemField("Name", Arrays.asList("name"), true, true, true)));
Arrays.asList(new ItemFieldDV("Name", Arrays.asList("name"), null, true, true, true)));
displayFields = itemFields;
mainTabPanel = new GeonaMainTabPanel(appManagerBus, displayFields, sortByFields, searchByFields,
initialSortFilter);
// TWICE BECAUSE THE MAIN PANEL COULD BE NULL BEFORE
setListDocumentConfig(listDocumentConfigs);
setListUseCaseDescriptors(listUCDescriptors);
geoNaMainForm = new GeonaDataEntryMainForm(appManagerBus);
mainTabPanel.addFormPanel(geoNaMainForm);
@ -283,9 +284,32 @@ public class GeoPortalDataEntryApp implements EntryPoint {
private void loadGeoportalConfigs(final String scope) {
GWT.log("loading GeoportalConfigsAndBuildCards in the scope: " + scope);
orderedCards = new ArrayList<GeoNaFormCardModel>();
// TODO PASS THE RIGHT ID
GeoportalDataEntryServiceAsync.Util.getInstance().getListDocumentConfigurationForId("id",
new AsyncCallback<List<DocumentConfigDV>>() {
// // TODO PASS THE RIGHT ID
// GeoportalDataEntryServiceAsync.Util.getInstance().getListDocumentConfigurationForId("id",
// new AsyncCallback<List<DocumentConfigDV>>() {
//
// @Override
// public void onFailure(Throwable caught) {
// GWT.log("caught: " + caught);
// Window.alert(caught.toString());
// }
//
// @Override
// public void onSuccess(List<DocumentConfigDV> result) {
// listUCDescriptors = result;
// GWT.log("List<DocumentConfigDV>: " + result);
//
// if (result == null || result.size() == 0) {
// Window.alert("No Configuration found in this scope. Please contact the support");
// return;
// }
//
// setListDocumentConfig(listUCDescriptors);
// }
// });
GeoportalDataEntryServiceAsync.Util.getInstance().getListUseCaseDescriptors(null,
new AsyncCallback<List<UseCaseDescriptorDV>>() {
@Override
public void onFailure(Throwable caught) {
@ -294,8 +318,10 @@ public class GeoPortalDataEntryApp implements EntryPoint {
}
@Override
public void onSuccess(List<DocumentConfigDV> result) {
listDocumentConfigs = result;
public void onSuccess(List<UseCaseDescriptorDV> result) {
listUCDescriptors = result;
GWT.log("List<UseCaseDescriptorDV>: " + listUCDescriptors);
listUCDescriptors = result;
GWT.log("List<DocumentConfigDV>: " + result);
if (result == null || result.size() == 0) {
@ -303,19 +329,20 @@ public class GeoPortalDataEntryApp implements EntryPoint {
return;
}
setListDocumentConfig(listDocumentConfigs);
setListUseCaseDescriptors(listUCDescriptors);
}
});
}
private synchronized void setListDocumentConfig(List<DocumentConfigDV> listDocumentConfigs) {
GWT.log("Setting setListDocumentConfig: " + listDocumentConfigs);
if (listDocumentConfigs != null) {
private synchronized void setListUseCaseDescriptors(List<UseCaseDescriptorDV> listUCDescriptors) {
GWT.log("Setting listUCDescriptors: " + listUCDescriptors);
if (listUCDescriptors != null) {
if (mainTabPanel != null) {
//Just to be sure that its set once
if(mainTabPanel.getListDocumentConfig()==null) {
mainTabPanel.setListDocumentConfig(listDocumentConfigs);
// Just to be sure that its set once
if (mainTabPanel.getListUCDescriptors() == null) {
mainTabPanel.setListUseCaseDescriptors(listUCDescriptors);
}
}
}
@ -345,15 +372,14 @@ public class GeoPortalDataEntryApp implements EntryPoint {
}
private void createNewDataEntyFor(DocumentConfigDV dcDV) {
private void createNewDataEntyFor(HandlerDeclarationDV handlerDeclarationDV, List<GcubeProfileDV> listGPs) {
dataEntryProjectCreated = true;
mainTabPanel.setLoaderVisible("Loading...", true);
orderedCards.clear();
resetUI();
ConfigurationDV config = dcDV.getConfiguration();
List<GeoNaFormCardModel> cardsPerIT = mapGcubeProfilePerItemType.get(dcDV.getItemType());
mainTabPanel.setPageHeader(dcDV);
List<GeoNaFormCardModel> cardsPerIT = mapGcubeProfilePerItemType.get(handlerDeclarationDV.getItemType());
mainTabPanel.setPageHeader(handlerDeclarationDV);
if (cardsPerIT != null) {
orderedCards.addAll(cardsPerIT);
@ -362,12 +388,12 @@ public class GeoPortalDataEntryApp implements EntryPoint {
}
numberOfCards = 0;
expectedCards = config.getGcubeProfiles().size();
expectedCards = listGPs.size();
GWT.log("expectedCards are: " + expectedCards);
TreeMap<Integer, GeoNaFormCardModel> treemapOrderedGNAProfiles = new TreeMap<Integer, GeoNaFormCardModel>();
for (int i = 0; i < expectedCards; i++) {
GcubeProfileDV gcubeProfiles = config.getGcubeProfiles().get(i);
GcubeProfileDV gcubeProfiles = listGPs.get(i);
final int order = i;
GWT.log("calling getProfilesInTheScope for secondaryType: " + gcubeProfiles.getGcubeSecondaryType()
+ ", name: " + gcubeProfiles.getGcubeName());
@ -394,9 +420,8 @@ public class GeoPortalDataEntryApp implements EntryPoint {
maxOccurs = maxOccurs <= 0 ? Integer.MAX_VALUE : maxOccurs;
// TODO MUST BE MANAGED MIN_OCCURS
ProjectFormCard cct = new ProjectFormCard(
gcubeProfiles.getSectionName(), gcubeProfiles.getSectionTitle(), order,
maxOccurs > 1, minOccurs, maxOccurs);
ProjectFormCard cct = new ProjectFormCard(gcubeProfiles.getSectionName(),
gcubeProfiles.getSectionTitle(), order, maxOccurs > 1, minOccurs, maxOccurs);
GeoNaFormCardModel geonaForm = new GeoNaFormCardModel(metaDataProfileBean, null, cct,
gcubeProfiles);
@ -409,7 +434,7 @@ public class GeoPortalDataEntryApp implements EntryPoint {
Collection<GeoNaFormCardModel> gnaCardsModels = treemapOrderedGNAProfiles.values();
GWT.log("TreMap values: " + gnaCardsModels);
orderedCards.addAll(gnaCardsModels);
mapGcubeProfilePerItemType.put(dcDV.getItemType(),
mapGcubeProfilePerItemType.put(handlerDeclarationDV.getItemType(),
new ArrayList<GeoNaFormCardModel>(gnaCardsModels));
buildNewCards(orderedCards, OPERATION.UPDATE);
}
@ -596,7 +621,7 @@ public class GeoPortalDataEntryApp implements EntryPoint {
public void onCreateNewProject(CreateNewProjectEvent newProjectEvent) {
GWT.log("Crate new project");
if (!dataEntryProjectCreated) {
createNewDataEntyFor(newProjectEvent.getDocumentConfiguration());
createNewDataEntyFor(newProjectEvent.getHandler(), newProjectEvent.getListGcubeProfiles());
return;
}
@ -605,23 +630,23 @@ public class GeoPortalDataEntryApp implements EntryPoint {
DialogConfirm confirm = new DialogConfirm(null, "Creating New Project...",
"The current project (is not saved) and will be lost. Confirm?");
confirm.getYesButton().addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
confirm.hide();
createNewDataEntyFor(newProjectEvent.getDocumentConfiguration());
createNewDataEntyFor(newProjectEvent.getHandler(), newProjectEvent.getListGcubeProfiles());
// buildNewCards(orderedCards, OPERATION.NEW);
}
});
confirm.center();
} else if (projectSavedWithSuccess) {
// means the project has been saved
createNewDataEntyFor(newProjectEvent.getDocumentConfiguration());
createNewDataEntyFor(newProjectEvent.getHandler(), newProjectEvent.getListGcubeProfiles());
// buildNewCards(orderedCards, OPERATION.NEW);
} else {
@ -633,12 +658,12 @@ public class GeoPortalDataEntryApp implements EntryPoint {
@Override
public void onClick(ClickEvent event) {
confirm.hide();
createNewDataEntyFor(newProjectEvent.getDocumentConfiguration());
createNewDataEntyFor(newProjectEvent.getHandler(), newProjectEvent.getListGcubeProfiles());
}
});
confirm.center();
}
@ -654,7 +679,14 @@ public class GeoPortalDataEntryApp implements EntryPoint {
if (sortFilter == null) {
sortFilter = mainTabPanel.getCurrentSortFilter();
}
grpw = new GeonaRecordsPaginatedView(appManagerBus, RECORD_TYPE.CONCESSIONE, displayFields, sortFilter);
String profileID = getListOfRecordsEvent.getProfileID();
if (profileID == null) {
new DialogInform(null, "Error", "No user case descriptor selected").center();
return;
}
grpw = new GeonaRecordsPaginatedView(appManagerBus, profileID, displayFields, sortFilter);
mainTabPanel.showListOfConcessioniView(grpw);
}
});
@ -691,6 +723,7 @@ public class GeoPortalDataEntryApp implements EntryPoint {
switch (action) {
case UPDATED_PROJECT:
appManagerBus.fireEvent(new GetListOfRecordsEvent(RECORD_TYPE.CONCESSIONE,
actionPerformedOnItemEvent.getProfileID(), null,
mainTabPanel.getCurrentSortFilter()));
break;
}
@ -891,7 +924,7 @@ public class GeoPortalDataEntryApp implements EntryPoint {
hp.add(alert);
appManagerBus.fireEvent(
new GetListOfRecordsEvent(RECORD_TYPE.CONCESSIONE,
new GetListOfRecordsEvent(RECORD_TYPE.CONCESSIONE,grpw.getProfileID(),null,
mainTabPanel.getCurrentSortFilter()));
}

View File

@ -5,7 +5,7 @@ import java.util.List;
import org.gcube.application.geoportalcommon.shared.GeoNaItemRef;
import org.gcube.application.geoportalcommon.shared.ResultSetPaginatedData;
import org.gcube.application.geoportalcommon.shared.SearchingFilter;
import org.gcube.application.geoportalcommon.shared.geoportalconfig.DocumentConfigDV;
import org.gcube.application.geoportalcommon.shared.geoportal.UseCaseDescriptorDV;
import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV;
import org.gcube.application.geoportalcommon.shared.products.content.WorkspaceContentDV;
import org.gcube.application.geoportalcommon.shared.products.paths.FileSetPathsDV;
@ -56,17 +56,18 @@ public interface GeoportalDataEntryService extends RemoteService {
GeoNaItemRef getLinksFor(String itemId, RECORD_TYPE recordType) throws Exception;
/**
* Gets the list concessioni.
* Gets the list projects.
*
* @param theProfileID the the profile ID
* @param start the start
* @param limit the limit
* @param filter the filter
* @param reloadFromService the reload from service
* @return the list concessioni
* @return the list projects
* @throws Exception the exception
*/
public ResultSetPaginatedData getListConcessioni(Integer start, Integer limit, SearchingFilter filter,
boolean reloadFromService) throws Exception;
public ResultSetPaginatedData getListProjects(String theProfileID, Integer start, Integer limit,
SearchingFilter filter, boolean reloadFromService) throws Exception;
/**
* Delete record.
@ -141,11 +142,12 @@ public interface GeoportalDataEntryService extends RemoteService {
GNADataEntryExtConfigProfile readDataViewerConfig() throws Exception;
/**
* Gets the document configuration for id.
* Gets the list use case descriptors.
*
* @param id the id
* @return the document configuration for id
* @param handlersIds the handlers ids
* @return the list use case descriptors
* @throws Exception the exception
*/
List<DocumentConfigDV> getListDocumentConfigurationForId(String id);
List<UseCaseDescriptorDV> getListUseCaseDescriptors(List<String> handlersIds) throws Exception;
}

View File

@ -5,7 +5,7 @@ import java.util.List;
import org.gcube.application.geoportalcommon.shared.GeoNaItemRef;
import org.gcube.application.geoportalcommon.shared.ResultSetPaginatedData;
import org.gcube.application.geoportalcommon.shared.SearchingFilter;
import org.gcube.application.geoportalcommon.shared.geoportalconfig.DocumentConfigDV;
import org.gcube.application.geoportalcommon.shared.geoportal.UseCaseDescriptorDV;
import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV;
import org.gcube.application.geoportalcommon.shared.products.content.WorkspaceContentDV;
import org.gcube.application.geoportalcommon.shared.products.paths.FileSetPathsDV;
@ -45,7 +45,7 @@ public interface GeoportalDataEntryServiceAsync {
void getLinksFor(String itemId, RECORD_TYPE recordType, AsyncCallback<GeoNaItemRef> callback);
void getListConcessioni(Integer start, Integer limit, SearchingFilter filter, boolean reloadFromService,
void getListProjects(String theProfileID, Integer start, Integer limit, SearchingFilter filter, boolean reloadFromService,
AsyncCallback<ResultSetPaginatedData> callback);
void deleteRecord(String itemId, RECORD_TYPE recordType, AsyncCallback<Boolean> callback);
@ -64,6 +64,8 @@ public interface GeoportalDataEntryServiceAsync {
void readDataViewerConfig(AsyncCallback<GNADataEntryExtConfigProfile> asyncCallback);
void getListDocumentConfigurationForId(String id, AsyncCallback<List<DocumentConfigDV>> callback);
// void getListDocumentConfigurationForId(String id, AsyncCallback<List<DocumentConfigDV>> callback);
void getListUseCaseDescriptors(List<String> handlersIds, AsyncCallback<List<UseCaseDescriptorDV>> callback);
}

View File

@ -19,6 +19,7 @@ public class ActionPerformedOnItemEvent<T extends RecordDV> extends GwtEvent<Act
public static Type<ActionPerformedOnItemEventHandler> TYPE = new Type<ActionPerformedOnItemEventHandler>();
private List<T> selectItems;
private ACTION_PERFORMED_ON_ITEM action;
private String profileID;
/**
* Instantiates a new action performed on item event.
@ -26,7 +27,8 @@ public class ActionPerformedOnItemEvent<T extends RecordDV> extends GwtEvent<Act
* @param selectItems the select items
* @param doAction the do action
*/
public ActionPerformedOnItemEvent(List<T> selectItems, ACTION_PERFORMED_ON_ITEM doAction) {
public ActionPerformedOnItemEvent(String profileID, List<T> selectItems, ACTION_PERFORMED_ON_ITEM doAction) {
this.profileID = profileID;
this.selectItems = selectItems;
this.action = doAction;
}
@ -80,5 +82,9 @@ public class ActionPerformedOnItemEvent<T extends RecordDV> extends GwtEvent<Act
public ACTION_PERFORMED_ON_ITEM getAction() {
return action;
}
public String getProfileID() {
return profileID;
}
}

View File

@ -1,27 +1,37 @@
package org.gcube.portlets.user.geoportaldataentry.client.events;
import org.gcube.application.geoportalcommon.shared.geoportalconfig.DocumentConfigDV;
import java.util.List;
import org.gcube.application.geoportalcommon.shared.geoportal.HandlerDeclarationDV;
import org.gcube.application.geoportalcommon.shared.geoportal.config.GcubeProfileDV;
import com.google.gwt.event.shared.GwtEvent;
/**
* The Class CreateNewProjectEvent.
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Oct 13, 2020
* Mar 17, 2022
*/
public class CreateNewProjectEvent extends GwtEvent<CreateNewProjectEventHandler> {
/** The type. */
public static Type<CreateNewProjectEventHandler> TYPE = new Type<CreateNewProjectEventHandler>();
private DocumentConfigDV documentConfiguration;
private HandlerDeclarationDV handler;
private List<GcubeProfileDV> listGcubeProfiles;
/**
* Instantiates a new cancel upload event.
* Instantiates a new creates the new project event.
*
* @param handler the handler
* @param listGcubeProfiles the list gcube profiles
*/
public CreateNewProjectEvent(DocumentConfigDV documentConfiguration) {
this.documentConfiguration = documentConfiguration;
// (passing this second argument in order to avoid twice the casting as
// List<GcubeProfileDV>)
public CreateNewProjectEvent(HandlerDeclarationDV handler, List<GcubeProfileDV> listGcubeProfiles) {
this.handler = handler;
this.listGcubeProfiles = listGcubeProfiles;
}
/**
@ -29,7 +39,9 @@ public class CreateNewProjectEvent extends GwtEvent<CreateNewProjectEventHandler
*
* @return the associated type
*/
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see com.google.gwt.event.shared.GwtEvent#getAssociatedType()
*/
@Override
@ -42,16 +54,29 @@ public class CreateNewProjectEvent extends GwtEvent<CreateNewProjectEventHandler
*
* @param handler the handler
*/
/* (non-Javadoc)
* @see com.google.gwt.event.shared.GwtEvent#dispatch(com.google.gwt.event.shared.EventHandler)
/*
* (non-Javadoc)
*
* @see
* com.google.gwt.event.shared.GwtEvent#dispatch(com.google.gwt.event.shared.
* EventHandler)
*/
@Override
protected void dispatch(CreateNewProjectEventHandler handler) {
handler.onCreateNewProject(this);
}
public DocumentConfigDV getDocumentConfiguration() {
return documentConfiguration;
public HandlerDeclarationDV getHandler() {
return handler;
}
/**
* Gets the list gcube profiles.
*
* @return the list gcube profiles
*/
public List<GcubeProfileDV> getListGcubeProfiles() {
return listGcubeProfiles;
}
}

View File

@ -19,13 +19,22 @@ public class GetListOfRecordsEvent extends GwtEvent<GetListOfRecordsEventHandler
public static Type<GetListOfRecordsEventHandler> TYPE = new Type<GetListOfRecordsEventHandler>();
private RECORD_TYPE recordType;
private SearchingFilter sortFilter;
private String profileID;
private String profileName;
/**
* Instantiates a new cancel upload event.
*
* @param recordType the record type
* @param theUseCaseDesc the the use case desc
* @param sortFilter the sort filter
*/
public GetListOfRecordsEvent(ConstantsGeoPortalDataEntryApp.RECORD_TYPE recordType, SearchingFilter sortFilter) {
public GetListOfRecordsEvent(ConstantsGeoPortalDataEntryApp.RECORD_TYPE recordType, String profileID,
String profileName, SearchingFilter sortFilter) {
this.recordType = recordType;
this.sortFilter = sortFilter;
this.profileID = profileID;
this.profileName = profileName;
}
/**
@ -60,12 +69,30 @@ public class GetListOfRecordsEvent extends GwtEvent<GetListOfRecordsEventHandler
handler.onGetList(this);
}
/**
* Gets the record type.
*
* @return the record type
*/
public RECORD_TYPE getRecordType() {
return recordType;
}
/**
* Gets the sort filter.
*
* @return the sort filter
*/
public SearchingFilter getSortFilter() {
return sortFilter;
}
public String getProfileID() {
return profileID;
}
public String getProfileName() {
return profileName;
}
}

View File

@ -5,19 +5,20 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.gcube.application.geoportalcommon.shared.ItemField;
import org.gcube.application.geoportalcommon.shared.SearchingFilter;
import org.gcube.application.geoportalcommon.shared.SearchingFilter.LOGICAL_OP;
import org.gcube.application.geoportalcommon.shared.SearchingFilter.ORDER;
import org.gcube.application.geoportalcommon.shared.WhereClause;
import org.gcube.application.geoportalcommon.shared.config.ACTION_ON_ITEM;
import org.gcube.application.geoportalcommon.shared.geoportalconfig.ConfigurationDV;
import org.gcube.application.geoportalcommon.shared.geoportalconfig.DocumentConfigDV;
import org.gcube.application.geoportalcommon.shared.geoportal.ConfigurationDV;
import org.gcube.application.geoportalcommon.shared.geoportal.GEOPORTAL_DATA_HANDLER;
import org.gcube.application.geoportalcommon.shared.geoportal.HandlerDeclarationDV;
import org.gcube.application.geoportalcommon.shared.geoportal.UseCaseDescriptorDV;
import org.gcube.application.geoportalcommon.shared.geoportal.config.GcubeProfileDV;
import org.gcube.application.geoportalcommon.shared.geoportal.config.ItemFieldDV;
import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV;
import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.RECORD_TYPE;
import org.gcube.portlets.user.geoportaldataentry.client.events.ActionOnItemEvent;
import org.gcube.portlets.user.geoportaldataentry.client.events.CreateNewProjectEvent;
import org.gcube.portlets.user.geoportaldataentry.client.events.GetListOfRecordsEvent;
import org.gcube.portlets.user.geoportaldataentry.client.ui.form.GeonaDataEntryMainForm;
import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.DialogInform;
import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.LoaderIcon;
@ -149,23 +150,23 @@ public class GeonaMainTabPanel extends Composite {
@UiField
PageHeader pageHeaderDataEntry;
@UiField
Hero introGNAHero;
private HandlerManager appManagerBus;
private List<ItemField> sortByFields;
private List<ItemFieldDV> sortByFields;
private List<ItemField> searchForFields;
private List<ItemFieldDV> searchForFields;
private SearchingFilter currentSortFilter;
private GeonaRecordsPaginatedView grpw = null;
private List<ItemField> displayFields;
private List<ItemFieldDV> displayFields;
private List<DocumentConfigDV> listDocumentConfig;
private List<UseCaseDescriptorDV> listUCDescriptors;
/**
* Instantiates a new geona main tab panel.
@ -174,8 +175,8 @@ public class GeonaMainTabPanel extends Composite {
* @param sortByFields the sort by fields
* @param initialSortFilter
*/
public GeonaMainTabPanel(HandlerManager appManagerBus, List<ItemField> displayFields, List<ItemField> sortByFields,
List<ItemField> searchForFields, SearchingFilter initialSortFilter) {
public GeonaMainTabPanel(HandlerManager appManagerBus, List<ItemFieldDV> displayFields,
List<ItemFieldDV> sortByFields, List<ItemFieldDV> searchForFields, SearchingFilter initialSortFilter) {
initWidget(uiBinder.createAndBindUi(this));
this.appManagerBus = appManagerBus;
this.sortByFields = sortByFields;
@ -196,7 +197,7 @@ public class GeonaMainTabPanel extends Composite {
bindEvents();
resetSearch.setIconSize(IconSize.TWO_TIMES);
resetSearch.setType(ButtonType.LINK);
setLoaderVisible("", false);
}
@ -223,7 +224,10 @@ public class GeonaMainTabPanel extends Composite {
@Override
public void onClick(ClickEvent event) {
Window.alert("buttonReloadConcessioni MUST BE REVISITED");
/*
appManagerBus.fireEvent(new GetListOfRecordsEvent(RECORD_TYPE.CONCESSIONE, getCurrentSortFilter()));
*/
}
});
@ -237,7 +241,7 @@ public class GeonaMainTabPanel extends Composite {
}
});
for (ItemField record_FIELD : sortByFields) {
for (ItemFieldDV record_FIELD : sortByFields) {
// if (record_FIELD.equals(RECORD_FIELD.RECORD_STATUS))
// continue;
@ -252,7 +256,10 @@ public class GeonaMainTabPanel extends Composite {
@Override
public void onClick(ClickEvent event) {
alertSortBy.setText(labelASC);
Window.alert("ASC MUST BE REVISITED");
/*
appManagerBus.fireEvent(new GetListOfRecordsEvent(RECORD_TYPE.CONCESSIONE, getCurrentSortFilter()));
*/
}
});
@ -266,12 +273,15 @@ public class GeonaMainTabPanel extends Composite {
@Override
public void onClick(ClickEvent event) {
alertSortBy.setText(labelDESC);
Window.alert("DESC MUST BE REVISITED");
/*
appManagerBus.fireEvent(new GetListOfRecordsEvent(RECORD_TYPE.CONCESSIONE, getCurrentSortFilter()));
*/
}
});
}
for (ItemField record_FIELD : searchForFields) {
for (ItemFieldDV record_FIELD : searchForFields) {
NavLink nav = new NavLink(record_FIELD.getDisplayName());
dropdownSearchFor.add(nav);
@ -362,8 +372,11 @@ public class GeonaMainTabPanel extends Composite {
@Override
public void onClick(ClickEvent event) {
searchField.setText("");
Window.alert("resetSearch MUST BE REVISITED");
/*
appManagerBus.fireEvent(new GetListOfRecordsEvent(RECORD_TYPE.CONCESSIONE, getCurrentSortFilter()));
resetSearch.setVisible(false);
*/
}
});
@ -381,10 +394,14 @@ public class GeonaMainTabPanel extends Composite {
}
resetSearch.setVisible(true);
Window.alert("doSearchEvent MUST BE REVISITED");
/*
appManagerBus.fireEvent(new GetListOfRecordsEvent(RECORD_TYPE.CONCESSIONE, getCurrentSortFilter()));
*/
}
private String toLabelFilter(ItemField itemField, ORDER direction) {
private String toLabelFilter(ItemFieldDV itemField, ORDER direction) {
String labelFilter = itemField.getDisplayName() + LABEL_FILTER_SEPARATOR + direction.name();
return labelFilter;
}
@ -429,8 +446,8 @@ public class GeonaMainTabPanel extends Composite {
SearchingFilter sortFilter = null;
try {
ItemField recordField = null;
for (ItemField value : sortByFields) {
ItemFieldDV recordField = null;
for (ItemFieldDV value : sortByFields) {
if (array[0].equalsIgnoreCase(value.getDisplayName())) {
recordField = value;
break;
@ -454,7 +471,7 @@ public class GeonaMainTabPanel extends Composite {
String searchForField = "";
for (ItemField recordField : searchForFields) {
for (ItemFieldDV recordField : searchForFields) {
if (recordField.getDisplayName().equals(alertSearchFor.getText())) {
searchForField = recordField.getJsonFields().get(0);
continue;
@ -489,61 +506,110 @@ public class GeonaMainTabPanel extends Composite {
*
*/
public void instanceAndShowListOfConcessioni() {
Window.alert("instanceAndShowListOfConcessioni MUST BE REVISITED");
/*
grpw = new GeonaRecordsPaginatedView(appManagerBus, RECORD_TYPE.CONCESSIONE, displayFields, currentSortFilter);
showListOfConcessioniView(grpw);
*/
}
public void setListDocumentConfig(List<DocumentConfigDV> listDocumentConfig) {
GWT.log("Setting listDocumentConfig: "+listDocumentConfig);
this.listDocumentConfig = listDocumentConfig;
public void setListUseCaseDescriptors(List<UseCaseDescriptorDV> listUCDescriptors) {
GWT.log("Setting listUCDescriptors: " + listUCDescriptors);
this.listUCDescriptors = listUCDescriptors;
ddCreateNewProject.clear();
for (DocumentConfigDV documentConfigDV : listDocumentConfig) {
NavLink link = new NavLink(documentConfigDV.getItemType());
link.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
ConfigurationDV config = documentConfigDV.getConfiguration();
for (UseCaseDescriptorDV ucd : listUCDescriptors) {
HandlerDeclarationDV dataEntryHandler = getDataEntryHandler(ucd);
if (dataEntryHandler != null) {
ConfigurationDV<?> config = dataEntryHandler.getConfiguration();
List<GcubeProfileDV> listGcubeProfiles = toListGcubeProfiles(config);
final List<GcubeProfileDV> listProfiles = listGcubeProfiles;
NavLink link = new NavLink(ucd.getName());
link.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
if (listProfiles == null || listProfiles.size() == 0) {
DialogInform di = new DialogInform(null, "No configuration found",
"No GcubeProfile found in the Configuration for " + config.getConfiguration());
di.center();
return;
}
appManagerBus.fireEvent(new CreateNewProjectEvent(dataEntryHandler, listProfiles));
if (config.getGcubeProfiles() == null || config.getGcubeProfiles().size() == 0) {
DialogInform di = new DialogInform(null, "No configuration found", "No GcubeProfile found in the Configuration for " + documentConfigDV.getItemType());
di.center();
return;
}
});
appManagerBus.fireEvent(new CreateNewProjectEvent(documentConfigDV));
ddCreateNewProject.add(link);
}
});
ddCreateNewProject.add(link);
}
}
//IF one type of document is available, fire CreateNewProjectEvent(documentConfigDV));
if(listDocumentConfig.size()==1) {
// IF one type of document is available, fire
// CreateNewProjectEvent(documentConfigDV));
if (listUCDescriptors.size() == 1) {
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
@Override
public void execute() {
GWT.log("One Config loaded. Firing CreateNewProjectEvent");
appManagerBus.fireEvent(new CreateNewProjectEvent(listDocumentConfig.get(0)));
UseCaseDescriptorDV useCaseDescriptor = listUCDescriptors.get(0);
HandlerDeclarationDV dataEntryHandler = getDataEntryHandler(useCaseDescriptor);
if (dataEntryHandler != null) {
ConfigurationDV<?> config = dataEntryHandler.getConfiguration();
List<GcubeProfileDV> listGcubeProfiles = toListGcubeProfiles(config);
appManagerBus.fireEvent(new CreateNewProjectEvent(dataEntryHandler, listGcubeProfiles));
}
}
});
}
}
public void setPageHeader(DocumentConfigDV dcDV) {
private HandlerDeclarationDV getDataEntryHandler(UseCaseDescriptorDV useCaseDescriptor) {
for (HandlerDeclarationDV handler : useCaseDescriptor.getHandlers()) {
GEOPORTAL_DATA_HANDLER dataHandlerType = handler.getDataHandlerType();
// Checking if the handler if of geoportal_data_entry type
if (dataHandlerType != null
&& dataHandlerType.getType().equals(GEOPORTAL_DATA_HANDLER.geoportal_data_entry.getType())) {
return handler;
}
}
return null;
}
private List<GcubeProfileDV> toListGcubeProfiles(ConfigurationDV<?> config) {
try {
return (List<GcubeProfileDV>) config.getConfiguration();
} catch (Exception e) {
GWT.log("Error on casting " + ConfigurationDV.class.getName() + " to List of "
+ GcubeProfileDV.class.getName());
}
return null;
}
public void setPageHeader(HandlerDeclarationDV hDV) {
introGNAHero.setVisible(false);
this.pageHeaderDataEntry.setVisible(true);
this.pageHeaderDataEntry.setText("");
this.pageHeaderDataEntry.setSubtext("New: "+dcDV.getItemType());
this.pageHeaderDataEntry.setSubtext("New: " + hDV.getItemType());
}
public List<DocumentConfigDV> getListDocumentConfig() {
return listDocumentConfig;
public List<UseCaseDescriptorDV> getListUCDescriptors() {
return listUCDescriptors;
}
}

View File

@ -2,11 +2,10 @@ package org.gcube.portlets.user.geoportaldataentry.client.ui;
import java.util.List;
import org.gcube.application.geoportalcommon.shared.ItemField;
import org.gcube.application.geoportalcommon.shared.ResultSetPaginatedData;
import org.gcube.application.geoportalcommon.shared.SearchingFilter;
import org.gcube.application.geoportalcommon.shared.geoportal.config.ItemFieldDV;
import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV;
import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.RECORD_TYPE;
import org.gcube.portlets.user.geoportaldataentry.client.GeoPortalDataEntryApp;
import org.gcube.portlets.user.geoportaldataentry.client.ui.table.ItemsTable;
import org.gcube.portlets.user.geoportaldataentry.client.ui.table.SortedCellTable;
@ -47,10 +46,10 @@ public class GeonaRecordsPaginatedView {
private MyCustomDataProvider<ConcessioneDV> dataProvider = new MyCustomDataProvider<ConcessioneDV>();
protected Widget orginalLoadingIndicator = null;
private LoaderIcon loadingPanel = new LoaderIcon("Loading data...");
//private int serverStartIndex;
// private int serverStartIndex;
private HandlerManager eventBus;
private RECORD_TYPE recordType;
private SearchingFilter currentSortFilter;
private String profileID;
/**
* Instantiates a new geona records paginated view.
@ -60,9 +59,9 @@ public class GeonaRecordsPaginatedView {
* @param displayFields the display fields
* @param currentSortFilter the sort by field
*/
public GeonaRecordsPaginatedView(HandlerManager eventbus, RECORD_TYPE recordType,
List<ItemField> displayFields, SearchingFilter currentSortFilter) {
this.recordType = recordType;
public GeonaRecordsPaginatedView(HandlerManager eventbus, String profileID, List<ItemFieldDV> displayFields,
SearchingFilter currentSortFilter) {
this.profileID = profileID;
this.currentSortFilter = currentSortFilter;
this.initClassFirstRangeChanged = true;
this.eventBus = eventbus;
@ -72,7 +71,7 @@ public class GeonaRecordsPaginatedView {
orginalLoadingIndicator = itemsTable.getCellTable().getLoadingIndicator();
initPagination(ITEMS_PER_PAGE);
// loadNewPage(ITEM_START_INDEX, ITEMS_PER_PAGE, false);
loadItemsForType(recordType);
loadItemsForType(profileID);
}
/**
@ -114,12 +113,13 @@ public class GeonaRecordsPaginatedView {
/**
* Load new page.
*
* @param startIdx the start idx
* @param limit the limit
* @param resetStore the reset store
* @param invalidCache the invalid cache
* @param startIdx the start idx
* @param limit the limit
* @param resetStore the reset store
* @param currentSortFilter the current sort filter
* @param invalidCache the invalid cache
*/
private void loadNewPage(final int startIdx, final int limit, final boolean resetStore,
private void loadNewPage(String profileID, final int startIdx, final int limit, final boolean resetStore,
final SearchingFilter currentSortFilter, final boolean invalidCache) {
// initFirstRangeChanged = resetStore;
GWT.log("loadNewPage with parameters [startIdx: " + startIdx + ", limit: " + limit + ", resetStore:"
@ -131,12 +131,12 @@ public class GeonaRecordsPaginatedView {
if (resetStore) {
GWT.log("Cleaning all data...");
newStartIndex = 0;
//serverStartIndex = 0;
// serverStartIndex = 0;
GWT.log("Store reset performed start index is: " + newStartIndex);
getTableDataProvider().updateRowCount(ITEMS_PER_PAGE, false);
}
loadConcessioni(newStartIndex, limit, currentSortFilter, invalidCache);
loadProjects(profileID, newStartIndex, limit, currentSortFilter, invalidCache);
}
/**
@ -144,10 +144,10 @@ public class GeonaRecordsPaginatedView {
*
* @param recordType the record type
*/
public void loadItemsForType(RECORD_TYPE recordType) {
this.recordType = recordType;
private void loadItemsForType(String profileID) {
this.profileID = profileID;
getCellTable().setVisibleRangeAndClearData(new Range(ITEM_START_INDEX, ITEMS_PER_PAGE), false);
loadNewPage(ITEM_START_INDEX, ITEMS_PER_PAGE, true, currentSortFilter, true);
loadNewPage(profileID, ITEM_START_INDEX, ITEMS_PER_PAGE, true, currentSortFilter, true);
}
/**
@ -157,7 +157,7 @@ public class GeonaRecordsPaginatedView {
*/
private void setNewPageResult(ResultSetPaginatedData result) {
GWT.log("setNewPageResult: " + result);
//serverStartIndex = result.getServerEndIndex();
// serverStartIndex = result.getServerEndIndex();
SelectionModel<? super ConcessioneDV> sm = getCellTable().getSelectionModel();
if (sm instanceof SingleSelectionModel) {
@ -169,7 +169,10 @@ public class GeonaRecordsPaginatedView {
}
getTableDataProvider().updateRowCount((int) result.getTotalItems(), true);
getTableDataProvider().updateRowData(result.getClientStartIndex(), result.getData());
// TODO MUST USE PROJECT
// getTableDataProvider().updateRowData(result.getClientStartIndex(),
// result.getData());
if (result.getData().size() == 0) {
getCellTable().setLoadingIndicator(new Label("No data"));
@ -190,20 +193,23 @@ public class GeonaRecordsPaginatedView {
}
/**
* Load concessioni.
* Load projects.
*
* @param <T> the generic type
* @param theProfileID the the profile ID
* @param newStartIndex the new start index
* @param limit the limit
* @param serverIndex the server index
* @param sortFilter the sort filter
* @param invalidCache the invalid cache
*/
private <T> void loadConcessioni(int newStartIndex, int limit, SearchingFilter sortFilter,
private <T> void loadProjects(String theProfileID, int newStartIndex, int limit, SearchingFilter sortFilter,
boolean invalidCache) {
showLoading(true);
GWT.log("calling loadItemsForStatus with parameters [startIndex: " + newStartIndex + ", limit: " + limit+ ", sortFilter: " + sortFilter + "]");
GeoPortalDataEntryApp.geoportalDataEntryService.getListConcessioni(newStartIndex, limit, sortFilter, invalidCache,
new AsyncCallback<ResultSetPaginatedData>() {
GWT.log("calling loadItemsForStatus with parameters [theProfileID: " + theProfileID + ", startIndex: "
+ newStartIndex + ", limit: " + limit + ", sortFilter: " + sortFilter + "]");
GeoPortalDataEntryApp.geoportalDataEntryService.getListProjects(theProfileID, newStartIndex, limit, sortFilter,
invalidCache, new AsyncCallback<ResultSetPaginatedData>() {
@Override
public void onFailure(Throwable caught) {
@ -289,7 +295,7 @@ public class GeonaRecordsPaginatedView {
return;
}
GWT.log("Range changed: " + start + " " + length + " visible count: " + display.getVisibleItemCount());
loadNewPage(start, length, false, currentSortFilter, false);
loadNewPage(profileID, start, length, false, currentSortFilter, false);
// eventBus.fireEvent(new TableRangeViewChangedEvent<T>(start, length));
}
@ -322,5 +328,9 @@ public class GeonaRecordsPaginatedView {
public FlowPanel getPagerPanel() {
return pagerPanel;
}
public String getProfileID() {
return profileID;
}
}

View File

@ -1,6 +1,6 @@
package org.gcube.portlets.user.geoportaldataentry.client.ui.card;
import org.gcube.application.geoportalcommon.shared.geoportalconfig.GcubeProfileDV;
import org.gcube.application.geoportalcommon.shared.geoportal.config.GcubeProfileDV;
import org.gcube.portlets.user.geoportaldataentry.client.ProjectFormCard;
import org.gcube.portlets.widgets.mpformbuilder.client.form.generic.CreateMetadataForm;
import org.gcube.portlets.widgets.mpformbuilder.shared.metadata.MetaDataProfileBean;

View File

@ -1,6 +1,5 @@
package org.gcube.portlets.user.geoportaldataentry.client.ui.edit;
import java.util.Arrays;
import java.util.List;
import org.gcube.application.geoportalcommon.shared.products.BaseConcessioneDV;
@ -181,8 +180,11 @@ public class EditModeRecord extends Composite {
// TODO: handle exception
}
Window.alert("buttonJSONUpdate must be revisited");
/*
editorManagerBus.fireEvent(new ActionPerformedOnItemEvent<ConcessioneDV>(null,
ACTION_PERFORMED_ON_ITEM.UPDATED_PROJECT));
*/
}
@ -200,8 +202,12 @@ public class EditModeRecord extends Composite {
"Project '" + result.getNome() + "' updated correctly");
di.setZIndex(100000);
di.center();
Window.alert("buttonJSONUpdate ConcessioneDV must be revisited");
/*
editorManagerBus.fireEvent(new ActionPerformedOnItemEvent<ConcessioneDV>(
Arrays.asList(result), ACTION_PERFORMED_ON_ITEM.UPDATED_PROJECT));
*/
}
});
@ -221,8 +227,13 @@ public class EditModeRecord extends Composite {
instanceJSONEditor();
if (action.equals(ACTION_PERFORMED_ON_ITEM.UPDATED_PROJECT)) {
Window.alert("ACTION_PERFORMED_ON_ITEM.UPDATED_PROJECT ConcessioneDV must be revisited");
/*
appManagerBus.fireEvent(new ActionPerformedOnItemEvent<ConcessioneDV>(
(List<ConcessioneDV>) items, ACTION_PERFORMED_ON_ITEM.UPDATED_PROJECT));
*/
}
}

View File

@ -1,7 +1,6 @@
package org.gcube.portlets.user.geoportaldataentry.client.ui.edit;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
@ -14,11 +13,9 @@ import org.gcube.application.geoportalcommon.shared.products.model.AbstractRelaz
import org.gcube.application.geoportalcommon.shared.products.model.LayerConcessioneDV;
import org.gcube.application.geoportalcommon.shared.products.model.RelazioneScavoDV;
import org.gcube.application.geoportalcommon.shared.products.model.UploadedImageDV;
import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.ACTION_PERFORMED_ON_ITEM;
import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.RECORD_TYPE;
import org.gcube.portlets.user.geoportaldataentry.client.GeoPortalDataEntryApp;
import org.gcube.portlets.user.geoportaldataentry.client.GeoportalDataEntryServiceAsync;
import org.gcube.portlets.user.geoportaldataentry.client.events.ActionPerformedOnItemEvent;
import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.DialogConfirm;
import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.DialogInform;
import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.StringUtil;
@ -262,8 +259,14 @@ public class UpdateFileset extends Composite {
GWT.log("new concessione: "+fullConcessione);
buttonUpdate.setEnabled(true);
showUploadFileGUI();
Window.alert("updateSectionForRecord must be revisited");
/*
editorManagerBus.fireEvent(
new ActionPerformedOnItemEvent<ConcessioneDV>(Arrays.asList(fullConcessione), ACTION_PERFORMED_ON_ITEM.UPDATED_PROJECT));
*/
}
});

View File

@ -10,7 +10,7 @@ import java.util.List;
import java.util.Set;
import org.gcube.application.geoportalcommon.ConvertToDataViewModel;
import org.gcube.application.geoportalcommon.shared.ItemField;
import org.gcube.application.geoportalcommon.shared.geoportal.config.ItemFieldDV;
import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV;
import org.gcube.application.geoportalcommon.shared.products.model.ValidationReportDV;
import org.gcube.application.geoportalcommon.shared.products.model.ValidationReportDV.ValidationStatus;
@ -51,7 +51,7 @@ public class ItemsTable<T extends ConcessioneDV> extends AbstractItemsCellTable<
private static final String NO_DATA = "No data";
public static DateTimeFormat dtformat = DateTimeFormat.getFormat(ConvertToDataViewModel.DATE_FORMAT);
private AbstractDataProvider<T> dataProvider;
private List<ItemField> displayFields;
private List<ItemFieldDV> displayFields;
private boolean isAsyncronusTable;
/**
@ -61,7 +61,7 @@ public class ItemsTable<T extends ConcessioneDV> extends AbstractItemsCellTable<
* @param displayFields the display fields
* @param startSortByColumn the start sort by column
*/
public ItemsTable(HandlerManager eventBus, List<ItemField> displayFields) {
public ItemsTable(HandlerManager eventBus, List<ItemFieldDV> displayFields) {
this.eventBus = eventBus;
this.displayFields = displayFields;
}
@ -94,7 +94,7 @@ public class ItemsTable<T extends ConcessioneDV> extends AbstractItemsCellTable<
int i = 0;
for (ItemField itemField : displayFields) {
for (ItemFieldDV itemField : displayFields) {
String displayName = itemField.getDisplayName();
// NAME
TextColumn<T> col = new TextColumn<T>() {
@ -445,7 +445,7 @@ public class ItemsTable<T extends ConcessioneDV> extends AbstractItemsCellTable<
*
* @return the displayFields
*/
public List<ItemField> getDisplayFields() {
public List<ItemFieldDV> getDisplayFields() {
return displayFields;
}

View File

@ -0,0 +1,217 @@
package org.gcube.portlets.user.geoportaldataentry.server;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import org.gcube.application.geoportalcommon.shared.geoportal.config.GcubeProfileDV;
import org.gcube.portlets.user.geoportaldataentry.shared.GeoNaFormDataObject;
import org.gcube.portlets.widgets.mpformbuilder.shared.GenericDatasetBean;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The Class FormDataObjectToJSON.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Mar 10, 2022
*/
public class FormDataObjectToJSON {
private static final Logger LOG = LoggerFactory.getLogger(FormDataObjectToJSON.class);
/**
* Convert.
*
* @param listGeonaFormObjects the list geona form objects
* @return the JSON object
* @throws JSONException the JSON exception
*/
public JSONObject convert(List<GeoNaFormDataObject> listGeonaFormObjects) throws JSONException {
JSONObject theDocument = JSONObjecOrdered.instance();
for (GeoNaFormDataObject geoNaFormDataObject : listGeonaFormObjects) {
List<GenericDatasetBean> listGDB = geoNaFormDataObject.getListGDB();
GcubeProfileDV profile = geoNaFormDataObject.getGcubeProfileDV();
LOG.debug("The profile is: " + profile);
String jsonPathExp = String.format("%s%s", profile.getParentName(), profile.getSectionName());
LOG.debug("The json path to build: " + jsonPathExp);
// jsonPathExp = "$.chidl1.child2.child3";
String toJsonPathExp = jsonPathExp.replaceFirst("\\$", "");
String[] jsonPathDeep = toJsonPathExp.split("\\.");
List<JSONObject> listJSONObject = toListJonObject(listGDB, jsonPathDeep);
// adding as JSONObject to theDocument at first deep level (under the root or at section specified)
if (listJSONObject.size() == 1) {
theDocument = deepMerge(listJSONObject.get(0), theDocument);
//theDocument = theDocument.put(listJSONObject.get(0), jsonArray);
} else {
// adding as JSONArray to theDocument under the section specified
// to jsonPathDeep[1]
JSONArray jsonArray = new JSONArray();
for (JSONObject jsonObject : listJSONObject) {
// reading the i-mo JSONObject created in the list with the key as
// jsonPathDeep[1]
jsonArray.put(jsonObject.get(jsonPathDeep[1]));
}
theDocument.put(jsonPathDeep[1], jsonArray);
}
LOG.debug("Partial Root Document is: " + theDocument);
}
LOG.debug("Final JSON Document is: " + theDocument);
return theDocument;
}
/**
* Generic dataset bean to JSON.
*
* @param gdb the gdb
* @return the JSON object
* @throws JSONException the JSON exception
*/
private JSONObject genericDatasetBeanToJSON(GenericDatasetBean gdb) throws JSONException {
JSONObject sectJSONObject = JSONObjecOrdered.instance();
LinkedHashMap<String, List<String>> mapFields = gdb.getFormDataEntryFields();
LOG.debug("Map ordered: " + mapFields);
for (String key : mapFields.keySet()) {
List<String> listValues = mapFields.get(key);
if (listValues == null || listValues.isEmpty()) {
continue;
}
// key/value as string
if (listValues.size() == 1) {
sectJSONObject.put(key, listValues.get(0));
continue;
}
// value is a list
JSONArray array = new JSONArray();
for (String value : listValues) {
array.put(value);
}
sectJSONObject.put(key, array);
}
return sectJSONObject;
}
/**
* To list jon object.
*
* @param listGDB the list GDB
* @param jsonPathDeep the json path deep
* @return the list
* @throws JSONException the JSON exception
*/
private List<JSONObject> toListJonObject(List<GenericDatasetBean> listGDB, String[] jsonPathDeep)
throws JSONException {
List<JSONObject> listJSONObject = new ArrayList<JSONObject>();
for (GenericDatasetBean gdb : listGDB) {
JSONObject sectRootObject = JSONObjecOrdered.instance();
JSONObject jsonObject = genericDatasetBeanToJSON(gdb);
LOG.debug("Adding section : " + jsonObject);
LOG.trace("jsonPathDeep: " + Arrays.asList(jsonPathDeep) + " size: " + jsonPathDeep.length);
// Adding JSONObject to ROOT DOCUMENT POSITION (using PLACEHOLDER_ROOT_POINTER_JSON_DOC)
if (jsonPathDeep.length == 0) {
sectRootObject = deepMerge(jsonObject, sectRootObject);
} else {
// DEPTH >= 1
sectRootObject.put(jsonPathDeep[jsonPathDeep.length - 1], jsonObject);
JSONObject deepJSON = sectRootObject;
System.out.println("sectRootObject: " + sectRootObject.toString());
for (int i = jsonPathDeep.length - 2; i > 0; i--) {
JSONObject newOne = JSONObjecOrdered.instance();
newOne.put(jsonPathDeep[i], deepJSON);
deepJSON = newOne;
}
sectRootObject = deepJSON;
}
listJSONObject.add(sectRootObject);
}
LOG.info("For listGDB : " + listGDB);
LOG.info("returning : " + listJSONObject);
return listJSONObject;
}
/**
* Merge "source" into "target". If fields have equal name, merge them
* recursively.
*
* @param source the source
* @param target the target
* @return the merged object (target).
* @throws JSONException the JSON exception
*/
public static JSONObject deepMerge(JSONObject source, JSONObject target) throws JSONException {
for (String key : JSONObject.getNames(source)) {
Object value = source.get(key);
if (!target.has(key)) {
// new value for "key":
target.put(key, value);
} else {
// existing value for "key" - recursively deep merge:
if (value instanceof JSONObject) {
JSONObject valueJson = (JSONObject) value;
deepMerge(valueJson, target.getJSONObject(key));
} else {
target.put(key, value);
}
}
}
return target;
}
/**
* The Class JSONObjecOrdered.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Mar 10, 2022
*/
public static class JSONObjecOrdered {
/**
* Instance.
*
* @return the JSON object
*/
public static JSONObject instance() {
JSONObject jsonObject = new JSONObject();
try {
Field changeMap = jsonObject.getClass().getDeclaredField("map");
changeMap.setAccessible(true);
changeMap.set(jsonObject, new LinkedHashMap<>());
changeMap.setAccessible(false);
} catch (IllegalAccessException | NoSuchFieldException e) {
}
return jsonObject;
}
}
}

View File

@ -1,21 +1,25 @@
package org.gcube.portlets.user.geoportaldataentry.server;
import java.lang.reflect.Field;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.gcube.application.geoportal.common.model.document.Project;
import org.gcube.application.geoportal.common.model.legacy.Concessione;
import org.gcube.application.geoportal.common.model.rest.AddSectionToConcessioneRequest;
import org.gcube.application.geoportal.common.model.rest.TempFile;
import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor;
import org.gcube.application.geoportal.common.rest.MongoConcessioni;
import org.gcube.application.geoportalcommon.ConvertToDataValueObjectModel;
import org.gcube.application.geoportalcommon.ConvertToDataViewModel;
import org.gcube.application.geoportalcommon.GeoportalCommon;
import org.gcube.application.geoportalcommon.MockDocumentConfigurationReader;
import org.gcube.application.geoportalcommon.MongoServiceCommon;
import org.gcube.application.geoportalcommon.ProjectDVBuilder;
import org.gcube.application.geoportalcommon.geoportal.GeoportalClientCaller;
import org.gcube.application.geoportalcommon.geoportal.ProjectsCaller;
import org.gcube.application.geoportalcommon.geoportal.UseCaseDescriptorCaller;
import org.gcube.application.geoportalcommon.shared.GNADataEntryConfigProfile;
import org.gcube.application.geoportalcommon.shared.GNADataViewerConfigProfile;
import org.gcube.application.geoportalcommon.shared.GeoNaItemRef;
@ -26,8 +30,10 @@ import org.gcube.application.geoportalcommon.shared.config.GcubeUserRole;
import org.gcube.application.geoportalcommon.shared.config.RoleRights;
import org.gcube.application.geoportalcommon.shared.config.RoleRights.OPERATION_TYPE;
import org.gcube.application.geoportalcommon.shared.exception.GNAConfigException;
import org.gcube.application.geoportalcommon.shared.geoportalconfig.DocumentConfigDV;
import org.gcube.application.geoportalcommon.shared.geoportalconfig.GcubeProfileDV;
import org.gcube.application.geoportalcommon.shared.geoportal.GEOPORTAL_DATA_HANDLER;
import org.gcube.application.geoportalcommon.shared.geoportal.ProjectDV;
import org.gcube.application.geoportalcommon.shared.geoportal.UseCaseDescriptorDV;
import org.gcube.application.geoportalcommon.shared.geoportal.config.GcubeProfileDV;
import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV;
import org.gcube.application.geoportalcommon.shared.products.content.WorkspaceContentDV;
import org.gcube.application.geoportalcommon.shared.products.paths.FileSetPathsDV;
@ -48,8 +54,6 @@ import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault;
import org.gcube.vomanagement.usermanagement.impl.LiferayRoleManager;
import org.gcube.vomanagement.usermanagement.model.GCubeRole;
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -80,7 +84,7 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
GNADataEntryConfigProfile profile = SessionUtil.getGNADataEntryConfigProfile(getThreadLocalRequest());
if (profile == null) {
LOG.info(GNADataEntryConfigProfile.class.getSimpleName() + " is null, loading configurations from IS");
//to be sure
// to be sure
SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true);
GeoportalCommon gCommon = new GeoportalCommon();
profile = gCommon.readGNADataEntryConfig();
@ -91,77 +95,6 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
return profile;
}
private JSONObject genericDatasetBeanToJSON(GenericDatasetBean gdb) throws JSONException {
JSONObject sectJSONObject = JSONObjecOrdered.instance();
LinkedHashMap<String, List<String>> mapFields = gdb.getFormDataEntryFields();
System.out.println("Map ordered: "+mapFields);
for (String key : mapFields.keySet()) {
List<String> listValues = mapFields.get(key);
if (listValues == null || listValues.isEmpty()) {
continue;
}
// key/value as string
if (listValues.size() == 1) {
sectJSONObject.put(key, listValues.get(0));
continue;
}
// value is a list
JSONArray array = new JSONArray();
for (String value : listValues) {
array.put(value);
}
sectJSONObject.put(key, array);
}
return sectJSONObject;
}
/**
* Merge "source" into "target". If fields have equal name, merge them recursively.
* @return the merged object (target).
*/
public static JSONObject deepMerge(JSONObject source, JSONObject target) throws JSONException {
for (String key: JSONObject.getNames(source)) {
Object value = source.get(key);
if (!target.has(key)) {
// new value for "key":
target.put(key, value);
} else {
// existing value for "key" - recursively deep merge:
if (value instanceof JSONObject) {
JSONObject valueJson = (JSONObject)value;
deepMerge(valueJson, target.getJSONObject(key));
} else {
target.put(key, value);
}
}
}
return target;
}
public static class JSONObjecOrdered {
public static JSONObject instance() {
JSONObject jsonObject = new JSONObject();
try {
Field changeMap = jsonObject.getClass().getDeclaredField("map");
changeMap.setAccessible(true);
changeMap.set(jsonObject, new LinkedHashMap<>());
changeMap.setAccessible(false);
} catch (IllegalAccessException | NoSuchFieldException e) {
}
return jsonObject;
}
}
/**
* Save geona data forms.
@ -174,309 +107,58 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
public CommitReport saveGeonaDataForms(List<GeoNaFormDataObject> listGeonaFormObjects) throws Exception {
LOG.info("saveGeonaDataForms called");
String mongoId = null;
MongoServiceUtil serviceUtil = new MongoServiceUtil();
MongoConcessioni clientMongo = null;
MongoServiceUtil mongoService = new MongoServiceUtil();
try {
GCubeUser user = SessionUtil.getCurrentUser(this.getThreadLocalRequest());
FormDataObjectToJSON metadataConverter = new FormDataObjectToJSON();
JSONObject theDocument = metadataConverter.convert(listGeonaFormObjects);
String theDocumentString = theDocument.toString();
LOG.info("Got Document: " + theDocumentString);
SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true);
clientMongo = serviceUtil.getInstanceMongoConcessioni();
JSONObject rootDocument = JSONObjecOrdered.instance();
LOG.debug("Going to create the project...");
Project theProject = mongoService.createNew("ProfileID", theDocumentString);
LOG.info("Project created with id: " + theProject.getId() + " and profileID: " + theProject.getProfileID());
// Uploading files
LOG.debug("Going to upload the files");
for (GeoNaFormDataObject geoNaFormDataObject : listGeonaFormObjects) {
List<GenericDatasetBean> listGDB = geoNaFormDataObject.getListGDB();
GcubeProfileDV profile = geoNaFormDataObject.getGcubeProfileDV();
LOG.debug("The profile is: " + profile);
String jsonPathExp = String.format("%s%s", profile.getParentName(), profile.getSectionName());
LOG.debug("The json path to build: " + jsonPathExp);
//jsonPathExp = "$.chidl1.child2.child3";
String toJsonPathExp = jsonPathExp.replaceFirst("\\$", "");
JSONObject sectRootObject = JSONObjecOrdered.instance();
LOG.info("The profile is: " + profile);
String sectionPath = profile.getParentName() + profile.getSectionName();
for (GenericDatasetBean gdb : listGDB) {
List<FileUploaded> files = gdb.getFilesUploaded();
if (files.size() > 0) {
LOG.info("Uploading files in the section path: " + sectionPath);
for (int i = 0; i < files.size(); i++) {
FileUploaded file = files.get(i);
LOG.debug("Uploading file: " + file.getFileName());
// As single object
if (files.size() == 1) {
String fieldName = profile.getSectionName();
LOG.debug("Using field name: " + fieldName);
mongoService.registerFileSet("ProfileID", theProject,
new File(file.getTempSystemPath()), profile.getParentName(),
profile.getSectionName(), "");
JSONObject jsonObject = genericDatasetBeanToJSON(gdb);
LOG.debug("Adding section : " + jsonObject);
String[] jsonPathDeep = toJsonPathExp.split("\\.");
LOG.trace("jsonPathDeep: " + Arrays.asList(jsonPathDeep) + " size: " + jsonPathDeep.length);
// ROOT $.
if (jsonPathDeep.length == 0) {
sectRootObject = deepMerge(jsonObject, sectRootObject);
//System.out.println("jsonPathDeep.length==0: " + sectRootObject.toString(4));
//rootDocument.put(jsonPathDeep[0], sectRootObject);
rootDocument = deepMerge(sectRootObject, rootDocument);
}
// DEPTH >= 1
if (jsonPathDeep.length > 1) {
sectRootObject.put(jsonPathDeep[jsonPathDeep.length - 1], jsonObject);
JSONObject deepJSON = sectRootObject;
System.out.println("sectRootObject: " + sectRootObject.toString());
for (int i = jsonPathDeep.length - 2; i > 0; i--) {
JSONObject newOne = JSONObjecOrdered.instance();
newOne.put(jsonPathDeep[i], deepJSON);
deepJSON = newOne;
} else {
// As Array of objects
String fieldName = profile.getSectionName() + "[" + i + "]";
LOG.debug("Using field name: " + fieldName);
mongoService.registerFileSet("ProfileID", theProject,
new File(file.getTempSystemPath()), profile.getParentName(), fieldName, "");
}
}
System.out.println("ext deepJSON: " + deepJSON);
rootDocument = deepMerge(deepJSON, rootDocument);
}
}
System.out.println("Partial Root Document is: "+rootDocument);
}
System.out.println("Final Document is: "+rootDocument);
return null;
// for (ProjectFormCard geoNaFormDataObject : toMap.keySet()) {
//
// List<GeoNaFormDataObject> list = toMap.get(geoNaFormDataObject);
// List<GenericDatasetBean> listGDB = list.get(0).getListGDB();
// GenericDatasetBean idp = listGDB.get(0);
//
// idp.getFormDataEntryFields();
//
// geoNaFormDataObject.
// }
//
/*
// Saving Data
// Informazioni di Progetto
List<GeoNaFormDataObject> list = toMap.get(ProjectFormCard.INFORMAZIONI_DI_PROGETTO);
if (list == null || list.isEmpty() || list.get(0) == null || list.get(0).getListGDB() == null)
throw new Exception(
"Error: no data found for " + ProjectFormCard.INFORMAZIONI_DI_PROGETTO.getTitle());
List<GenericDatasetBean> listGDB = list.get(0).getListGDB();
GenericDatasetBean idp = listGDB.get(0);
LOG.debug("\n\n");
LOG.debug(ProjectFormCard.INFORMAZIONI_DI_PROGETTO + " building with client obj: " + idp);
Concessione concessione = ConvertToServiceModel.toConcessione(idp, user);
LOG.debug("Built " + ProjectFormCard.INFORMAZIONI_DI_PROGETTO + " as server obj: " + concessione);
// Register New Concessione
concessioneNew = clientMongo.createNew(concessione);
// ABSTRACT_RELAZIONE_DI_SCAVO
list = toMap.get(ProjectFormCard.ABSTRACT_RELAZIONE_DI_SCAVO);
if (list == null || list.isEmpty() || list.get(0) == null || list.get(0).getListGDB() == null)
throw new Exception(
"Error: no data found for " + ProjectFormCard.ABSTRACT_RELAZIONE_DI_SCAVO.getTitle());
listGDB = list.get(0).getListGDB();
GenericDatasetBean ards = listGDB.get(0);
LOG.debug("\n\n");
LOG.debug(ProjectFormCard.ABSTRACT_RELAZIONE_DI_SCAVO + " building with client obj: " + ards);
AbstractRelazione abstractRelazioneDiScavo = ConvertToServiceModel.toAbstractRelazioneScavo(ards);
// Setting Abstract Relazione
concessioneNew.setAbstractRelazione(abstractRelazioneDiScavo);
// RELAZIONE_DI_SCAVO
list = toMap.get(ProjectFormCard.RELAZIONE_DI_SCAVO);
if (list == null || list.isEmpty() || list.get(0) == null || list.get(0).getListGDB() == null)
throw new Exception(
"Error: no data found for " + ProjectFormCard.RELAZIONE_DI_SCAVO.getTitle());
listGDB = list.get(0).getListGDB();
GenericDatasetBean rds = listGDB.get(0);
LOG.debug("\n\n");
LOG.debug(ProjectFormCard.RELAZIONE_DI_SCAVO + " building with client obj: " + rds);
RelazioneScavo relazioneDiScavo = ConvertToServiceModel.toRelazioneScavo(rds);
LOG.debug("Built " + ProjectFormCard.RELAZIONE_DI_SCAVO + " as server obj: " + relazioneDiScavo);
// Setting Relazione
concessioneNew.setRelazioneScavo(relazioneDiScavo);
// IMMAGINI_RAPPRESENTATIVE
list = toMap.get(ProjectFormCard.IMMAGINI_RAPPRESENTATIVE);
if (list == null || list.isEmpty() || list.get(0) == null || list.get(0).getListGDB() == null)
throw new Exception(
"Error: no data found for " + ProjectFormCard.IMMAGINI_RAPPRESENTATIVE.getTitle());
List<GenericDatasetBean> imgRaprsLst = list.get(0).getListGDB();
List<UploadedImage> immaginiRappresentativeService = null;
if (imgRaprsLst.size() > 0) {
immaginiRappresentativeService = new ArrayList<UploadedImage>(imgRaprsLst.size());
for (GenericDatasetBean imgRapr : imgRaprsLst) {
LOG.debug("\n\n");
LOG.debug(ProjectFormCard.IMMAGINI_RAPPRESENTATIVE + " building with client obj: "
+ imgRapr);
UploadedImage img = ConvertToServiceModel.toImmaginiRappresentative(imgRapr);
LOG.debug("Built " + ProjectFormCard.IMMAGINI_RAPPRESENTATIVE + " as server obj: " + img);
immaginiRappresentativeService.add(img);
}
}
// Setting Immagini Rappresentative
if (immaginiRappresentativeService != null) {
concessioneNew.setImmaginiRappresentative(immaginiRappresentativeService);
}
// POSIZIONAMENTO_DELL_AREA_DI_INDAGINE
list = toMap.get(ProjectFormCard.POSIZIONAMENTO_DELL_AREA_DI_INDAGINE);
if (list == null || list.isEmpty() || list.get(0) == null || list.get(0).getListGDB() == null)
throw new Exception("Error: no data found for "
+ ProjectFormCard.POSIZIONAMENTO_DELL_AREA_DI_INDAGINE.getTitle());
listGDB = list.get(0).getListGDB();
GenericDatasetBean pad = listGDB.get(0);
LayerConcessione layerPad = null;
if (pad != null) {
LOG.debug("\n\n");
LOG.debug(ProjectFormCard.POSIZIONAMENTO_DELL_AREA_DI_INDAGINE + " building with client obj: "
+ pad);
layerPad = ConvertToServiceModel.toLayerConcessione(pad);
LOG.debug("Built " + ProjectFormCard.POSIZIONAMENTO_DELL_AREA_DI_INDAGINE + " as server obj: "
+ layerPad);
}
// Setting Posizionamento Di Scavo
if (layerPad != null) {
concessioneNew.setPosizionamentoScavo(layerPad);
}
// PIANTA_DI_FINE_SCAVO
list = toMap.get(ProjectFormCard.PIANTA_DI_FINE_SCAVO);
if (list == null || list.isEmpty() || list.get(0) == null || list.get(0).getListGDB() == null)
throw new Exception(
"Error: no data found for " + ProjectFormCard.PIANTA_DI_FINE_SCAVO.getTitle());
listGDB = list.get(0).getListGDB();
List<GenericDatasetBean> listPfs = listGDB;
// Managing N:N
List<LayerConcessione> pianteFineScavo = null;
if (listPfs.size() > 0) {
pianteFineScavo = new ArrayList<LayerConcessione>(listPfs.size());
for (GenericDatasetBean pfs : listPfs) {
LOG.debug("\n\n");
LOG.debug(ProjectFormCard.PIANTA_DI_FINE_SCAVO + " building with client obj: " + pfs);
LayerConcessione layerPfs = ConvertToServiceModel.toLayerConcessione(pfs);
LOG.debug("Built " + ProjectFormCard.PIANTA_DI_FINE_SCAVO + " as server obj: " + layerPfs);
pianteFineScavo.add(layerPfs);
}
}
// Setting Piante fine Scavo
if (pianteFineScavo != null) {
concessioneNew.setPianteFineScavo(pianteFineScavo);
}
// Registering Meta
clientMongo.replace(concessioneNew);
mongoId = concessioneNew.getMongo_id();
LOG.info("Registered the meta. Called mongo.replace for: " + concessioneNew);
// UPLOADING FILES
LOG.info("Now uploading the files...");
// Building TempFile for ABSTRACT DELLA RELAZIONE DI SCAVO
SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true);
List<TempFile> ardsFiles = serviceUtil.toTemFiles(ards.getFilesUploaded());
// Building TempFile for ABSTRACT RELAZIONE
if (ardsFiles != null && ardsFiles.size() > 0) {
// saving into back-end
//TODO MUST BE REVISITED
AddSectionToConcessioneRequest request = new AddSectionToConcessioneRequest(Paths.ABSTRACT_RELAZIONE, ardsFiles);
clientMongo.registerFileSet(mongoId, request);
LOG.info("Registered the mongoId " + mongoId + " request " + Paths.RELAZIONE + "with "
+ ardsFiles.size() + " file/s");
}
// Building TempFile for RELAZIONE DI SCAVO
SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true);
List<TempFile> files = serviceUtil.toTemFiles(rds.getFilesUploaded());
// Upload file to Concessione. Should be one file.
if (files != null && files.size() > 0) {
// saving into back-end
//TODO MUST BE REVISITED
AddSectionToConcessioneRequest request = new AddSectionToConcessioneRequest(Paths.RELAZIONE, files);
clientMongo.registerFileSet(mongoId, request);
LOG.info("Registered the mongoId " + mongoId + " request " + Paths.RELAZIONE + "with " + files.size()
+ " file/s");
}
// IMMAGINI RAPPRESENTATIVE
for (int i = 0; i < imgRaprsLst.size(); i++) {
LOG.debug("\n\n");
GenericDatasetBean imgRapr = imgRaprsLst.get(i);
// Building TempFile for Immagini
SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true);
files = serviceUtil.toTemFiles(imgRapr.getFilesUploaded());
// Upload file to Concessione. The size is always 1 so it is consistent with the
// 'for' index
if (files != null && files.size() > 0) {
// saving into back-end
//TODO MUST BE REVISITED
AddSectionToConcessioneRequest request = new AddSectionToConcessioneRequest(Paths.imgByIndex(i),
files);
clientMongo.registerFileSet(mongoId, request);
LOG.info("Registered the mongoId " + mongoId + " request " + Paths.IMMAGINI + "with " + files.size()
+ " file/s");
}
}
// POSIZIONAMENTO
// Building TempFile for POSIZIONAMENTO
SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true);
files = serviceUtil.toTemFiles(pad.getFilesUploaded());
// Upload file to Concessione
if (files != null && files.size() > 0) {
// saving into back-end
//TODO MUST BE REVISITED
AddSectionToConcessioneRequest request = new AddSectionToConcessioneRequest(Paths.POSIZIONAMENTO,
files);
clientMongo.registerFileSet(mongoId, request);
LOG.info("Registered the mongoId " + mongoId + " request " + Paths.POSIZIONAMENTO + "with "
+ files.size() + " file/s");
}
// PIANTE FINE SCAVO
if (listPfs.size() > 0) {
for (int i = 0; i < listPfs.size(); i++) {
// Building TempFile for PIANTA_DI_FINE_SCAVO
GenericDatasetBean pfs = listPfs.get(i);
SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true);
files = serviceUtil.toTemFiles(pfs.getFilesUploaded());
// Upload file to Concessione Section by Path 'Relazione'
if (files != null && files.size() > 0) {
// saving into back-end
//TODO MUST BE REVISITED
AddSectionToConcessioneRequest request = new AddSectionToConcessioneRequest(
Paths.piantaByIndex(i), files);
clientMongo.registerFileSet(mongoId, request);
LOG.info("Registered the mongoId " + mongoId + " request " + Paths.PIANTE + "with "
+ files.size() + " file/s");
}
}
}*/
} catch (Exception e) {
LOG.error("Error on converting form data: ", e);
@ -571,36 +253,75 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
}
/**
* Gets the list concessioni.
* Gets the list projects.
*
* @param start the start
* @param limit the limit
* @param filter the filter
* @param reloadFromService the reload from service
* @return the list concessioni
* @return the list projects
* @throws Exception the exception
*/
@Override
public ResultSetPaginatedData getListConcessioni(Integer start, Integer limit, SearchingFilter filter,
boolean reloadFromService) throws Exception {
LOG.info("getListConcessioni called wit start: " + start + ", limit: " + limit + ", filter: " + filter);
public ResultSetPaginatedData getListProjects(String theProfileID, Integer start, Integer limit,
SearchingFilter filter, boolean reloadFromService) throws Exception {
LOG.info("getListProjects called with profileID: " + theProfileID + ", start: " + start + ", limit: " + limit
+ ", filter: " + filter);
try {
ProjectsCaller client = GeoportalClientCaller.projects();
SessionUtil.getCurrentContext(getThreadLocalRequest(), true);
MongoServiceCommon serviceCommon = new MongoServiceCommon();
// TODO MUST BE REPLACED BY COUNT
List<Concessione> listOfConcessioni = SessionUtil.getListOfConcessioni(getThreadLocalRequest(),
reloadFromService);
int listConcessioniSize = listOfConcessioni.size();
List<ProjectDV> listProjectDV = SessionUtil.getListOfProjectsForProfileID(getThreadLocalRequest(),
theProfileID);
ProjectDVBuilder projectBuilder = ProjectDVBuilder.newBuilder().fullDocumentMap(true);
if (reloadFromService || listProjectDV == null) {
List<Project> listProject = client.getListForProfileID(theProfileID);
listProjectDV = new ArrayList<ProjectDV>(listProject.size());
for (Project project : listProject) {
listProjectDV.add(ConvertToDataValueObjectModel.toProjectDV(project, projectBuilder));
}
SessionUtil.setListOfProjectsForProfileID(getThreadLocalRequest(), theProfileID, listProjectDV);
}
int listConcessioniSize = listProjectDV.size();
ResultSetPaginatedData searchedData = client.queryOnMongo(theProfileID, listConcessioniSize, start, limit,
filter, projectBuilder);
// public ResultSetPaginatedData queryOnMongo(String profileID, Integer totalItems, Integer offset, Integer limit,
// SearchingFilter filter, String recordType, ProjectDVBuilder projectDVBuilder) throws Exception {
/*
* SessionUtil.getCurrentContext(getThreadLocalRequest(), true);
* MongoServiceCommon serviceCommon = new MongoServiceCommon();
*
* // TODO MUST BE REPLACED BY COUNT List<Concessione> listOfConcessioni =
* SessionUtil.getListOfConcessioni(getThreadLocalRequest(), reloadFromService);
* int listConcessioniSize = listOfConcessioni.size();
*
* ResultSetPaginatedData searchedData =
* serviceCommon.queryOnMongo(listConcessioniSize, start, limit, filter,
* "concessione"); return searchedData;
*/
if (LOG.isDebugEnabled()) {
LOG.debug("returning {}", searchedData.getData());
}
List<ProjectDV> data = searchedData.getData();
if (data != null) {
LOG.info("returning {} project/s", data.size());
}
ResultSetPaginatedData searchedData = serviceCommon.queryOnMongo(listConcessioniSize, start, limit, filter,
"concessione");
return searchedData;
} catch (Exception e) {
LOG.error("Error on loading paginated and filtered list of concessioni: ", e);
LOG.error("Error on loading paginated and filtered list of projects for id: ", e);
throw new Exception("Error occurred on loading list of Concessioni. Error: " + e.getMessage());
}
@ -829,34 +550,31 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
LOG.debug(newFiles.size() + " new file/s has/have been added to list of files");
}
//TODO MUST BE REVISITED
// TODO MUST BE REVISITED
/*
if (section.contains("abstract_relazione")) {
* if (section.contains("abstract_relazione")) {
*
* toEditPath = Paths.ABSTRACT_RELAZIONE; request = new
* AddSectionToConcessioneRequest(toEditPath, files);
*
* } else if (section.contains("immagini")) { toEditPath =
* Paths.imgByIndex(pathIndex); request = new
* AddSectionToConcessioneRequest(toEditPath, files);
*
* } else if (section.contains("relazione")) { toEditPath = Paths.RELAZIONE;
* request = new AddSectionToConcessioneRequest(toEditPath, files);
*
* } else if (section.contains("posizionamentoScavo")) { toEditPath =
* Paths.POSIZIONAMENTO; request = new
* AddSectionToConcessioneRequest(toEditPath, files);
*
* } else if (section.contains("piante")) { toEditPath =
* Paths.piantaByIndex(pathIndex); request = new
* AddSectionToConcessioneRequest(toEditPath, files); }
*
*/
toEditPath = Paths.ABSTRACT_RELAZIONE;
request = new AddSectionToConcessioneRequest(toEditPath, files);
} else if (section.contains("immagini")) {
toEditPath = Paths.imgByIndex(pathIndex);
request = new AddSectionToConcessioneRequest(toEditPath, files);
} else if (section.contains("relazione")) {
toEditPath = Paths.RELAZIONE;
request = new AddSectionToConcessioneRequest(toEditPath, files);
} else if (section.contains("posizionamentoScavo")) {
toEditPath = Paths.POSIZIONAMENTO;
request = new AddSectionToConcessioneRequest(toEditPath, files);
} else if (section.contains("piante")) {
toEditPath = Paths.piantaByIndex(pathIndex);
request = new AddSectionToConcessioneRequest(toEditPath, files);
}
*/
// Unpublish
LOG.info("Unpublishing " + itemId);
clientMongo.unPublish(itemId);
@ -892,7 +610,13 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
"Error occurred on updating the project with id: " + itemId + ". Error: " + e.getMessage());
}
}
/**
* Read data viewer config.
*
* @return the GNA data entry ext config profile
* @throws Exception the exception
*/
@Override
public GNADataEntryExtConfigProfile readDataViewerConfig() throws Exception {
LOG.info("readDataViewerConfig called");
@ -982,11 +706,132 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
return gnaDEExtConfig;
}
}
// @Override
// public List<DocumentConfigDV> getListDocumentConfigurationForId(String id) throws Exception {
//// MockDocumentConfigurationReader mock = new MockDocumentConfigurationReader();
//// return mock.getListDocumentConfig();
//
// UseCaseDescriptorCaller client = GeoportalClientCaller.useCaseDescriptors();
//
// //TODO ID MUST BE THE HANDLER ID
// List<UseCaseDescriptor> useCaseDescriptor;
// try {
// List<String> handlersIds = Arrays.asList(GEOPORTAL_DATA_HANDLER.geoportal_data_entry.getId(), GEOPORTAL_DATA_HANDLER.geoportal_data_list.getId());
// useCaseDescriptor = client.getListForHandlerIds(handlersIds);
// } catch (Exception e1) {
// throw new Exception("Error when contacting the Geoportal service. Refresh and try again or contact the support");
// }
//
// List<UseCaseDescriptorDV> listUCD = new ArrayList<UseCaseDescriptorDV>(useCaseDescriptor.size());
// for (UseCaseDescriptor ucd : useCaseDescriptor) {
// listUCD.add(ConvertToDataValueObjectModel.toUseCaseDescriptorDV(ucd, null));
// }
//
// List<DocumentConfigDV> listDocumentConfig = new ArrayList<DocumentConfigDV>();
//
// for (UseCaseDescriptorDV useCaseDescriptorDV : listUCD) {
// DocumentConfigDV documentConfigDV = new DocumentConfigDV();
// documentConfigDV.setId(useCaseDescriptorDV.getId());
// documentConfigDV.setType(useCaseDescriptorDV.getName());
// documentConfigDV.setItemType(useCaseDescriptorDV.getName());
// ConfigHandlerDV config = new ConfigHandlerDV();
// List<HandlerDeclarationDV> handlers = useCaseDescriptorDV.getHandlers();
// List<GcubeProfileDV> gcubeProfiles = new ArrayList<GcubeProfileDV>();
// for (HandlerDeclarationDV handler : handlers) {
// ConfigurationDV<?> docConfig = handler.getConfiguration();
// try {
// List<GcubeProfileDV> theConfig = (List<GcubeProfileDV>) docConfig.getConfiguration();
// if(theConfig!=null) {
// gcubeProfiles.addAll(gcubeProfiles);
// }
// }catch (Exception e) {
// LOG.warn("The configuration read for "+documentConfigDV.getId()+ " is not a List of "+GcubeProfileDV.class.getSimpleName()+", skipping it");
// }
// }
//
// if(gcubeProfiles.size()>0) {
// config.setGcubeProfiles(gcubeProfiles);
// documentConfigDV.setConfiguration(config);
// listDocumentConfig.add(documentConfigDV);
// }
// }
//
// return listDocumentConfig;
//
//
// }
/**
* Gets the list use case descriptors.
*
* @param handlersIds the handlers ids
* @return the list use case descriptors
* @throws Exception the exception
*/
@Override
public List<DocumentConfigDV> getListDocumentConfigurationForId(String id){
MockDocumentConfigurationReader mock = new MockDocumentConfigurationReader();
return mock.getListDocumentConfig();
public List<UseCaseDescriptorDV> getListUseCaseDescriptors(List<String> handlersIds) throws Exception {
LOG.info("getListUseCaseDescriptors called for handlersIds: " + handlersIds);
try {
List<UseCaseDescriptor> listUseCaseDescriptor = null;
SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true);
try {
UseCaseDescriptorCaller client = GeoportalClientCaller.useCaseDescriptors();
if (handlersIds == null) {
handlersIds = Arrays.asList(GEOPORTAL_DATA_HANDLER.geoportal_data_entry.getId());
LOG.info("handlersIds is null, so using default: " + handlersIds);
}
//listUseCaseDescriptor = client.getListForHandlerIds(handlersIds);
listUseCaseDescriptor = client.getList();
} catch (Exception e) {
String error = "Error on contacting the Geoportal service";
LOG.error(error+ " for handlers: " + handlersIds, e);
throw new Exception(
"Error when contacting the Geoportal service. Refresh and try again or contact the support");
}
if (listUseCaseDescriptor == null) {
listUseCaseDescriptor = new ArrayList<UseCaseDescriptor>();
}
List<UseCaseDescriptorDV> listUCDDV = new ArrayList<UseCaseDescriptorDV>(listUseCaseDescriptor.size());
for (UseCaseDescriptor ucd : listUseCaseDescriptor) {
listUCDDV.add(ConvertToDataValueObjectModel.toUseCaseDescriptorDV(ucd, null));
}
// MOCK
/*
* List<UseCaseDescriptorDV> listUCDDV = new ArrayList<UseCaseDescriptorDV>();
* UseCaseDescriptorDV usecaseDescriptorDV = new UseCaseDescriptorDV("theId",
* "version", "listConcessioni", null); List<HandlerDeclarationDV> handlers =
* new ArrayList<HandlerDeclarationDV>();
*
* List<GcubeProfileDV> gcubeProfiles = new ArrayList<GcubeProfileDV>();
* GcubeProfileDV profile = new GcubeProfileDV();
* profile.setGcubeName("GcubeName");
* profile.setGcubeSecondaryType("GcubeSecondaryType");
* gcubeProfiles.add(profile);
*
* ConfigurationDV<List<GcubeProfileDV>> configuration = new
* ConfigurationDV<List<GcubeProfileDV>>(gcubeProfiles); HandlerDeclarationDV
* handler = new
* HandlerDeclarationDV(GEOPORTAL_DATA_HANDLER.geoportal_data_entry.getId(),
* GEOPORTAL_DATA_HANDLER.geoportal_data_entry.getType(), "Concessioni",
* configuration, GEOPORTAL_DATA_HANDLER.geoportal_data_entry);
*
* handlers.add(handler); usecaseDescriptorDV.setHandlers(handlers);
* listUCDDV.add(usecaseDescriptorDV);
*/
LOG.info("for handlersIds {} returning {} " + UseCaseDescriptor.class.getSimpleName(), handlersIds,
listUCDDV.size());
return listUCDDV;
} catch (Exception e) {
LOG.error("Error on getting list of Use Case Descriptors", e);
throw new Exception("An error occurred when getting list of Use Case Descriptors", e);
}
}
}

View File

@ -1,19 +1,29 @@
package org.gcube.portlets.user.geoportaldataentry.server;
import static org.gcube.application.geoportal.client.GeoportalAbstractPlugin.mongoConcessioni;
import static org.gcube.application.geoportal.client.plugins.GeoportalAbstractPlugin.projects;
import static org.gcube.application.geoportal.client.plugins.GeoportalAbstractPlugin.useCaseDescriptors;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import org.bson.Document;
import org.gcube.application.geoportal.client.utils.Serialization;
import org.gcube.application.geoportal.common.model.document.Project;
import org.gcube.application.geoportal.common.model.legacy.Concessione;
import org.gcube.application.geoportal.common.model.rest.RegisterFileSetRequest;
import org.gcube.application.geoportal.common.model.rest.TempFile;
import org.gcube.application.geoportal.common.rest.MongoConcessioni;
import org.gcube.application.geoportal.common.rest.Projects;
import org.gcube.application.geoportal.common.rest.UseCaseDescriptorsI;
import org.gcube.application.geoportal.common.utils.FileSets;
import org.gcube.application.geoportal.common.utils.StorageUtils;
import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV;
import org.gcube.application.geoportalcommon.shared.products.content.WorkspaceContentDV;
@ -22,6 +32,8 @@ import org.gcube.portlets.widgets.mpformbuilder.shared.upload.FileUploaded;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.core.JsonProcessingException;
/**
* The Class MongoServiceCommon.
*
@ -33,13 +45,50 @@ public class MongoServiceUtil {
private static Logger LOG = LoggerFactory.getLogger(MongoServiceUtil.class);
UseCaseDescriptorsI client = null;
public UseCaseDescriptorsI useCaseDescriptorsClient() {
return useCaseDescriptors().build();
}
public Projects<Project> getProjectsClient(String profileID) {
return projects(profileID).build();
}
public Project createNew(String profileID, String jsonDocument) throws RemoteException {
Document myDocument = Document.parse(jsonDocument);
Projects<Project> client = getProjectsClient(profileID);
// Create project
Project project = client.createNew(myDocument);
return project;
}
public void registerFileSet(String profileID, Project project, File theFile,
String parentPath, String fieldName, String fieldDefinition)
throws RemoteException, FileNotFoundException, JsonProcessingException {
Projects<Project> client = getProjectsClient(profileID);
// Prepare request
RegisterFileSetRequest fsRequest = FileSets.prepareRequest(new StorageUtils(), parentPath, fieldName,
fieldDefinition, theFile);
project = client.registerFileSet(project.getId(), fsRequest);
System.out.println("Resulting Project : " + project);
System.out.println("JSON Reprepsentation : " + Serialization.write(project));
}
/**
* Gets the instance mongo concessioni.
*
* @return the instance mongo concessioni
*/
public MongoConcessioni getInstanceMongoConcessioni() {
return mongoConcessioni().build();
// return mongoConcessioni().build();
LOG.warn("\n\n\nMUST BE PORTED TO NEW MONGO CLIENT");
return null;
}
/**

View File

@ -15,6 +15,7 @@ import org.gcube.application.geoportal.common.rest.MongoConcessioni;
import org.gcube.application.geoportalcommon.GeoportalCommon;
import org.gcube.application.geoportalcommon.shared.GNADataEntryConfigProfile;
import org.gcube.application.geoportalcommon.shared.GNADataViewerConfigProfile;
import org.gcube.application.geoportalcommon.shared.geoportal.ProjectDV;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.portal.PortalContext;
import org.gcube.common.scope.api.ScopeProvider;
@ -43,6 +44,8 @@ public class SessionUtil {
private static final String LATEST_RESULT_SET_SORTED = "LATEST_RESULT_SET_SORTED";
private static final String GEONA_DATAVIEWER_PROFILE = "GEONA_DATAVIEWER_PROFILE";
private static final String LIST_OF_CONCESSIONI = "LIST_OF_CONCESSIONI";
private static final String LIST_OF_PROJECTS = "LIST_OF_PROJECTS";
/** The log. */
private static Logger LOG = LoggerFactory.getLogger(SessionUtil.class);
@ -127,6 +130,34 @@ public class SessionUtil {
}
/**
* Gets the list of projects for profile ID.
*
* @param httpServletRequest the http servlet request
* @param profileID the profile ID
* @return the list of projects for profile ID
* @throws Exception the exception
*/
public static List<ProjectDV> getListOfProjectsForProfileID(HttpServletRequest httpServletRequest, String profileID)
throws Exception {
HttpSession session = httpServletRequest.getSession();
return (List<ProjectDV>) session.getAttribute(LIST_OF_PROJECTS + profileID);
}
/**
* Sets the list of projects for profile ID.
*
* @param httpServletRequest the http servlet request
* @param profileID the profile ID
* @param listOfProjects the list of projects
* @throws Exception the exception
*/
public static void setListOfProjectsForProfileID(HttpServletRequest httpServletRequest,
String profileID, List<ProjectDV> listOfProjects) throws Exception {
HttpSession session = httpServletRequest.getSession();
session.setAttribute(LIST_OF_PROJECTS + profileID, listOfProjects);
}
/**
* Gets the list of concessioni.
*

View File

@ -0,0 +1,61 @@
package org.gcube.portlets.user.geoportaldataentry.shared;
import java.io.Serializable;
import java.util.List;
import org.gcube.application.geoportalcommon.shared.geoportal.config.GcubeProfileDV;
public class ConfigHandlerDV implements Serializable {
/**
*
*/
private static final long serialVersionUID = 372838411789432170L;
private String id;
private String type; // is case in the JSON
private List<GcubeProfileDV> gcubeProfiles;
public ConfigHandlerDV() {
}
public String getId() {
return id;
}
public String getType() {
return type;
}
public List<GcubeProfileDV> getGcubeProfiles() {
return gcubeProfiles;
}
public void setId(String id) {
this.id = id;
}
public void setType(String type) {
this.type = type;
}
public void setGcubeProfiles(List<GcubeProfileDV> gcubeProfiles) {
this.gcubeProfiles = gcubeProfiles;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("ConfigHandlerDV [id=");
builder.append(id);
builder.append(", type=");
builder.append(type);
builder.append(", gcubeProfiles=");
builder.append(gcubeProfiles);
builder.append("]");
return builder.toString();
}
}

View File

@ -0,0 +1,66 @@
package org.gcube.portlets.user.geoportaldataentry.shared;
import java.io.Serializable;
public class DocumentConfigDV implements Serializable {
/**
*
*/
private static final long serialVersionUID = 7538079431272352662L;
private String id;
private String type;
private String itemType;
private ConfigHandlerDV configuration;
public DocumentConfigDV() {
}
public String getId() {
return id;
}
public String getType() {
return type;
}
public ConfigHandlerDV getConfiguration() {
return configuration;
}
public void setId(String id) {
this.id = id;
}
public String getItemType() {
return itemType;
}
public void setItemType(String itemType) {
this.itemType = itemType;
}
public void setType(String type) {
this.type = type;
}
public void setConfiguration(ConfigHandlerDV configuration) {
this.configuration = configuration;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("DocumentConfigDV [id=");
builder.append(id);
builder.append(", type=");
builder.append(type);
builder.append(", itemType=");
builder.append(itemType);
builder.append(", configuration=");
builder.append(configuration);
builder.append("]");
return builder.toString();
}
}

View File

@ -3,7 +3,7 @@ package org.gcube.portlets.user.geoportaldataentry.shared;
import java.io.Serializable;
import java.util.List;
import org.gcube.application.geoportalcommon.shared.geoportalconfig.GcubeProfileDV;
import org.gcube.application.geoportalcommon.shared.geoportal.config.GcubeProfileDV;
import org.gcube.portlets.widgets.mpformbuilder.shared.GenericDatasetBean;
public class GeoNaFormDataObject implements Serializable {

View File

@ -1,181 +1,181 @@
package org.gcube.portlets.user.geoportaldataentry;
import static org.gcube.application.geoportal.client.GeoportalAbstractPlugin.mongoConcessioni;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.bson.Document;
import org.gcube.application.geoportal.common.model.legacy.Concessione;
import org.gcube.application.geoportal.common.model.rest.QueryRequest;
import org.gcube.application.geoportal.common.model.rest.QueryRequest.OrderedRequest;
import org.gcube.application.geoportal.common.model.rest.QueryRequest.OrderedRequest.Direction;
import org.gcube.application.geoportal.common.model.rest.QueryRequest.PagedRequest;
import org.gcube.application.geoportal.common.rest.MongoConcessioni;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.scope.api.ScopeProvider;
import com.mongodb.BasicDBList;
import com.mongodb.BasicDBObject;
import com.mongodb.BasicDBObjectBuilder;
public class TestClass {
private static String TOKEN = "";
private static String CONTEXT = "/gcube/devsec/devVRE";
private static String USERNAME = "francesco.mangiacrapa";
//@Before
public void init() {
ScopeProvider.instance.set(CONTEXT);
SecurityTokenProvider.instance.set(TOKEN);
}
// @Test
public void getListConcessioniTest() throws Exception {
MongoConcessioni clientMongo = mongoConcessioni().build();
Iterator<Concessione> concessioni = clientMongo.getList();
List<Concessione> listOfConcessioni = new ArrayList<Concessione>();
if (concessioni != null) {
while (concessioni.hasNext()) {
Concessione concessione = (Concessione) concessioni.next();
listOfConcessioni.add(concessione);
}
}
int i = 0;
for (Concessione concessione : listOfConcessioni) {
System.out.println(++i + " " + concessione);
}
}
//@Test
public void queryConcessioniTest() throws Exception {
try {
MongoConcessioni clientMongo = mongoConcessioni().build();
int offsetIndex = 0;
int limitIndex = 25;
Direction sDirection = Direction.ASCENDING;
List<String> orderByFields = Arrays.asList("nome");
Map<String, Object> searchFields = new HashMap<String, Object>();
searchFields.put("nome", "test");
searchFields.put("authors", "fra");
QueryRequest request = new QueryRequest();
PagedRequest paging = new PagedRequest();
paging.setOffset(offsetIndex);
paging.setLimit(limitIndex);
request.setPaging(paging);
OrderedRequest ordering = new OrderedRequest();
ordering.setDirection(sDirection);
ordering.setFields(orderByFields);
request.setOrdering(ordering);
Document query = null;
if (searchFields != null) {
BasicDBObjectBuilder builder = BasicDBObjectBuilder.start();
query = new Document();
for (String key : searchFields.keySet()) {
// builder.append(key, new BasicDBObject("$eq", searchFields.get(key)));
BasicDBObject bs = new BasicDBObject();
bs.append("$regex", searchFields.get(key));
bs.append("$options", "i");
builder.append(key, bs);
// query.put(key, new BasicDBObject("$eq", searchFields.get(key)));
// query = new Document(key, searchFields.get(key));
}
// query.putAll(builder.get().toMap());
// request.setFilter(query);
BasicDBList list = new BasicDBList();
list.add(builder.get().toMap());
query.put("$or", list);
// or(query);
request.setFilter(query);
// ************************************************ AND
// query = new Document();
// for (String key : searchFields.keySet()) {
// //AND
// BasicDBObject bs = new BasicDBObject();
// bs.append("$regex", searchFields.get(key));
// bs.append("$options", "i");
// query.put(key, bs);
//
// }
// request.setFilter(query);
// ******************************************** END AND
}
// OR
/*
* query = new Document(); BasicDBObject container = new BasicDBObject();
* BsonArray bArray = new BsonArray(); for (String key : searchFields.keySet())
* { //AND BasicDBObject bs = new BasicDBObject(); bs.append("$regex",
* searchFields.get(key)); bs.append("$options", "i"); query.put(key, bs);
*
* //container.put(key, bs);
*
*
* // BasicDBObject bs2 = new BasicDBObject(); // bs2.append("$regex",
* searchFields.get(key)); // bs2.append("$options", "i"); // BsonDocument bsK =
* new BsonDocument(); // bsK.append(key, new BsonString(bs2.toJson())); //
* bArray.add(bsK);
*
* } // query.put("$or", bArray);
*
* BasicDBList list = new BasicDBList(); list.add(query);
*
* Document orDocument = new Document(); orDocument.put("$or", list); // query =
* orDocument; request.setFilter(query);
*/
System.out.println("Paging offset: " + offsetIndex + ", limit: " + limitIndex);
System.out.println("Direction: " + sDirection);
System.out.println("Order by Fields: " + orderByFields);
System.out.println("Search for: " + query);
System.out.println("Search for Query to JSON: " + query.toJson());
Iterator<Concessione> concessioni = clientMongo.query(request);
if (concessioni.hasNext()) {
System.out.println("Found concessioni, printing them...");
} else
System.out.println("No concessione found");
if (concessioni != null) {
while (concessioni.hasNext()) {
Concessione concessione = (Concessione) concessioni.next();
System.out.println(concessione.getNome());
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
// @Test
// public void readUserRights() throws Exception {
// new GNARoleRitghtsConfigReader();
// List<RoleRights> listUserRights = GNARoleRitghtsConfigReader.readRoleRightsConfig();
// System.out.println(listUserRights);
//package org.gcube.portlets.user.geoportaldataentry;
//
//
//
//import java.util.ArrayList;
//import java.util.Arrays;
//import java.util.HashMap;
//import java.util.Iterator;
//import java.util.List;
//import java.util.Map;
//
//import org.bson.Document;
//import org.gcube.application.geoportal.common.model.legacy.Concessione;
//import org.gcube.application.geoportal.common.model.rest.QueryRequest;
//import org.gcube.application.geoportal.common.model.rest.QueryRequest.OrderedRequest;
//import org.gcube.application.geoportal.common.model.rest.QueryRequest.OrderedRequest.Direction;
//import org.gcube.application.geoportal.common.model.rest.QueryRequest.PagedRequest;
//import org.gcube.application.geoportal.common.rest.MongoConcessioni;
//import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
//import org.gcube.common.scope.api.ScopeProvider;
//
//import com.mongodb.BasicDBList;
//import com.mongodb.BasicDBObject;
//import com.mongodb.BasicDBObjectBuilder;
//
//public class TestClass {
//
// private static String TOKEN = "";
// private static String CONTEXT = "/gcube/devsec/devVRE";
// private static String USERNAME = "francesco.mangiacrapa";
//
// //@Before
// public void init() {
// ScopeProvider.instance.set(CONTEXT);
// SecurityTokenProvider.instance.set(TOKEN);
// }
}
//
// // @Test
// public void getListConcessioniTest() throws Exception {
// MongoConcessioni clientMongo = mongoConcessioni().build();
// Iterator<Concessione> concessioni = clientMongo.getList();
// List<Concessione> listOfConcessioni = new ArrayList<Concessione>();
// if (concessioni != null) {
// while (concessioni.hasNext()) {
// Concessione concessione = (Concessione) concessioni.next();
// listOfConcessioni.add(concessione);
//
// }
// }
// int i = 0;
// for (Concessione concessione : listOfConcessioni) {
// System.out.println(++i + " " + concessione);
// }
// }
//
// //@Test
// public void queryConcessioniTest() throws Exception {
// try {
// MongoConcessioni clientMongo = mongoConcessioni().build();
// int offsetIndex = 0;
// int limitIndex = 25;
// Direction sDirection = Direction.ASCENDING;
// List<String> orderByFields = Arrays.asList("nome");
//
// Map<String, Object> searchFields = new HashMap<String, Object>();
// searchFields.put("nome", "test");
// searchFields.put("authors", "fra");
//
// QueryRequest request = new QueryRequest();
// PagedRequest paging = new PagedRequest();
// paging.setOffset(offsetIndex);
// paging.setLimit(limitIndex);
// request.setPaging(paging);
//
// OrderedRequest ordering = new OrderedRequest();
//
// ordering.setDirection(sDirection);
//
// ordering.setFields(orderByFields);
// request.setOrdering(ordering);
//
// Document query = null;
//
// if (searchFields != null) {
//
// BasicDBObjectBuilder builder = BasicDBObjectBuilder.start();
//
// query = new Document();
//
// for (String key : searchFields.keySet()) {
// // builder.append(key, new BasicDBObject("$eq", searchFields.get(key)));
// BasicDBObject bs = new BasicDBObject();
// bs.append("$regex", searchFields.get(key));
// bs.append("$options", "i");
// builder.append(key, bs);
// // query.put(key, new BasicDBObject("$eq", searchFields.get(key)));
// // query = new Document(key, searchFields.get(key));
// }
//
//// query.putAll(builder.get().toMap());
//// request.setFilter(query);
//
// BasicDBList list = new BasicDBList();
// list.add(builder.get().toMap());
// query.put("$or", list);
// // or(query);
// request.setFilter(query);
//
// // ************************************************ AND
//// query = new Document();
//// for (String key : searchFields.keySet()) {
//// //AND
//// BasicDBObject bs = new BasicDBObject();
//// bs.append("$regex", searchFields.get(key));
//// bs.append("$options", "i");
//// query.put(key, bs);
////
//// }
//// request.setFilter(query);
// // ******************************************** END AND
// }
//
// // OR
// /*
// * query = new Document(); BasicDBObject container = new BasicDBObject();
// * BsonArray bArray = new BsonArray(); for (String key : searchFields.keySet())
// * { //AND BasicDBObject bs = new BasicDBObject(); bs.append("$regex",
// * searchFields.get(key)); bs.append("$options", "i"); query.put(key, bs);
// *
// * //container.put(key, bs);
// *
// *
// * // BasicDBObject bs2 = new BasicDBObject(); // bs2.append("$regex",
// * searchFields.get(key)); // bs2.append("$options", "i"); // BsonDocument bsK =
// * new BsonDocument(); // bsK.append(key, new BsonString(bs2.toJson())); //
// * bArray.add(bsK);
// *
// * } // query.put("$or", bArray);
// *
// * BasicDBList list = new BasicDBList(); list.add(query);
// *
// * Document orDocument = new Document(); orDocument.put("$or", list); // query =
// * orDocument; request.setFilter(query);
// */
//
// System.out.println("Paging offset: " + offsetIndex + ", limit: " + limitIndex);
// System.out.println("Direction: " + sDirection);
// System.out.println("Order by Fields: " + orderByFields);
// System.out.println("Search for: " + query);
// System.out.println("Search for Query to JSON: " + query.toJson());
//
// Iterator<Concessione> concessioni = clientMongo.query(request);
//
// if (concessioni.hasNext()) {
// System.out.println("Found concessioni, printing them...");
// } else
// System.out.println("No concessione found");
//
// if (concessioni != null) {
// while (concessioni.hasNext()) {
// Concessione concessione = (Concessione) concessioni.next();
// System.out.println(concessione.getNome());
//
// }
//
// }
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
//
// // @Test
//// public void readUserRights() throws Exception {
//// new GNARoleRitghtsConfigReader();
//// List<RoleRights> listUserRights = GNARoleRitghtsConfigReader.readRoleRightsConfig();
//// System.out.println(listUserRights);
//// }
//
//
//
//}

View File

@ -0,0 +1,117 @@
package org.gcube.portlets.user.geoportaldataentry;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor;
import org.gcube.application.geoportalcommon.ConvertToDataValueObjectModel;
import org.gcube.application.geoportalcommon.geoportal.GeoportalClientCaller;
import org.gcube.application.geoportalcommon.geoportal.UseCaseDescriptorCaller;
import org.gcube.application.geoportalcommon.shared.geoportal.GEOPORTAL_DATA_HANDLER;
import org.gcube.application.geoportalcommon.shared.geoportal.UseCaseDescriptorDV;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.scope.api.ScopeProvider;
import org.junit.Before;
import org.junit.Test;
public class UCD_Tests {
private UseCaseDescriptorCaller client = null;
// private static String CONTEXT = "/pred4s/preprod/preVRE";
// private static String TOKEN = ""; //preVRE
private static String CONTEXT = "/gcube/devsec/devVRE";
private static String TOKEN = ""; // devVRE
private static String PROFILE_ID = "profiledConcessioni";
@Before
public void getClient() {
// assumeTrue(GCubeTest.isTestInfrastructureEnabled());
ScopeProvider.instance.set(CONTEXT);
SecurityTokenProvider.instance.set(TOKEN);
client = GeoportalClientCaller.useCaseDescriptors();
}
// @Test
public void getList() throws Exception {
ScopeProvider.instance.set(CONTEXT);
SecurityTokenProvider.instance.set(TOKEN);
List<UseCaseDescriptor> listOfUCD = client.getList();
int i = 0;
for (UseCaseDescriptor useCaseDescriptor : listOfUCD) {
System.out.println(++i + ") " + useCaseDescriptor);
}
}
// @Test
public void getItemByID() throws Exception {
ScopeProvider.instance.set(CONTEXT);
SecurityTokenProvider.instance.set(TOKEN);
UseCaseDescriptor ucd = client.getUCDForId(PROFILE_ID);
System.out.println(ucd);
}
// @Test
public void convertToDVObject() throws Exception {
ScopeProvider.instance.set(CONTEXT);
SecurityTokenProvider.instance.set(TOKEN);
List<UseCaseDescriptor> listOfUCD = client.getList();
int i = 0;
for (UseCaseDescriptor useCaseDescriptor : listOfUCD) {
System.out.println(++i + ") " + useCaseDescriptor);
ConvertToDataValueObjectModel.toUseCaseDescriptorDV(useCaseDescriptor, null);
}
}
@Test
public void getUCDForHandlerIds() throws Exception {
ScopeProvider.instance.set(CONTEXT);
SecurityTokenProvider.instance.set(TOKEN);
// List<String> handlersIds = Arrays.asList(GEOPORTAL_DATA_HANDLER.geoportal_data_entry.getId());
// List<UseCaseDescriptor> listOfUCD = client
// .getListForHandlerIds(handlersIds);
// int i = 0;
// for (UseCaseDescriptor useCaseDescriptor : listOfUCD) {
// System.out.println(++i + ") " + useCaseDescriptor);
// UseCaseDescriptorDV ucdDV = ConvertToDataValueObjectModel.toUseCaseDescriptorDV(useCaseDescriptor, null);
// System.out.println("returned " + ucdDV);
// }
List<String> handlersIds = Arrays.asList(GEOPORTAL_DATA_HANDLER.geoportal_data_entry.getId());
List<UseCaseDescriptor> listUseCaseDescriptor;
try {
UseCaseDescriptorCaller client = GeoportalClientCaller.useCaseDescriptors();
if (handlersIds == null) {
handlersIds = Arrays.asList(GEOPORTAL_DATA_HANDLER.geoportal_data_entry.getId());
System.out.println("handlersIds is null, so using default: " + handlersIds);
}
listUseCaseDescriptor = client.getListForHandlerIds(handlersIds);
} catch (Exception e) {
String error = "Error on contacting the Geoportal service";
System.out.println(error + " for handlers: " + handlersIds);
throw new Exception(
"Error when contacting the Geoportal service. Refresh and try again or contact the support", e);
}
if (listUseCaseDescriptor == null) {
listUseCaseDescriptor = new ArrayList<UseCaseDescriptor>();
}
List<UseCaseDescriptorDV> listUCDDV = new ArrayList<UseCaseDescriptorDV>(listUseCaseDescriptor.size());
for (UseCaseDescriptor ucd : listUseCaseDescriptor) {
listUCDDV.add(ConvertToDataValueObjectModel.toUseCaseDescriptorDV(ucd, null));
}
System.out.println(listUCDDV);
}
}

View File

@ -1,196 +1,64 @@
package org.gcube.portlets.user.geoportaldataentry;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.gcube.application.geoportalcommon.MockDocumentConfigurationReader;
import org.gcube.application.geoportalcommon.shared.geoportalconfig.GcubeProfileDV;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.portlets.user.geoportaldataentry.shared.GeoNaFormDataObject;
import org.gcube.portlets.widgets.mpformbuilder.shared.GenericDatasetBean;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.junit.Test;
import com.google.gwt.dev.util.collect.HashMap;
public class WriteDocument {
private static String TOKEN = "";
private static String CONTEXT = "/gcube/devsec/devVRE";
private static String USERNAME = "francesco.mangiacrapa";
// @Before
public void init() {
ScopeProvider.instance.set(CONTEXT);
}
//@Test
public void writeMockJson() throws Exception {
List<GeoNaFormDataObject> listGeonaFormObjects = new ArrayList<GeoNaFormDataObject>();
MockDocumentConfigurationReader mock = new MockDocumentConfigurationReader();
System.out.println(mock.getListDocumentConfig());
LinkedHashMap<String, List<String>> formDataEntryFields = new LinkedHashMap<String, List<String>>();
formDataEntryFields.put("Title", Arrays.asList("My Title"));
formDataEntryFields.put("My Desr", Arrays.asList("My Descr Value"));
formDataEntryFields.put("Field1", Arrays.asList("Field1 Value"));
List<GenericDatasetBean> listGDC = new ArrayList<GenericDatasetBean>();
GenericDatasetBean genericDatasetBean = new GenericDatasetBean();
genericDatasetBean.setFormDataEntryFields(formDataEntryFields);
listGDC.add(genericDatasetBean);
// GenericDatasetBean gdb = new GenericDatasetBean(null, formDataEntryFields, null);
//package org.gcube.portlets.user.geoportaldataentry;
//
//import java.util.ArrayList;
//import java.util.Arrays;
//import java.util.LinkedHashMap;
//import java.util.List;
//
//import org.gcube.application.geoportalcommon.MockDocumentConfigurationReader;
//import org.gcube.common.scope.api.ScopeProvider;
//import org.gcube.portlets.user.geoportaldataentry.server.FormDataObjectToJSON;
//import org.gcube.portlets.user.geoportaldataentry.shared.GeoNaFormDataObject;
//import org.gcube.portlets.widgets.mpformbuilder.shared.GenericDatasetBean;
//import org.json.JSONObject;
//import org.junit.Before;
//import org.junit.Test;
//
//public class WriteDocument {
//
// private static String TOKEN = "";
// private static String CONTEXT = "/gcube/devsec/devVRE";
// private static String USERNAME = "francesco.mangiacrapa";
//
// //@Before
// public void init() {
// ScopeProvider.instance.set(CONTEXT);
// }
//
// //@Test
// public void writeMockJson() throws Exception {
//
// List<GeoNaFormDataObject> listGeonaFormObjects = new ArrayList<GeoNaFormDataObject>();
// MockDocumentConfigurationReader mock = new MockDocumentConfigurationReader();
// System.out.println(mock.getListDocumentConfig());
//
// LinkedHashMap<String, List<String>> formDataEntryFields = new LinkedHashMap<String, List<String>>();
// formDataEntryFields.put("Title", Arrays.asList("My Title"));
// formDataEntryFields.put("My Desr", Arrays.asList("My Descr Value"));
// formDataEntryFields.put("Field1", Arrays.asList("Field1 Value"));
//
// List<GenericDatasetBean> listGDC = new ArrayList<GenericDatasetBean>();
// GenericDatasetBean genericDatasetBean = new GenericDatasetBean();
// genericDatasetBean.setFormDataEntryFields(formDataEntryFields);
// listGDC.add(genericDatasetBean);
//// GenericDatasetBean gdb = new GenericDatasetBean(null, formDataEntryFields, null);
////
//// for (GenericDatasetBean genericDatasetBean : listGDC) {
//// genericDatasetBean
//// }
//
// GeoNaFormDataObject gnform = new GeoNaFormDataObject(listGDC, mock.getListDocumentConfig().get(0).getConfiguration().getGcubeProfiles().get(0));
// System.out.println(gnform);
//
// listGeonaFormObjects.add(gnform);
//
// for (GenericDatasetBean genericDatasetBean : listGDC) {
// genericDatasetBean
// }
GeoNaFormDataObject gnform = new GeoNaFormDataObject(listGDC,
mock.getListDocumentConfig().get(0).getConfiguration().getGcubeProfiles().get(1));
System.out.println(gnform);
listGeonaFormObjects.add(gnform);
JSONObject rootDocument = JSONObjecOrdered.instance();
for (GeoNaFormDataObject geoNaFormDataObject : listGeonaFormObjects) {
List<GenericDatasetBean> listGDB = geoNaFormDataObject.getListGDB();
GcubeProfileDV profile = geoNaFormDataObject.getGcubeProfileDV();
System.out.println("The profile is: " + profile);
String jsonPathExp = String.format("%s%s", profile.getParentName(), profile.getSectionName());
//jsonPathExp = "$.chidl1.child2.child3";
jsonPathExp = jsonPathExp.replaceFirst("\\$", "");
System.out.println("The json path to build: " + jsonPathExp);
JSONObject sectRootObject = JSONObjecOrdered.instance();
for (GenericDatasetBean gdb : listGDB) {
JSONObject jsonObject = genericDatasetBeanToJSON(gdb);
String sectionToString = jsonObject.toString();
System.out.println("Adding section : " + sectionToString);
String[] jsonPathDeep = jsonPathExp.split("\\.");
System.out.println("jsonPathDeep: " + Arrays.asList(jsonPathDeep) + " size: " + jsonPathDeep.length);
// ROOT $.
if (jsonPathDeep.length == 0) {
sectRootObject = deepMerge(jsonObject, sectRootObject);
System.out.println("JSON:"+sectRootObject);
//rootDocument.put(jsonPathDeep[0], sectRootObject);
rootDocument = deepMerge(sectRootObject, rootDocument);
}
// DEPTH >= 1
if (jsonPathDeep.length > 1) {
sectRootObject.put(jsonPathDeep[jsonPathDeep.length - 1], jsonObject);
JSONObject deepJSON = sectRootObject;
System.out.println("sectRootObject: " + sectRootObject);
for (int i = jsonPathDeep.length - 2; i > 0; i--) {
JSONObject newOne = JSONObjecOrdered.instance();
newOne.put(jsonPathDeep[i], deepJSON);
deepJSON = newOne;
}
System.out.println("ext deepJSON: " + deepJSON);
rootDocument = deepMerge(deepJSON, rootDocument);
}
}
System.out.println("Document: " + rootDocument); // Print it with specified indentation
}
}
public static class JSONObjecOrdered {
public static JSONObject instance() {
JSONObject jsonObject = new JSONObject();
try {
Field changeMap = jsonObject.getClass().getDeclaredField("map");
changeMap.setAccessible(true);
changeMap.set(jsonObject, new LinkedHashMap<>());
changeMap.setAccessible(false);
} catch (IllegalAccessException | NoSuchFieldException e) {
}
return jsonObject;
}
}
private JSONObject innerJSONBuilder(JSONObject source, String key, JSONObject jsonValue) throws JSONException {
source.put(key, jsonValue);
System.out.println("innerJSONBuilder: " + source.toString(4));
return source.getJSONObject(key);
}
private JSONObject genericDatasetBeanToJSON(GenericDatasetBean gdb) throws JSONException {
JSONObject sectJSONObject = JSONObjecOrdered.instance();
Map<String, List<String>> mapFields = gdb.getFormDataEntryFields();
System.out.println("Map is: "+mapFields);
for (String key : mapFields.keySet()) {
List<String> listValues = mapFields.get(key);
if (listValues == null || listValues.isEmpty()) {
continue;
}
// key/value as string
if (listValues.size() == 1) {
sectJSONObject.put(key, listValues.get(0));
continue;
}
// value is a list
JSONArray array = new JSONArray();
for (String value : listValues) {
array.put(value);
}
sectJSONObject.put(key, array);
}
System.out.println("sectJSONObject: "+sectJSONObject);
return sectJSONObject;
}
/**
* Merge "source" into "target". If fields have equal name, merge them
* recursively.
*
* @return the merged object (target).
*/
public static JSONObject deepMerge(JSONObject source, JSONObject target) throws JSONException {
for (String key : JSONObject.getNames(source)) {
System.out.println("key: "+key);
Object value = source.get(key);
if (!target.has(key)) {
// new value for "key":
target.put(key, value);
} else {
// existing value for "key" - recursively deep merge:
if (value instanceof JSONObject) {
JSONObject valueJson = (JSONObject) value;
deepMerge(valueJson, target.getJSONObject(key));
} else {
target.put(key, value);
}
}
}
return target;
}
}
// FormDataObjectToJSON formConverter = new FormDataObjectToJSON();
// JSONObject json = formConverter.convert(listGeonaFormObjects);
//
// System.out.println(json);
// }
//
//
//
//
//}