Example usage for com.liferay.portal.kernel.service CompanyLocalServiceUtil getCompany

List of usage examples for com.liferay.portal.kernel.service CompanyLocalServiceUtil getCompany

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.service CompanyLocalServiceUtil getCompany.

Prototype

public static com.liferay.portal.kernel.model.Company getCompany(long companyId)
        throws com.liferay.portal.kernel.exception.PortalException 

Source Link

Document

Returns the company with the primary key.

Usage

From source file:at.graz.meduni.bibbox.liferay.portlet.service.impl.ApplicationInstanceServiceImpl.java

License:Open Source License

private JSONObject installApplication(String applicationname, String version, String instanceid,
        String instancename, String data) {
    JSONObject returnobject = JSONFactoryUtil.createJSONObject();

    if (ApplicationInstanceLocalServiceUtil.checkInstanceNameAvailable(instanceid)) {
        returnobject.put("status", "error");
        returnobject.put("error", "InstanceId alredy exists!");
        return returnobject;
    }//from w w w. ja v a2 s .c  o  m

    ApplicationInstanceLocalServiceUtil.registerApplication(applicationname, version, instanceid, instancename);

    long userId = 0;
    long groupId = 0;
    try {
        User user = this.getGuestOrUser();
        Company company = CompanyLocalServiceUtil.getCompany(user.getCompanyId());
        groupId = company.getGroupId();
        userId = user.getUserId();
    } catch (Exception e) {
        System.err.println(FormatExceptionMessage.formatExceptionMessage("error", log_portlet_, log_classname_,
                "installApplication(String applicationname, String version, String instanceid, String instancename, String data)",
                "Error getting user from api call."));
        e.printStackTrace();
    }

    Map<String, Serializable> taskContextMap = new HashMap<>();

    taskContextMap.put("instanceId", instanceid);
    taskContextMap.put("data", data);

    try {
        BackgroundTaskManagerUtil.addBackgroundTask(userId, groupId,
                BibboxBackgroundTaskExecutorNames.BIBBOX_INSTANCE_INSTALLER_BACKGROUND_TASK_EXECUTOR,
                new String[] { "BIBBOXDocker-portlet" }, InstallApplicationBG.class, taskContextMap,
                new ServiceContext());
    } catch (PortalException e) {
        System.err.println(FormatExceptionMessage.formatExceptionMessage("error", log_portlet_, log_classname_,
                "installApplication(String applicationname, String version, String instanceid, String instancename, String data)",
                "Error starting Background Task. For instance: " + instanceid));
        e.printStackTrace();
    }

    returnobject.put("status", "installing");
    returnobject.put("instanceid", instanceid);

    return returnobject;
}

From source file:at.graz.meduni.bibbox.liferay.portlet.service.impl.ApplicationInstanceServiceImpl.java

License:Open Source License

private JSONObject deleteInstance(String instanceId) {
    JSONObject returnobject = JSONFactoryUtil.createJSONObject();
    ApplicationInstance applicationinstance = ApplicationInstanceLocalServiceUtil
            .getApplicationInstance(instanceId);
    if (applicationinstance == null) {
        returnobject.put("status", "error");
        returnobject.put("error", "InstanceId dose not exist!");
    } else {//  www. jav a 2 s .  c om
        applicationinstance.setDeleted(true);
        applicationinstance.setStatus("deleting");
        ApplicationInstanceLocalServiceUtil.updateApplicationInstance(applicationinstance);

        long userId = 0;
        long groupId = 0;

        try {
            User user = this.getGuestOrUser();
            Company company = CompanyLocalServiceUtil.getCompany(user.getCompanyId());
            groupId = company.getGroupId();
            userId = user.getUserId();
        } catch (Exception e) {
            System.err.println(FormatExceptionMessage.formatExceptionMessage("error", log_portlet_,
                    log_classname_, "getUserObject()", "Error getting user from api call"));
            e.printStackTrace();
        }

        Map<String, Serializable> taskContextMap = new HashMap<>();
        taskContextMap.put("instanceId", instanceId);

        try {
            BackgroundTaskManagerUtil.addBackgroundTask(userId, groupId,
                    BibboxBackgroundTaskExecutorNames.BIBBOX_INSTANCE_DELETE_BACKGROUND_TASK_EXECUTOR,
                    new String[] { "BIBBOXDocker-portlet" }, DeleteApplication.class, taskContextMap,
                    new ServiceContext());
        } catch (PortalException e) {
            System.err.println(FormatExceptionMessage.formatExceptionMessage("error", log_portlet_,
                    log_classname_, "getUserObject()", "Error starting delete Task."));
            e.printStackTrace();
        }

        returnobject.put("status", "installing");
        returnobject.put("instanceid", instanceId);
    }
    return returnobject;
}

From source file:at.graz.meduni.bibbox.liferay.portlet.service.impl.ApplicationInstanceServiceImpl.java

License:Open Source License

private JSONObject startInstance(String instanceId) {
    JSONObject returnobject = JSONFactoryUtil.createJSONObject();
    ApplicationInstance applicationinstance = ApplicationInstanceLocalServiceUtil
            .getApplicationInstance(instanceId);
    if (applicationinstance == null) {
        returnobject.put("status", "error");
        returnobject.put("error", "InstanceId dose not exist!");
        String activityId = addMessageActivity("Starting Instance " + instanceId, "STARTAPP", "RUNNING",
                "UNKNOWN");
        ActivitiesProtocol.addActivityLogEntry(activityId, "ERROR", "InstanceId dose not exist!");
        finishActivity(activityId, "FINISHED", "ERROR");
    } else {/*from  w w  w  .  jav a  2s  .  c  o  m*/
        ApplicationInstanceStatus applicationinstancestatus = ApplicationInstanceStatusLocalServiceUtil
                .getApplicationInstanceStatusByInstanceId(applicationinstance.getApplicationInstanceId());
        applicationinstancestatus.setStatus("starting");
        applicationinstancestatus = ApplicationInstanceStatusLocalServiceUtil
                .updateApplicationInstanceStatus(applicationinstancestatus);

        long userId = 0;
        long groupId = 0;
        try {
            User user = this.getGuestOrUser();
            Company company = CompanyLocalServiceUtil.getCompany(user.getCompanyId());
            groupId = company.getGroupId();
            userId = user.getUserId();
        } catch (Exception e) {
            System.err.println(FormatExceptionMessage.formatExceptionMessage("error", log_portlet_,
                    log_classname_, "startInstance(String instanceId)", "Error getting user from api call."));
            e.printStackTrace();
        }

        Map<String, Serializable> taskContextMap = new HashMap<>();

        taskContextMap.put("instanceId", instanceId);
        taskContextMap.put("command", "start");

        try {
            BackgroundTaskManagerUtil.addBackgroundTask(userId, groupId,
                    BibboxBackgroundTaskExecutorNames.BIBBOX_INSTANCE_CONTROLE_BACKGROUND_TASK_EXECUTOR,
                    new String[] { "BIBBOXDocker-portlet" }, ControleApplication.class, taskContextMap,
                    new ServiceContext());
        } catch (PortalException e) {
            System.err.println(FormatExceptionMessage.formatExceptionMessage("error", log_portlet_,
                    log_classname_, "startInstance(String instanceId)",
                    "Error starting Background Task. For instance: " + instanceId));
            e.printStackTrace();
        }
    }
    applicationinstance = null;
    returnobject.put("status", "starting");
    return returnobject;
}

From source file:at.graz.meduni.bibbox.liferay.portlet.service.impl.ApplicationInstanceServiceImpl.java

License:Open Source License

private JSONObject stopInstance(String instanceId) {
    JSONObject returnobject = JSONFactoryUtil.createJSONObject();
    ApplicationInstance applicationinstance = ApplicationInstanceLocalServiceUtil
            .getApplicationInstance(instanceId);
    if (applicationinstance == null) {
        returnobject.put("status", "error");
        returnobject.put("error", "InstanceId dose not exist!");
        String activityId = addMessageActivity("Stopping Instance " + instanceId, "STOPAPP", "RUNNING",
                "UNKNOWN");
        ActivitiesProtocol.addActivityLogEntry(activityId, "ERROR", "InstanceId dose not exist!");
        finishActivity(activityId, "FINISHED", "ERROR");
    } else {/* w  ww  .  j  a  va 2 s.  c  o m*/
        ApplicationInstanceStatus applicationinstancestatus = ApplicationInstanceStatusLocalServiceUtil
                .getApplicationInstanceStatusByInstanceId(applicationinstance.getApplicationInstanceId());
        applicationinstancestatus.setStatus("stopping");
        applicationinstancestatus = ApplicationInstanceStatusLocalServiceUtil
                .updateApplicationInstanceStatus(applicationinstancestatus);

        long userId = 0;
        long groupId = 0;
        try {
            User user = this.getGuestOrUser();
            Company company = CompanyLocalServiceUtil.getCompany(user.getCompanyId());
            groupId = company.getGroupId();
            userId = user.getUserId();
        } catch (Exception e) {
            System.err.println(FormatExceptionMessage.formatExceptionMessage("error", log_portlet_,
                    log_classname_, "stopInstance(String instanceId)", "Error getting user from api call."));
            e.printStackTrace();
        }

        Map<String, Serializable> taskContextMap = new HashMap<>();

        taskContextMap.put("instanceId", instanceId);
        taskContextMap.put("command", "stop");

        try {
            BackgroundTaskManagerUtil.addBackgroundTask(userId, groupId,
                    BibboxBackgroundTaskExecutorNames.BIBBOX_INSTANCE_CONTROLE_BACKGROUND_TASK_EXECUTOR,
                    new String[] { "BIBBOXDocker-portlet" }, ControleApplication.class, taskContextMap,
                    new ServiceContext());
        } catch (PortalException e) {
            System.err.println(FormatExceptionMessage.formatExceptionMessage("error", log_portlet_,
                    log_classname_, "stopInstance(String instanceId)",
                    "Error starting Background Task. For instance: " + instanceId));
            e.printStackTrace();
        }
    }
    returnobject.put("status", "stopping");
    return returnobject;
}

From source file:at.graz.meduni.bibbox.liferay.portlet.service.impl.ApplicationInstanceServiceImpl.java

License:Open Source License

private JSONObject restartInstance(String instanceId) {
    JSONObject returnobject = JSONFactoryUtil.createJSONObject();
    ApplicationInstance applicationinstance = ApplicationInstanceLocalServiceUtil
            .getApplicationInstance(instanceId);
    if (applicationinstance == null) {
        returnobject.put("status", "error");
        returnobject.put("error", "InstanceId dose not exist!");
        String activityId = addMessageActivity("Restart Instance " + instanceId, "RESTARTAPP", "RUNNING",
                "UNKNOWN");
        ActivitiesProtocol.addActivityLogEntry(activityId, "ERROR", "InstanceId dose not exist!");
        finishActivity(activityId, "FINISHED", "ERROR");
    } else {//from   w ww .j a  v a  2s  .  c om
        ApplicationInstanceStatus applicationinstancestatus = ApplicationInstanceStatusLocalServiceUtil
                .getApplicationInstanceStatusByInstanceId(applicationinstance.getApplicationInstanceId());
        applicationinstancestatus.setStatus("restarting");
        applicationinstancestatus = ApplicationInstanceStatusLocalServiceUtil
                .updateApplicationInstanceStatus(applicationinstancestatus);

        long userId = 0;
        long groupId = 0;
        try {
            User user = this.getGuestOrUser();
            Company company = CompanyLocalServiceUtil.getCompany(user.getCompanyId());
            groupId = company.getGroupId();
            userId = user.getUserId();
        } catch (Exception e) {
            System.err.println(FormatExceptionMessage.formatExceptionMessage("error", log_portlet_,
                    log_classname_, "restartInstance(String instanceId)", "Error getting user from api call."));
            e.printStackTrace();
        }

        Map<String, Serializable> taskContextMap = new HashMap<>();

        taskContextMap.put("instanceId", instanceId);
        taskContextMap.put("command", "restart");

        try {
            BackgroundTaskManagerUtil.addBackgroundTask(userId, groupId,
                    BibboxBackgroundTaskExecutorNames.BIBBOX_INSTANCE_CONTROLE_BACKGROUND_TASK_EXECUTOR,
                    new String[] { "BIBBOXDocker-portlet" }, ControleApplication.class, taskContextMap,
                    new ServiceContext());
        } catch (PortalException e) {
            System.err.println(FormatExceptionMessage.formatExceptionMessage("error", log_portlet_,
                    log_classname_, "restartInstance(String instanceId)",
                    "Error starting Background Task. For instance: " + instanceId));
            e.printStackTrace();
        }
    }
    returnobject.put("status", "restarting");
    return returnobject;
}

From source file:com.gleo.groupphoto.web.portlet.action.ViewUserDetailsActionMVCRenderCommand.java

License:Open Source License

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

    long userId = ParamUtil.getLong(renderRequest, "userId");
    ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY);

    String organizationsHTML = StringPool.BLANK;
    Contact contact = null;/*from   w ww  .  j av a  2s . c om*/
    List<Organization> organizations = null;
    User user = null;
    Company company = null;
    Locale locale = themeDisplay.getLocale();

    String birthday = null;
    String jobTitle = null;
    String gender = null;
    String comments = null;

    // Get User
    if (userId > 0) {

        try {
            user = UserLocalServiceUtil.getUser(userId);
            company = CompanyLocalServiceUtil.getCompany(user.getCompanyId());

        } catch (PortalException e) {
            LOGGER.error(e);
        }

        if (user != null) {
            // Get Contact
            try {
                contact = user.getContact();

            } catch (PortalException e) {
                LOGGER.error(e);
            }

            // Get Organizations
            organizations = OrganizationLocalServiceUtil.getUserOrganizations(user.getUserId());
            StringBundler organizationsHTMLBundler = new StringBundler(organizations.size() * 2);

            if (!organizations.isEmpty()) {
                organizationsHTMLBundler.append(organizations.get(0).getName());
            }

            for (int i = 1; i < organizations.size(); i++) {
                organizationsHTMLBundler.append(", ");
                organizationsHTMLBundler.append(organizations.get(i).getName());
            }
            organizationsHTML = organizationsHTMLBundler.toString();

            // Fields
            setFields(renderRequest, contact, user, company, locale, birthday, gender, jobTitle);

            // Contact
            String className = Contact.class.getName();
            long classPK = contact.getContactId();

            List<Address> personalAddresses = Collections.emptyList();
            List<Address> organizationAddresses = new ArrayList<Address>();
            List<EmailAddress> emailAddresses = Collections.emptyList();
            List<Website> websites = Collections.emptyList();
            List<Phone> personalPhones = Collections.emptyList();
            List<Phone> organizationPhones = new ArrayList<Phone>();

            if (classPK > 0) {
                try {
                    personalAddresses = AddressServiceUtil.getAddresses(className, classPK);
                } catch (PortalException pe) {
                    LOGGER.error(pe);
                }

                try {
                    emailAddresses = EmailAddressServiceUtil.getEmailAddresses(className, classPK);
                } catch (PortalException pe) {
                    LOGGER.error(pe);
                }

                try {
                    websites = WebsiteServiceUtil.getWebsites(className, classPK);
                } catch (PortalException pe) {
                    LOGGER.error(pe);
                }
                try {
                    personalPhones = PhoneServiceUtil.getPhones(className, classPK);
                } catch (PortalException pe) {
                    LOGGER.error(pe);
                }

            }

            for (int i = 0; i < organizations.size(); i++) {
                try {
                    organizationAddresses.addAll(AddressServiceUtil.getAddresses(Organization.class.getName(),
                            organizations.get(i).getOrganizationId()));
                } catch (Exception e) {
                }
            }

            for (int i = 0; i < organizations.size(); i++) {
                try {
                    organizationPhones.addAll(PhoneServiceUtil.getPhones(Organization.class.getName(),
                            organizations.get(i).getOrganizationId()));
                } catch (Exception e) {
                }
            }

            // Comments
            comments = user.getComments();

            LOGGER.info("comments" + comments);
            if (comments != null && !comments.trim().equals(StringPool.BLANK)) {
                comments = StringUtil.replace(BBCodeTranslatorUtil.getHTML(user.getComments()),
                        ThemeConstants.TOKEN_THEME_IMAGES_PATH + EMOTICONS,
                        themeDisplay.getPathThemeImages() + EMOTICONS);
            }

            renderRequest.setAttribute("organizationAddresses", organizationAddresses);
            renderRequest.setAttribute("personalAddresses", personalAddresses);
            renderRequest.setAttribute("emailAddresses", emailAddresses);
            renderRequest.setAttribute("organizationAddresses", organizationAddresses);
            renderRequest.setAttribute("websites", websites);
            renderRequest.setAttribute("personalPhones", personalPhones);
            renderRequest.setAttribute("organizationPhones", organizationPhones);

        }
    }

    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("userId =" + userId);
        LOGGER.debug("birthday =" + birthday);
        LOGGER.debug("gender =" + gender);
        LOGGER.debug("jobTitle =" + jobTitle);
        LOGGER.debug("comments =" + comments);
    }

    renderRequest.setAttribute("organizations", organizations);
    renderRequest.setAttribute("organizationsHTML", organizationsHTML);
    renderRequest.setAttribute("user2", user);
    renderRequest.setAttribute("contact", contact);
    renderRequest.setAttribute("languageUtil", LanguageUtil.getLanguage());
    renderRequest.setAttribute("locale", locale);
    renderRequest.setAttribute("comments", comments);
    renderRequest.setAttribute("htmlUtil", HtmlUtil.getHtml());

    return "/userdetails/jsp/user_details.jsp";
}

From source file:com.liferay.asset.publisher.lar.test.AssetPublisherExportImportTest.java

License:Open Source License

@Test
public void testExportImportSeveralScopedAssetEntries() throws Exception {
    List<Group> groups = new ArrayList<>();

    Company company = CompanyLocalServiceUtil.getCompany(layout.getCompanyId());

    Group companyGroup = company.getGroup();

    groups.add(companyGroup);/* w w  w.  j a  v a2s.c om*/

    groups.add(group);

    Group group2 = GroupTestUtil.addGroup();

    groups.add(group2);

    Group layoutGroup1 = GroupTestUtil.addGroup(TestPropsValues.getUserId(), layout);

    groups.add(layoutGroup1);

    Layout layout2 = LayoutTestUtil.addLayout(group);

    Group layoutGroup2 = GroupTestUtil.addGroup(TestPropsValues.getUserId(), layout2);

    groups.add(layoutGroup2);

    testExportImportAssetEntries(groups);
}

From source file:com.liferay.asset.publisher.lar.test.AssetPublisherExportImportTest.java

License:Open Source License

@Test
public void testGlobalScopeId() throws Exception {
    Map<String, String[]> preferenceMap = new HashMap<>();

    Company company = CompanyLocalServiceUtil.getCompany(layout.getCompanyId());

    Group companyGroup = company.getGroup();

    preferenceMap.put("scopeIds",
            new String[] { AssetPublisherHelper.SCOPE_ID_GROUP_PREFIX + companyGroup.getGroupId() });

    PortletPreferences portletPreferences = getImportedPortletPreferences(preferenceMap);

    Assert.assertEquals(AssetPublisherHelper.SCOPE_ID_GROUP_PREFIX + companyGroup.getGroupId(),
            portletPreferences.getValue("scopeIds", null));
    Assert.assertEquals(null, portletPreferences.getValue("scopeId", null));
}

From source file:com.liferay.asset.publisher.lar.test.AssetPublisherExportImportTest.java

License:Open Source License

@Test
public void testSeveralLayoutScopeIds() throws Exception {
    Company company = CompanyLocalServiceUtil.getCompany(layout.getCompanyId());

    Layout secondLayout = LayoutTestUtil.addLayout(group);

    GroupTestUtil.addGroup(TestPropsValues.getUserId(), secondLayout);

    Map<String, String[]> preferenceMap = new HashMap<>();

    GroupTestUtil.addGroup(TestPropsValues.getUserId(), layout);

    Group companyGroup = company.getGroup();

    preferenceMap.put("scopeIds",
            new String[] { AssetPublisherHelper.SCOPE_ID_GROUP_PREFIX + companyGroup.getGroupId(),
                    AssetPublisherHelper.SCOPE_ID_LAYOUT_UUID_PREFIX + layout.getUuid(),
                    AssetPublisherHelper.SCOPE_ID_LAYOUT_UUID_PREFIX + secondLayout.getUuid() });

    PortletPreferences portletPreferences = getImportedPortletPreferences(preferenceMap);

    Layout importedSecondLayout = LayoutLocalServiceUtil.fetchLayoutByUuidAndGroupId(secondLayout.getUuid(),
            importedGroup.getGroupId(), importedLayout.isPrivateLayout());

    Assert.assertEquals(null, portletPreferences.getValue("scopeId", null));

    StringBundler sb = new StringBundler(8);

    sb.append(AssetPublisherHelper.SCOPE_ID_GROUP_PREFIX);
    sb.append(companyGroup.getGroupId());
    sb.append(StringPool.COMMA);//from w w  w  . jav  a  2  s.co  m
    sb.append(AssetPublisherHelper.SCOPE_ID_LAYOUT_UUID_PREFIX);
    sb.append(importedLayout.getUuid());
    sb.append(StringPool.COMMA);
    sb.append(AssetPublisherHelper.SCOPE_ID_LAYOUT_UUID_PREFIX);
    sb.append(importedSecondLayout.getUuid());

    Assert.assertEquals(sb.toString(), StringUtil.merge(portletPreferences.getValues("scopeIds", null)));
}

From source file:com.liferay.asset.publisher.lar.test.AssetPublisherExportImportTest.java

License:Open Source License

protected void testDynamicExportImport(Map<String, String[]> preferenceMap,
        List<AssetEntry> expectedAssetEntries, boolean filtering) throws Exception {

    if (filtering) {

        // Creating entries to validate filtering

        addAssetEntries(group, 2, new ArrayList<AssetEntry>(), ServiceContextTestUtil.getServiceContext());
    }//from   ww  w.java  2s .  c o m

    String scopeId = _assetPublisherHelper.getScopeId(group, group.getGroupId());

    preferenceMap.put("scopeIds", new String[] { scopeId });

    preferenceMap.put("selectionStyle", new String[] { "dynamic" });

    PortletPreferences portletPreferences = getImportedPortletPreferences(preferenceMap);

    Company company = CompanyLocalServiceUtil.getCompany(TestPropsValues.getCompanyId());

    AssetEntryQuery assetEntryQuery = _assetPublisherHelper.getAssetEntryQuery(portletPreferences,
            importedGroup.getGroupId(), layout, null, null);

    SearchContainer<AssetEntry> searchContainer = new SearchContainer<>();

    searchContainer.setTotal(10);

    List<AssetEntryResult> actualAssetEntryResults = _assetPublisherHelper.getAssetEntryResults(searchContainer,
            assetEntryQuery, layout, portletPreferences, StringPool.BLANK, null, null, company.getCompanyId(),
            importedGroup.getGroupId(), TestPropsValues.getUserId(), assetEntryQuery.getClassNameIds(), null);

    List<AssetEntry> actualAssetEntries = new ArrayList<>();

    for (AssetEntryResult assetEntryResult : actualAssetEntryResults) {
        actualAssetEntries.addAll(assetEntryResult.getAssetEntries());
    }

    assertAssetEntries(expectedAssetEntries, actualAssetEntries);
}