Example usage for com.liferay.portal.kernel.theme ThemeDisplay getCompanyId

List of usage examples for com.liferay.portal.kernel.theme ThemeDisplay getCompanyId

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.theme ThemeDisplay getCompanyId.

Prototype

public long getCompanyId() 

Source Link

Document

Returns the portal instance ID.

Usage

From source file:com.liferay.site.my.sites.web.internal.portlet.MySitesPortlet.java

License:Open Source License

public void updateGroupUsers(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    long groupId = ParamUtil.getLong(actionRequest, "groupId");

    long[] addUserIds = StringUtil.split(ParamUtil.getString(actionRequest, "addUserIds"), 0L);

    addUserIds = filterAddUserIds(groupId, addUserIds);

    long[] removeUserIds = StringUtil.split(ParamUtil.getString(actionRequest, "removeUserIds"), 0L);

    removeUserIds = filterRemoveUserIds(groupId, removeUserIds);

    ServiceContext serviceContext = ServiceContextFactory.getInstance(actionRequest);

    _userService.addGroupUsers(groupId, addUserIds, serviceContext);
    _userService.unsetGroupUsers(groupId, removeUserIds, serviceContext);

    LiveUsers.joinGroup(themeDisplay.getCompanyId(), groupId, addUserIds);
    LiveUsers.leaveGroup(themeDisplay.getCompanyId(), groupId, removeUserIds);
}

From source file:com.liferay.users.admin.web.internal.portlet.action.EditUserMVCActionCommand.java

License:Open Source License

protected User addUser(ActionRequest actionRequest) throws Exception {
    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    boolean autoScreenName = ParamUtil.getBoolean(actionRequest, "autoScreenName");
    String screenName = ParamUtil.getString(actionRequest, "screenName");
    String emailAddress = ParamUtil.getString(actionRequest, "emailAddress");
    long facebookId = 0;
    String languageId = ParamUtil.getString(actionRequest, "languageId");
    String firstName = ParamUtil.getString(actionRequest, "firstName");
    String middleName = ParamUtil.getString(actionRequest, "middleName");
    String lastName = ParamUtil.getString(actionRequest, "lastName");
    long prefixId = ParamUtil.getInteger(actionRequest, "prefixId");
    long suffixId = ParamUtil.getInteger(actionRequest, "suffixId");
    boolean male = ParamUtil.getBoolean(actionRequest, "male", true);
    int birthdayMonth = ParamUtil.getInteger(actionRequest, "birthdayMonth");
    int birthdayDay = ParamUtil.getInteger(actionRequest, "birthdayDay");
    int birthdayYear = ParamUtil.getInteger(actionRequest, "birthdayYear");
    String comments = ParamUtil.getString(actionRequest, "comments");
    String jobTitle = ParamUtil.getString(actionRequest, "jobTitle");
    long[] organizationIds = UsersAdminUtil.getOrganizationIds(actionRequest);
    boolean sendEmail = true;

    ServiceContext serviceContext = ServiceContextFactory.getInstance(User.class.getName(), actionRequest);

    User user = _userService.addUser(themeDisplay.getCompanyId(), true, null, null, autoScreenName, screenName,
            emailAddress, facebookId, null, LocaleUtil.fromLanguageId(languageId), firstName, middleName,
            lastName, prefixId, suffixId, male, birthdayMonth, birthdayDay, birthdayYear, jobTitle, null,
            organizationIds, null, null, new ArrayList<Address>(), new ArrayList<EmailAddress>(),
            new ArrayList<Phone>(), new ArrayList<Website>(), new ArrayList<AnnouncementsDelivery>(), sendEmail,
            serviceContext);//  ww w .ja va2 s .  co m

    user = _userService.updateUser(user.getUserId(), StringPool.BLANK, StringPool.BLANK, StringPool.BLANK,
            user.getPasswordReset(), null, null, user.getScreenName(), user.getEmailAddress(), facebookId,
            user.getOpenId(), true, null, languageId, user.getTimeZoneId(), user.getGreeting(), comments,
            firstName, middleName, lastName, prefixId, suffixId, male, birthdayMonth, birthdayDay, birthdayYear,
            null, null, null, null, null, jobTitle, null, null, null, null, null, null, null, null, null, null,
            serviceContext);

    return user;
}

From source file:com.liferay.users.admin.web.internal.portlet.action.ExportUsersMVCResourceCommand.java

License:Open Source License

protected List<User> getUsers(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
        throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) resourceRequest.getAttribute(WebKeys.THEME_DISPLAY);

    PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();

    boolean exportAllUsers = PortalPermissionUtil.contains(permissionChecker, ActionKeys.EXPORT_USER);

    if (!exportAllUsers && !PortletPermissionUtil.contains(permissionChecker, UsersAdminPortletKeys.USERS_ADMIN,
            ActionKeys.EXPORT_USER)) {//  w w  w  .  ja  v  a  2  s .  c om

        return Collections.emptyList();
    }

    LiferayPortletResponse liferayPortletResponse = _portal.getLiferayPortletResponse(resourceResponse);

    PortletURL portletURL = liferayPortletResponse.createRenderURL(UsersAdminPortletKeys.USERS_ADMIN);

    UserSearch userSearch = new UserSearch(resourceRequest, portletURL);

    UserSearchTerms searchTerms = (UserSearchTerms) userSearch.getSearchTerms();

    LinkedHashMap<String, Object> params = new LinkedHashMap<>();

    long organizationId = searchTerms.getOrganizationId();

    if (organizationId > 0) {
        params.put("usersOrgs", Long.valueOf(organizationId));
    } else if (!exportAllUsers) {
        User user = themeDisplay.getUser();

        Long[] organizationIds = ArrayUtil.toArray(user.getOrganizationIds(true));

        if (organizationIds.length > 0) {
            params.put("usersOrgs", organizationIds);
        }
    }

    long roleId = searchTerms.getRoleId();

    if (roleId > 0) {
        params.put("usersRoles", Long.valueOf(roleId));
    }

    long userGroupId = searchTerms.getUserGroupId();

    if (userGroupId > 0) {
        params.put("usersUserGroups", Long.valueOf(userGroupId));
    }

    Indexer<?> indexer = IndexerRegistryUtil.nullSafeGetIndexer(User.class);

    if (indexer.isIndexerEnabled() && PropsValues.USERS_SEARCH_WITH_INDEX) {
        params.put("expandoAttributes", searchTerms.getKeywords());
    }

    if (searchTerms.isAdvancedSearch()) {
        return _userLocalService.search(themeDisplay.getCompanyId(), searchTerms.getFirstName(),
                searchTerms.getMiddleName(), searchTerms.getLastName(), searchTerms.getScreenName(),
                searchTerms.getEmailAddress(), searchTerms.getStatus(), params, searchTerms.isAndOperator(),
                QueryUtil.ALL_POS, QueryUtil.ALL_POS, (OrderByComparator<User>) null);
    } else {
        return _userLocalService.search(themeDisplay.getCompanyId(), searchTerms.getKeywords(),
                searchTerms.getStatus(), params, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
                (OrderByComparator<User>) null);
    }
}

From source file:com.liferay.wiki.web.internal.display.context.DefaultWikiListPagesDisplayContext.java

License:Open Source License

@Override
public void populateResultsAndTotal(SearchContainer searchContainer) throws PortalException {

    WikiPage page = (WikiPage) _request.getAttribute(WikiWebKeys.WIKI_PAGE);

    ThemeDisplay themeDisplay = (ThemeDisplay) _request.getAttribute(WebKeys.THEME_DISPLAY);

    String navigation = ParamUtil.getString(_request, "navigation", "all-pages");

    String keywords = ParamUtil.getString(_request, "keywords");

    int total = 0;
    List<WikiPage> results = new ArrayList<>();

    if (Validator.isNotNull(keywords)) {
        Indexer<WikiPage> indexer = IndexerRegistryUtil.getIndexer(WikiPage.class);

        SearchContext searchContext = SearchContextFactory.getInstance(_request);

        searchContext.setAttribute("paginationType", "more");
        searchContext.setEnd(searchContainer.getEnd());
        searchContext.setIncludeAttachments(true);
        searchContext.setIncludeDiscussions(true);
        searchContext.setKeywords(keywords);
        searchContext.setNodeIds(new long[] { _wikiNode.getNodeId() });
        searchContext.setStart(searchContainer.getStart());

        Hits hits = indexer.search(searchContext);

        searchContainer.setTotal(hits.getLength());

        List<SearchResult> searchResults = SearchResultUtil.getSearchResults(hits, themeDisplay.getLocale());

        for (SearchResult searchResult : searchResults) {
            WikiPage wikiPage = WikiPageLocalServiceUtil.getPage(searchResult.getClassPK());

            results.add(wikiPage);/*w ww.j  a  va2 s .  c  om*/
        }
    } else if (navigation.equals("all-pages")) {
        total = WikiPageServiceUtil.getPagesCount(themeDisplay.getScopeGroupId(), _wikiNode.getNodeId(), true,
                themeDisplay.getUserId(), true, WorkflowConstants.STATUS_APPROVED);

        searchContainer.setTotal(total);

        OrderByComparator<WikiPage> obc = WikiPortletUtil
                .getPageOrderByComparator(searchContainer.getOrderByCol(), searchContainer.getOrderByType());

        results = WikiPageServiceUtil.getPages(themeDisplay.getScopeGroupId(), _wikiNode.getNodeId(), true,
                themeDisplay.getUserId(), true, WorkflowConstants.STATUS_APPROVED, searchContainer.getStart(),
                searchContainer.getEnd(), obc);
    } else if (navigation.equals("categorized-pages") || navigation.equals("tagged-pages")) {

        AssetEntryQuery assetEntryQuery = new AssetEntryQuery(WikiPage.class.getName(), searchContainer);

        assetEntryQuery.setEnablePermissions(true);

        total = AssetEntryServiceUtil.getEntriesCount(assetEntryQuery);

        searchContainer.setTotal(total);

        assetEntryQuery.setEnd(searchContainer.getEnd());
        assetEntryQuery.setStart(searchContainer.getStart());

        List<AssetEntry> assetEntries = AssetEntryServiceUtil.getEntries(assetEntryQuery);

        for (AssetEntry assetEntry : assetEntries) {
            WikiPageResource pageResource = WikiPageResourceLocalServiceUtil
                    .getPageResource(assetEntry.getClassPK());

            WikiPage assetPage = WikiPageLocalServiceUtil.getPage(pageResource.getNodeId(),
                    pageResource.getTitle());

            results.add(assetPage);
        }
    } else if (navigation.equals("draft-pages") || navigation.equals("pending-pages")) {

        long draftUserId = themeDisplay.getUserId();

        PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();

        if (permissionChecker.isContentReviewer(themeDisplay.getCompanyId(), themeDisplay.getScopeGroupId())) {

            draftUserId = 0;
        }

        int status = WorkflowConstants.STATUS_DRAFT;

        if (navigation.equals("pending-pages")) {
            status = WorkflowConstants.STATUS_PENDING;
        }

        total = WikiPageServiceUtil.getPagesCount(themeDisplay.getScopeGroupId(), draftUserId,
                _wikiNode.getNodeId(), status);

        searchContainer.setTotal(total);

        results = WikiPageServiceUtil.getPages(themeDisplay.getScopeGroupId(), draftUserId,
                _wikiNode.getNodeId(), status, searchContainer.getStart(), searchContainer.getEnd());
    } else if (navigation.equals("frontpage")) {
        WikiWebComponentProvider wikiWebComponentProvider = WikiWebComponentProvider
                .getWikiWebComponentProvider();

        WikiGroupServiceConfiguration wikiGroupServiceConfiguration = wikiWebComponentProvider
                .getWikiGroupServiceConfiguration();

        WikiPage wikiPage = WikiPageServiceUtil.getPage(themeDisplay.getScopeGroupId(), _wikiNode.getNodeId(),
                wikiGroupServiceConfiguration.frontPageName());

        searchContainer.setTotal(1);

        results.add(wikiPage);
    } else if (navigation.equals("history")) {
        total = WikiPageLocalServiceUtil.getPagesCount(page.getNodeId(), page.getTitle());

        searchContainer.setTotal(total);

        results = WikiPageLocalServiceUtil.getPages(page.getNodeId(), page.getTitle(), QueryUtil.ALL_POS,
                QueryUtil.ALL_POS, new PageVersionComparator());
    } else if (navigation.equals("incoming-links")) {
        List<WikiPage> links = WikiPageLocalServiceUtil.getIncomingLinks(page.getNodeId(), page.getTitle());

        total = links.size();

        searchContainer.setTotal(total);

        results = ListUtil.subList(links, searchContainer.getStart(), searchContainer.getEnd());
    } else if (navigation.equals("orphan-pages")) {
        List<WikiPage> orphans = WikiPageServiceUtil.getOrphans(themeDisplay.getScopeGroupId(),
                _wikiNode.getNodeId());

        total = orphans.size();

        searchContainer.setTotal(total);

        results = ListUtil.subList(orphans, searchContainer.getStart(), searchContainer.getEnd());
    } else if (navigation.equals("outgoing-links")) {
        List<WikiPage> links = WikiPageLocalServiceUtil.getOutgoingLinks(page.getNodeId(), page.getTitle());

        total = links.size();

        searchContainer.setTotal(total);

        results = ListUtil.subList(links, searchContainer.getStart(), searchContainer.getEnd());
    } else if (navigation.equals("recent-changes")) {
        total = WikiPageServiceUtil.getRecentChangesCount(themeDisplay.getScopeGroupId(),
                _wikiNode.getNodeId());

        searchContainer.setTotal(total);

        results = WikiPageServiceUtil.getRecentChanges(themeDisplay.getScopeGroupId(), _wikiNode.getNodeId(),
                searchContainer.getStart(), searchContainer.getEnd());
    }

    searchContainer.setResults(results);
}

From source file:com.liferay.wiki.web.internal.portlet.configuration.icon.NodeSubscriptionPortletConfigurationIcon.java

License:Open Source License

protected boolean isSubscribed(PortletRequest portletRequest, WikiNode node) {

    ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);

    return _subscriptionLocalService.isSubscribed(themeDisplay.getCompanyId(), themeDisplay.getUserId(),
            WikiNode.class.getName(), node.getNodeId());
}

From source file:com.liferay.wiki.web.internal.portlet.configuration.icon.PageSubscriptionPortletConfigurationIcon.java

License:Open Source License

protected boolean isSubscribed(PortletRequest portletRequest, WikiPage page) {

    ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);

    return _subscriptionLocalService.isSubscribed(themeDisplay.getCompanyId(), themeDisplay.getUserId(),
            WikiNode.class.getName(), page.getNodeId());
}

From source file:it.infn.ct.indigo.futuregateway.portlet.action.FGAddAppMVCActionCommand.java

License:Apache License

@Override
protected final void doProcessAction(final ActionRequest actionRequest, final ActionResponse actionResponse)
        throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    String redirect = PortalUtil.escapeRedirect(ParamUtil.getString(actionRequest, "redirect"));
    String name = ParamUtil.getString(actionRequest, "fg-app-name");
    String description = ParamUtil.getString(actionRequest, "fg-app-description");
    boolean enabled = ParamUtil.getBoolean(actionRequest, "fg-app-enabled");
    String outcome = ParamUtil.getString(actionRequest, "fg-app-outcome");
    String[] paramNames = ParamUtil.getStringValues(actionRequest, "fg-app-parameter-name");
    String[] paramValues = ParamUtil.getStringValues(actionRequest, "fg-app-parameter-value");
    String[] paramDescriptions = ParamUtil.getStringValues(actionRequest, "fg-app-parameter-description");
    String[] infras = ParamUtil.getStringValues(actionRequest, "fg-app-infrastructure");
    String[] fileUrls = ParamUtil.getStringValues(actionRequest, "fg-app-file-url");
    UploadPortletRequest upr = PortalUtil.getUploadPortletRequest(actionRequest);
    File[] files = upr.getFiles("fg-app-file-update");
    String[] fileNames = upr.getFileNames("fg-app-file-update");
    Map<String, File> fileToTransfer = new HashMap<>();

    JSONObject jApp = JSONFactoryUtil.createJSONObject();
    jApp.put("name", name);
    jApp.put("description", description);
    jApp.put("enabled", enabled);
    jApp.put("outcome", outcome);

    JSONArray jParams = JSONFactoryUtil.createJSONArray();
    for (int i = 0; i < paramNames.length; i++) {
        if (Validator.isNotNull(paramNames[i])) {
            JSONObject jPar = JSONFactoryUtil.createJSONObject();
            jPar.put("name", paramNames[i]);
            jPar.put("value", paramValues[i]);
            jPar.put("description", paramDescriptions[i]);
            jParams.put(jPar);/*from  w  w w .jav a 2s  .c o  m*/
        }
    }
    jApp.put("parameters", jParams);

    JSONArray jInfras = JSONFactoryUtil.createJSONArray();
    for (String in : infras) {
        jInfras.put(in);
    }
    jApp.put("infrastructures", jInfras);

    if (Validator.isNotNull(fileNames)) {
        JSONArray jFiles = JSONFactoryUtil.createJSONArray();
        for (int i = 0; i < fileNames.length; i++) {
            if (Validator.isNotNull(fileNames[i])) {
                jFiles.put(fileNames[i]);
                fileToTransfer.put(fileNames[i], files[i]);
            } else {
                if (Validator.isNotNull(fileUrls[i])) {
                    jFiles.put(fileUrls[i]);
                }
            }
        }
        jApp.put("files", jFiles);
    }
    try {
        String resourceId = fgServerManager.addResource(themeDisplay.getCompanyId(),
                FGServerConstants.APPLICATION_COLLECTION, jApp.toJSONString(), themeDisplay.getUserId());
        if (!fileToTransfer.isEmpty()) {
            fgServerManager.submitFilesResource(themeDisplay.getCompanyId(),
                    FGServerConstants.APPLICATION_COLLECTION, resourceId, fileToTransfer,
                    themeDisplay.getUserId());
        }
        sendRedirect(actionRequest, actionResponse, redirect);
    } catch (IOException io) {
        log.error(io.getMessage());
        SessionErrors.add(actionRequest, io.getClass(), io);
        try {
            Map<String, String> mapInfras = fgServerManager.getInfrastructures(themeDisplay.getCompanyId(),
                    themeDisplay.getUserId());
            actionRequest.setAttribute(FGServerConstants.INFRASTRUCTURE_COLLECTION, mapInfras);
        } catch (Exception e) {
            if (e instanceof PrincipalException) {
                SessionErrors.add(actionRequest, e.getClass());
                actionResponse.setRenderParameter("mvcPath", "/error.jsp");
            } else {
                throw new PortletException(e);
            }
        }
        actionResponse.setRenderParameter("mvcPath", "/add_application.jsp");
    }
}

From source file:it.infn.ct.indigo.futuregateway.portlet.action.FGAddAppMVCRenderCommand.java

License:Apache License

@Override
public final String render(final RenderRequest renderRequest, final RenderResponse renderResponse)
        throws PortletException {

    ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY);
    try {/*from  w w w.j  a  v  a 2s.co m*/
        Map<String, String> infras = fgServerManager.getInfrastructures(themeDisplay.getCompanyId(),
                themeDisplay.getUserId());
        if (infras.isEmpty()) {
            return "/application-no-infras.jsp";
        }
        renderRequest.setAttribute(FGServerConstants.INFRASTRUCTURE_COLLECTION, infras);
    } catch (Exception e) {
        if (e instanceof IOException) {
            SessionErrors.add(renderRequest, e.getClass());
            return "/error.jsp";
        } else {
            throw new PortletException(e);
        }
    }
    return "/add_application.jsp";
}

From source file:it.infn.ct.indigo.futuregateway.portlet.action.FGAddInfraMVCActionCommand.java

License:Apache License

@Override
protected final void doProcessAction(final ActionRequest actionRequest, final ActionResponse actionResponse)
        throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    String redirect = PortalUtil.escapeRedirect(ParamUtil.getString(actionRequest, "redirect"));
    String name = ParamUtil.getString(actionRequest, "fg-infra-name");
    String description = ParamUtil.getString(actionRequest, "fg-infra-description");
    boolean enabled = ParamUtil.getBoolean(actionRequest, "fg-infra-enabled");
    boolean virtual = ParamUtil.getBoolean(actionRequest, "fg-infra-virtual");
    String[] paramNames = ParamUtil.getStringValues(actionRequest, "fg-infra-parameter-name");
    String[] paramValues = ParamUtil.getStringValues(actionRequest, "fg-infra-parameter-value");
    String[] paramDescriptions = ParamUtil.getStringValues(actionRequest, "fg-infra-parameter-description");

    JSONObject jInfra = JSONFactoryUtil.createJSONObject();
    jInfra.put("name", name);
    jInfra.put("description", description);
    jInfra.put("enabled", enabled);
    jInfra.put("virtual", virtual);
    JSONArray jParams = JSONFactoryUtil.createJSONArray();
    for (int i = 0; i < paramNames.length; i++) {
        JSONObject jPar = JSONFactoryUtil.createJSONObject();
        jPar.put("name", paramNames[i]);
        jPar.put("value", paramValues[i]);
        jPar.put("description", paramDescriptions[i]);
        jParams.put(jPar);//  w w w . ja  va  2  s  . c o  m
    }
    jInfra.put("parameters", jParams);

    try {
        fgServerManager.addResource(themeDisplay.getCompanyId(), FGServerConstants.INFRASTRUCTURE_COLLECTION,
                jInfra.toJSONString(), themeDisplay.getUserId());
        sendRedirect(actionRequest, actionResponse, redirect);
    } catch (IOException io) {
        log.error(io.getMessage());
        SessionErrors.add(actionRequest, io.getClass(), io);
        actionResponse.setRenderParameter("mvcPath", "/add_infrastructure.jsp");
    }
}

From source file:it.infn.ct.indigo.futuregateway.portlet.action.FGEditAppMVCActionCommand.java

License:Apache License

@Override
protected final void doProcessAction(final ActionRequest actionRequest, final ActionResponse actionResponse)
        throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    String redirect = PortalUtil.escapeRedirect(ParamUtil.getString(actionRequest, "redirect"));
    String id = ParamUtil.getString(actionRequest, "fg-app-id");
    String name = ParamUtil.getString(actionRequest, "fg-app-name");
    String description = ParamUtil.getString(actionRequest, "fg-app-description");
    boolean enabled = ParamUtil.getBoolean(actionRequest, "fg-app-enabled");
    String outcome = ParamUtil.getString(actionRequest, "fg-app-outcome");
    String[] paramNames = ParamUtil.getStringValues(actionRequest, "fg-app-parameter-name");
    String[] paramValues = ParamUtil.getStringValues(actionRequest, "fg-app-parameter-value");
    String[] paramDescriptions = ParamUtil.getStringValues(actionRequest, "fg-app-parameter-description");
    String[] infras = ParamUtil.getStringValues(actionRequest, "fg-app-infrastructure");
    String[] fileUrls = ParamUtil.getStringValues(actionRequest, "fg-app-file-url");
    String[] fileOld = ParamUtil.getStringValues(actionRequest, "fg-app-file-old");
    UploadPortletRequest upr = PortalUtil.getUploadPortletRequest(actionRequest);
    InputStream[] files = upr.getFilesAsStream("fg-app-file-update", true);
    String[] fileNames = upr.getFileNames("fg-app-file-update");
    Map<String, InputStream> fileToTransfer = new HashMap<>();

    JSONObject jApp = JSONFactoryUtil.createJSONObject();
    if (!id.isEmpty()) {
        jApp.put("id", id);
    }/*from  www  .ja  va 2 s. co  m*/
    jApp.put("name", name);
    jApp.put("description", description);
    jApp.put("enabled", enabled);
    jApp.put("outcome", outcome);

    JSONArray jParams = JSONFactoryUtil.createJSONArray();
    for (int i = 0; i < paramNames.length; i++) {
        if (Validator.isNotNull(paramNames[i])) {
            JSONObject jPar = JSONFactoryUtil.createJSONObject();
            jPar.put("name", paramNames[i]);
            jPar.put("value", paramValues[i]);
            if (paramDescriptions.length == paramNames.length) {
                jPar.put("description", paramDescriptions[i]);
            }
            jParams.put(jPar);
        }
    }
    jApp.put("parameters", jParams);

    JSONArray jInfras = JSONFactoryUtil.createJSONArray();
    for (String in : infras) {
        jInfras.put(in);
    }
    jApp.put("infrastructures", jInfras);

    if (Validator.isNotNull(fileNames)) {
        JSONArray jFiles = JSONFactoryUtil.createJSONArray();
        for (int i = 0; i < fileNames.length; i++) {
            if (Validator.isNotNull(fileNames[i])) {
                jFiles.put(fileNames[i]);
                fileToTransfer.put(fileNames[i], files[i]);
            } else {
                if (fileUrls.length == fileNames.length && Validator.isNotNull(fileUrls[i])) {
                    jFiles.put(fileUrls[i]);
                } else {
                    if (fileOld[i].compareTo("N/A") != 0) {
                        jFiles.put(fileOld[i]);
                    }
                }
            }
        }
        jApp.put("files", jFiles);
    }
    try {
        String resourceId = fgServerManager.addResource(themeDisplay.getCompanyId(),
                FGServerConstants.APPLICATION_COLLECTION, id, jApp.toJSONString(), themeDisplay.getUserId());
        if (!fileToTransfer.isEmpty()) {
            fgServerManager.submitFilesResource(themeDisplay.getCompanyId(),
                    FGServerConstants.APPLICATION_COLLECTION, resourceId, fileToTransfer,
                    themeDisplay.getUserId());
        }
        sendRedirect(actionRequest, actionResponse, redirect);
    } catch (IOException io) {
        log.error(io.getMessage());
        SessionErrors.add(actionRequest, io.getClass(), io);
        try {
            Map<String, String> mapInfras = fgServerManager.getInfrastructures(themeDisplay.getCompanyId(),
                    themeDisplay.getUserId());
            actionRequest.setAttribute(FGServerConstants.INFRASTRUCTURE_COLLECTION, mapInfras);
        } catch (Exception e) {
            if (e instanceof PrincipalException) {
                SessionErrors.add(actionRequest, e.getClass());
                actionResponse.setRenderParameter("mvcPath", "/error.jsp");
            } else {
                throw new PortletException(e);
            }
        }
        actionResponse.setRenderParameter("mvcPath", "/add_application.jsp");
    }
}