Example usage for com.liferay.portal.kernel.service ServiceContext isAddGroupPermissions

List of usage examples for com.liferay.portal.kernel.service ServiceContext isAddGroupPermissions

Introduction

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

Prototype

public boolean isAddGroupPermissions() 

Source Link

Document

Returns true if this service context is being passed as a parameter to a method which manipulates a resource to which default group permissions apply.

Usage

From source file:ch.inofix.timetracker.service.impl.TaskRecordLocalServiceImpl.java

License:Open Source License

@Override
@Indexable(type = IndexableType.REINDEX)
public TaskRecord addTaskRecord(long userId, String workPackage, String description, String ticketURL,
        Date endDate, Date startDate, int status, long duration, ServiceContext serviceContext)
        throws PortalException {

    // TaskRecord

    User user = userPersistence.findByPrimaryKey(userId);
    long groupId = serviceContext.getScopeGroupId();

    // TODO//from w  ww . j a  v  a  2  s. c  o m
    // validate(groupId, urlTitle);

    long taskRecordId = counterLocalService.increment();

    TaskRecord taskRecord = taskRecordPersistence.create(taskRecordId);

    taskRecord.setUuid(serviceContext.getUuid());
    taskRecord.setGroupId(groupId);
    taskRecord.setCompanyId(user.getCompanyId());
    taskRecord.setUserId(user.getUserId());
    taskRecord.setUserName(user.getFullName());
    taskRecord.setExpandoBridgeAttributes(serviceContext);

    taskRecord.setWorkPackage(workPackage);
    taskRecord.setDescription(description);
    taskRecord.setTicketURL(ticketURL);
    taskRecord.setEndDate(endDate);
    taskRecord.setStartDate(startDate);
    taskRecord.setStatus(status);
    taskRecord.setDuration(duration);

    taskRecord = taskRecordPersistence.update(taskRecord);

    // Resources

    if (serviceContext.isAddGroupPermissions() || serviceContext.isAddGuestPermissions()) {
        addTaskRecordResources(taskRecord, serviceContext.isAddGroupPermissions(),
                serviceContext.isAddGuestPermissions());
    } else {
        addTaskRecordResources(taskRecord, serviceContext.getModelPermissions());
    }

    // Asset

    updateAsset(userId, taskRecord, serviceContext.getAssetCategoryIds(), serviceContext.getAssetTagNames(),
            serviceContext.getAssetLinkEntryIds(), serviceContext.getAssetPriority());

    return taskRecord;

}

From source file:com.liferay.blogs.service.impl.BlogsEntryLocalServiceImpl.java

License:Open Source License

@Indexable(type = IndexableType.REINDEX)
@Override//from w w  w  . j av  a2 s  . c  om
public BlogsEntry addEntry(long userId, String title, String subtitle, String urlTitle, String description,
        String content, Date displayDate, boolean allowPingbacks, boolean allowTrackbacks, String[] trackbacks,
        String coverImageCaption, ImageSelector coverImageImageSelector, ImageSelector smallImageImageSelector,
        ServiceContext serviceContext) throws PortalException {

    // Entry

    User user = userPersistence.findByPrimaryKey(userId);
    long groupId = serviceContext.getScopeGroupId();

    long entryId = counterLocalService.increment();

    validate(title, urlTitle, content);

    BlogsEntry entry = blogsEntryPersistence.create(entryId);

    entry.setUuid(serviceContext.getUuid());
    entry.setGroupId(groupId);
    entry.setCompanyId(user.getCompanyId());
    entry.setUserId(user.getUserId());
    entry.setUserName(user.getFullName());
    entry.setTitle(title);
    entry.setSubtitle(subtitle);

    if (Validator.isNotNull(urlTitle)) {
        entry.setUrlTitle(getUniqueUrlTitle(entryId, groupId, urlTitle));
    }

    entry.setDescription(description);
    entry.setContent(content);
    entry.setDisplayDate(displayDate);
    entry.setAllowPingbacks(allowPingbacks);
    entry.setAllowTrackbacks(allowTrackbacks);
    entry.setStatus(WorkflowConstants.STATUS_DRAFT);
    entry.setStatusByUserId(userId);
    entry.setStatusDate(serviceContext.getModifiedDate(null));
    entry.setExpandoBridgeAttributes(serviceContext);

    blogsEntryPersistence.update(entry);

    // Resources

    if (serviceContext.isAddGroupPermissions() || serviceContext.isAddGuestPermissions()) {

        addEntryResources(entry, serviceContext.isAddGroupPermissions(),
                serviceContext.isAddGuestPermissions());
    } else {
        addEntryResources(entry, serviceContext.getModelPermissions());
    }

    // Asset

    updateAsset(userId, entry, serviceContext.getAssetCategoryIds(), serviceContext.getAssetTagNames(),
            serviceContext.getAssetLinkEntryIds(), serviceContext.getAssetPriority());

    // Images

    long coverImageFileEntryId = 0;
    String coverImageURL = null;

    if (coverImageImageSelector != null) {
        coverImageURL = coverImageImageSelector.getImageURL();

        if (coverImageImageSelector.getImageBytes() != null) {
            coverImageFileEntryId = addCoverImageFileEntry(userId, groupId, entryId, coverImageImageSelector);
        }
    }

    long smallImageFileEntryId = 0;
    String smallImageURL = null;

    if (smallImageImageSelector != null) {
        smallImageURL = smallImageImageSelector.getImageURL();

        if (smallImageImageSelector.getImageBytes() != null) {
            smallImageFileEntryId = addSmallImageFileEntry(userId, groupId, entryId, smallImageImageSelector);
        }
    }

    validate(smallImageFileEntryId);

    entry.setCoverImageCaption(coverImageCaption);
    entry.setCoverImageFileEntryId(coverImageFileEntryId);
    entry.setCoverImageURL(coverImageURL);

    if ((smallImageFileEntryId != 0) || Validator.isNotNull(smallImageURL)) {

        entry.setSmallImage(true);
    }

    entry.setSmallImageFileEntryId(smallImageFileEntryId);
    entry.setSmallImageURL(smallImageURL);

    blogsEntryPersistence.update(entry);

    // Workflow

    if (ArrayUtil.isNotEmpty(trackbacks)) {
        serviceContext.setAttribute("trackbacks", trackbacks);
    } else {
        serviceContext.setAttribute("trackbacks", null);
    }

    return startWorkflowInstance(userId, entry, serviceContext);
}

From source file:com.liferay.dynamic.data.lists.service.impl.DDLRecordSetLocalServiceImpl.java

License:Open Source License

/**
 * Adds a record set referencing the DDM structure.
 *
 * @param  userId the primary key of the record set's creator/owner
 * @param  groupId the primary key of the record set's group
 * @param  ddmStructureId the primary key of the record set's DDM structure
 * @param  recordSetKey the record set's mnemonic primary key. If
 *         <code>null</code>, the record set key will be autogenerated.
 * @param  nameMap the record set's locales and localized names
 * @param  descriptionMap the record set's locales and localized
 *         descriptions/*from w  ww.  j  ava  2 s .  co  m*/
 * @param  minDisplayRows the record set's minimum number of rows to be
 *         displayed in spreadsheet view.
 * @param  scope the record set's scope, used to scope the record set's
 *         data. For more information search
 *         <code>DDLRecordSetConstants</code> in the
 *         <code>dynamic.data.lists.api</code> module for constants starting
 *         with the "SCOPE_" prefix.
 * @param  serviceContext the service context to be applied. Can set the
 *         UUID, guest permissions, and group permissions for the record
 *         set.
 * @return the record set
 * @throws PortalException if a portal exception occurred
 */
@Override
public DDLRecordSet addRecordSet(long userId, long groupId, long ddmStructureId, String recordSetKey,
        Map<Locale, String> nameMap, Map<Locale, String> descriptionMap, int minDisplayRows, int scope,
        ServiceContext serviceContext) throws PortalException {

    // Record set

    User user = userLocalService.getUser(userId);

    if (Validator.isNull(recordSetKey)) {
        recordSetKey = String.valueOf(counterLocalService.increment());
    }

    validate(groupId, ddmStructureId, recordSetKey, nameMap);

    long recordSetId = counterLocalService.increment();

    DDLRecordSet recordSet = ddlRecordSetPersistence.create(recordSetId);

    recordSet.setUuid(serviceContext.getUuid());
    recordSet.setGroupId(groupId);
    recordSet.setCompanyId(user.getCompanyId());
    recordSet.setUserId(user.getUserId());
    recordSet.setUserName(user.getFullName());
    recordSet.setDDMStructureId(ddmStructureId);
    recordSet.setRecordSetKey(recordSetKey);
    recordSet.setNameMap(nameMap);
    recordSet.setDescriptionMap(descriptionMap);
    recordSet.setMinDisplayRows(minDisplayRows);
    recordSet.setScope(scope);

    ddlRecordSetPersistence.update(recordSet);

    // Resources

    if (serviceContext.isAddGroupPermissions() || serviceContext.isAddGuestPermissions()) {

        addRecordSetResources(recordSet, serviceContext.isAddGroupPermissions(),
                serviceContext.isAddGuestPermissions());
    } else {
        addRecordSetResources(recordSet, serviceContext.getGroupPermissions(),
                serviceContext.getGuestPermissions());
    }

    // Dynamic data mapping structure link

    long classNameId = classNameLocalService.getClassNameId(DDLRecordSet.class);

    ddmStructureLinkLocalService.addStructureLink(classNameId, recordSetId, ddmStructureId);

    return recordSet;
}

From source file:com.liferay.dynamic.data.mapping.service.impl.DDMDataProviderInstanceLocalServiceImpl.java

License:Open Source License

@Override
public DDMDataProviderInstance addDataProviderInstance(long userId, long groupId, Map<Locale, String> nameMap,
        Map<Locale, String> descriptionMap, DDMFormValues ddmFormValues, String type,
        ServiceContext serviceContext) throws PortalException {

    // Data provider instance

    User user = userLocalService.getUser(userId);

    validate(nameMap, ddmFormValues);/*from   w ww. j  av  a 2s .c  o  m*/

    long dataProviderInstanceId = counterLocalService.increment();

    DDMDataProviderInstance dataProviderInstance = ddmDataProviderInstancePersistence
            .create(dataProviderInstanceId);

    dataProviderInstance.setUuid(serviceContext.getUuid());
    dataProviderInstance.setGroupId(groupId);
    dataProviderInstance.setCompanyId(user.getCompanyId());
    dataProviderInstance.setUserId(user.getUserId());
    dataProviderInstance.setUserName(user.getFullName());
    dataProviderInstance.setNameMap(nameMap);
    dataProviderInstance.setDescriptionMap(descriptionMap);
    dataProviderInstance.setDefinition(ddmFormValuesJSONSerializer.serialize(ddmFormValues));
    dataProviderInstance.setType(type);

    ddmDataProviderInstancePersistence.update(dataProviderInstance);

    // Resources

    if (serviceContext.isAddGroupPermissions() || serviceContext.isAddGuestPermissions()) {

        addDataProviderInstanceResources(dataProviderInstance, serviceContext.isAddGroupPermissions(),
                serviceContext.isAddGuestPermissions());
    } else {
        addDataProviderInstanceResources(dataProviderInstance, serviceContext.getModelPermissions());
    }

    return dataProviderInstance;
}

From source file:com.liferay.dynamic.data.mapping.service.impl.DDMFormInstanceLocalServiceImpl.java

License:Open Source License

@Override
public DDMFormInstance addFormInstance(long userId, long groupId, long ddmStructureId,
        Map<Locale, String> nameMap, Map<Locale, String> descriptionMap, DDMFormValues settingsDDMFormValues,
        ServiceContext serviceContext) throws PortalException {

    Locale defaultLocale = getDDMFormDefaultLocale(ddmStructureId);

    validate(ddmStructureId, nameMap, settingsDDMFormValues, defaultLocale);

    User user = userLocalService.getUser(userId);

    long ddmFormInstanceId = counterLocalService.increment();

    DDMFormInstance ddmFormInstance = ddmFormInstancePersistence.create(ddmFormInstanceId);

    ddmFormInstance.setUuid(serviceContext.getUuid());
    ddmFormInstance.setGroupId(groupId);
    ddmFormInstance.setCompanyId(user.getCompanyId());
    ddmFormInstance.setUserId(user.getUserId());
    ddmFormInstance.setUserName(user.getFullName());
    ddmFormInstance.setStructureId(ddmStructureId);
    ddmFormInstance.setVersion(_VERSION_DEFAULT);
    ddmFormInstance.setNameMap(nameMap, defaultLocale);
    ddmFormInstance.setDescriptionMap(descriptionMap, defaultLocale);
    ddmFormInstance.setSettings(ddmFormValuesJSONSerializer.serialize(settingsDDMFormValues));

    DDMFormInstance updatedDDMFormInstance = ddmFormInstancePersistence.update(ddmFormInstance);

    updateWorkflowDefinitionLink(ddmFormInstance, settingsDDMFormValues, serviceContext);

    if (serviceContext.isAddGroupPermissions() || serviceContext.isAddGuestPermissions()) {

        addFormInstanceResources(ddmFormInstance, serviceContext.isAddGroupPermissions(),
                serviceContext.isAddGuestPermissions());
    } else {// w ww.j a  va2 s.  c om
        addFormInstanceResources(ddmFormInstance, serviceContext.getGroupPermissions(),
                serviceContext.getGuestPermissions());
    }

    long structureVersionId = getStructureVersionId(ddmStructureId);

    addFormInstanceVersion(structureVersionId, user, ddmFormInstance, _VERSION_DEFAULT, serviceContext);

    return updatedDDMFormInstance;
}

From source file:com.liferay.dynamic.data.mapping.service.impl.DDMStructureLocalServiceImpl.java

License:Open Source License

@Override
public DDMStructure addStructure(long userId, long groupId, long parentStructureId, long classNameId,
        String structureKey, Map<Locale, String> nameMap, Map<Locale, String> descriptionMap, DDMForm ddmForm,
        DDMFormLayout ddmFormLayout, String storageType, int type, ServiceContext serviceContext)
        throws PortalException {

    // Structure//from ww w. java  2s  . c  o  m

    User user = userLocalService.getUser(userId);

    if (Validator.isNull(structureKey)) {
        structureKey = String.valueOf(counterLocalService.increment());
    } else {
        structureKey = StringUtil.toUpperCase(structureKey.trim());
    }

    validate(groupId, parentStructureId, classNameId, structureKey, nameMap, ddmForm);

    long structureId = counterLocalService.increment();

    DDMStructure structure = ddmStructurePersistence.create(structureId);

    structure.setUuid(serviceContext.getUuid());
    structure.setGroupId(groupId);
    structure.setCompanyId(user.getCompanyId());
    structure.setUserId(user.getUserId());
    structure.setUserName(user.getFullName());
    structure.setVersionUserId(user.getUserId());
    structure.setVersionUserName(user.getFullName());
    structure.setParentStructureId(parentStructureId);
    structure.setClassNameId(classNameId);
    structure.setStructureKey(structureKey);
    structure.setVersion(DDMStructureConstants.VERSION_DEFAULT);
    structure.setDescriptionMap(descriptionMap, ddmForm.getDefaultLocale());
    structure.setNameMap(nameMap, ddmForm.getDefaultLocale());
    structure.setDefinition(ddmFormJSONSerializer.serialize(ddmForm));
    structure.setStorageType(storageType);
    structure.setType(type);

    ddmStructurePersistence.update(structure);

    // Resources

    if (serviceContext.isAddGroupPermissions() || serviceContext.isAddGuestPermissions()) {

        addStructureResources(structure, serviceContext.isAddGroupPermissions(),
                serviceContext.isAddGuestPermissions());
    } else {
        addStructureResources(structure, serviceContext.getModelPermissions());
    }

    // Structure version

    DDMStructureVersion structureVersion = addStructureVersion(user, structure,
            DDMStructureConstants.VERSION_DEFAULT, serviceContext);

    // Structure layout

    ddmStructureLayoutLocalService.addStructureLayout(userId, groupId, structureVersion.getStructureVersionId(),
            ddmFormLayout, serviceContext);

    // Data provider instance links

    addDataProviderInstanceLinks(groupId, structureId, ddmForm);

    return structure;
}

From source file:com.liferay.dynamic.data.mapping.service.impl.DDMTemplateLocalServiceImpl.java

License:Open Source License

/**
 * Adds a template with additional parameters.
 *
 * @param  userId the primary key of the template's creator/owner
 * @param  groupId the primary key of the group
 * @param  classNameId the primary key of the class name for the template's
 *         related model//  w  w w  . j a  va2s  .  c o  m
 * @param  classPK the primary key of the template's related entity
 * @param  resourceClassNameId the primary key of the class name for
 *         template's resource model
 * @param  templateKey the unique string identifying the template
 *         (optionally <code>null</code>)
 * @param  nameMap the template's locales and localized names
 * @param  descriptionMap the template's locales and localized descriptions
 * @param  type the template's type. For more information, see
 *         DDMTemplateConstants in the dynamic-data-mapping-api module.
 * @param  mode the template's mode. For more information, see
 *         DDMTemplateConstants in the dynamic-data-mapping-api module.
 * @param  language the template's script language. For more information,
 *         see DDMTemplateConstants in the dynamic-data-mapping-api module.
 * @param  script the template's script
 * @param  cacheable whether the template is cacheable
 * @param  smallImage whether the template has a small image
 * @param  smallImageURL the template's small image URL (optionally
 *         <code>null</code>)
 * @param  smallImageFile the template's small image file (optionally
 *         <code>null</code>)
 * @param  serviceContext the service context to be applied. Can set the
 *         UUID, creation date, modification date, guest permissions, and
 *         group permissions for the template.
 * @return the template
 * @throws PortalException if a portal exception occurred
 */
@Override
public DDMTemplate addTemplate(long userId, long groupId, long classNameId, long classPK,
        long resourceClassNameId, String templateKey, Map<Locale, String> nameMap,
        Map<Locale, String> descriptionMap, String type, String mode, String language, String script,
        boolean cacheable, boolean smallImage, String smallImageURL, File smallImageFile,
        ServiceContext serviceContext) throws PortalException {

    // Template

    User user = userLocalService.getUser(userId);

    if (Validator.isNull(templateKey)) {
        templateKey = String.valueOf(counterLocalService.increment());
    } else {
        templateKey = StringUtil.toUpperCase(templateKey.trim());
    }

    script = formatScript(type, language, script);

    byte[] smallImageBytes = null;

    if (smallImage) {
        try {
            smallImageBytes = FileUtil.getBytes(smallImageFile);
        } catch (IOException ioe) {
        }

        if ((smallImageBytes == null) || Validator.isUrl(smallImageURL)) {
            smallImage = false;
        }
    }

    validate(groupId, classNameId, templateKey, nameMap, script, smallImage, smallImageURL, smallImageFile,
            smallImageBytes);

    long templateId = counterLocalService.increment();

    DDMTemplate template = ddmTemplatePersistence.create(templateId);

    template.setUuid(serviceContext.getUuid());
    template.setGroupId(groupId);
    template.setCompanyId(user.getCompanyId());
    template.setUserId(user.getUserId());
    template.setUserName(user.getFullName());
    template.setVersionUserId(user.getUserId());
    template.setVersionUserName(user.getFullName());
    template.setClassNameId(classNameId);
    template.setClassPK(classPK);
    template.setResourceClassNameId(resourceClassNameId);
    template.setTemplateKey(templateKey);
    template.setVersion(DDMTemplateConstants.VERSION_DEFAULT);
    template.setNameMap(nameMap);
    template.setDescriptionMap(descriptionMap);
    template.setType(type);
    template.setMode(mode);
    template.setLanguage(language);
    template.setScript(script);
    template.setCacheable(cacheable);
    template.setSmallImage(smallImage);
    template.setSmallImageId(counterLocalService.increment());
    template.setSmallImageURL(smallImageURL);

    ddmTemplatePersistence.update(template);

    // Resources

    if (serviceContext.isAddGroupPermissions() || serviceContext.isAddGuestPermissions()) {

        addTemplateResources(template, serviceContext.isAddGroupPermissions(),
                serviceContext.isAddGuestPermissions());
    } else {
        addTemplateResources(template, serviceContext.getModelPermissions());
    }

    // Small image

    saveImages(smallImage, template.getSmallImageId(), smallImageFile, smallImageBytes);

    // Template version

    addTemplateVersion(user, template, DDMTemplateConstants.VERSION_DEFAULT, serviceContext);

    return template;
}

From source file:com.liferay.journal.service.impl.JournalArticleLocalServiceImpl.java

License:Open Source License

/**
 * Adds a web content article with additional parameters.
 *
 * <p>//from   w w  w  .  ja  v a2 s.c o  m
 * The web content articles hold HTML content wrapped in XML. The XML lets
 * you specify the article's default locale and available locales. Here is a
 * content example:
 * </p>
 *
 * <p>
 * <pre>
 * <code>
 * &lt;?xml version='1.0' encoding='UTF-8'?&gt;
 * &lt;root default-locale="en_US" available-locales="en_US"&gt;
 *    &lt;static-content language-id="en_US"&gt;
 *       &lt;![CDATA[&lt;p&gt;&lt;b&gt;&lt;i&gt;test&lt;i&gt; content&lt;b&gt;&lt;/p&gt;]]&gt;
 *    &lt;/static-content&gt;
 * &lt;/root&gt;
 * </code>
 * </pre>
 * </p>
 *
 * @param  userId the primary key of the web content article's creator/owner
 * @param  groupId the primary key of the web content article's group
 * @param  folderId the primary key of the web content article folder
 * @param  classNameId the primary key of the DDMStructure class if the web
 *         content article is related to a DDM structure, the primary key of
 *         the class name associated with the article, or
 *         JournalArticleConstants.CLASSNAME_ID_DEFAULT in the journal-api
 *         module otherwise
 * @param  classPK the primary key of the DDM structure, if the primary key
 *         of the DDMStructure class is given as the
 *         <code>classNameId</code> parameter, the primary key of the class
 *         associated with the web content article, or <code>0</code>
 *         otherwise
 * @param  articleId the primary key of the web content article
 * @param  autoArticleId whether to auto generate the web content article ID
 * @param  version the web content article's version
 * @param  titleMap the web content article's locales and localized titles
 * @param  descriptionMap the web content article's locales and localized
 *         descriptions
 * @param  content the HTML content wrapped in XML
 * @param  ddmStructureKey the primary key of the web content article's DDM
 *         structure, if the article is related to a DDM structure, or
 *         <code>null</code> otherwise
 * @param  ddmTemplateKey the primary key of the web content article's DDM
 *         template
 * @param  layoutUuid the unique string identifying the web content
 *         article's display page
 * @param  displayDateMonth the month the web content article is set to
 *         display
 * @param  displayDateDay the calendar day the web content article is set to
 *         display
 * @param  displayDateYear the year the web content article is set to
 *         display
 * @param  displayDateHour the hour the web content article is set to
 *         display
 * @param  displayDateMinute the minute the web content article is set to
 *         display
 * @param  expirationDateMonth the month the web content article is set to
 *         expire
 * @param  expirationDateDay the calendar day the web content article is set
 *         to expire
 * @param  expirationDateYear the year the web content article is set to
 *         expire
 * @param  expirationDateHour the hour the web content article is set to
 *         expire
 * @param  expirationDateMinute the minute the web content article is set to
 *         expire
 * @param  neverExpire whether the web content article is not set to auto
 *         expire
 * @param  reviewDateMonth the month the web content article is set for
 *         review
 * @param  reviewDateDay the calendar day the web content article is set for
 *         review
 * @param  reviewDateYear the year the web content article is set for review
 * @param  reviewDateHour the hour the web content article is set for review
 * @param  reviewDateMinute the minute the web content article is set for
 *         review
 * @param  neverReview whether the web content article is not set for review
 * @param  indexable whether the web content article is searchable
 * @param  smallImage whether the web content article has a small image
 * @param  smallImageURL the web content article's small image URL
 * @param  smallImageFile the web content article's small image file
 * @param  images the web content's images
 * @param  articleURL the web content article's accessible URL
 * @param  serviceContext the service context to be applied. Can set the
 *         UUID, creation date, modification date, expando bridge
 *         attributes, guest permissions, group permissions, asset category
 *         IDs, asset tag names, asset link entry IDs, URL title, and
 *         workflow actions for the web content article. Can also set
 *         whether to add the default guest and group permissions.
 * @return the web content article
 */
@Indexable(type = IndexableType.REINDEX)
@Override
public JournalArticle addArticle(long userId, long groupId, long folderId, long classNameId, long classPK,
        String articleId, boolean autoArticleId, double version, Map<Locale, String> titleMap,
        Map<Locale, String> descriptionMap, String content, String ddmStructureKey, String ddmTemplateKey,
        String layoutUuid, int displayDateMonth, int displayDateDay, int displayDateYear, int displayDateHour,
        int displayDateMinute, int expirationDateMonth, int expirationDateDay, int expirationDateYear,
        int expirationDateHour, int expirationDateMinute, boolean neverExpire, int reviewDateMonth,
        int reviewDateDay, int reviewDateYear, int reviewDateHour, int reviewDateMinute, boolean neverReview,
        boolean indexable, boolean smallImage, String smallImageURL, File smallImageFile,
        Map<String, byte[]> images, String articleURL, ServiceContext serviceContext) throws PortalException {

    // Article

    User user = userLocalService.getUser(userId);
    articleId = StringUtil.toUpperCase(StringUtil.trim(articleId));

    Date displayDate = null;
    Date expirationDate = null;
    Date reviewDate = null;

    if (classNameId == JournalArticleConstants.CLASSNAME_ID_DEFAULT) {
        displayDate = PortalUtil.getDate(displayDateMonth, displayDateDay, displayDateYear, displayDateHour,
                displayDateMinute, user.getTimeZone(), null);

        if (!neverExpire) {
            expirationDate = PortalUtil.getDate(expirationDateMonth, expirationDateDay, expirationDateYear,
                    expirationDateHour, expirationDateMinute, user.getTimeZone(),
                    ArticleExpirationDateException.class);
        }

        if (!neverReview) {
            reviewDate = PortalUtil.getDate(reviewDateMonth, reviewDateDay, reviewDateYear, reviewDateHour,
                    reviewDateMinute, user.getTimeZone(), ArticleReviewDateException.class);
        }
    }

    byte[] smallImageBytes = null;

    try {
        smallImageBytes = FileUtil.getBytes(smallImageFile);
    } catch (IOException ioe) {
    }

    Date now = new Date();

    validateDDMStructureId(groupId, folderId, ddmStructureKey);

    if (autoArticleId) {
        articleId = String.valueOf(counterLocalService.increment());
    }

    validate(user.getCompanyId(), groupId, classNameId, articleId, autoArticleId, version, titleMap, content,
            ddmStructureKey, ddmTemplateKey, displayDate, expirationDate, smallImage, smallImageURL,
            smallImageFile, smallImageBytes, serviceContext);

    validateReferences(groupId, ddmStructureKey, ddmTemplateKey, layoutUuid, smallImage, smallImageURL,
            smallImageBytes, 0, content);

    serviceContext.setAttribute("articleId", articleId);

    long id = counterLocalService.increment();

    String articleResourceUuid = GetterUtil.getString(serviceContext.getAttribute("articleResourceUuid"));

    long resourcePrimKey = journalArticleResourceLocalService.getArticleResourcePrimKey(articleResourceUuid,
            groupId, articleId);

    JournalArticle article = journalArticlePersistence.create(id);

    Locale locale = getArticleDefaultLocale(content);

    String title = titleMap.get(locale);

    article.setUuid(serviceContext.getUuid());
    article.setResourcePrimKey(resourcePrimKey);
    article.setGroupId(groupId);
    article.setCompanyId(user.getCompanyId());
    article.setUserId(user.getUserId());
    article.setUserName(user.getFullName());
    article.setFolderId(folderId);
    article.setClassNameId(classNameId);
    article.setClassPK(classPK);
    article.setTreePath(article.buildTreePath());
    article.setArticleId(articleId);
    article.setVersion(version);
    article.setUrlTitle(getUniqueUrlTitle(id, groupId, articleId, title, null, serviceContext));

    content = format(user, groupId, article, content);

    article.setContent(content);

    article.setDDMStructureKey(ddmStructureKey);
    article.setDDMTemplateKey(ddmTemplateKey);
    article.setDefaultLanguageId(LocaleUtil.toLanguageId(locale));
    article.setLayoutUuid(layoutUuid);
    article.setDisplayDate(displayDate);
    article.setExpirationDate(expirationDate);
    article.setReviewDate(reviewDate);
    article.setIndexable(indexable);
    article.setSmallImage(smallImage);
    article.setSmallImageId(counterLocalService.increment());
    article.setSmallImageURL(smallImageURL);

    if ((expirationDate == null) || expirationDate.after(now)) {
        article.setStatus(WorkflowConstants.STATUS_DRAFT);
    } else {
        article.setStatus(WorkflowConstants.STATUS_EXPIRED);
    }

    article.setStatusByUserId(userId);
    article.setStatusDate(serviceContext.getModifiedDate(now));
    article.setExpandoBridgeAttributes(serviceContext);

    journalArticlePersistence.update(article);

    // Article localization

    _addArticleLocalizedFields(user.getCompanyId(), article.getId(), titleMap, descriptionMap);

    // Resources

    if (serviceContext.isAddGroupPermissions() || serviceContext.isAddGuestPermissions()) {

        addArticleResources(article, serviceContext.isAddGroupPermissions(),
                serviceContext.isAddGuestPermissions());
    } else {
        addArticleResources(article, serviceContext.getGroupPermissions(),
                serviceContext.getGuestPermissions());
    }

    // Small image

    saveImages(smallImage, article.getSmallImageId(), smallImageFile, smallImageBytes);

    // Asset

    updateAsset(userId, article, serviceContext.getAssetCategoryIds(), serviceContext.getAssetTagNames(),
            serviceContext.getAssetLinkEntryIds(), serviceContext.getAssetPriority());

    // Dynamic data mapping

    if (classNameLocalService.getClassNameId(DDMStructure.class) == classNameId) {

        updateDDMStructurePredefinedValues(classPK, content, serviceContext);
    } else {
        updateDDMLinks(id, groupId, ddmStructureKey, ddmTemplateKey, true);
    }

    // Email

    PortletPreferences preferences = ServiceContextUtil.getPortletPreferences(serviceContext);

    articleURL = buildArticleURL(articleURL, groupId, folderId, articleId);

    serviceContext.setAttribute("articleURL", articleURL);

    sendEmail(article, articleURL, preferences, "requested", serviceContext);

    // Workflow

    if (classNameId == JournalArticleConstants.CLASSNAME_ID_DEFAULT) {
        startWorkflowInstance(userId, article, serviceContext);
    } else {
        updateStatus(userId, article, WorkflowConstants.STATUS_APPROVED, null, serviceContext,
                new HashMap<String, Serializable>());
    }

    return journalArticlePersistence.findByPrimaryKey(article.getId());
}

From source file:com.liferay.journal.service.impl.JournalFeedLocalServiceImpl.java

License:Open Source License

@Override
public JournalFeed addFeed(long userId, long groupId, String feedId, boolean autoFeedId, String name,
        String description, String ddmStructureKey, String ddmTemplateKey, String ddmRendererTemplateKey,
        int delta, String orderByCol, String orderByType, String targetLayoutFriendlyUrl,
        String targetPortletId, String contentField, String feedFormat, double feedVersion,
        ServiceContext serviceContext) throws PortalException {

    // Feed//from  w w  w  .  j av  a 2  s .  com

    User user = userLocalService.getUser(userId);
    feedId = StringUtil.toUpperCase(StringUtil.trim(feedId));

    validate(user.getCompanyId(), groupId, feedId, autoFeedId, name, ddmStructureKey, targetLayoutFriendlyUrl,
            contentField);

    if (autoFeedId) {
        feedId = String.valueOf(counterLocalService.increment());
    }

    long id = counterLocalService.increment();

    JournalFeed feed = journalFeedPersistence.create(id);

    feed.setUuid(serviceContext.getUuid());
    feed.setGroupId(groupId);
    feed.setCompanyId(user.getCompanyId());
    feed.setUserId(user.getUserId());
    feed.setUserName(user.getFullName());
    feed.setFeedId(feedId);
    feed.setName(name);
    feed.setDescription(description);
    feed.setDDMStructureKey(ddmStructureKey);
    feed.setDDMTemplateKey(ddmTemplateKey);
    feed.setDDMRendererTemplateKey(ddmRendererTemplateKey);
    feed.setDelta(delta);
    feed.setOrderByCol(orderByCol);
    feed.setOrderByType(orderByType);
    feed.setTargetLayoutFriendlyUrl(targetLayoutFriendlyUrl);
    feed.setTargetPortletId(targetPortletId);
    feed.setContentField(contentField);

    if (Validator.isNull(feedFormat)) {
        feed.setFeedFormat(RSSUtil.FORMAT_DEFAULT);
        feed.setFeedVersion(RSSUtil.VERSION_DEFAULT);
    } else {
        feed.setFeedFormat(feedFormat);
        feed.setFeedVersion(feedVersion);
    }

    feed.setExpandoBridgeAttributes(serviceContext);

    journalFeedPersistence.update(feed);

    // Resources

    if (serviceContext.isAddGroupPermissions() || serviceContext.isAddGuestPermissions()) {

        addFeedResources(feed, serviceContext.isAddGroupPermissions(), serviceContext.isAddGuestPermissions());
    } else {
        addFeedResources(feed, serviceContext.getGroupPermissions(), serviceContext.getGuestPermissions());
    }

    return feed;
}

From source file:com.liferay.wiki.service.impl.WikiNodeLocalServiceImpl.java

License:Open Source License

@Override
public WikiNode addNode(long userId, String name, String description, ServiceContext serviceContext)
        throws PortalException {

    // Node/*from  ww w. ja  v  a 2  s  . c  o m*/

    User user = userPersistence.findByPrimaryKey(userId);
    long groupId = serviceContext.getScopeGroupId();

    validate(groupId, name);

    long nodeId = counterLocalService.increment();

    WikiNode node = wikiNodePersistence.create(nodeId);

    node.setUuid(serviceContext.getUuid());
    node.setGroupId(groupId);
    node.setCompanyId(user.getCompanyId());
    node.setUserId(user.getUserId());
    node.setUserName(user.getFullName());
    node.setName(name);
    node.setDescription(description);

    try {
        wikiNodePersistence.update(node);
    } catch (SystemException se) {
        if (_log.isWarnEnabled()) {
            _log.warn("Add failed, fetch {groupId=" + groupId + ", name=" + name + "}");
        }

        node = wikiNodePersistence.fetchByG_N(groupId, name, false);

        if (node == null) {
            throw se;
        }

        return node;
    }

    // Resources

    if (serviceContext.isAddGroupPermissions() || serviceContext.isAddGuestPermissions()) {

        addNodeResources(node, serviceContext.isAddGroupPermissions(), serviceContext.isAddGuestPermissions());
    } else {
        addNodeResources(node, serviceContext.getGroupPermissions(), serviceContext.getGuestPermissions());
    }

    return node;
}