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.WORKFLOW_PHASE; 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.materialization.innerobject.FilesetDV; import org.gcube.application.geoportalcommon.shared.geoportal.materialization.innerobject.PayloadDV; 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.application.geoportalcommon.shared.geoportal.view.ProjectView; import org.gcube.application.geoportaldatamapper.shared.MetaDataProfileBeanExt; 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.RelationActionHandlerEvent.RELACTION_ACTION_TYPE; 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.edit.UpdateRecord; 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.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.gdvw.client.GeoportalDataViewerWidget; import org.gcube.portlets.widgets.gdvw.client.project.ProjectViewer; 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.DataTypeWrapper; import org.gcube.portlets.widgets.mpformbuilder.shared.metadata.MetaDataProfileBean; import org.gcube.portlets.widgets.mpformbuilder.shared.metadata.MetadataFieldWrapper; import org.gcube.portlets.widgets.mpformbuilder.shared.upload.FilePath; import org.gcube.portlets.widgets.mpformbuilder.shared.upload.FileUploaded; import org.gcube.portlets.widgets.mpformbuilder.shared.upload.FileUploadedRemote; 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.github.gwtbootstrap.client.ui.constants.LabelType; 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.Anchor; 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 onModuleLoad(). */ public class GeoPortalDataEntryApp implements EntryPoint { public static final GeoportalDataEntryServiceAsync geoportalDataEntryService = GWT .create(GeoportalDataEntryService.class); private final HandlerManager appManagerBus = new HandlerManager(null); private LinkedHashMap mapForms = new LinkedHashMap(); private GeonaDataEntryMainForm geoNaMainForm = null; private GeonaMainTabPanel mainTabPanel; private LinkedHashMap> savedMap = new LinkedHashMap>(); 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 gnaCardsModels = new * ArrayList(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() { @Override public void onFailure(Throwable caught) { String errorMsg = "Sorry, an error occurred 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() { @Override public void onFailure(Throwable caught) { String errorMsg = "Sorry, an error occurred 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(); try { ConstantsGeoPortalDataEntryApp.ROOT_PANEL_DIV_LOADERS.insert(loaderConfigurations, 0); } catch (Exception e) { } GeoportalDataEntryServiceAsync.Util.getInstance().getListUseCaseDescriptors( ConstantsGeoPortalDataEntryApp.HANDLERS_IDS, new AsyncCallback>() { @Override public void onFailure(Throwable caught) { String errorMsg = "Sorry, an error occurred 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 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 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 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 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(cardsPerIT)); // return; // } numberOfCards = 0; expectedCards = listGPs.size(); GWT.log("expectedCards are: " + expectedCards); TreeMap treemapOrderedGNAProfiles = new TreeMap(); 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>() { @Override public void onFailure(Throwable caught) { mainTabPanel.setLoaderVisible("Loading...", false); Window.alert(caught.getMessage()); } @Override public void onSuccess(List 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, appManagerBus); treemapOrderedGNAProfiles.put(order, geonaForm); } if (getNumberOfCards() >= expectedCards) { mainTabPanel.setLoaderVisible("Loading...", false); // ordered values Collection gnaCardsModels = treemapOrderedGNAProfiles.values(); GWT.log("TreeMap values: " + gnaCardsModels); List listGNAFormCardModel = new ArrayList( gnaCardsModels); geoportalCaches.putGcubeProfilePerItemType(handlerDeclarationDV.getItemType(), listGNAFormCardModel); // orderedCards.addAll(new ArrayList(gnaCardsModels)); buildNewCards(profileID, handlerDeclarationDV.getItemType(), listGNAFormCardModel); } } }); } } /** * 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 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 stepsOnPostCreation = new ArrayList(); 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() { @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, false); 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 listRelationshipsDef = geoportalCaches .getListRelationshipDefinitionForProfileId(profileID); // Loading list of relationships definition ProfileID if (listRelationshipsDef == null || listRelationshipsDef.isEmpty()) { GeoPortalDataEntryApp.geoportalDataEntryService.getRelationshipsDefinition(profileID, new AsyncCallback>() { @Override public void onSuccess(List relationshipDef) { GWT.log("getRelationshipNames for " + profileID + " are: " + relationshipDef); geoportalCaches.putListRelationshipsDefinitionForProfileID(profileID, relationshipDef); mainTabPanel.enableRelatioshipFacilities( relationshipDef != null && !relationshipDef.isEmpty()); } @Override public void onFailure(Throwable caught) { } }); } } searchingFilter.setProjection(seachingFilterParameters.getProjection()); List 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 void onClick(ClickItemEvent 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: { 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) && !myRole.equals(GcubeUserRole.DATA_EDITOR)) { String action = RELACTION_ACTION_TYPE.DELETE + " Relation"; String msg = "You are not authorized to perform the action: " + action; ModalWindow modalW = new ModalWindow(new Image(Images.ICONS.accessDenied()), "Forbidden: " + action, msg, AlertType.WARNING); modalW.show(); return; } 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 " + relationName + "
"; htmlMsg += "From Project:
  • " + firstProject + "
"; htmlMsg += "" + relationName + "
"; htmlMsg += "To Project:
  • " + secondProject + "
"; htmlMsg += "
"; 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() { @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 += "
    "; htmlMsg += "
  • id: " + fromProjectID + "
  • "; htmlMsg += "
  • profile: " + fromProfileID + "
  • "; htmlMsg += "
  • " + result.getFirstEntryOfMap().getKey() + ": " + result.getFirstEntryOfMap().getValue() + "
  • "; htmlMsg += "
"; htmlMsg += "has been deleted the relationship " + relationName + " 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 listDocuments = Arrays.asList(result); appManagerBus.fireEvent(new OperationOnItemEvent(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 " + relation + "
"; htmlMsg += "From Project:
  • " + firstProject + "
"; htmlMsg += "" + relation + "
"; htmlMsg += "To Project:
  • " + secondProject + "
"; htmlMsg += "
"; 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() { @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 += "
    "; htmlMsg += "
  • id: " + fromProjectID + "
  • "; htmlMsg += "
  • profile: " + fromProfileID + "
  • "; htmlMsg += "
  • " + createRelationHE.getFromProject().getFirstEntryOfMap().getKey() + ": " + createRelationHE.getFromProject().getFirstEntryOfMap().getValue() + "
  • "; htmlMsg += "
"; htmlMsg += "has been created the relationship " + relationSelected.getLabel() + " 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 void onDoActionFired( final WorkflowActionOnSelectedItemEvent 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 " + wActionOnItem.getAction().getCallSteps() + " on the project with:"; htmlMsg += "
    "; htmlMsg += "
  • id: " + resultDocumentDV.getId() + "
  • "; htmlMsg += "
  • profile: " + resultDocumentDV.getProfileID() + "
  • "; htmlMsg += "
  • " + resultDocumentDV.getFirstEntryOfMap().getKey() + ": " + resultDocumentDV.getFirstEntryOfMap().getValue() + "
  • "; htmlMsg += "
"; htmlMsg += "
"; 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() { @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() { @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( 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 void onDoActionPerformedFired( OperationPerformedOnItemEvent actionPerformedOnItemEvent) { if (actionPerformedOnItemEvent != null) { ACTION_PERFORMED_ON_ITEM action = actionPerformedOnItemEvent.getAction(); List items = actionPerformedOnItemEvent.getSelectItems(); if (items == null) { if (grpw != null) { items = (List) 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 void onDoActionFired(OperationOnItemEvent showItemEvent) { GWT.log("Fired event: " + showItemEvent); if (showItemEvent != null) { OPERATION_ON_ITEM action = showItemEvent.getAction(); List items = showItemEvent.getSelectItems(); if (items == null) { if (grpw != null) { items = (List) 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.setTitle("Show on Map the Project..."); modal.setCloseVisible(true); if (resultDocumentDV.getLifecycleInfo() != null) { String phase = resultDocumentDV.getLifecycleInfo().getPhase(); // IF the project is not in DRAFT phase, showing an alert and no Update Mode // will // be activated if (phase != null && phase.compareToIgnoreCase(WORKFLOW_PHASE.DRAFT.getLabel()) == 0) { Alert alert = new Alert( ConstantsGeoPortalDataEntryApp.SHOW_ON_MAP_NOT_AVAILABLE_IN_DRAFT); alert.setType(AlertType.WARNING); alert.setClose(false); modal.add(alert); modal.show(); return; } } final HorizontalPanel hpGetLink = new HorizontalPanel(); final LoaderIcon lc = new LoaderIcon("Just moment getting link..."); hpGetLink.add(lc); modal.add(hpGetLink); GeoportalDataEntryServiceAsync.Util.getInstance().getLinksFor(resultDocumentDV.getId(), resultDocumentDV.getProfileID(), new AsyncCallback() { @Override public void onFailure(Throwable caught) { try { hpGetLink.setVisible(false); modal.remove(hpGetLink); } catch (Exception e) { // TODO: handle exception } Alert alert = new Alert(caught.getMessage(), AlertType.ERROR); alert.setClose(false); hpGetLink.add(alert); // newBrowserWindow.close(); } @Override public void onSuccess(GeoportalItemReferences result) { try { hpGetLink.setVisible(false); modal.remove(hpGetLink); } catch (Exception e) { // TODO: handle exception } String theURL = result.getRestrictedLink().getShortURL() != null ? result.getRestrictedLink().getShortURL() : result.getRestrictedLink().getCompleteURL(); // newBrowserWindow.setUrl(theURL); Anchor anchor = new Anchor(theURL); anchor.setHref(theURL); anchor.setTarget("_blank"); anchor.setTitle( "Show on Map the project with id: " + resultDocumentDV.getId()); com.github.gwtbootstrap.client.ui.Label label = new com.github.gwtbootstrap.client.ui.Label( "Go to Map by clicking the link"); label.setType(LabelType.SUCCESS); modal.add(label); modal.add(new HTML("
")); modal.add(anchor); } }); modal.show(); break; } case VIEW_REPORT: { final Modal modal2 = new Modal(true, true); modal2.setTitle( "Publication Report for Project ID: " + resultDocumentDV.getId() + ""); 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() { @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( "Update Project with id: " + resultDocumentDV.getId() + ""); // modal3.setWidth(950); // modal3.setHeight("700px"); modal3.setCloseVisible(true); ((Element) modal3.getElement().getChildNodes().getItem(1)).addClassName("modal-body-edit"); int height = Window.getClientHeight() * 70 / 100; int width = Window.getClientWidth() * 70 / 100; modal3.setWidth(width); modal3.setHeight(height + "px"); // #24569 boolean isNotInDRAFT = false; if (resultDocumentDV.getLifecycleInfo() != null) { String phase = resultDocumentDV.getLifecycleInfo().getPhase(); // IF the project is not in DRAFT phase, showing an alert and no Update Mode // will // be activated if (phase != null && phase.compareToIgnoreCase(WORKFLOW_PHASE.DRAFT.getLabel()) != 0) { Alert alert = new Alert( ConstantsGeoPortalDataEntryApp.ALERT_MESSAGE_PROJECT_NOT_EDITABLE); alert.setType(AlertType.WARNING); alert.setClose(false); modal3.add(alert); isNotInDRAFT = true; } } UpdateRecord ur = new UpdateRecord(appManagerBus, resultDocumentDV.getProfileID(), resultDocumentDV.getId(), width, height); if (isNotInDRAFT) { ur.noUpdateMode(); } modal3.add(ur); modal3.show(); break; } case CREATE_RELATION: { // #24571 boolean isNotInDRAFT = false; if (resultDocumentDV.getLifecycleInfo() != null) { String phase = resultDocumentDV.getLifecycleInfo().getPhase(); // IF the project is not in DRAFT, showing an alert and the no Update Mode will // be activated if (phase != null && phase.compareToIgnoreCase(WORKFLOW_PHASE.DRAFT.getLabel()) != 0) { String msg = ConstantsGeoPortalDataEntryApp.ALERT_MESSAGE_CREATE_RELATION_FORBIDDEN; ModalWindow modalW = new ModalWindow(new Image(Images.ICONS.accessDenied()), "Forbidden: " + action, msg, AlertType.WARNING); modalW.show(); isNotInDRAFT = true; } } // Allowing the Create Relation only in DRAFT phase if (!isNotInDRAFT) { mainTabPanel.showCreateRelationPanel(true, resultDocumentDV); } break; } case VIEW_RELATIONSHIPS: { GWT.log("VIEW_RELATIONSHIPS fired"); mainTabPanel.showViewProjectRelationsPanel(true, resultDocumentDV); break; } // It is the show document case VIEW_PROJECT_AS_DOCUMENT: { GWT.log("VIEW VIEW_PROJECT_AS_DOCUMENT fired"); final Modal modal = new Modal(true, true); modal.setCloseVisible(true); final int height = Window.getClientHeight() * 70 / 100; int width = Window.getClientWidth() * 70 / 100; modal.setMaxHeigth("none"); modal.setWidth(width); modal.setHeight(height + "px"); modal.setTitle( "View Document for Project ID: " + resultDocumentDV.getId() + ""); final HorizontalPanel hp = new HorizontalPanel(); final LoaderIcon lc = new LoaderIcon("Loading Project... please wait"); hp.add(lc); modal.add(hp); GeoportalDataEntryServiceAsync.Util.getInstance().getProjectView( resultDocumentDV.getProfileID(), resultDocumentDV.getProjectID(), new AsyncCallback() { @Override public void onFailure(Throwable caught) { hp.clear(); modal.setTitle("Error :-("); Alert alert = new Alert( "Sorry, I cannot show 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(ProjectView result) { hp.clear(); GeoportalDataViewerWidget wid = new GeoportalDataViewerWidget(); ProjectViewer viewer = wid.getProjectViewer(result); viewer.setTocContentVisible(true); viewer.setHeight((height - 80) + "px"); modal.add(viewer); } }); modal.show(); break; } case VIEW_PROJECT_AS_JSON: { GWT.log("VIEW VIEW_PROJECT_AS_JSON fired"); final Modal modal = new Modal(true, true); modal.setCloseVisible(true); final int height = Window.getClientHeight() * 70 / 100; int width = Window.getClientWidth() * 70 / 100; modal.setMaxHeigth("none"); modal.setWidth(width); modal.setHeight(height + "px"); modal.setTitle( "View as JSON for Project ID: " + resultDocumentDV.getId() + ""); EditModeRecord editMode = new EditModeRecord(appManagerBus, resultDocumentDV, height); modal.add(editMode); modal.show(); break; } case DELETE_PROJECT: { String htmlMsg = "Going to delete the project with:"; htmlMsg += "
    "; htmlMsg += "
  • id: " + resultDocumentDV.getId() + "
  • "; htmlMsg += "
  • profile: " + resultDocumentDV.getProfileID() + "
  • "; htmlMsg += "
  • " + resultDocumentDV.getFirstEntryOfMap().getKey() + ": " + resultDocumentDV.getFirstEntryOfMap().getValue() + "
  • "; htmlMsg += "
"; htmlMsg += "
"; 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() { @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, appManagerBus); // 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() { @Override public void onFailure(Throwable caught) { // silent } @Override public void onSuccess(Integer result) { GWT.log("Purged " + result + " file/s uploaded"); } }); } /** * 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 * @param appManagerBus the app manager bus * @return the geo na form card model */ public static GeoNaFormCardModel buildNewFormCardModelFromProfile( GcubeProfileDV gcubeProfile, int order, T metaDataProfileBean, OPERATION operation, HandlerManager appManagerBus) { // 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); List fileset = null; if (metaDataProfileBean instanceof MetaDataProfileBeanExt) { MetaDataProfileBeanExt metaDataProfileBeanExt = (MetaDataProfileBeanExt) metaDataProfileBean; fileset = metaDataProfileBeanExt.getListFileset(); } GeoNaFormCardModel geoNaFormCardModel = new GeoNaFormCardModel(metaDataProfileBean, null, cct, gcubeProfile); // In case of UPDATE operation, the fields of kind File will be not mandatory. if (operation != null && operation.equals(OPERATION.UPDATE)) { List fields = geoNaFormCardModel.getMetadataProfileBean().getMetadataFields(); for (MetadataFieldWrapper metadataFieldWrapper : fields) { if (metadataFieldWrapper.getMandatory() && metadataFieldWrapper.getType().equals(DataTypeWrapper.File)) { metadataFieldWrapper.setMandatory(false); } } } CreateMetadataForm baseForm = null; if (fileset == null) { GWT.log("Instancing CreateMetadataForm without files"); baseForm = new CreateMetadataForm(Arrays.asList(geoNaFormCardModel.getMetadataProfileBean()), appManagerBus, operation); } else { GWT.log("Instancing CreateMetadataForm with files"); List files = toListFileUploadedRemote(fileset); GWT.log("files are: " + files); baseForm = new CreateMetadataForm(Arrays.asList(geoNaFormCardModel.getMetadataProfileBean()), appManagerBus, operation, files); } geoNaFormCardModel.setMetadataForm(baseForm); return geoNaFormCardModel; } public static List toListFileUploadedRemote(List fileset) { if (fileset == null || fileset.size() == 0) return null; List fileUploaded = new ArrayList(); for (FilesetDV filesetDV : fileset) { GWT.log("filesetDV fieldName: " + filesetDV.getFilesetFieldName() + " profile: " + filesetDV.getGcubeProfileFieldName()); for (PayloadDV payload : filesetDV.getListPayload()) { FileUploadedRemote fu = new FileUploadedRemote(); fu.setFileName(payload.getName()); fu.setUrl(payload.getLink()); fu.setMimeType(payload.getMimetype()); // adding FilePath according to spefic file registred in the UCD FilePath filePath = new FilePath(filesetDV.getGcubeProfileFieldName(), filesetDV.getFilesetFieldName()); fu.setFilePath(filePath); fileUploaded.add(fu); } } return fileUploaded; } }