private Application cloneApplication(Application app) { Application newApp = new Application(); newApp.setApplicationName(app.getApplicationName()); newApp.setDisplayName(app.getDisplayName()); newApp.setType(app.getType()); newApp.setDescription(app.getDescription()); newApp.setAccessPermissions(app.getAccessPermissions()); newApp.setContentId(app.getContentId()); return newApp; }
/** * Creates the file element. * * @param document the document * @param applicationCategory the application category * @return the element * @throws Exception the exception */ private Element createFileElement( Document document, ApplicationCategory applicationCategory, String host) throws Exception { Element files = document.createElement("Files"); List<Application> listApplication = applicationRegistryService.getApplications(applicationCategory, ApplicationType.GADGET); for (Application application : listApplication) { Gadget gadget = gadgetRegistryService.getGadget(application.getApplicationName()); Element file = document.createElement("File"); file.setAttribute("name", gadget.getName()); file.setAttribute("fileType", "nt_unstructured"); file.setAttribute("size", "0"); file.setAttribute("thumbnail", gadget.getThumbnail()); file.setAttribute("description", gadget.getDescription()); String fullurl = ""; if (gadget.isLocal()) { fullurl = "/" + PortalContainer.getCurrentRestContextName() + "/" + gadget.getUrl(); } else { fullurl = gadget.getUrl(); } file.setAttribute("url", fullurl); String data = "{\"context\":{\"country\":\"US\",\"language\":\"en\"},\"gadgets\":[{\"moduleId\":0,\"url\":\"" + fullurl + "\",\"prefs\":[]}]}"; URL url = new URL(host + "/eXoGadgetServer/gadgets/metadata"); URLConnection conn = url.openConnection(); conn.setDoOutput(true); OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream()); wr.write(data); wr.flush(); String strMetadata = IOUtils.toString(conn.getInputStream(), "UTF-8"); wr.close(); JSONObject metadata = new JSONObject(strMetadata.toString()); ConversationState conversationState = ConversationState.getCurrent(); String userId = conversationState.getIdentity().getUserId(); String token = createToken(gadget.getUrl(), userId, userId, new Random().nextLong(), "default"); JSONObject obj = metadata.getJSONArray("gadgets").getJSONObject(0); obj.put("secureToken", token); file.setAttribute("metadata", metadata.toString()); files.appendChild(file); } return files; }
/** * Add Application to UiPage * * @param event * @throws Exception */ private static void addApplicationToPage(Event<UIAddNewApplication> event, boolean atStartup) throws Exception { UIPortalApplication uiPortalApp = Util.getUIPortalApplication(); UIPortal uiPortal = uiPortalApp.getShowedUIPortal(); PortalRequestContext pcontext = Util.getPortalRequestContext(); UIDesktopPage uiDesktopPage = uiPortal.findFirstComponentOfType(UIDesktopPage.class); if (uiDesktopPage == null) { pcontext.addUIComponentToUpdateByAjax( uiPortalApp.getChildById(UIPortalApplication.UI_WORKING_WS_ID)); UIMaskWorkspace maskWorkspace = uiPortalApp.getChildById(UIPortalApplication.UI_MASK_WS_ID); maskWorkspace.createEvent("Close", Event.Phase.DECODE, event.getRequestContext()).broadcast(); pcontext.setFullRender(true); return; } String applicationId = event.getRequestContext().getRequestParameter(UIComponent.OBJECTID); Application application = event.getSource().getApplication(applicationId); ApplicationType appType = application.getType(); UIPortlet uiPortlet = uiDesktopPage.createUIComponent(UIPortlet.class, null, null); ApplicationState appState; // TODO: Check if there 's already a portlet window of this portlet. A CloneApplicationState // should be created in such case appState = new TransientApplicationState<Object>(application.getContentId()); uiPortlet.setState(new PortletState(appState, appType)); uiPortlet.setPortletInPortal(false); if (atStartup) { uiPortlet.getProperties().setProperty("appStatus", "HIDE"); } String portletName = application.getApplicationName(); String displayName = application.getDisplayName(); if (displayName != null) { uiPortlet.setTitle(displayName); } else if (portletName != null) { uiPortlet.setTitle(portletName); } uiPortlet.setDescription(application.getDescription()); List<String> accessPers = application.getAccessPermissions(); String[] accessPermissions = accessPers.toArray(new String[accessPers.size()]); uiPortlet.setAccessPermissions(accessPermissions); // Add portlet to page uiDesktopPage.addChild(uiPortlet); if (uiDesktopPage.isModifiable()) { Page page = (Page) PortalDataMapper.buildModelObject(uiDesktopPage); if (page.getChildren() == null) { page.setChildren(new ArrayList<ModelObject>()); } DataStorage dataService = uiPortalApp.getApplicationComponent(DataStorage.class); dataService.save(page); // Rebuild the uiPage to synchronize (storageId, storageName) mapping page = dataService.getPage(page.getPageId()); page.setModifiable(true); uiDesktopPage.getChildren().clear(); PortalDataMapper.toUIPage(uiDesktopPage, page); } UIWorkingWorkspace uiWorkingWS = uiPortalApp.getChildById(UIPortalApplication.UI_WORKING_WS_ID); pcontext.setFullRender(true); pcontext.addUIComponentToUpdateByAjax(uiWorkingWS); }