Exemplo n.º 1
0
  @Override
  public void inject(HashMap<String, String> params) throws Exception {
    int number = getIntParam(params, NUMBER);
    String prefix = getStringValueParam(params, PREFIX, DEFAULT_GROUP_PREFIX);
    init(prefix, null, null, null, null);

    for (int i = 1; i <= number; i++) {
      //
      String groupName = groupName();
      Group group = groupHandler.createGroupInstance();
      group.setGroupName(groupName);
      group.setLabel(groupName);
      group.setDescription(groupName);
      try {
        // Save group
        groupHandler.addChild(null, group, true);
        //
        ++groupNumber;

      } catch (Exception e) {
        getLog().error(e);
      }

      //
      getLog().info("Group '" + groupName + "' generated");
    }
  }
Exemplo n.º 2
0
    public void execute(Event<UISpaceInfo> event) throws Exception {
      UISpaceInfo uiSpaceInfo = event.getSource();
      SpaceService spaceService = uiSpaceInfo.getSpaceService();
      UIPortal uiPortal = Util.getUIPortal();

      String id = uiSpaceInfo.getUIStringInput(SPACE_ID).getValue();
      String name = uiSpaceInfo.getUIStringInput(SPACE_DISPLAY_NAME).getValue();
      Space space = spaceService.getSpaceById(id);
      String oldDisplayName = space.getDisplayName();
      String existingDescription = space.getDescription();

      if (space == null) {
        // redirect to spaces
        event.getRequestContext().sendRedirect(Utils.getURI("all-spaces"));
        return;
      }

      UserNode selectedNode = uiPortal.getSelectedUserNode();
      UserNode renamedNode = null;

      boolean nameChanged = (!space.getDisplayName().equals(name));
      UIPortletApplication uiApp = uiSpaceInfo.getAncestorOfType(UIPortletApplication.class);
      if (nameChanged) {

        String cleanedString = SpaceUtils.cleanString(name);
        if (spaceService.getSpaceByUrl(cleanedString) != null) {
          // reset to origin values
          uiSpaceInfo.getUIStringInput(SPACE_DISPLAY_NAME).setValue(oldDisplayName);
          uiSpaceInfo.getUIFormTextAreaInput(SPACE_DESCRIPTION).setValue(existingDescription);

          //
          uiApp.addMessage(
              new ApplicationMessage(
                  "UISpaceInfo.msg.current-name-exist", null, ApplicationMessage.INFO));
          return;
        }

        renamedNode = uiSpaceInfo.renamePageNode(name, space);
        if (renamedNode == null) {
          return;
        }
      }
      uiSpaceInfo.invokeSetBindingBean(space);

      String spaceDescription = space.getDescription();
      if (spaceDescription == null || spaceDescription.trim().length() == 0) {
        ResourceBundle resourceBundle = event.getRequestContext().getApplicationResourceBundle();
        space.setDescription(resourceBundle.getString(MSG_DEFAULT_SPACE_DESCRIPTION));
        uiSpaceInfo.getUIFormTextAreaInput(SPACE_DESCRIPTION).setValue(space.getDescription());
      } else {
        space.setDescription(StringEscapeUtils.escapeHtml(space.getDescription()));
        if (!existingDescription.equals(spaceDescription)) {
          space.setField(UpdatedField.DESCRIPTION);
        }
      }

      space.setEditor(Utils.getViewerRemoteId());

      if (nameChanged) {
        space.setDisplayName(oldDisplayName);
        String remoteId = Utils.getViewerRemoteId();
        spaceService.renameSpace(remoteId, space, name);

        // rename group label
        OrganizationService organizationService =
            (OrganizationService)
                ExoContainerContext.getCurrentContainer()
                    .getComponentInstanceOfType(OrganizationService.class);
        GroupHandler groupHandler = organizationService.getGroupHandler();
        Group group = groupHandler.findGroupById(space.getGroupId());
        group.setLabel(space.getDisplayName());
        groupHandler.saveGroup(group, true);
      } else {
        spaceService.updateSpace(space);
      }

      if (nameChanged) {
        if (renamedNode != null) {
          // update space navigation (change name).
          selectedNode = renamedNode;
          PortalRequestContext prContext = Util.getPortalRequestContext();
          prContext.createURL(NodeURL.TYPE).setNode(selectedNode);
          event.getRequestContext().sendRedirect(Utils.getSpaceURL(selectedNode));
          return;
        }
      } else {
        uiApp.addMessage(
            new ApplicationMessage(
                "UISpaceInfo.msg.update-success", null, ApplicationMessage.INFO));
      }
    }