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

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

Introduction

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

Prototype

public String[] getAssetTagNames() 

Source Link

Document

Returns the asset tag names to be applied to an asset entry if the service context is being passed as a parameter to a method which manipulates the asset entry.

Usage

From source file:ch.inofix.contact.service.impl.ContactLocalServiceImpl.java

License:Open Source License

@Override
@Indexable(type = IndexableType.REINDEX)
public Contact addContact(long userId, String card, String uid, ServiceContext serviceContext)
        throws PortalException {

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

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

    // TODO
    // validate();

    long contactId = counterLocalService.increment();

    Contact contact = contactPersistence.create(contactId);

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

    contact.setCard(card);
    contact.setUid(uid);

    contact = contactPersistence.update(contact);

    // Resources

    resourceLocalService.addModelResources(contact, serviceContext);

    // Asset

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

    // Social

    JSONObject extraDataJSONObject = JSONFactoryUtil.createJSONObject();

    // TODO
    // extraDataJSONObject.put("title", contact.getName());

    socialActivityLocalService.addActivity(userId, groupId, Contact.class.getName(), contactId,
            ContactActivityKeys.ADD_CONTACT, extraDataJSONObject.toString(), 0);

    return contact;
}

From source file:ch.inofix.contact.service.impl.ContactLocalServiceImpl.java

License:Open Source License

@Override
@Indexable(type = IndexableType.REINDEX)
public Contact updateContact(long userId, long contactId, String card, String uid,
        ServiceContext serviceContext) throws PortalException {

    // Contact//from   www  . j  a v a  2  s.  c o  m

    long groupId = serviceContext.getScopeGroupId();

    Contact contact = contactPersistence.findByPrimaryKey(contactId);

    // TODO: validate the vCard string

    contact.setGroupId(groupId);
    contact.setExpandoBridgeAttributes(serviceContext);
    contact.setCard(card);

    contactPersistence.update(contact);

    // Asset

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

    // Social

    JSONObject extraDataJSONObject = JSONFactoryUtil.createJSONObject();

    // extraDataJSONObject.put("title", contact.getName());

    socialActivityLocalService.addActivity(userId, groupId, Contact.class.getName(), contact.getContactId(),
            ContactActivityKeys.UPDATE_CONTACT, extraDataJSONObject.toString(), 0);

    return contact;
}

From source file:ch.inofix.referencemanager.service.impl.BibliographyLocalServiceImpl.java

License:Open Source License

@Indexable(type = IndexableType.REINDEX)
@Override/*from  ww  w  .  ja v  a 2  s. c o  m*/
public Bibliography addBibliography(long userId, String title, String description, String urlTitle,
        String comments, String preamble, String strings, ServiceContext serviceContext)
        throws PortalException {

    // Bibliography

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

    validate(groupId, urlTitle);

    long bibliographyId = counterLocalService.increment();

    Bibliography bibliography = bibliographyPersistence.create(bibliographyId);

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

    bibliography.setTitle(title);
    bibliography.setDescription(description);
    bibliography.setUrlTitle(urlTitle);
    bibliography.setComments(comments);
    bibliography.setPreamble(preamble);
    bibliography.setStrings(strings);

    bibliographyPersistence.update(bibliography);

    // Resources

    resourceLocalService.addModelResources(bibliography, serviceContext);

    // Asset

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

    // Social

    JSONObject extraDataJSONObject = JSONFactoryUtil.createJSONObject();

    extraDataJSONObject.put("title", bibliography.getTitle());

    socialActivityLocalService.addActivity(userId, groupId, Bibliography.class.getName(), bibliographyId,
            BibliographyActivityKeys.ADD_BIBLIOGRAPHY, extraDataJSONObject.toString(), 0);

    return bibliography;

}

From source file:ch.inofix.referencemanager.service.impl.BibliographyLocalServiceImpl.java

License:Open Source License

@Indexable(type = IndexableType.REINDEX)
public Bibliography updateBibliography(long bibliographyId, long userId, String title, String description,
        String urlTitle, String comments, String preamble, String strings, ServiceContext serviceContext)
        throws PortalException {

    // Bibliography

    User user = userPersistence.findByPrimaryKey(userId);

    Bibliography bibliography = bibliographyPersistence.findByPrimaryKey(bibliographyId);

    long groupId = serviceContext.getScopeGroupId();

    if (!bibliography.getUrlTitle().equals(urlTitle)) {

        // modified urlTitle

        validate(groupId, urlTitle);/*from w ww.  j  a  v a 2  s  .  co m*/
    }

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

    bibliography.setTitle(title);
    bibliography.setDescription(description);
    bibliography.setUrlTitle(urlTitle);
    bibliography.setComments(comments);
    bibliography.setPreamble(preamble);
    bibliography.setStrings(strings);

    bibliographyPersistence.update(bibliography);

    // Resources

    resourceLocalService.addModelResources(bibliography, serviceContext);

    // Asset

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

    // Social

    JSONObject extraDataJSONObject = JSONFactoryUtil.createJSONObject();

    extraDataJSONObject.put("title", bibliography.getTitle());

    socialActivityLocalService.addActivity(userId, groupId, Bibliography.class.getName(), bibliographyId,
            BibliographyActivityKeys.UPDATE_BIBLIOGRAPHY, extraDataJSONObject.toString(), 0);

    return bibliography;

}

From source file:ch.inofix.referencemanager.service.impl.ReferenceLocalServiceImpl.java

License:Open Source License

@Indexable(type = IndexableType.REINDEX)
@Override//from  ww  w  .j a  v  a  2s  .co  m
public Reference addReference(long userId, String bibTeX, long[] bibliographyIds, ServiceContext serviceContext)
        throws PortalException {

    // Reference

    User user = userPersistence.findByPrimaryKey(userId);

    long groupId = serviceContext.getScopeGroupId();

    long companyId = user.getCompanyId();

    long referenceId = counterLocalService.increment();

    Reference reference = referencePersistence.create(referenceId);

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

    BibTeXEntry bibTeXEntry = BibTeXUtil.getBibTeXEntry(bibTeX);
    if (bibTeXEntry != null) {
        Key key = new Key("bibshare-id");
        Value value = new StringValue(String.valueOf(referenceId), Style.QUOTED);
        bibTeXEntry.addField(key, value);
    } else {
        // TODO: raise an error and report to the user that something is
        // wrong with the bibtex-src.
    }

    bibTeX = BibTeXUtil.format(bibTeXEntry);

    reference.setBibTeX(bibTeX);

    referencePersistence.update(reference);

    // Match user and group references against common references

    long defaultGroupId = GetterUtil.getLong(PropsUtil.get("default.group.id"));

    if (reference.getGroupId() != defaultGroupId) {

        match(reference);

    }

    // BibRefRelation

    for (long bibliographyId : bibliographyIds) {

        Bibliography bibliography = bibliographyLocalService.getBibliography(bibliographyId);

        long bibRefRelationId = counterLocalService.increment();
        BibRefRelation bibRefRelation = bibRefRelationPersistence.create(bibRefRelationId);

        bibRefRelation.setGroupId(bibliography.getGroupId());
        bibRefRelation.setCompanyId(bibliography.getCompanyId());
        bibRefRelation.setUserId(bibliography.getUserId());
        bibRefRelation.setUserName(bibliography.getUserName());

        bibRefRelation.setBibliographyId(bibliography.getBibliographyId());
        bibRefRelation.setReferenceId(referenceId);

        bibRefRelationPersistence.update(bibRefRelation);

    }

    // Resources

    resourceLocalService.addModelResources(reference, serviceContext);

    // Asset

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

    // Social

    JSONObject extraDataJSONObject = JSONFactoryUtil.createJSONObject();

    extraDataJSONObject.put("title", reference.getCitation());

    socialActivityLocalService.addActivity(userId, groupId, Reference.class.getName(), referenceId,
            ReferenceActivityKeys.ADD_REFERENCE, extraDataJSONObject.toString(), 0);

    return reference;

}

From source file:ch.inofix.referencemanager.service.impl.ReferenceLocalServiceImpl.java

License:Open Source License

@Indexable(type = IndexableType.REINDEX)
public Reference updateReference(long referenceId, long userId, String bibTeX, long[] bibliographyIds,
        ServiceContext serviceContext) throws PortalException {

    // Reference//w w  w  .  java 2  s.  co  m

    User user = userPersistence.findByPrimaryKey(userId);

    Reference reference = referencePersistence.findByPrimaryKey(referenceId);
    long groupId = serviceContext.getScopeGroupId();
    long companyId = user.getCompanyId();

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

    BibTeXEntry bibTeXEntry = BibTeXUtil.getBibTeXEntry(bibTeX);
    if (bibTeXEntry != null) {
        Key key = new Key("bibshare-last-modified");
        Value value = new StringValue(String.valueOf(new Date().getTime()), Style.QUOTED);
        bibTeXEntry.addField(key, value);
    } else {
        // TODO: raise an error and report to the user that something is
        // wrong with the bibtex-src.
    }

    bibTeX = BibTeXUtil.format(bibTeXEntry);

    reference.setBibTeX(bibTeX);

    reference = referencePersistence.update(reference);

    // Match user and group references against common references

    long defaultGroupId = GetterUtil.getLong(PropsUtil.get("default.group.id"));

    if (reference.getGroupId() != defaultGroupId) {
        match(reference);
    }

    // BibRefRelation

    for (long bibliographyId : bibliographyIds) {

        Bibliography bibliography = bibliographyLocalService.getBibliography(bibliographyId);

        long bibRefRelationId = counterLocalService.increment();
        BibRefRelation bibRefRelation = bibRefRelationPersistence.create(bibRefRelationId);

        bibRefRelation.setGroupId(bibliography.getGroupId());
        bibRefRelation.setCompanyId(bibliography.getCompanyId());
        bibRefRelation.setUserId(bibliography.getUserId());
        bibRefRelation.setUserName(bibliography.getUserName());

        bibRefRelation.setBibliographyId(bibliography.getBibliographyId());
        bibRefRelation.setReferenceId(referenceId);

        bibRefRelationPersistence.update(bibRefRelation);

    }

    // Resources

    resourceLocalService.addModelResources(reference, serviceContext);

    // Asset

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

    // Social

    JSONObject extraDataJSONObject = JSONFactoryUtil.createJSONObject();

    extraDataJSONObject.put("title", reference.getCitation());

    socialActivityLocalService.addActivity(userId, groupId, Reference.class.getName(), referenceId,
            ReferenceActivityKeys.UPDATE_REFERENCE, extraDataJSONObject.toString(), 0);

    return reference;

}

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/*ww w . j a v a  2s  .  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:ch.inofix.timetracker.service.impl.TaskRecordLocalServiceImpl.java

License:Open Source License

@Override
@Indexable(type = IndexableType.REINDEX)
public TaskRecord updateTaskRecord(long taskRecordId, 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);

    TaskRecord taskRecord = taskRecordPersistence.findByPrimaryKey(taskRecordId);

    long groupId = serviceContext.getScopeGroupId();

    // TODO: validate taskRecord

    taskRecord.setUuid(serviceContext.getUuid());
    taskRecord.setGroupId(groupId);//  w w w.j a  va2 s.  c o m
    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);

    taskRecordPersistence.update(taskRecord);

    // Resources

    resourceLocalService.addModelResources(taskRecord, serviceContext);

    // Asset

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

    return taskRecord;

}

From source file:com.bemis.portal.fileuploader.service.impl.FileUploaderLocalServiceImpl.java

License:Open Source License

/**
 * Uploads the file into the destination folder
 * If the file does not exist, adds the file. If exists, updates the existing file
 * Adds tags and categories to documents
 *
 * @param file//from ww  w.  ja va 2  s .  c om
 * @param fileDescription
 * @param fileName
 * @param changeLog
 * @param serviceContext
 * @return FileEntry
 * @throws PortalException
 */
public FileEntry uploadFile(File file, String fileDescription, String fileName, String changeLog,
        ServiceContext serviceContext) throws PortalException {

    if (_log.isDebugEnabled()) {
        _log.debug("Invoking uploadFile....");
    }

    long companyId = serviceContext.getCompanyId();
    long groupId = serviceContext.getScopeGroupId();
    long userId = serviceContext.getUserId();

    // see https://issues.liferay.com/browse/LPS-66607

    User user = userLocalService.getUser(userId);

    // Check permissions

    _fileUploadHelper.checkPermission(companyId, groupId, userId);

    String title = FilenameUtils.removeExtension(fileName);

    long folderId = GetterUtil.getLong(serviceContext.getAttribute(DESTINATION_FOLDER_ID));

    fileName = file.getName();

    String mimeType = MimeTypesUtil.getContentType(fileName);

    boolean majorVersion = true;

    DLFileEntry dlFileEntry = _dlFileEntryLocalService.fetchFileEntry(groupId, folderId, title);

    FileEntry fileEntry = null;

    if (Validator.isNull(dlFileEntry)) {
        fileEntry = addFileEntry(userId, groupId, folderId, fileName, mimeType, title, fileDescription,
                changeLog, file, serviceContext);
    } else {
        fileEntry = updateFileEntry(userId, dlFileEntry, fileName, mimeType, title, fileDescription, changeLog,
                majorVersion, file, serviceContext);
    }

    FileVersion fileVersion = fileEntry.getFileVersion();

    long[] assetCategoryIds = _fileUploadHelper.getAssetCategoryIds(groupId, title, serviceContext);

    String[] assetTagNames = serviceContext.getAssetTagNames();

    if (_log.isDebugEnabled()) {
        _log.debug(">>> Updating FileEntry with tags and categories");
    }

    _dlAppLocalService.updateAsset(userId, fileEntry, fileVersion, assetCategoryIds, assetTagNames, null);

    // Post processing uploaded file

    _fileUploadHelper.postProcessUpload(file, fileEntry.getFileEntryId(), serviceContext);

    return fileEntry;
}

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

License:Open Source License

@Indexable(type = IndexableType.REINDEX)
@Override/*from   w  w  w . j a  v  a  2s  . 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);
}