Example usage for com.liferay.portal.kernel.model Company getGroupId

List of usage examples for com.liferay.portal.kernel.model Company getGroupId

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.model Company getGroupId.

Prototype

public long getGroupId() throws com.liferay.portal.kernel.exception.PortalException;

Source Link

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  . j  a  v a  2  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 {//from   w  w w .  j av  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 {// w  w w.  j  ava 2  s  .  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 {//from  w  w  w. ja  v a2 s.  co 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 ww  w  .  j a  va  2s .c o  m
        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.liferay.asset.publisher.lar.test.AssetPublisherExportImportTest.java

License:Open Source License

protected void testExportImportAssetEntries(List<Group> scopeGroups) throws Exception {

    List<AssetEntry> assetEntries = new ArrayList<>();
    String[] scopeIds = new String[0];

    for (Group scopeGroup : scopeGroups) {
        ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext();

        if (scopeGroup.isLayout()) {

            // Creating structures and templates in layout scope group is
            // not possible

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

            serviceContext.setAttribute("ddmGroupId", company.getGroupId());
        }//from w  w  w. j  a va 2 s  .  co  m

        assetEntries = addAssetEntries(scopeGroup, 3, assetEntries, serviceContext);

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

        scopeIds = ArrayUtil.append(scopeIds, scopeId);
    }

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

    preferenceMap.put("assetEntryXml", getAssetEntriesXmls(assetEntries));
    preferenceMap.put("scopeIds", scopeIds);

    PortletPreferences importedPortletPreferences = getImportedPortletPreferences(preferenceMap);

    String[] importedScopeIds = importedPortletPreferences.getValues("scopeIds", null);

    long[] selectedGroupIds = getGroupIdsFromScopeIds(importedScopeIds, importedLayout);

    List<AssetEntry> actualAssetEntries = _assetPublisherHelper.getAssetEntries(new MockPortletRequest(),
            importedPortletPreferences, _permissionChecker, selectedGroupIds, false, false);

    assertAssetEntries(assetEntries, actualAssetEntries);
}

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

License:Open Source License

protected void testSortByAssetVocabulary(boolean globalVocabulary) throws Exception {

    long groupId = group.getGroupId();

    if (globalVocabulary) {
        Company company = CompanyLocalServiceUtil.getCompany(layout.getCompanyId());

        groupId = company.getGroupId();
    }/*  w  w  w . j a v a  2s  . c om*/

    AssetVocabulary assetVocabulary = AssetVocabularyLocalServiceUtil.addVocabulary(TestPropsValues.getUserId(),
            groupId, RandomTestUtil.randomString(), ServiceContextTestUtil.getServiceContext(groupId));

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

    preferenceMap.put("assetVocabularyId", new String[] { String.valueOf(assetVocabulary.getVocabularyId()) });

    PortletPreferences portletPreferences = getImportedPortletPreferences(preferenceMap);

    Assert.assertNotNull("Portlet preference \"assetVocabularyId\" is null",
            portletPreferences.getValue("assetVocabularyId", null));

    long importedAssetVocabularyId = GetterUtil.getLong(portletPreferences.getValue("assetVocabularyId", null));

    AssetVocabulary importedVocabulary = AssetVocabularyLocalServiceUtil
            .fetchAssetVocabulary(importedAssetVocabularyId);

    Assert.assertNotNull("Vocabulary " + importedAssetVocabularyId + " does not exist", importedVocabulary);

    long expectedGroupId = groupId;

    if (!globalVocabulary) {
        expectedGroupId = importedGroup.getGroupId();
    }

    Assert.assertEquals(
            "Vocabulary " + importedAssetVocabularyId + " does not belong to group " + expectedGroupId,
            expectedGroupId, importedVocabulary.getGroupId());

    AssetVocabularyLocalServiceUtil.deleteAssetVocabulary(assetVocabulary);
}

From source file:com.liferay.exportimport.test.BasePrototypePropagationTestCase.java

License:Open Source License

@Before
public void setUp() throws Exception {
    ServiceContextThreadLocal.pushServiceContext(ServiceContextTestUtil.getServiceContext());

    ServiceTestUtil.setUser(TestPropsValues.getUser());

    // Group/*w  w  w.  j av  a 2s.  c  o  m*/

    group = GroupTestUtil.addGroup();

    // Global scope article

    Company company = CompanyLocalServiceUtil.fetchCompany(group.getCompanyId());

    globalGroupId = company.getGroupId();

    globalJournalArticle = JournalTestUtil.addArticle(globalGroupId, "Global Article", "Global Content");

    // Layout prototype

    layoutPrototype = LayoutTestUtil.addLayoutPrototype(RandomTestUtil.randomString());

    layoutPrototypeLayout = layoutPrototype.getLayout();

    LayoutTestUtil.updateLayoutTemplateId(layoutPrototypeLayout, initialLayoutTemplateId);

    doSetUp();
}

From source file:com.liferay.exportimport.test.util.lar.BaseStagedModelDataHandlerTestCase.java

License:Open Source License

protected void validateAssets(StagedModel stagedModel, StagedModelAssets stagedModelAssets, Group group)
        throws Exception {

    if (stagedModelAssets == null) {
        return;/* w  w w . j a v a  2  s .c  om*/
    }

    AssetEntry importedAssetEntry = fetchAssetEntry(stagedModel, group);

    if (isAssetPrioritySupported()) {
        AssetEntry assetEntry = stagedModelAssets.getAssetEntry();

        Assert.assertEquals(assetEntry.getPriority(), importedAssetEntry.getPriority(), 0D);
    }

    List<AssetCategory> importedAssetCategories = AssetCategoryLocalServiceUtil
            .getEntryCategories(importedAssetEntry.getEntryId());

    Assert.assertEquals(importedAssetCategories.toString(), 2, importedAssetCategories.size());

    AssetCategory stagedAssetCategory = stagedModelAssets.getAssetCategory();

    AssetCategory importedAssetCategory = null;

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

    long companyGroupId = company.getGroupId();

    for (AssetCategory assetCategory : importedAssetCategories) {
        long groupId = assetCategory.getGroupId();

        if (groupId != companyGroupId) {
            importedAssetCategory = assetCategory;

            break;
        }
    }

    Assert.assertEquals(stagedAssetCategory.getUuid(), importedAssetCategory.getUuid());

    List<AssetTag> importedAssetTags = AssetTagLocalServiceUtil.getEntryTags(importedAssetEntry.getEntryId());

    Assert.assertEquals(importedAssetTags.toString(), 1, importedAssetTags.size());

    AssetTag assetTag = stagedModelAssets.getAssetTag();
    AssetTag importedAssetTag = importedAssetTags.get(0);

    Assert.assertEquals(assetTag.getName(), importedAssetTag.getName());

    AssetVocabulary assetVocabulary = stagedModelAssets.getAssetVocabulary();
    AssetVocabulary importedAssetVocabulary = AssetVocabularyLocalServiceUtil
            .getVocabulary(importedAssetCategory.getVocabularyId());

    Assert.assertEquals(assetVocabulary.getUuid(), importedAssetVocabulary.getUuid());
}

From source file:com.liferay.journal.internal.upgrade.v0_0_3.UpgradeJournalArticleType.java

License:Open Source License

protected void updateArticleType() throws Exception {
    try (LoggingTimer loggingTimer = new LoggingTimer()) {
        if (!hasSelectedArticleTypes()) {
            return;
        }//from   w  ww.  ja  va 2s .  c  o  m

        List<String> types = getArticleTypes();

        if (types.size() <= 0) {
            return;
        }

        Locale localeThreadLocalDefaultLocale = LocaleThreadLocal.getDefaultLocale();

        try {
            List<Company> companies = _companyLocalService.getCompanies();

            for (Company company : companies) {
                LocaleThreadLocal.setDefaultLocale(company.getLocale());

                Set<Locale> locales = LanguageUtil.getAvailableLocales(company.getGroupId());

                Locale defaultLocale = LocaleUtil
                        .fromLanguageId(UpgradeProcessUtil.getDefaultLanguageId(company.getCompanyId()));

                Map<Locale, String> nameMap = LocalizationUtil.getLocalizationMap(locales, defaultLocale,
                        "type");

                AssetVocabulary assetVocabulary = addAssetVocabulary(company.getGroupId(),
                        company.getCompanyId(), "type", nameMap, new HashMap<Locale, String>());

                Map<String, Long> journalArticleTypesToAssetCategoryIds = new HashMap<>();

                for (String type : types) {
                    AssetCategory assetCategory = addAssetCategory(company.getGroupId(), company.getCompanyId(),
                            type, assetVocabulary.getVocabularyId());

                    journalArticleTypesToAssetCategoryIds.put(type, assetCategory.getCategoryId());
                }

                updateArticles(company.getCompanyId(), journalArticleTypesToAssetCategoryIds);
            }
        } finally {
            LocaleThreadLocal.setDefaultLocale(localeThreadLocalDefaultLocale);
        }
    }
}