1708 lines
62 KiB
Java
1708 lines
62 KiB
Java
package org.gcube.portlets.user.geoportaldataentry.client;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.Arrays;
|
|
import java.util.Collection;
|
|
import java.util.LinkedHashMap;
|
|
import java.util.List;
|
|
import java.util.TreeMap;
|
|
|
|
import org.gcube.application.geoportalcommon.shared.GeoportalItemReferences;
|
|
import org.gcube.application.geoportalcommon.shared.SearchingFilter;
|
|
import org.gcube.application.geoportalcommon.shared.config.GcubeUserRole;
|
|
import org.gcube.application.geoportalcommon.shared.config.OPERATION_ON_ITEM;
|
|
import org.gcube.application.geoportalcommon.shared.config.RoleRights;
|
|
import org.gcube.application.geoportalcommon.shared.config.RoleRights.OPERATION_TYPE;
|
|
import org.gcube.application.geoportalcommon.shared.geoportal.DocumentDV;
|
|
import org.gcube.application.geoportalcommon.shared.geoportal.ResultDocumentDV;
|
|
import org.gcube.application.geoportalcommon.shared.geoportal.config.GcubeProfileDV;
|
|
import org.gcube.application.geoportalcommon.shared.geoportal.config.ItemFieldDV;
|
|
import org.gcube.application.geoportalcommon.shared.geoportal.project.LifecycleInformationDV;
|
|
import org.gcube.application.geoportalcommon.shared.geoportal.project.ProjectDV;
|
|
import org.gcube.application.geoportalcommon.shared.geoportal.ucd.GEOPORTAL_DATA_HANDLER;
|
|
import org.gcube.application.geoportalcommon.shared.geoportal.ucd.HandlerDeclarationDV;
|
|
import org.gcube.application.geoportalcommon.shared.geoportal.ucd.RelationshipDefinitionDV;
|
|
import org.gcube.application.geoportalcommon.shared.geoportal.ucd.UseCaseDescriptorDV;
|
|
import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.ACTION_PERFORMED_ON_ITEM;
|
|
import org.gcube.portlets.user.geoportaldataentry.client.GeoPortalClientCaches.CacheSearchingFilterParametersFromConfig;
|
|
import org.gcube.portlets.user.geoportaldataentry.client.events.ClickItemEvent;
|
|
import org.gcube.portlets.user.geoportaldataentry.client.events.ClickItemEventHandler;
|
|
import org.gcube.portlets.user.geoportaldataentry.client.events.CloseCreateRelationGUIEvent;
|
|
import org.gcube.portlets.user.geoportaldataentry.client.events.CloseCreateRelationGUIEventHandler;
|
|
import org.gcube.portlets.user.geoportaldataentry.client.events.CreateNewProjectEvent;
|
|
import org.gcube.portlets.user.geoportaldataentry.client.events.CreateNewProjectEventHandler;
|
|
import org.gcube.portlets.user.geoportaldataentry.client.events.GetListOfRecordsEvent;
|
|
import org.gcube.portlets.user.geoportaldataentry.client.events.GetListOfRecordsEventHandler;
|
|
import org.gcube.portlets.user.geoportaldataentry.client.events.OperationOnItemEvent;
|
|
import org.gcube.portlets.user.geoportaldataentry.client.events.OperationOnItemEventHandler;
|
|
import org.gcube.portlets.user.geoportaldataentry.client.events.OperationPerformedOnItemEvent;
|
|
import org.gcube.portlets.user.geoportaldataentry.client.events.OperationPerformedOnItemEventHandler;
|
|
import org.gcube.portlets.user.geoportaldataentry.client.events.RelationActionHandler;
|
|
import org.gcube.portlets.user.geoportaldataentry.client.events.RelationActionHandlerEvent;
|
|
import org.gcube.portlets.user.geoportaldataentry.client.events.SaveGeonaDataFormsEvent;
|
|
import org.gcube.portlets.user.geoportaldataentry.client.events.SaveGeonaDataFormsHandler;
|
|
import org.gcube.portlets.user.geoportaldataentry.client.events.TreeItemEvent;
|
|
import org.gcube.portlets.user.geoportaldataentry.client.events.TreeItemEventHandler;
|
|
import org.gcube.portlets.user.geoportaldataentry.client.events.WorkflowActionOnSelectedItemEvent;
|
|
import org.gcube.portlets.user.geoportaldataentry.client.events.WorkflowActionOnSelectedItemEventHandler;
|
|
import org.gcube.portlets.user.geoportaldataentry.client.resource.Images;
|
|
import org.gcube.portlets.user.geoportaldataentry.client.ui.GeonaMainTabPanel;
|
|
import org.gcube.portlets.user.geoportaldataentry.client.ui.GeonaRecordsPaginatedView;
|
|
import org.gcube.portlets.user.geoportaldataentry.client.ui.ModalWindow;
|
|
import org.gcube.portlets.user.geoportaldataentry.client.ui.card.GeoNaFormCardModel;
|
|
import org.gcube.portlets.user.geoportaldataentry.client.ui.edit.EditModeRecord;
|
|
import org.gcube.portlets.user.geoportaldataentry.client.ui.form.GeonaDataEntryMainForm;
|
|
import org.gcube.portlets.user.geoportaldataentry.client.ui.report.LifecycleInformationPanel;
|
|
import org.gcube.portlets.user.geoportaldataentry.client.ui.report.ReportTemplateToHTML;
|
|
import org.gcube.portlets.user.geoportaldataentry.client.ui.tree.NodeItem;
|
|
import org.gcube.portlets.user.geoportaldataentry.client.ui.tree.TreeItemPanel;
|
|
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;
|
|
import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.ModalConfirm;
|
|
import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.NewBrowserWindow;
|
|
import org.gcube.portlets.user.geoportaldataentry.shared.CommitReport;
|
|
import org.gcube.portlets.user.geoportaldataentry.shared.GNADataEntryExtendedConfigProfile;
|
|
import org.gcube.portlets.user.geoportaldataentry.shared.GeoNaFormDataObject;
|
|
import org.gcube.portlets.user.geoportaldataentry.shared.GeoportalISConfig;
|
|
import org.gcube.portlets.user.geoportaldataentry.shared.Tree_Node;
|
|
import org.gcube.portlets.user.geoportaldataentry.shared.UserRights;
|
|
import org.gcube.portlets.widgets.mpformbuilder.client.MetadataProfileFormBuilderServiceAsync;
|
|
import org.gcube.portlets.widgets.mpformbuilder.client.form.generic.CreateMetadataForm;
|
|
import org.gcube.portlets.widgets.mpformbuilder.client.form.generic.CreateMetadataForm.OPERATION;
|
|
import org.gcube.portlets.widgets.mpformbuilder.shared.metadata.MetaDataProfileBean;
|
|
|
|
import com.github.gwtbootstrap.client.ui.Alert;
|
|
import com.github.gwtbootstrap.client.ui.Button;
|
|
import com.github.gwtbootstrap.client.ui.Modal;
|
|
import com.github.gwtbootstrap.client.ui.constants.AlertType;
|
|
import com.github.gwtbootstrap.client.ui.constants.ButtonType;
|
|
import com.google.gwt.core.client.EntryPoint;
|
|
import com.google.gwt.core.client.GWT;
|
|
import com.google.gwt.core.client.Scheduler;
|
|
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
|
|
import com.google.gwt.dom.client.Element;
|
|
import com.google.gwt.dom.client.Style.Unit;
|
|
import com.google.gwt.event.dom.client.ClickEvent;
|
|
import com.google.gwt.event.dom.client.ClickHandler;
|
|
import com.google.gwt.event.logical.shared.ResizeEvent;
|
|
import com.google.gwt.event.logical.shared.ResizeHandler;
|
|
import com.google.gwt.event.shared.HandlerManager;
|
|
import com.google.gwt.user.client.Window;
|
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
|
import com.google.gwt.user.client.ui.HTML;
|
|
import com.google.gwt.user.client.ui.HorizontalPanel;
|
|
import com.google.gwt.user.client.ui.Image;
|
|
import com.google.gwt.user.client.ui.Label;
|
|
import com.google.gwt.user.client.ui.RootPanel;
|
|
import com.google.gwt.user.client.ui.TreeItem;
|
|
import com.google.gwt.user.client.ui.VerticalPanel;
|
|
|
|
/**
|
|
* Entry point classes define <code>onModuleLoad()</code>.
|
|
*/
|
|
public class GeoPortalDataEntryApp implements EntryPoint {
|
|
|
|
public static final GeoportalDataEntryServiceAsync geoportalDataEntryService = GWT
|
|
.create(GeoportalDataEntryService.class);
|
|
|
|
private final HandlerManager appManagerBus = new HandlerManager(null);
|
|
|
|
private LinkedHashMap<String, GeoNaFormCardModel> mapForms = new LinkedHashMap<String, GeoNaFormCardModel>();
|
|
|
|
private GeonaDataEntryMainForm geoNaMainForm = null;
|
|
|
|
private GeonaMainTabPanel mainTabPanel;
|
|
|
|
private LinkedHashMap<String, Tree_Node<GeoNaFormDataObject>> savedMap = new LinkedHashMap<String, Tree_Node<GeoNaFormDataObject>>();
|
|
|
|
private boolean projectSavedWithSuccess;
|
|
|
|
private GeonaRecordsPaginatedView grpw = null;
|
|
|
|
private UserRights myRights = null;
|
|
|
|
private LoaderIcon loaderApplication = new LoaderIcon("Step 1 of 2. Loading Application facilities, please wait");
|
|
|
|
private LoaderIcon loaderConfigurations = new LoaderIcon("Step 2 of 2. Loading Configurations, please wait");
|
|
|
|
private GeoportalISConfig geoportalISConfigs;
|
|
|
|
private int numberOfCards = 0;
|
|
|
|
private int expectedCards = 0;
|
|
|
|
private synchronized void incrementNumberOfCards() {
|
|
numberOfCards++;
|
|
}
|
|
|
|
private synchronized int getNumberOfCards() {
|
|
return numberOfCards;
|
|
}
|
|
|
|
private boolean dataEntryProjectCreated = false;
|
|
|
|
private TreeItemPanel treeItemPanel;
|
|
|
|
private GeoPortalClientCaches geoportalCaches;
|
|
|
|
/**
|
|
* This is the entry point method.
|
|
*/
|
|
public void onModuleLoad() {
|
|
/*
|
|
* ArrayList<GeoNaFormCardModel> gnaCardsModels = new
|
|
* ArrayList<GeoNaFormCardModel>(10); GcubeProfileDV gprofile = new
|
|
* GcubeProfileDV(); gprofile.setParentName("$.");
|
|
* gprofile.setSectionTitle("Istruzione"); GeoNaFormCardModel fcm = new
|
|
* GeoNaFormCardModel(); fcm.setGcubeProfile(gprofile); gnaCardsModels.add(fcm);
|
|
*
|
|
* for (int i = 0; i < 2; i++) { GcubeProfileDV gprofile1 = new
|
|
* GcubeProfileDV(); gprofile1.setParentName("$.livello1");
|
|
* gprofile1.setSectionTitle("Secondaria Superiore "+i); GeoNaFormCardModel fcm1
|
|
* = new GeoNaFormCardModel(); fcm1.setGcubeProfile(gprofile1);
|
|
* gnaCardsModels.add(fcm1); }
|
|
*
|
|
* for (int i = 0; i < 3; i++) { GcubeProfileDV gprofile2 = new
|
|
* GcubeProfileDV(); gprofile2.setParentName("$.livello1.livello2");
|
|
* gprofile2.setSectionTitle("Alberghiero di Pisa "+i); GeoNaFormCardModel fcm2
|
|
* = new GeoNaFormCardModel(); fcm2.setGcubeProfile(gprofile2);
|
|
* gnaCardsModels.add(fcm2); }
|
|
*
|
|
* TreeItemPanel tip = new TreeItemPanel("Concessione", gnaCardsModels);
|
|
* RootPanel.get(GeoPortalDataEntryApp.DIV_PORTLET_ID).add(tip.getTree());
|
|
*/
|
|
geoportalCaches = new GeoPortalClientCaches();
|
|
|
|
ConstantsGeoPortalDataEntryApp.ROOT_PANEL_DIV_LOADERS.getElement()
|
|
.addClassName(ConstantsGeoPortalDataEntryApp.CSS_CLASS_GEOPORTAL_LOADERS_CENTER);
|
|
ConstantsGeoPortalDataEntryApp.ROOT_PANEL_DIV_LOADERS.add(loaderApplication);
|
|
|
|
mainTabPanel = new GeonaMainTabPanel(appManagerBus);
|
|
geoNaMainForm = new GeonaDataEntryMainForm(appManagerBus);
|
|
mainTabPanel.addFormPanel(geoNaMainForm);
|
|
|
|
ConstantsGeoPortalDataEntryApp.ROOT_PANEL_DIV_PORTLET.add(mainTabPanel);
|
|
|
|
// ROOT_PANEL_DIV_PORTLET.getElement().getStyle().setOpacity(0.3);
|
|
ConstantsGeoPortalDataEntryApp.ROOT_PANEL_DIV_PORTLET.getElement()
|
|
.addClassName(ConstantsGeoPortalDataEntryApp.CSS_CLASS_ANIMATE_FADE_IN_OUT);
|
|
|
|
GeoportalDataEntryServiceAsync.Util.getInstance().getGeonaInitConfig(new AsyncCallback<GeoportalISConfig>() {
|
|
|
|
@Override
|
|
public void onFailure(Throwable caught) {
|
|
String errorMsg = "Sorry, an error occurrend when loading configurations. Please, contact the support";
|
|
Alert alert = new Alert(errorMsg, AlertType.ERROR);
|
|
alert.setClose(false);
|
|
try {
|
|
ConstantsGeoPortalDataEntryApp.ROOT_PANEL_DIV_LOADERS.remove(loaderApplication);
|
|
} catch (Exception e) {
|
|
|
|
}
|
|
ConstantsGeoPortalDataEntryApp.ROOT_PANEL_DIV_PORTLET.add(alert);
|
|
Window.alert(errorMsg);
|
|
}
|
|
|
|
@Override
|
|
public void onSuccess(GeoportalISConfig geoportalISConfig) {
|
|
geoportalISConfigs = geoportalISConfig;
|
|
|
|
if (geoportalISConfig != null && geoportalISConfig.getScope() != null) {
|
|
|
|
loadGeoportalConfigs(geoportalISConfig.getScope());
|
|
} else
|
|
Window.alert("Sorry, no scope found in the session. Re-login and try again");
|
|
|
|
}
|
|
});
|
|
|
|
// Loading Geoportal Configurations from IS
|
|
GeoportalDataEntryServiceAsync.Util.getInstance()
|
|
.readDataViewerConfig(new AsyncCallback<GNADataEntryExtendedConfigProfile>() {
|
|
|
|
@Override
|
|
public void onFailure(Throwable caught) {
|
|
String errorMsg = "Sorry, an error occurrend on istancing the application. Please, contact the support";
|
|
Alert alert = new Alert(errorMsg, AlertType.ERROR);
|
|
alert.setClose(false);
|
|
try {
|
|
ConstantsGeoPortalDataEntryApp.ROOT_PANEL_DIV_LOADERS.remove(loaderApplication);
|
|
ConstantsGeoPortalDataEntryApp.ROOT_PANEL_DIV_PORTLET.getElement()
|
|
.removeClassName(ConstantsGeoPortalDataEntryApp.CSS_CLASS_ANIMATE_FADE_IN_OUT);
|
|
} catch (Exception e) {
|
|
|
|
}
|
|
ConstantsGeoPortalDataEntryApp.ROOT_PANEL_DIV_LOADERS.add(alert);
|
|
Window.alert(errorMsg);
|
|
|
|
}
|
|
|
|
@Override
|
|
public void onSuccess(GNADataEntryExtendedConfigProfile gNADataEntryConfig) {
|
|
GWT.log(GNADataEntryExtendedConfigProfile.class.getSimpleName() + " loaded: "
|
|
+ gNADataEntryConfig);
|
|
|
|
try {
|
|
ConstantsGeoPortalDataEntryApp.ROOT_PANEL_DIV_LOADERS.remove(loaderApplication);
|
|
} catch (Exception e) {
|
|
|
|
}
|
|
|
|
// PERMISSIONS
|
|
myRights = gNADataEntryConfig.getUserRights();
|
|
initGUI();
|
|
GcubeUserRole userRole = myRights.getRoleRights().getUserRole();
|
|
mainTabPanel.setRole(userRole);
|
|
// GUI Presentation
|
|
mainTabPanel.setGUIPresentation(gNADataEntryConfig.getDataEntryGUIPresentation());
|
|
|
|
RoleRights roleRights = myRights.getRoleRights();
|
|
boolean canCreateNewItem = roleRights.getListPermessions().keySet()
|
|
.contains(OPERATION_ON_ITEM.CREATE_NEW_PROJECT);
|
|
|
|
if (!canCreateNewItem) {
|
|
// removing Tab "Create New Project"
|
|
mainTabPanel.removeTab(0);
|
|
// activating Tab "List of Project"
|
|
mainTabPanel.setTabActive(0);
|
|
// mainTabPanel.instanceAndShowListOfProjects();
|
|
}
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
private void initGUI() {
|
|
bindEvents();
|
|
Window.addResizeHandler(new ResizeHandler() {
|
|
@Override
|
|
public void onResize(ResizeEvent event) {
|
|
GWT.log("onWindowResized width: " + event.getWidth() + " height: " + event.getHeight());
|
|
updateSize();
|
|
|
|
}
|
|
});
|
|
|
|
updateSize();
|
|
}
|
|
|
|
private static native void click(Element element)/*-{
|
|
element.click();
|
|
}-*/;
|
|
|
|
private void loadGeoportalConfigs(final String scope) {
|
|
GWT.log("loading GeoportalConfigsAndBuildCards in the scope: " + scope);
|
|
// orderedCards = new ArrayList<GeoNaFormCardModel>();
|
|
try {
|
|
ConstantsGeoPortalDataEntryApp.ROOT_PANEL_DIV_LOADERS.insert(loaderConfigurations, 0);
|
|
} catch (Exception e) {
|
|
|
|
}
|
|
GeoportalDataEntryServiceAsync.Util.getInstance().getListUseCaseDescriptors(
|
|
ConstantsGeoPortalDataEntryApp.HANDLERS_IDS, new AsyncCallback<List<UseCaseDescriptorDV>>() {
|
|
|
|
@Override
|
|
public void onFailure(Throwable caught) {
|
|
String errorMsg = "Sorry, an error occurrend on loading configurations. Please, contact the support";
|
|
Alert alert = new Alert(errorMsg, AlertType.ERROR);
|
|
alert.setClose(false);
|
|
try {
|
|
ConstantsGeoPortalDataEntryApp.ROOT_PANEL_DIV_LOADERS.remove(loaderConfigurations);
|
|
ConstantsGeoPortalDataEntryApp.ROOT_PANEL_DIV_PORTLET.getElement()
|
|
.removeClassName(ConstantsGeoPortalDataEntryApp.CSS_CLASS_ANIMATE_FADE_IN_OUT);
|
|
} catch (Exception e) {
|
|
|
|
}
|
|
ConstantsGeoPortalDataEntryApp.ROOT_PANEL_DIV_LOADERS.add(alert);
|
|
Window.alert(errorMsg);
|
|
GWT.log(caught.getMessage());
|
|
}
|
|
|
|
@Override
|
|
public void onSuccess(List<UseCaseDescriptorDV> result) {
|
|
GWT.log("ListUseCaseDescriptors loaded: " + result);
|
|
|
|
if (result == null || result.size() == 0) {
|
|
Window.alert("No Configuration found in this scope. Please contact the support");
|
|
return;
|
|
}
|
|
|
|
initDataEntryAppForListUseCaseDescriptors(result);
|
|
// After loading of UCD I can instance the "List of Project" view
|
|
mainTabPanel.instanceAndShowListOfProjects();
|
|
try {
|
|
ConstantsGeoPortalDataEntryApp.ROOT_PANEL_DIV_PORTLET.getElement()
|
|
.removeClassName(ConstantsGeoPortalDataEntryApp.CSS_CLASS_ANIMATE_FADE_IN_OUT);
|
|
ConstantsGeoPortalDataEntryApp.ROOT_PANEL_DIV_LOADERS.remove(loaderConfigurations);
|
|
ConstantsGeoPortalDataEntryApp.ROOT_PANEL_DIV_LOADERS.getElement()
|
|
.removeClassName(ConstantsGeoPortalDataEntryApp.CSS_CLASS_GEOPORTAL_LOADERS_CENTER);
|
|
} catch (Exception e) {
|
|
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
private void initDataEntryAppForListUseCaseDescriptors(List<UseCaseDescriptorDV> listUCDescriptors) {
|
|
GWT.log("initDataEntryAppForListUseCaseDescriptors with size: " + listUCDescriptors.size());
|
|
ConstantsGeoPortalDataEntryApp.printUCDs(listUCDescriptors);
|
|
|
|
mainTabPanel.initMainAccordingToListUseCaseDescriptors(listUCDescriptors);
|
|
|
|
for (final UseCaseDescriptorDV ucdDV : listUCDescriptors) {
|
|
geoportalCaches.putUCDForProfileId(ucdDV.getProfileID(), ucdDV);
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* Update window size
|
|
*/
|
|
public void updateSize() {
|
|
|
|
try {
|
|
RootPanel workspace = ConstantsGeoPortalDataEntryApp.ROOT_PANEL_DIV_PORTLET;
|
|
int topBorder = workspace.getAbsoluteTop();
|
|
int footer = 85; // footer is bottombar + sponsor
|
|
int headerSize = 90;
|
|
// int headerSize = 30;
|
|
int rootHeight = Window.getClientHeight() - topBorder - headerSize - footer;// - ((footer ==
|
|
// null)?0:(footer.getOffsetHeight()-15));
|
|
|
|
GWT.log("New workspace dimension Height: " + rootHeight);
|
|
mainTabPanel.setInternalHeight(rootHeight);
|
|
// mainTabPanel.setlistOfProjectCenterPanelHeight(rootHeight-20+"px");
|
|
} catch (Exception e) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private void createNewDataEntyFor(String profileID, HandlerDeclarationDV handlerDeclarationDV,
|
|
List<GcubeProfileDV> listGPs) {
|
|
dataEntryProjectCreated = true;
|
|
mainTabPanel.setLoaderVisible("Loading...", true);
|
|
// orderedCards.clear();
|
|
resetUI();
|
|
mainTabPanel.setPageHeader(handlerDeclarationDV);
|
|
|
|
//TODO AVOIDING THE CACHE
|
|
//TODO I NEED TO CHECK WHY THE BY USING THE CACHE THE WEB-FORM IS FULL (EQUAL TO PREVIOUS ONE) AND NOT RESET PERFORMED
|
|
|
|
|
|
// List<GeoNaFormCardModel> cardsPerIT = geoportalCaches.getGcubeProfilePerItemType(handlerDeclarationDV.getItemType());
|
|
// if (cardsPerIT != null) {
|
|
// GWT.log("Profiles/Cards per Item Type are: " + cardsPerIT);
|
|
// // orderedCards.addAll(cardsPerIT);
|
|
// buildNewCards(profileID, handlerDeclarationDV.getItemType(), new ArrayList<GeoNaFormCardModel>(cardsPerIT));
|
|
// return;
|
|
// }
|
|
|
|
numberOfCards = 0;
|
|
expectedCards = listGPs.size();
|
|
GWT.log("expectedCards are: " + expectedCards);
|
|
TreeMap<Integer, GeoNaFormCardModel> treemapOrderedGNAProfiles = new TreeMap<Integer, GeoNaFormCardModel>();
|
|
|
|
for (int i = 0; i < expectedCards; i++) {
|
|
GcubeProfileDV gcubeProfile = listGPs.get(i);
|
|
final int order = i;
|
|
GWT.log("calling getProfilesInTheScope for secondaryType: " + gcubeProfile.getGcubeSecondaryType()
|
|
+ ", name: " + gcubeProfile.getGcubeName());
|
|
MetadataProfileFormBuilderServiceAsync.Util.getInstance().getProfilesInTheScopeForName(
|
|
geoportalISConfigs.getScope(), gcubeProfile.getGcubeSecondaryType(), gcubeProfile.getGcubeName(),
|
|
new AsyncCallback<List<MetaDataProfileBean>>() {
|
|
|
|
@Override
|
|
public void onSuccess(List<MetaDataProfileBean> result) {
|
|
|
|
incrementNumberOfCards();
|
|
GWT.log("loaded " + getNumberOfCards() + " of " + expectedCards + " card/s");
|
|
GWT.log("Returned " + result.size() + " profile/s");
|
|
// orderedCards = setGeoNaFormsOrder(result);
|
|
for (MetaDataProfileBean metaDataProfileBean : result) {
|
|
|
|
String theMetaType = metaDataProfileBean.getType().toLowerCase();
|
|
GWT.log("Building form card for type: " + theMetaType);
|
|
|
|
GeoNaFormCardModel geonaForm = buildNewFormCardModelFromProfile(gcubeProfile, order,
|
|
metaDataProfileBean, OPERATION.UPDATE);
|
|
|
|
treemapOrderedGNAProfiles.put(order, geonaForm);
|
|
}
|
|
|
|
if (getNumberOfCards() >= expectedCards) {
|
|
mainTabPanel.setLoaderVisible("Loading...", false);
|
|
// ordered values
|
|
Collection<GeoNaFormCardModel> gnaCardsModels = treemapOrderedGNAProfiles.values();
|
|
GWT.log("TreeMap values: " + gnaCardsModels);
|
|
List<GeoNaFormCardModel> listGNAFormCardModel = new ArrayList<GeoNaFormCardModel>(gnaCardsModels);
|
|
geoportalCaches.putGcubeProfilePerItemType(handlerDeclarationDV.getItemType(),
|
|
listGNAFormCardModel);
|
|
// orderedCards.addAll(new ArrayList<GeoNaFormCardModel>(gnaCardsModels));
|
|
buildNewCards(profileID, handlerDeclarationDV.getItemType(),
|
|
listGNAFormCardModel);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onFailure(Throwable caught) {
|
|
mainTabPanel.setLoaderVisible("Loading...", false);
|
|
Window.alert(caught.getMessage());
|
|
}
|
|
});
|
|
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Builds the new form card model from profile.
|
|
*
|
|
* @param gcubeProfile the gcube profile
|
|
* @param order the order
|
|
* @param metaDataProfileBean the meta data profile bean
|
|
* @param operation the operation
|
|
* @return the geo na form card model
|
|
*/
|
|
private GeoNaFormCardModel buildNewFormCardModelFromProfile(GcubeProfileDV gcubeProfile, int order,
|
|
MetaDataProfileBean metaDataProfileBean, OPERATION operation) {
|
|
|
|
// Managing Forms repeatability
|
|
int minOccurs = gcubeProfile.getMinOccurs();
|
|
minOccurs = minOccurs <= 0 ? 0 : minOccurs;
|
|
int maxOccurs = gcubeProfile.getMaxOccurs();
|
|
maxOccurs = maxOccurs <= 0 ? Integer.MAX_VALUE : maxOccurs;
|
|
|
|
// TODO MUST BE MANAGED MIN_OCCURS
|
|
ProjectFormCard cct = new ProjectFormCard(gcubeProfile.getSectionName(), gcubeProfile.getSectionTitle(), order,
|
|
maxOccurs > 1, minOccurs, maxOccurs);
|
|
|
|
GeoNaFormCardModel geoNaFormCardModel = new GeoNaFormCardModel(metaDataProfileBean, null, cct, gcubeProfile);
|
|
|
|
CreateMetadataForm baseForm = new CreateMetadataForm(Arrays.asList(geoNaFormCardModel.getMetadataProfileBean()),
|
|
appManagerBus, operation);
|
|
geoNaFormCardModel.setMetadataForm(baseForm);
|
|
|
|
return geoNaFormCardModel;
|
|
}
|
|
|
|
private void buildNewCards(String profileID, String itemTypeTitle, Collection<GeoNaFormCardModel> orderedCards) {
|
|
|
|
projectSavedWithSuccess = false; // resetting state of saving
|
|
mainTabPanel.setLoaderVisible("Loading...", true);
|
|
geoNaMainForm.setVisibleFormActions(true);
|
|
resetUI();
|
|
//geoNaMainForm.removeTree(treeItemPanel);
|
|
|
|
geoNaMainForm.enableButtonSave(true);
|
|
mainTabPanel.setLoaderVisible("", false);
|
|
|
|
treeItemPanel = new TreeItemPanel(profileID, itemTypeTitle, orderedCards, appManagerBus);
|
|
geoNaMainForm.addTree(treeItemPanel);
|
|
|
|
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
|
|
|
|
@Override
|
|
public void execute() {
|
|
TreeItem firstChild = treeItemPanel.getRoot().getChild(0);
|
|
treeItemPanel.getTree().setSelectedItem(firstChild, true);
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
private void resetUI() {
|
|
geoNaMainForm.resetUI();
|
|
// geoNaMainForm.remeTree(treeItemPanel);
|
|
mapForms.clear();
|
|
}
|
|
|
|
private void bindEvents() {
|
|
|
|
appManagerBus.addHandler(SaveGeonaDataFormsEvent.TYPE, new SaveGeonaDataFormsHandler() {
|
|
|
|
@Override
|
|
public void onSave(final SaveGeonaDataFormsEvent saveGeonaDataFormsEvent) {
|
|
|
|
geoNaMainForm.enableButtonSave(false);
|
|
|
|
if (saveGeonaDataFormsEvent.getTreeNode() != null) {
|
|
|
|
final Modal modal = new Modal(true);
|
|
modal.setCloseVisible(false);
|
|
modal.setTitle("Saving project...");
|
|
modal.hide(false);
|
|
modal.setWidth(800);
|
|
modal.setMaxHeigth("650px");
|
|
final VerticalPanel modalContainerPanel = new VerticalPanel();
|
|
final LoaderIcon loader = new LoaderIcon();
|
|
loader.setText("Trying to save the data, please wait...");
|
|
modalContainerPanel.add(loader);
|
|
modal.add(modalContainerPanel);
|
|
|
|
String[] listPostActionOnSave = mainTabPanel
|
|
.getPostCreationActionOnSave(saveGeonaDataFormsEvent.getProfileID());
|
|
|
|
List<String> stepsOnPostCreation = new ArrayList<String>();
|
|
if (listPostActionOnSave != null) {
|
|
for (String step : listPostActionOnSave) {
|
|
stepsOnPostCreation.add(step);
|
|
}
|
|
}
|
|
|
|
GWT.log("Calling saveGeonaDataForms, stepsOnPostCreation are " + stepsOnPostCreation);
|
|
|
|
GeoportalDataEntryServiceAsync.Util.getInstance().saveGeonaDataForms(
|
|
saveGeonaDataFormsEvent.getProfileID(), saveGeonaDataFormsEvent.getTreeNode(),
|
|
stepsOnPostCreation, new AsyncCallback<CommitReport>() {
|
|
|
|
@Override
|
|
public void onFailure(Throwable caught) {
|
|
modalContainerPanel.clear();
|
|
modal.setCloseVisible(true);
|
|
try {
|
|
modal.remove(loader);
|
|
} catch (Exception e) {
|
|
}
|
|
Alert alert = new Alert(caught.getMessage());
|
|
alert.setType(AlertType.ERROR);
|
|
alert.setClose(false);
|
|
modal.add(alert);
|
|
// resetUI();
|
|
geoNaMainForm.enableButtonSave(true);
|
|
}
|
|
|
|
@Override
|
|
public void onSuccess(CommitReport result) {
|
|
modalContainerPanel.clear();
|
|
modal.setCloseVisible(true);
|
|
modal.setTitle("Project Saved!");
|
|
|
|
LifecycleInformationDV lcDV = result.getLifecycleInformation();
|
|
|
|
switch (lcDV.getLastOperationStatus()) {
|
|
case OK: {
|
|
String success = HTMLUtil.getHTMLElement(HTML_TAG.span, 14, "32CD32", null,
|
|
"SUCCESS");
|
|
String msg = lcDV.getLastInvokedStep() + "terminated with: " + success;
|
|
projectSavedWithSuccess = true;
|
|
geoNaMainForm.showAlertOnSaveAction(msg, AlertType.SUCCESS, true);
|
|
purgeFileUploaded();
|
|
break;
|
|
}
|
|
case WARNING: {
|
|
geoNaMainForm.enableButtonSave(true);
|
|
break;
|
|
}
|
|
case ERROR: {
|
|
geoNaMainForm.enableButtonSave(true);
|
|
break;
|
|
}
|
|
default:
|
|
break;
|
|
}
|
|
|
|
savedMap.put(result.getProjectID(), saveGeonaDataFormsEvent.getTreeNode());
|
|
|
|
LifecycleInformationPanel lip = new LifecycleInformationPanel(result.getProjectID(),
|
|
result.getProfileID(), result.getProjectAsJSON(), lcDV, true);
|
|
|
|
modalContainerPanel.add(lip);
|
|
|
|
}
|
|
});
|
|
|
|
modal.show();
|
|
} else
|
|
geoNaMainForm.enableButtonSave(true);
|
|
|
|
}
|
|
});
|
|
|
|
appManagerBus.addHandler(TreeItemEvent.TYPE, new TreeItemEventHandler() {
|
|
|
|
@Override
|
|
public void onTreeItemEvent(TreeItemEvent treeItemEvent) {
|
|
|
|
TreeItem selectedItem = treeItemEvent.getSelectItem();
|
|
NodeItem selectedNode = treeItemEvent.selectedAsNodeItem();
|
|
|
|
if (selectedItem == null) {
|
|
selectedItem = geoNaMainForm.getTreeItemPanel().getSelectItem();
|
|
|
|
if (selectedItem == null)
|
|
return;
|
|
|
|
selectedNode = (NodeItem) selectedItem.getWidget();
|
|
}
|
|
|
|
GWT.log("TreeItemEvent selected node is: " + selectedNode);
|
|
|
|
if (selectedNode.isRoot()) {
|
|
return;
|
|
}
|
|
|
|
GeoNaFormCardModel nodeCard = selectedNode.getGeoNaFormCardModel();
|
|
|
|
switch (treeItemEvent.getActionPerformed()) {
|
|
case SELECTED: {
|
|
geoNaMainForm.enableButtonRemoveSection(false);
|
|
geoNaMainForm.enableButtonDuplicateSection(false);
|
|
geoNaMainForm.setSelectedForm(nodeCard.getMetadataForm());
|
|
|
|
// if(nodeCount>1) {
|
|
// geoNaMainForm.enableButtonRemoveSection(true);
|
|
// }
|
|
//
|
|
if (nodeCard.getFormCard().isInternalRepeatibleForm()) {
|
|
geoNaMainForm.enableButtonDuplicateSection(true);
|
|
}
|
|
|
|
if (selectedNode.isCanBeDeleted()) {
|
|
geoNaMainForm.enableButtonRemoveSection(true);
|
|
}
|
|
|
|
break;
|
|
}
|
|
case DELETE: {
|
|
|
|
geoNaMainForm.getTreeItemPanel().removeChild(selectedItem.getParentItem(), selectedItem,
|
|
selectedNode.getJsonSectionFullPath());
|
|
geoNaMainForm.resetInputPanel();
|
|
break;
|
|
}
|
|
|
|
case DUPLICATE: {
|
|
|
|
GWT.log("DUPLICATING node: " + selectedNode.getHtmlNode());
|
|
|
|
int nodeCountPerJSONFullPAth = geoNaMainForm.getTreeItemPanel()
|
|
.countNodeForFullPath(selectedNode.getJsonSectionFullPath());
|
|
|
|
if (nodeCountPerJSONFullPAth >= nodeCard.getFormCard().getMaxFormRepeatability()) {
|
|
|
|
DialogInform di = new DialogInform(new Image(Images.ICONS.accessDenied()), "Maximun reached",
|
|
"Maximun number of data reached for " + nodeCard.getFormCard().getTitle());
|
|
di.center();
|
|
return;
|
|
}
|
|
|
|
TreeItem newSubTree = cloneSubTreeItems(selectedItem);
|
|
// TO DEBUG
|
|
// TreeVisitUtil.postOrderVisit(newSubTree);
|
|
TreeItem parentItem = selectedItem.getParentItem();
|
|
int nextSiblingIndex = -1;
|
|
if (parentItem != null) {
|
|
nextSiblingIndex = parentItem.getChildIndex(selectedItem);
|
|
nextSiblingIndex++;
|
|
}
|
|
geoNaMainForm.getTreeItemPanel().addChild(selectedItem.getParentItem(), nextSiblingIndex,
|
|
newSubTree);
|
|
break;
|
|
}
|
|
|
|
default:
|
|
break;
|
|
}
|
|
|
|
}
|
|
});
|
|
|
|
appManagerBus.addHandler(CreateNewProjectEvent.TYPE, new CreateNewProjectEventHandler() {
|
|
|
|
@Override
|
|
public void onCreateNewProject(CreateNewProjectEvent newProjectEvent) {
|
|
GWT.log("Create new project");
|
|
if (!dataEntryProjectCreated) {
|
|
createNewDataEntyFor(newProjectEvent.getProfileID(), newProjectEvent.getHandler(),
|
|
newProjectEvent.getListGcubeProfiles());
|
|
return;
|
|
}
|
|
|
|
// means the form was not submitted
|
|
if (savedMap.size() == 0) {
|
|
|
|
ModalConfirm confirm = new ModalConfirm(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.getProfileID(), newProjectEvent.getHandler(),
|
|
newProjectEvent.getListGcubeProfiles());
|
|
}
|
|
|
|
});
|
|
|
|
confirm.show();
|
|
|
|
} else if (projectSavedWithSuccess) {
|
|
// means the project has been saved
|
|
createNewDataEntyFor(newProjectEvent.getProfileID(), newProjectEvent.getHandler(),
|
|
newProjectEvent.getListGcubeProfiles());
|
|
} else {
|
|
|
|
ModalConfirm confirm = new ModalConfirm(null, "Creating New Project...",
|
|
"The data entry form/s will be cleaned. Confirm?");
|
|
|
|
confirm.getYesButton().addClickHandler(new ClickHandler() {
|
|
|
|
@Override
|
|
public void onClick(ClickEvent event) {
|
|
confirm.hide();
|
|
|
|
createNewDataEntyFor(newProjectEvent.getProfileID(), newProjectEvent.getHandler(),
|
|
newProjectEvent.getListGcubeProfiles());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
confirm.show();
|
|
}
|
|
|
|
}
|
|
});
|
|
|
|
appManagerBus.addHandler(GetListOfRecordsEvent.TYPE, new GetListOfRecordsEventHandler() {
|
|
|
|
@Override
|
|
public void onGetList(GetListOfRecordsEvent getListOfRecordsEvent) {
|
|
GWT.log("Fired: " + getListOfRecordsEvent);
|
|
SearchingFilter searchingFilter = getListOfRecordsEvent.getSearchingFilter();
|
|
|
|
|
|
CacheSearchingFilterParametersFromConfig seachingFilterParameters =
|
|
geoportalCaches.getFilterParametersForProfileId(getListOfRecordsEvent.getProfileID(), GEOPORTAL_DATA_HANDLER.geoportal_data_list);
|
|
|
|
// CacheSearchingFilterParametersFromConfig seachingFilterParameters = geoportalCaches
|
|
// .getFilterParametersForProfileId(getListOfRecordsEvent.getProfileID());
|
|
|
|
final String profileID = getListOfRecordsEvent.getProfileID();
|
|
if (profileID == null) {
|
|
new DialogInform(null, "Error", "No Use Case Descriptor selected").center();
|
|
return;
|
|
}
|
|
|
|
if (searchingFilter == null || getListOfRecordsEvent.isOnApplicationInit()
|
|
|| getListOfRecordsEvent.isReloadFilteringParameters()) {
|
|
mainTabPanel.setFilteringParameters(seachingFilterParameters);
|
|
searchingFilter = mainTabPanel.getCurrentProjectsSearchingFilter();
|
|
|
|
// Searching in the cache if the list of relationship definition is present
|
|
List<RelationshipDefinitionDV> listRelationshipsDef = geoportalCaches
|
|
.getListRelationshipDefinitionForProfileId(profileID);
|
|
// Loading list of relationships definition ProfileID
|
|
if (listRelationshipsDef == null || listRelationshipsDef.isEmpty()) {
|
|
|
|
GeoPortalDataEntryApp.geoportalDataEntryService.getRelationshipsDefinition(profileID,
|
|
new AsyncCallback<List<RelationshipDefinitionDV>>() {
|
|
|
|
@Override
|
|
public void onSuccess(List<RelationshipDefinitionDV> relationshipDef) {
|
|
GWT.log("getRelationshipNames for " + profileID + " are: " + relationshipDef);
|
|
geoportalCaches.putListRelationshipsDefinitionForProfileID(profileID,
|
|
relationshipDef);
|
|
mainTabPanel.enableRelatioshipFacilities(
|
|
relationshipDef != null && !relationshipDef.isEmpty());
|
|
}
|
|
|
|
@Override
|
|
public void onFailure(Throwable caught) {
|
|
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
// TODO MUST MANAGE getListOfRecordsEvent.isReloadFilteringParameters()
|
|
|
|
searchingFilter.setProjection(seachingFilterParameters.getProjection());
|
|
|
|
List<ItemFieldDV> displayFields = seachingFilterParameters.getDisplayFields();
|
|
|
|
grpw = new GeonaRecordsPaginatedView(appManagerBus, profileID, displayFields, searchingFilter);
|
|
|
|
mainTabPanel.showListOfProjectsView(grpw);
|
|
|
|
// The Project Type is changed
|
|
if (getListOfRecordsEvent.isReloadFilteringParameters()) {
|
|
// Setting the action panel according to profileID
|
|
mainTabPanel.initActionListPanel(geoportalCaches.getUCDForProfileID(profileID));
|
|
// Displaying the create relation button only if list of relation names exits
|
|
|
|
}
|
|
|
|
}
|
|
});
|
|
|
|
appManagerBus.addHandler(ClickItemEvent.TYPE, new ClickItemEventHandler() {
|
|
|
|
@Override
|
|
public <T> void onClick(ClickItemEvent<T> clickItemEvent) {
|
|
|
|
if (clickItemEvent.getSelectItems() != null) {
|
|
mainTabPanel.showActionsOnSelected(clickItemEvent.getSelectItems());
|
|
}
|
|
|
|
}
|
|
});
|
|
|
|
appManagerBus.addHandler(RelationActionHandlerEvent.TYPE, new RelationActionHandler() {
|
|
|
|
@Override
|
|
public void onCreateRelation(RelationActionHandlerEvent createRelationHE) {
|
|
|
|
if (createRelationHE.getRelactionActionType() == null)
|
|
return;
|
|
|
|
switch (createRelationHE.getRelactionActionType()) {
|
|
case DELETE: {
|
|
|
|
if (createRelationHE.getFromProject() == null || createRelationHE.getToProject() == null) {
|
|
DialogInform di = new DialogInform(null, "No selection", "You must select a Project");
|
|
di.center();
|
|
return;
|
|
}
|
|
|
|
String firstProject = createRelationHE.getFromProject().getFirstEntryOfMap().getKey() + ": "
|
|
+ createRelationHE.getFromProject().getFirstEntryOfMap().getValue() + " (id:"
|
|
+ createRelationHE.getFromProject().getId() + ")";
|
|
|
|
final String relationName = createRelationHE.getRelationName();
|
|
|
|
String secondProject = createRelationHE.getToProject().getFirstEntryOfMap().getKey() + ": "
|
|
+ createRelationHE.getToProject().getFirstEntryOfMap().getValue() + " (id:"
|
|
+ createRelationHE.getToProject().getId() + ")";
|
|
|
|
String htmlMsg = "Going to delete the relation <b>" + relationName + "</b><br>";
|
|
htmlMsg += "<i style='color:#333;'>From Project:</i><ul><li>" + firstProject + "</li></ul>";
|
|
htmlMsg += "<b>" + relationName + "</b><br>";
|
|
htmlMsg += "<i style='color:#333;'>To Project:</i><ul><li>" + secondProject + "</li></ul>";
|
|
htmlMsg += "<br>";
|
|
htmlMsg += "Would you like to proceed?";
|
|
|
|
final ModalConfirm dialog = new ModalConfirm(null,
|
|
"Deleting relationship " + relationName + ", Confirm?", htmlMsg);
|
|
|
|
dialog.getYesButton().addClickHandler(new ClickHandler() {
|
|
|
|
@Override
|
|
public void onClick(ClickEvent event) {
|
|
dialog.hide();
|
|
|
|
final Modal modal = new Modal(true, true);
|
|
modal.setTitle("Deleting relationship...");
|
|
modal.setWidth(800);
|
|
modal.setCloseVisible(false);
|
|
String fromProfileID = createRelationHE.getFromProject().getProfileID();
|
|
String fromProjectID = createRelationHE.getFromProject().getId();
|
|
String toProfileID = createRelationHE.getToProject().getProfileID();
|
|
String toProjectID = createRelationHE.getToProject().getId();
|
|
final VerticalPanel modalContainerPanel = new VerticalPanel();
|
|
final LoaderIcon loader = new LoaderIcon("Trying to delete the relation " + relationName
|
|
+ " from Project ID: " + fromProjectID + " to Project ID: " + toProjectID);
|
|
modalContainerPanel.add(loader);
|
|
modal.add(modalContainerPanel);
|
|
|
|
GeoportalDataEntryServiceAsync.Util.getInstance().deleteRelationship(fromProfileID,
|
|
fromProjectID, relationName, toProfileID, toProjectID,
|
|
new AsyncCallback<ResultDocumentDV>() {
|
|
|
|
@Override
|
|
public void onFailure(Throwable caught) {
|
|
modalContainerPanel.clear();
|
|
modal.setCloseVisible(true);
|
|
try {
|
|
modal.remove(loader);
|
|
} catch (Exception e) {
|
|
}
|
|
Alert alert = new Alert(caught.getMessage());
|
|
alert.setType(AlertType.ERROR);
|
|
alert.setClose(false);
|
|
modal.add(alert);
|
|
|
|
}
|
|
|
|
@Override
|
|
public void onSuccess(ResultDocumentDV result) {
|
|
modal.setTitle("Relationship deleted");
|
|
modalContainerPanel.clear();
|
|
modal.setCloseVisible(true);
|
|
try {
|
|
modal.remove(loader);
|
|
} catch (Exception e) {
|
|
// TODO: handle exception
|
|
}
|
|
Alert alert = new Alert();
|
|
alert.setType(AlertType.SUCCESS);
|
|
alert.setClose(false);
|
|
alert.setText("Relationship " + relationName + " deleted correctly!");
|
|
modal.add(alert);
|
|
|
|
String htmlMsg = "In the project with:";
|
|
htmlMsg += "<ul>";
|
|
htmlMsg += "<li>id: " + fromProjectID + "</li>";
|
|
htmlMsg += "<li>profile: " + fromProfileID + "</li>";
|
|
htmlMsg += "<li>" + result.getFirstEntryOfMap().getKey() + ": "
|
|
+ result.getFirstEntryOfMap().getValue() + "</li>";
|
|
htmlMsg += "</ul>";
|
|
htmlMsg += "has been deleted the relationship <b>" + relationName
|
|
+ "</b> to the project wiht id: " + toProjectID;
|
|
modal.add(new HTML(htmlMsg));
|
|
// ReportTemplateToHTML rtth = new ReportTemplateToHTML("Relationship", result.getAsJSON(),
|
|
// false, false);
|
|
// rtth.showAsJSON(false);
|
|
// modal.add(rtth);
|
|
|
|
List<DocumentDV> listDocuments = Arrays.asList(result);
|
|
|
|
appManagerBus.fireEvent(new OperationOnItemEvent<DocumentDV>(listDocuments,
|
|
OPERATION_ON_ITEM.VIEW_RELATIONSHIPS));
|
|
|
|
appManagerBus.fireEvent(new GetListOfRecordsEvent(false, fromProfileID,
|
|
mainTabPanel.getCurrentProjectsSearchingFilter(), true));
|
|
|
|
}
|
|
});
|
|
|
|
modal.show();
|
|
}
|
|
|
|
});
|
|
|
|
dialog.show();
|
|
|
|
break;
|
|
}
|
|
case CREATE: {
|
|
|
|
if (createRelationHE.getFromProject() == null || createRelationHE.getToProject() == null) {
|
|
DialogInform di = new DialogInform(null, "No selection",
|
|
"You must select a Project from/to in the table");
|
|
di.center();
|
|
return;
|
|
}
|
|
|
|
String firstProject = createRelationHE.getFromProject().getFirstEntryOfMap().getKey() + ": "
|
|
+ createRelationHE.getFromProject().getFirstEntryOfMap().getValue() + " (id:"
|
|
+ createRelationHE.getFromProject().getId() + ")";
|
|
|
|
String relation = createRelationHE.getRelationSelected().getLabel();
|
|
|
|
String secondProject = createRelationHE.getToProject().getFirstEntryOfMap().getKey() + ": "
|
|
+ createRelationHE.getToProject().getFirstEntryOfMap().getValue() + " (id:"
|
|
+ createRelationHE.getToProject().getId() + ")";
|
|
|
|
String htmlMsg = "Going to create the relation <b>" + relation + "</b><br>";
|
|
htmlMsg += "<i style='color:#333;'>From Project:</i><ul><li>" + firstProject + "</li></ul>";
|
|
htmlMsg += "<b>" + relation + "</b><br>";
|
|
htmlMsg += "<i style='color:#333;'>To Project:</i><ul><li>" + secondProject + "</li></ul>";
|
|
htmlMsg += "<br>";
|
|
htmlMsg += "Would you like to proceed?";
|
|
|
|
final ModalConfirm dialog = new ModalConfirm(null,
|
|
"Creating relationship " + relation + ", Confirm?", htmlMsg);
|
|
|
|
dialog.getYesButton().addClickHandler(new ClickHandler() {
|
|
|
|
@Override
|
|
public void onClick(ClickEvent event) {
|
|
dialog.hide();
|
|
|
|
final Modal modal = new Modal(true, true);
|
|
modal.setTitle("Creating relationship...");
|
|
modal.setWidth(800);
|
|
modal.setCloseVisible(false);
|
|
final RelationshipDefinitionDV relationSelected = createRelationHE.getRelationSelected();
|
|
String fromProfileID = createRelationHE.getFromProject().getProfileID();
|
|
String fromProjectID = createRelationHE.getFromProject().getId();
|
|
String toProfileID = createRelationHE.getToProject().getProfileID();
|
|
String toProjectID = createRelationHE.getToProject().getId();
|
|
final VerticalPanel modalContainerPanel = new VerticalPanel();
|
|
final LoaderIcon loader = new LoaderIcon(
|
|
"Trying to create the relation " + relationSelected.getLabel()
|
|
+ " from Project ID: " + fromProjectID + " to Project ID: " + toProjectID);
|
|
modalContainerPanel.add(loader);
|
|
modal.add(modalContainerPanel);
|
|
|
|
GeoportalDataEntryServiceAsync.Util.getInstance().createRelationship(fromProfileID,
|
|
fromProjectID, relationSelected.getId(), toProfileID, toProjectID,
|
|
new AsyncCallback<Void>() {
|
|
|
|
@Override
|
|
public void onFailure(Throwable caught) {
|
|
modalContainerPanel.clear();
|
|
modal.setCloseVisible(true);
|
|
try {
|
|
modal.remove(loader);
|
|
} catch (Exception e) {
|
|
}
|
|
Alert alert = new Alert(caught.getMessage());
|
|
alert.setType(AlertType.ERROR);
|
|
alert.setClose(false);
|
|
modal.add(alert);
|
|
|
|
}
|
|
|
|
@Override
|
|
public void onSuccess(Void result) {
|
|
modal.setTitle("Relationship created");
|
|
modalContainerPanel.clear();
|
|
modal.setCloseVisible(true);
|
|
try {
|
|
modal.remove(loader);
|
|
} catch (Exception e) {
|
|
// TODO: handle exception
|
|
}
|
|
Alert alert = new Alert();
|
|
alert.setType(AlertType.SUCCESS);
|
|
alert.setClose(false);
|
|
alert.setText("Relationship " + relationSelected.getLabel()
|
|
+ " created correctly!");
|
|
modal.add(alert);
|
|
|
|
String htmlMsg = "In the project with:";
|
|
htmlMsg += "<ul>";
|
|
htmlMsg += "<li>id: " + fromProjectID + "</li>";
|
|
htmlMsg += "<li>profile: " + fromProfileID + "</li>";
|
|
htmlMsg += "<li>"
|
|
+ createRelationHE.getFromProject().getFirstEntryOfMap().getKey()
|
|
+ ": "
|
|
+ createRelationHE.getFromProject().getFirstEntryOfMap().getValue()
|
|
+ "</li>";
|
|
htmlMsg += "</ul>";
|
|
htmlMsg += "has been created the relationship <b>"
|
|
+ relationSelected.getLabel() + "</b> to the project wiht id: "
|
|
+ toProjectID;
|
|
modal.add(new HTML(htmlMsg));
|
|
// ReportTemplateToHTML rtth = new ReportTemplateToHTML("Relationship", result.getAsJSON(),
|
|
// false, false);
|
|
// rtth.showAsJSON(false);
|
|
// modal.add(rtth);
|
|
|
|
appManagerBus.fireEvent(new CloseCreateRelationGUIEvent());
|
|
|
|
appManagerBus.fireEvent(new GetListOfRecordsEvent(false, fromProfileID,
|
|
mainTabPanel.getCurrentProjectsSearchingFilter(), true));
|
|
}
|
|
});
|
|
|
|
modal.show();
|
|
}
|
|
|
|
});
|
|
|
|
dialog.show();
|
|
|
|
}
|
|
default:
|
|
break;
|
|
}
|
|
|
|
}
|
|
});
|
|
|
|
appManagerBus.addHandler(CloseCreateRelationGUIEvent.TYPE, new CloseCreateRelationGUIEventHandler() {
|
|
|
|
@Override
|
|
public void onClose(CloseCreateRelationGUIEvent closeCreateRelationGUI) {
|
|
mainTabPanel.showCreateRelationPanel(false, null);
|
|
|
|
}
|
|
});
|
|
|
|
appManagerBus.addHandler(WorkflowActionOnSelectedItemEvent.TYPE,
|
|
new WorkflowActionOnSelectedItemEventHandler() {
|
|
|
|
@Override
|
|
public <T extends DocumentDV> void onDoActionFired(
|
|
final WorkflowActionOnSelectedItemEvent<T> wActionOnItem) {
|
|
GWT.log("WorkflowActionOnSelectedItemEvent onDoActionFired item: " + wActionOnItem);
|
|
|
|
if (grpw.getSelectItems() == null || grpw.getSelectItems().size() == 0) {
|
|
DialogInform di = new DialogInform(null, "No selection",
|
|
"You must select a record in the table");
|
|
di.center();
|
|
return;
|
|
}
|
|
|
|
DocumentDV item = grpw.getSelectItems().get(0);
|
|
|
|
final ResultDocumentDV resultDocumentDV = (ResultDocumentDV) item;
|
|
|
|
String htmlMsg = "Going to perform the step/s <i><b>" + wActionOnItem.getAction().getCallSteps()
|
|
+ "</b></i> on the project with:";
|
|
htmlMsg += "<ul>";
|
|
htmlMsg += "<li>id: " + resultDocumentDV.getId() + "</li>";
|
|
htmlMsg += "<li>profile: " + resultDocumentDV.getProfileID() + "</li>";
|
|
htmlMsg += "<li>" + resultDocumentDV.getFirstEntryOfMap().getKey() + ": "
|
|
+ resultDocumentDV.getFirstEntryOfMap().getValue() + "</li>";
|
|
htmlMsg += "</ul>";
|
|
htmlMsg += "<br>";
|
|
htmlMsg += "Would you like to proceed?";
|
|
|
|
final ModalConfirm dialog = new ModalConfirm(null,
|
|
"Step/s " + wActionOnItem.getAction().getTitle() + ", Confirm?", htmlMsg);
|
|
dialog.addToCenterPanel(
|
|
new ReportTemplateToHTML("Project", resultDocumentDV.getDocumentAsJSON(), false));
|
|
|
|
dialog.getYesButton().addClickHandler(new ClickHandler() {
|
|
|
|
@Override
|
|
public void onClick(ClickEvent event) {
|
|
dialog.hide();
|
|
|
|
final Modal modal = new Modal(true, true);
|
|
modal.setCloseVisible(false);
|
|
modal.setTitle("Perfoming Steps...");
|
|
modal.hide(false);
|
|
modal.setWidth(800);
|
|
modal.setMaxHeigth("650px");
|
|
final VerticalPanel modalContainerPanel = new VerticalPanel();
|
|
final LoaderIcon loader = new LoaderIcon();
|
|
loader.setText("Trying to perfom step/s " + wActionOnItem.getAction().getCallSteps()
|
|
+ ", please wait...");
|
|
modalContainerPanel.add(loader);
|
|
modal.add(modalContainerPanel);
|
|
|
|
GeoportalDataEntryServiceAsync.Util.getInstance().performActionSteps(
|
|
resultDocumentDV.getProfileID(), resultDocumentDV.getId(),
|
|
wActionOnItem.getAction(), new AsyncCallback<ProjectDV>() {
|
|
|
|
@Override
|
|
public void onFailure(Throwable caught) {
|
|
modal.setCloseVisible(true);
|
|
try {
|
|
modalContainerPanel.remove(loader);
|
|
} catch (Exception e) {
|
|
}
|
|
Alert alert = new Alert(caught.getMessage());
|
|
alert.setType(AlertType.ERROR);
|
|
alert.setClose(false);
|
|
modal.add(alert);
|
|
}
|
|
|
|
@Override
|
|
public void onSuccess(final ProjectDV result) {
|
|
modal.setTitle("Step/s performed");
|
|
modal.setCloseVisible(true);
|
|
try {
|
|
modalContainerPanel.remove(loader);
|
|
} catch (Exception e) {
|
|
}
|
|
|
|
String stepString = wActionOnItem.getAction().getCallSteps().length==1?"Step":"Steps";
|
|
|
|
String stepsToString = "";
|
|
for (String step : wActionOnItem.getAction().getCallSteps()) {
|
|
stepsToString+=step+", ";
|
|
}
|
|
|
|
Alert alert = new Alert(
|
|
stepString +" "+ stepsToString
|
|
+ "performed correclty!");
|
|
alert.setType(AlertType.INFO);
|
|
alert.setClose(false);
|
|
modal.add(alert);
|
|
|
|
GeoportalDataEntryServiceAsync.Util.getInstance().getResultDocumentFoProjectByID(result.getProfileID(), result.getId(), new AsyncCallback<ResultDocumentDV>() {
|
|
|
|
@Override
|
|
public void onFailure(Throwable caught) {
|
|
// TODO Auto-generated method stub
|
|
|
|
}
|
|
|
|
@Override
|
|
public void onSuccess(ResultDocumentDV theResultDocument) {
|
|
VerticalPanel vp = new VerticalPanel();
|
|
vp.getElement().getStyle().setMarginTop(20, Unit.PX);
|
|
vp.add(new Label("Check outcome in the Publication Report"));
|
|
Button buttonShowPublicationReport = new Button(
|
|
"Show Publication Report");
|
|
buttonShowPublicationReport.setType(ButtonType.INFO);
|
|
buttonShowPublicationReport.addClickHandler(new ClickHandler() {
|
|
|
|
@Override
|
|
public void onClick(ClickEvent event) {
|
|
modal.hide();
|
|
appManagerBus.fireEvent(new OperationOnItemEvent<DocumentDV>(
|
|
Arrays.asList(theResultDocument),
|
|
OPERATION_ON_ITEM.VIEW_REPORT));
|
|
|
|
}
|
|
});
|
|
buttonShowPublicationReport.getElement().getStyle().setMarginTop(10, Unit.PX);
|
|
buttonShowPublicationReport.getElement().getStyle().setMarginBottom(20, Unit.PX);
|
|
vp.add(buttonShowPublicationReport);
|
|
|
|
modal.add(vp);
|
|
|
|
}
|
|
});
|
|
|
|
appManagerBus.fireEvent(new GetListOfRecordsEvent(false,
|
|
resultDocumentDV.getProfileID(),
|
|
mainTabPanel.getCurrentProjectsSearchingFilter(), true));
|
|
|
|
}
|
|
});
|
|
|
|
modal.show();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
dialog.show();
|
|
|
|
}
|
|
});
|
|
|
|
appManagerBus.addHandler(OperationPerformedOnItemEvent.TYPE, new OperationPerformedOnItemEventHandler() {
|
|
|
|
@Override
|
|
public <T extends DocumentDV> void onDoActionPerformedFired(
|
|
OperationPerformedOnItemEvent<T> actionPerformedOnItemEvent) {
|
|
if (actionPerformedOnItemEvent != null) {
|
|
|
|
ACTION_PERFORMED_ON_ITEM action = actionPerformedOnItemEvent.getAction();
|
|
List<T> items = actionPerformedOnItemEvent.getSelectItems();
|
|
|
|
if (items == null) {
|
|
if (grpw != null) {
|
|
items = (List<T>) grpw.getSelectItems();
|
|
}
|
|
}
|
|
|
|
if (items == null || items.size() == 0) {
|
|
Window.alert("No item selected");
|
|
return;
|
|
}
|
|
|
|
T item = items.get(0);
|
|
|
|
if (item == null)
|
|
return;
|
|
|
|
if (item instanceof DocumentDV) {
|
|
final DocumentDV concessione = (DocumentDV) item;
|
|
GWT.log("onDoActionPerformedFired item: " + concessione);
|
|
switch (action) {
|
|
case UPDATED_PROJECT:
|
|
// appManagerBus.fireEvent(new GetListOfRecordsEvent(RECORD_TYPE.CONCESSIONE,
|
|
// actionPerformedOnItemEvent.getProfileID(), null,
|
|
// mainTabPanel.getCurrentSortFilter()));
|
|
|
|
appManagerBus.fireEvent(new GetListOfRecordsEvent(false, grpw.getProfileID(),
|
|
mainTabPanel.getCurrentProjectsSearchingFilter(), false));
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
});
|
|
|
|
appManagerBus.addHandler(OperationOnItemEvent.TYPE, new OperationOnItemEventHandler() {
|
|
|
|
@Override
|
|
public <T extends DocumentDV> void onDoActionFired(OperationOnItemEvent<T> showItemEvent) {
|
|
|
|
GWT.log("Fired event: " + showItemEvent);
|
|
|
|
if (showItemEvent != null) {
|
|
|
|
OPERATION_ON_ITEM action = showItemEvent.getAction();
|
|
List<T> items = showItemEvent.getSelectItems();
|
|
|
|
if (items == null) {
|
|
if (grpw != null) {
|
|
items = (List<T>) grpw.getSelectItems();
|
|
}
|
|
}
|
|
|
|
if (items == null || items.size() == 0) {
|
|
DialogInform di = new DialogInform(null, "No selection",
|
|
"You must select a record in the 'List of Projects' table");
|
|
di.center();
|
|
return;
|
|
}
|
|
|
|
T item = items.get(0);
|
|
|
|
if (item == null)
|
|
return;
|
|
|
|
if (item instanceof ResultDocumentDV) {
|
|
|
|
final ResultDocumentDV resultDocumentDV = (ResultDocumentDV) item;
|
|
GWT.log("onDoActionFired item: " + resultDocumentDV);
|
|
|
|
// Checking if the user is NOT authorized to perform this action in two ways:
|
|
// 1. the map of actions allowed for the user does not contain the action;
|
|
RoleRights roleRights = myRights.getRoleRights();
|
|
OPERATION_TYPE operationType = roleRights.getListPermessions().get(action);
|
|
boolean allowedOperationForUser = operationType != null ? true : false;
|
|
|
|
GcubeUserRole myRole = myRights.getRoleRights().getUserRole();
|
|
|
|
// TODO REMOVE THIS IF AFTER ADDING ALL THE OPERATIONS IN THE IS
|
|
// OPERATIONS/RIGHTS CONFIGURATION
|
|
if (!myRole.equals(GcubeUserRole.DATA_MANAGER)) {
|
|
|
|
if (!allowedOperationForUser) {
|
|
|
|
String msg = "You are not authorized to perform the action: " + action.getLabel();
|
|
ModalWindow modalW = new ModalWindow(new Image(Images.ICONS.accessDenied()),
|
|
"Forbidden: " + action, msg, AlertType.WARNING);
|
|
modalW.show();
|
|
return;
|
|
}
|
|
// 2. the user cannot access to action (e.g. the user cannot write an item of
|
|
// another user)
|
|
// if so an error is shown
|
|
GcubeUserRole userRole = myRights.getRoleRights().getUserRole();
|
|
String creatorUsername = "";
|
|
try {
|
|
creatorUsername = resultDocumentDV.getPublicationInfoDV().getCreationInfo()
|
|
.getUsername();
|
|
} catch (Exception e) {
|
|
// TODO: handle exception
|
|
}
|
|
boolean allowedWriteActionOnItem = checkAccessToOperationType(userRole, operationType,
|
|
creatorUsername);
|
|
if (!allowedWriteActionOnItem) {
|
|
String title = "Forbidden: missing write access";
|
|
String msg = "You do not have write access to item: " + resultDocumentDV.getId();
|
|
if (!userRole.isWriteOwn()) {
|
|
msg = "You do not have write access to item: " + resultDocumentDV.getId();
|
|
} else if (!userRole.isWriteAny()) {
|
|
title = "Forbidden: missing ownership";
|
|
msg = "You are not the creator of: " + resultDocumentDV.getId()
|
|
+ ". You cannot access to it";
|
|
}
|
|
ModalWindow modalW = new ModalWindow(new Image(Images.ICONS.accessDenied()), title, msg,
|
|
AlertType.WARNING);
|
|
modalW.show();
|
|
return;
|
|
}
|
|
}
|
|
|
|
switch (action) {
|
|
case VIEW_ON_MAP: {
|
|
|
|
final Modal modal = new Modal(true, true);
|
|
modal.setCloseVisible(true);
|
|
final HorizontalPanel hpGetLink = new HorizontalPanel();
|
|
final LoaderIcon lc = new LoaderIcon("Just moment getting link...");
|
|
hpGetLink.add(lc);
|
|
modal.add(hpGetLink);
|
|
|
|
final NewBrowserWindow newBrowserWindow = NewBrowserWindow.open("", "_blank", "");
|
|
|
|
GeoportalDataEntryServiceAsync.Util.getInstance().getLinksFor(resultDocumentDV.getId(),
|
|
resultDocumentDV.getProfileID(), new AsyncCallback<GeoportalItemReferences>() {
|
|
@Override
|
|
public void onFailure(Throwable caught) {
|
|
hpGetLink.clear();
|
|
Alert alert = new Alert(caught.getMessage(), AlertType.ERROR);
|
|
alert.setClose(false);
|
|
hpGetLink.add(alert);
|
|
newBrowserWindow.close();
|
|
}
|
|
|
|
@Override
|
|
public void onSuccess(GeoportalItemReferences result) {
|
|
String theURL = result.getRestrictedLink().getShortURL() != null
|
|
? result.getRestrictedLink().getShortURL()
|
|
: result.getRestrictedLink().getCompleteURL();
|
|
newBrowserWindow.setUrl(theURL);
|
|
modal.hide();
|
|
}
|
|
});
|
|
|
|
modal.show();
|
|
|
|
break;
|
|
}
|
|
|
|
case VIEW_REPORT: {
|
|
|
|
final Modal modal2 = new Modal(true, true);
|
|
modal2.setTitle(
|
|
"<span style='font-size:20px;'>Publication Report for Project ID: <span style='color:#555; font-size:20px;'>"
|
|
+ resultDocumentDV.getId() + "</span></span>");
|
|
modal2.setWidth(800);
|
|
modal2.setCloseVisible(true);
|
|
final LoaderIcon lc = new LoaderIcon("Just moment loading lifecycle info...");
|
|
modal2.add(lc);
|
|
|
|
GeoportalDataEntryServiceAsync.Util.getInstance().getLifecycleInfoForProjectId(
|
|
resultDocumentDV.getProfileID(), resultDocumentDV.getId(),
|
|
new AsyncCallback<LifecycleInformationDV>() {
|
|
|
|
@Override
|
|
public void onFailure(Throwable caught) {
|
|
lc.setVisible(false);
|
|
modal2.add(
|
|
new HTML("No report available for: " + resultDocumentDV.getId()));
|
|
modal2.add(new Alert(caught.getMessage(), AlertType.ERROR));
|
|
}
|
|
|
|
@Override
|
|
public void onSuccess(LifecycleInformationDV result) {
|
|
lc.setVisible(false);
|
|
LifecycleInformationPanel lip = new LifecycleInformationPanel(
|
|
resultDocumentDV.getId(), resultDocumentDV.getProfileID(),
|
|
resultDocumentDV.getDocumentAsJSON(), result, false);
|
|
modal2.add(lip);
|
|
|
|
}
|
|
});
|
|
|
|
modal2.show();
|
|
|
|
break;
|
|
}
|
|
|
|
case EDIT_PROJECT: {
|
|
final Modal modal3 = new Modal(true, true);
|
|
modal3.setTitle(
|
|
"<span style='font-size:20px;'>Edit: <span style='color:#555; font-size:20px;'>"
|
|
+ resultDocumentDV.getId() + "</span></span>");
|
|
modal3.setWidth(950);
|
|
modal3.setHeight("700px");
|
|
modal3.setCloseVisible(true);
|
|
((Element) modal3.getElement().getChildNodes().getItem(1))
|
|
.addClassName("modal-body-custom");
|
|
EditModeRecord emr = new EditModeRecord(appManagerBus, resultDocumentDV);
|
|
modal3.add(emr);
|
|
modal3.show();
|
|
break;
|
|
}
|
|
case CREATE_RELATION: {
|
|
|
|
mainTabPanel.showCreateRelationPanel(true, resultDocumentDV);
|
|
|
|
break;
|
|
}
|
|
|
|
case VIEW_RELATIONSHIPS: {
|
|
GWT.log("VIEW_RELATIONSHIPS fired");
|
|
mainTabPanel.showViewProjectRelationsPanel(true, resultDocumentDV);
|
|
|
|
break;
|
|
}
|
|
|
|
case DELETE_PROJECT: {
|
|
|
|
String htmlMsg = "Going to delete the project with:";
|
|
htmlMsg += "<ul>";
|
|
htmlMsg += "<li>id: " + resultDocumentDV.getId() + "</li>";
|
|
htmlMsg += "<li>profile: " + resultDocumentDV.getProfileID() + "</li>";
|
|
htmlMsg += "<li>" + resultDocumentDV.getFirstEntryOfMap().getKey() + ": "
|
|
+ resultDocumentDV.getFirstEntryOfMap().getValue() + "</li>";
|
|
htmlMsg += "</ul>";
|
|
htmlMsg += "<br>";
|
|
htmlMsg += "This operation cannot be undone. Would you like to proceed?";
|
|
|
|
final ModalConfirm dialog = new ModalConfirm(null, "Delete Confirm?", htmlMsg);
|
|
dialog.addToCenterPanel(
|
|
new ReportTemplateToHTML("Project", resultDocumentDV.getDocumentAsJSON(), false));
|
|
dialog.show();
|
|
|
|
dialog.getYesButton().addClickHandler(new ClickHandler() {
|
|
|
|
@Override
|
|
public void onClick(ClickEvent event) {
|
|
dialog.hide();
|
|
final Modal modal = new Modal(true, true);
|
|
modal.setCloseVisible(true);
|
|
final HorizontalPanel hp = new HorizontalPanel();
|
|
final LoaderIcon lc = new LoaderIcon("Deleting Project...");
|
|
hp.add(lc);
|
|
modal.add(hp);
|
|
|
|
GeoportalDataEntryServiceAsync.Util.getInstance().deleteProject(
|
|
resultDocumentDV.getProfileID(), resultDocumentDV.getId(),
|
|
new AsyncCallback<Boolean>() {
|
|
|
|
@Override
|
|
public void onFailure(Throwable caught) {
|
|
hp.clear();
|
|
modal.setTitle("Error");
|
|
Alert alert = new Alert(
|
|
"Sorry, I cannot delete the Project with id '"
|
|
+ resultDocumentDV.getId()
|
|
+ "' Refresh an try again. Error: "
|
|
+ caught.getMessage(),
|
|
AlertType.ERROR);
|
|
alert.setClose(false);
|
|
hp.add(alert);
|
|
|
|
}
|
|
|
|
@Override
|
|
public void onSuccess(Boolean result) {
|
|
hp.clear();
|
|
if (result) {
|
|
modal.setTitle("Project deleted");
|
|
Alert alert = new Alert("Project with id '"
|
|
+ resultDocumentDV.getId() + "' deleted correclty",
|
|
AlertType.INFO);
|
|
alert.setClose(false);
|
|
hp.add(alert);
|
|
|
|
appManagerBus.fireEvent(new GetListOfRecordsEvent(false,
|
|
resultDocumentDV.getProfileID(),
|
|
mainTabPanel.getCurrentProjectsSearchingFilter(),
|
|
false));
|
|
} else {
|
|
modal.setTitle("Error");
|
|
Alert alert = new Alert(
|
|
"Sorry, I cannot delete the Project with id '"
|
|
+ resultDocumentDV.getId()
|
|
+ "' Refresh an try again",
|
|
AlertType.ERROR);
|
|
alert.setClose(false);
|
|
hp.add(alert);
|
|
}
|
|
|
|
}
|
|
});
|
|
modal.show();
|
|
}
|
|
|
|
});
|
|
break;
|
|
}
|
|
|
|
default:
|
|
break;
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
}
|
|
|
|
private TreeItem cloneSubTreeItems(TreeItem root) {
|
|
GWT.log("cloneSubTreeItems called");
|
|
|
|
if (root == null) {
|
|
GWT.log("cloneSubTreeItems returns, node is null");
|
|
return null;
|
|
}
|
|
|
|
GWT.log("cloneSubTreeItems called on: " + root.getText());
|
|
|
|
// Cloning
|
|
NodeItem theRootNode = (NodeItem) root.getWidget();
|
|
GeoNaFormCardModel nodeCard = theRootNode.getGeoNaFormCardModel();
|
|
GeoNaFormCardModel newNodeFormCard = buildNewFormCardModelFromProfile(nodeCard.getGcubeProfile(), -1,
|
|
nodeCard.getMetadataProfileBean(), OPERATION.UPDATE);
|
|
|
|
// create a new node with the same data as the root node
|
|
boolean canBeDuplicated = newNodeFormCard.getFormCard().isInternalRepeatibleForm();
|
|
// geoNaMainForm.getTreeItemPanel().createAndAddChild(theRootNode.getParentTreeItem(), newNodeFormCard,
|
|
// canBeDuplicated, true, theRootNode.getJsonSectionFullPath());
|
|
|
|
TreeItem newTreeItem = new TreeItem(
|
|
new NodeItem(root.getParentItem(), nodeCard.getGcubeProfile().getSectionTitle(), newNodeFormCard,
|
|
canBeDuplicated, true, theRootNode.getJsonSectionFullPath()));
|
|
String parentText = root.getParentItem() != null ? root.getParentItem().getText() : null;
|
|
GWT.log("newTreeItem created: " + newTreeItem.getText() + ", parent is: " + parentText);
|
|
|
|
// Total children count
|
|
int total = root.getChildCount();
|
|
// All the children
|
|
for (int i = 0; i < total; i++) {
|
|
TreeItem childCloned = cloneSubTreeItems(root.getChild(i));
|
|
newTreeItem.addItem(childCloned);
|
|
}
|
|
|
|
return newTreeItem;
|
|
|
|
}
|
|
|
|
private boolean checkAccessToOperationType(GcubeUserRole userRole, OPERATION_TYPE allowedAction,
|
|
String creatorUsername) {
|
|
|
|
boolean writeAnyAPassed = false;
|
|
boolean writeOwnPassed = false;
|
|
|
|
// Case ADMIN
|
|
if (userRole.isWriteAny()) {
|
|
writeAnyAPassed = true;
|
|
}
|
|
|
|
// Case EDITOR
|
|
// Going to check if the user can RW the record is owner of.
|
|
if (userRole.isWriteOwn()) {
|
|
String ownerUser = creatorUsername;
|
|
if (ownerUser == null || ownerUser.isEmpty()) {
|
|
writeOwnPassed = false;
|
|
} else if (ownerUser.compareTo(myRights.getMyUsername()) == 0) {
|
|
// if my username is equal the owner of the project
|
|
writeOwnPassed = true;
|
|
}
|
|
}
|
|
|
|
boolean operationAllowed = false;
|
|
switch (allowedAction) {
|
|
case READ:
|
|
// Access to READ operation is allowed to everyone
|
|
operationAllowed = true;
|
|
GWT.log(OPERATION_TYPE.READ + " ALLOWED? " + operationAllowed);
|
|
break;
|
|
case READ_WRITE:
|
|
// Access to READ_WRITE operation
|
|
operationAllowed = writeAnyAPassed || writeOwnPassed;
|
|
GWT.log(OPERATION_TYPE.READ_WRITE + " ALLOWED? " + operationAllowed);
|
|
break;
|
|
case WRITE:
|
|
// Access to WRITE operation
|
|
operationAllowed = writeAnyAPassed || writeOwnPassed;
|
|
GWT.log(OPERATION_TYPE.WRITE + " ALLOWED? " + operationAllowed);
|
|
break;
|
|
case UNKNOWN:
|
|
operationAllowed = false;
|
|
GWT.log(OPERATION_TYPE.UNKNOWN + " ALLOWED? " + operationAllowed);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
return operationAllowed;
|
|
}
|
|
|
|
private void purgeFileUploaded() {
|
|
|
|
MetadataProfileFormBuilderServiceAsync.Util.getInstance().purgeFilesUploaded(new AsyncCallback<Integer>() {
|
|
|
|
@Override
|
|
public void onFailure(Throwable caught) {
|
|
// silent
|
|
|
|
}
|
|
|
|
@Override
|
|
public void onSuccess(Integer result) {
|
|
GWT.log("Purged " + result + " file/s uploaded");
|
|
|
|
}
|
|
});
|
|
}
|
|
|
|
}
|