Beispiel #1
0
  private List<Application> filterApps(ApplicationCategory applicationCategory) {
    List<Application> applications = new ArrayList<Application>();

    if (applicationCategory.getApplications() == null) {
      return applications;
    }
    for (Application app : applicationCategory.getApplications()) {
      if (hasPermission(app.getAccessPermissions())) {
        applications.add(app);
      }
    }
    applicationCategory.setApplications(applications);
    return applications;
  }
Beispiel #2
0
  private Application getApplication(String id) throws Exception {

    List<ApplicationCategory> pCategories = getApplicationCategories();

    for (ApplicationCategory pCategory : pCategories) {
      List<Application> applications = pCategory.getApplications();
      for (Application application : applications) {
        if (application.getId().equals(id)) {
          return application;
        }
      }
    }

    return null;
  }
Beispiel #3
0
  /**
   * 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;
  }
  public void init() throws Exception {
    UIFormTableIteratorInputSet uiTableInputSet =
        createUIComponent(UIFormTableIteratorInputSet.class, null, null);
    uiTableInputSet.setName(getClass().getSimpleName());
    uiTableInputSet.setId(getClass().getSimpleName());
    uiTableInputSet.setColumns(TABLE_COLUMNS);
    addChild(uiTableInputSet);

    UIFormInputSet uiInputSet;
    UICheckBoxInput checkBoxInput;
    UIFormInputInfo uiInfo;

    HTMLEntityEncoder encoder = HTMLEntityEncoder.getInstance();

    //
    ApplicationRegistryService appRegService =
        getApplicationComponent(ApplicationRegistryService.class);
    List<ApplicationCategory> categories = getAllCategories();
    List<UIFormInputSet> uiInputSetList = new ArrayList<UIFormInputSet>();
    for (ApplicationCategory category : categories) {
      uiInputSet = new UIFormInputSet(category.getName());
      boolean defaultValue = false;
      if (application != null) {
        String definitionName = application.getDisplayName().replace(' ', '_');
        defaultValue = appRegService.getApplication(category.getName(), definitionName) != null;
      }
      checkBoxInput = new UICheckBoxInput("category_" + category.getName(), null, defaultValue);
      checkBoxInput.setOnChange("SelectBox");
      uiInfo =
          new UIFormInputInfo("categoryName", null, encoder.encode(category.getDisplayName(true)));
      uiInputSet.addChild(checkBoxInput);
      uiInputSet.addChild(uiInfo);
      uiTableInputSet.addChild(uiInputSet);
      uiInputSetList.add(uiInputSet);
    }

    UIFormPageIterator uiIterator = uiTableInputSet.getChild(UIFormPageIterator.class);
    SerializablePageList<UIFormInputSet> pageList =
        new SerializablePageList<UIFormInputSet>(UIFormInputSet.class, uiInputSetList, 5);
    uiIterator.setPageList(pageList);
  }
 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;
 }
Beispiel #6
0
 public int compare(Application p1, Application p2) {
   return p1.getDisplayName().compareToIgnoreCase(p2.getDisplayName());
 }
Beispiel #7
0
  /**
   * 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);
  }