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.GeoNaItemRef; import org.gcube.application.geoportalcommon.shared.SearchingFilter; import org.gcube.application.geoportalcommon.shared.config.ACTION_ON_ITEM; import org.gcube.application.geoportalcommon.shared.config.GcubeUserRole; import org.gcube.application.geoportalcommon.shared.config.RoleRights; import org.gcube.application.geoportalcommon.shared.config.RoleRights.OPERATION_TYPE; import org.gcube.application.geoportalcommon.shared.geoportal.ConfigurationDV; import org.gcube.application.geoportalcommon.shared.geoportal.DocumentDV; 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.ucd.HandlerDeclarationDV; import org.gcube.application.geoportalcommon.shared.geoportal.ucd.UseCaseDescriptorDV; import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV; 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.ActionOnItemEvent; import org.gcube.portlets.user.geoportaldataentry.client.events.ActionOnItemEventHandler; import org.gcube.portlets.user.geoportaldataentry.client.events.ActionPerformedOnItemEvent; import org.gcube.portlets.user.geoportaldataentry.client.events.ActionPerformedOnItemEventHandler; 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.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.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.card.GeoNaFormCardModel; import org.gcube.portlets.user.geoportaldataentry.client.ui.form.GeonaDataEntryMainForm; 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.DialogConfirm; import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.DialogInform; import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.HTMLUtil; import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.HTMLUtil.HTML_TAG; import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.LoaderIcon; import org.gcube.portlets.user.geoportaldataentry.shared.CommitReport; import org.gcube.portlets.user.geoportaldataentry.shared.GNADataEntryExtConfigProfile; import org.gcube.portlets.user.geoportaldataentry.shared.GeoNaFormDataObject; import org.gcube.portlets.user.geoportaldataentry.shared.GeonaISConfig; 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.Modal; import com.github.gwtbootstrap.client.ui.constants.AlertType; 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.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.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 { /** * The message displayed to the user when the server cannot be reached or * returns an error. */ private static final String SERVER_ERROR = "An error occurred while " + "attempting to contact the server. Please check your network " + "connection and try again."; public static final String DIV_PORTLET_ID = "geoportal-data-entry"; 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 Collection orderedCards = new // ArrayList(); private GeonaMainTabPanel mainTabPanel; private LinkedHashMap> savedMap = new LinkedHashMap>(); private boolean projectSavedWithSuccess; private GeonaRecordsPaginatedView grpw = null; private UserRights myRights = null; private LoaderIcon loaderApplication = new LoaderIcon("Loading Application facilities... please wait"); private LoaderIcon loaderConfigurations = new LoaderIcon("Loading Configurations... please wait"); private GeonaISConfig geonaISConfig; private int numberOfCards = 0; private int expectedCards = 0; private synchronized void incrementNumberOfCards() { numberOfCards++; } private synchronized int getNumberOfCards() { return numberOfCards; } // private List listUCDescriptors; 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(); RootPanel.get(DIV_PORTLET_ID).add(loaderApplication); mainTabPanel = new GeonaMainTabPanel(appManagerBus); geoNaMainForm = new GeonaDataEntryMainForm(appManagerBus); mainTabPanel.addFormPanel(geoNaMainForm); RootPanel.get(DIV_PORTLET_ID).add(mainTabPanel); GeoportalDataEntryServiceAsync.Util.getInstance().getGeonaInitConfig(new AsyncCallback() { @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 { RootPanel.get(DIV_PORTLET_ID).remove(loaderApplication); } catch (Exception e) { } RootPanel.get(DIV_PORTLET_ID).add(alert); Window.alert(errorMsg); } @Override public void onSuccess(GeonaISConfig result) { geonaISConfig = result; if (result != null && result.getScope() != null) { loadGeoportalConfigs(result.getScope()); } else Window.alert("Sorry, no scope found in the session. Re-login and try again"); } }); GeoportalDataEntryServiceAsync.Util.getInstance() .readDataViewerConfig(new AsyncCallback() { @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 { RootPanel.get(DIV_PORTLET_ID).remove(loaderApplication); } catch (Exception e) { } RootPanel.get(DIV_PORTLET_ID).add(alert); Window.alert(errorMsg); } @Override public void onSuccess(GNADataEntryExtConfigProfile gNADataEntryConfig) { GWT.log(GNADataEntryExtConfigProfile.class.getSimpleName() + " loaded: " + gNADataEntryConfig); // PERMISSIONS myRights = gNADataEntryConfig.getUserRights(); initGUI(); GcubeUserRole userRole = myRights.getRoleRights().getUserRole(); String msg = "Logged in as "; if (userRole != null && userRole.getName() != null) { msg += userRole.getName().substring(userRole.getName().indexOf("-") + 1, userRole.getName().length()); } else msg += "Member"; mainTabPanel.setRoleLabel(msg); RoleRights roleRights = myRights.getRoleRights(); boolean canCreateNewItem = roleRights.getListPermessions().keySet() .contains(ACTION_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(); return; } try { RootPanel.get(DIV_PORTLET_ID).remove(loaderApplication); } catch (Exception e) { } } }); } 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 { RootPanel.get(DIV_PORTLET_ID).insert(loaderConfigurations, 0); } catch (Exception e) { } GeoportalDataEntryServiceAsync.Util.getInstance().getListUseCaseDescriptors( ConstantsGeoPortalDataEntryApp.HANDLERS_IDS, new AsyncCallback>() { @Override public void onFailure(Throwable caught) { try { RootPanel.get(DIV_PORTLET_ID).remove(loaderConfigurations); } catch (Exception e) { } GWT.log("caught: " + caught); Window.alert(caught.toString()); } @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); try { RootPanel.get(DIV_PORTLET_ID).remove(loaderConfigurations); } catch (Exception e) { } } }); } private void initDataEntryAppForListUseCaseDescriptors(List listUCDescriptors) { GWT.log("initDataEntryAppForListUseCaseDescriptors with size: " + listUCDescriptors.size()); ConstantsGeoPortalDataEntryApp.printUCDs(listUCDescriptors); mainTabPanel.initMainAccordingToListUseCaseDescriptors(listUCDescriptors); for (UseCaseDescriptorDV ucdDV : listUCDescriptors) { List> listConfigurations = geoportalCaches .getHandlerConfigurationsForProfileId(ucdDV.getProfileID()); if (listConfigurations == null) { listConfigurations = new ArrayList>(); } for (HandlerDeclarationDV handler : ucdDV.getHandlers()) { ConfigurationDV config = handler.getConfiguration(); listConfigurations.add(config); } geoportalCaches.putHandlerConfigurationsForProfileId(ucdDV.getProfileID(), listConfigurations); } geoportalCaches.printCacheHandlerConfigurations(); } /** * Update window size */ public void updateSize() { try { RootPanel workspace = RootPanel.get(DIV_PORTLET_ID); 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); } catch (Exception e) { // TODO: handle exception } // appController.getMainPanel().setHeight(rootHeight); // appController.getMainPanel().setWidth(rootWidth); } private void createNewDataEntyFor(String profileID, HandlerDeclarationDV handlerDeclarationDV, List listGPs) { dataEntryProjectCreated = true; mainTabPanel.setLoaderVisible("Loading...", true); // orderedCards.clear(); resetUI(); List cardsPerIT = geoportalCaches .getGcubeProfilePerItemType(handlerDeclarationDV.getItemType()); mainTabPanel.setPageHeader(handlerDeclarationDV); 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( geonaISConfig.getScope(), gcubeProfile.getGcubeSecondaryType(), gcubeProfile.getGcubeName(), new AsyncCallback>() { @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); treemapOrderedGNAProfiles.put(order, geonaForm); } if (getNumberOfCards() >= expectedCards) { mainTabPanel.setLoaderVisible("Loading...", false); // ordered values Collection gnaCardsModels = treemapOrderedGNAProfiles.values(); GWT.log("TreeMap values: " + gnaCardsModels); geoportalCaches.putGcubeProfilePerItemType(handlerDeclarationDV.getItemType(), new ArrayList(gnaCardsModels)); // orderedCards.addAll(new ArrayList(gnaCardsModels)); buildNewCards(profileID, handlerDeclarationDV.getItemType(), new ArrayList(gnaCardsModels)); } } @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 orderedCards) { projectSavedWithSuccess = false; // resetting state of saving mainTabPanel.setLoaderVisible("Loading...", true); geoNaMainForm.setVisibleFormActions(true); resetUI(); 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); GeoportalDataEntryServiceAsync.Util.getInstance().saveGeonaDataForms( saveGeonaDataFormsEvent.getProfileID(), saveGeonaDataFormsEvent.getTreeNode(), 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); LifecycleInformationDV lcDV = result.getLifecycleInformation(); HTML htmlPhase = new HTML(); htmlPhase.setHTML("Current phase: " + lcDV.getPhase() + ""); HTML htmlStep = new HTML(); htmlStep.setHTML("Invoked Step: " + lcDV.getLastInvokedStep() + ""); HTML lastOperationStatus = new HTML(); switch (lcDV.getLastOperationStatus()) { case OK: { String success = HTMLUtil.getHTMLElement(HTML_TAG.span, 14, "32CD32", null, "SUCCESS"); String msg = lcDV.getLastInvokedStep() + "terminated with: " + success; lastOperationStatus.setHTML(msg); projectSavedWithSuccess = true; geoNaMainForm.showAlertOnSaveAction(msg, AlertType.SUCCESS, true); purgeFileUploaded(); break; } case WARNING: { String warning = HTMLUtil.getHTMLElement(HTML_TAG.span, 14, "FF8000", null, "WARNING"); String msg = lcDV.getLastInvokedStep() + "terminated with: " + warning; lastOperationStatus.setHTML(msg); geoNaMainForm.enableButtonSave(true); break; } case ERROR: { String error = HTMLUtil.getHTMLElement(HTML_TAG.span, 14, "FF0000", "bold", "ERROR"); String msg = lcDV.getLastInvokedStep() + "terminated with: " + error; lastOperationStatus.setHTML(msg); geoNaMainForm.enableButtonSave(true); break; } default: break; } modalContainerPanel.add(htmlPhase); modalContainerPanel.add(htmlStep); modalContainerPanel.add(lastOperationStatus); if (result.getProjectID() != null) { modalContainerPanel.add(new HTML("Record id: " + (result.getProjectID()))); try { savedMap.put(result.getProjectID(), saveGeonaDataFormsEvent.getTreeNode()); } catch (Exception e) { // TODO: handle exception } final HorizontalPanel hpGetLink = new HorizontalPanel(); final LoaderIcon lc = new LoaderIcon("Get link..."); hpGetLink.add(lc); modalContainerPanel.add(hpGetLink); GeoportalDataEntryServiceAsync.Util.getInstance().getLinksFor( result.getProjectID(), saveGeonaDataFormsEvent.getProfileID(), new AsyncCallback() { @Override public void onFailure(Throwable caught) { hpGetLink.clear(); } @Override public void onSuccess(GeoNaItemRef result) { hpGetLink.clear(); String theURL = result.getRestrictedLink().getShortURL() != null ? result.getRestrictedLink().getShortURL() : result.getRestrictedLink().getCompleteURL(); String htmlLink = "
Go to project: " + theURL + "
"; HTML html = new HTML(htmlLink); hpGetLink.add(html); // modal.add(html); } }); } // geoNaMainForm.enableButtonSave(true); // resetUI(); if (lcDV.getAsJSONString() != null) { modalContainerPanel .add(new ReportTemplateToHTML(lcDV.getAsJSONString(), false)); } } }); 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) { DialogConfirm confirm = new DialogConfirm(null, "Creating New Project...", "The current project (is not saved) and will be lost. Confirm?"); confirm.getYesButton().addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { confirm.hide(); // TODO QUA createNewDataEntyFor(newProjectEvent.getProfileID(), newProjectEvent.getHandler(), newProjectEvent.getListGcubeProfiles()); // buildNewCards(orderedCards, OPERATION.NEW); } }); confirm.center(); } else if (projectSavedWithSuccess) { // means the project has been saved // TODO HERE createNewDataEntyFor(newProjectEvent.getProfileID(), newProjectEvent.getHandler(), newProjectEvent.getListGcubeProfiles()); // buildNewCards(orderedCards, OPERATION.NEW); } else { DialogConfirm confirm = new DialogConfirm(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(); // TODO HERE // List cardsPerIT = // mapGcubeProfilePerItemType.get(newProjectEvent.getHandler().getItemType()); createNewDataEntyFor(newProjectEvent.getProfileID(), newProjectEvent.getHandler(), newProjectEvent.getListGcubeProfiles()); } }); confirm.center(); } } }); 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()); if (searchingFilter == null || getListOfRecordsEvent.isOnApplicationInit() || getListOfRecordsEvent.isReloadFilteringParameters()) { mainTabPanel.setFilteringParameters(seachingFilterParameters); searchingFilter = mainTabPanel.getCurrentSearchingFilter(); } //TODO MUST MANAGE getListOfRecordsEvent.isReloadFilteringParameters() searchingFilter.setProjection(seachingFilterParameters.getProjection()); List displayFields = seachingFilterParameters.getDisplayFields(); String profileID = getListOfRecordsEvent.getProfileID(); if (profileID == null) { new DialogInform(null, "Error", "No user case descriptor selected").center(); return; } grpw = new GeonaRecordsPaginatedView(appManagerBus, profileID, displayFields, searchingFilter); mainTabPanel.showListOfConcessioniView(grpw); } }); appManagerBus.addHandler(ActionPerformedOnItemEvent.TYPE, new ActionPerformedOnItemEventHandler() { @Override public void onDoActionPerformedFired( ActionPerformedOnItemEvent 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, null, grpw.getProfileID(), mainTabPanel.getCurrentSearchingFilter(), false)); break; } } } } }); appManagerBus.addHandler(ActionOnItemEvent.TYPE, new ActionOnItemEventHandler() { @Override public void onDoActionFired(ActionOnItemEvent showItemEvent) { GWT.log("Fired event: " + showItemEvent); if (showItemEvent != null) { ACTION_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 table"); di.center(); return; } T item = items.get(0); if (item == null) return; if (item instanceof DocumentDV) { Window.alert("ACTION MUST BE REVISITED"); // final DocumentDV concessione = (DocumentDV) item; // GWT.log("onDoActionFired item: " + concessione); // // // 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; // 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(); // boolean allowedWriteActionOnItem = checkAccessToOperationType(userRole, operationType, // concessione); // if (!allowedWriteActionOnItem) { // String title = "Forbidden: missing write access"; // String msg = "You do not have write access to item: " + concessione.getNome(); // if (!userRole.isWriteOwn()) { // msg = "You do not have write access to item: " + concessione.getNome(); // } else if (!userRole.isWriteAny()) { // title = "Forbidden: missing ownership"; // msg = "You are not the creator of: " + concessione.getNome() // + ". 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(concessione.getItemId(), // showItemEvent.getProfileID(), new AsyncCallback() { // @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(GeoNaItemRef 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( // "Report: " // + concessione.getNome() + ""); // modal2.setWidth(800); // modal2.setCloseVisible(true); // if (concessione.getValidationReport() == null) { // modal2.add(new HTML("No report available for: " + concessione.getNome())); // } else { // BuildValidationReport buildValidationReport = new BuildValidationReport( // concessione.getValidationReport()); // modal2.add(buildValidationReport); // } // modal2.show(); // // break; // // case EDIT_PROJECT: // final Modal modal3 = new Modal(true, true); // modal3.setTitle( // "Edit: " // + concessione.getNome() + ""); // modal3.setWidth(950); // modal3.setHeight("700px"); // modal3.setCloseVisible(true); // ((Element) modal3.getElement().getChildNodes().getItem(1)) // .addClassName("modal-body-custom"); // EditModeRecord emr = new EditModeRecord(appManagerBus, concessione, // RECORD_TYPE.CONCESSIONE); // modal3.add(emr); // modal3.show(); // break; // //// case UPDATED_PROJECT: //// appManagerBus.fireEvent(new GetListOfRecordsEvent(RECORD_TYPE.CONCESSIONE, //// mainTabPanel.getCurrentSortFilter())); //// break; // case DELETE_PROJECT: // // String htmlMsg = "Going to delete the project with:"; // htmlMsg += "
    "; // htmlMsg += "
  • id: " + concessione.getItemId() + "
  • "; // htmlMsg += "
  • name: " + concessione.getNome() + "
  • "; // htmlMsg += "
"; // htmlMsg += "
"; // htmlMsg += "This operation cannot be undone. Would you like to proceed?"; // // final DialogConfirm dialog = new DialogConfirm(null, "Delete Confirm?", htmlMsg); // dialog.center(); // // 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().deleteRecord( // concessione.getItemId(), RECORD_TYPE.CONCESSIONE, // new AsyncCallback() { // // @Override // public void onFailure(Throwable caught) { // hp.clear(); // Alert alert = new Alert(caught.getMessage(), AlertType.ERROR); // alert.setClose(false); // hp.add(alert); // // } // // @Override // public void onSuccess(Boolean result) { // if (result) { // hp.clear(); // Alert alert = new Alert("Project '" + concessione.getNome() // + "' deleted correclty", AlertType.INFO); // alert.setClose(false); // hp.add(alert); // // appManagerBus.fireEvent( // new GetListOfRecordsEvent(null, grpw.getProfileID(), // mainTabPanel.getCurrentSortFilter(), false)); // } // // } // }); // modal.show(); // } // }); // // 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, ConcessioneDV concessione) { 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 = concessione.getCreationUser(); if (ownerUser == null || ownerUser.isEmpty()) { writeOwnPassed = false; } else if (ownerUser.compareTo(myRights.getMyUsername()) == 0) { // if my username is equal the owner of the concessione 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"); } }); } }