List of usage examples for com.liferay.portal.kernel.service ServiceContext getModelPermissions
public ModelPermissions getModelPermissions()
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 va2 s. c om*/ // 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 ww w. ja va 2 s. c o m 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.docs.guestbook.service.impl.GuestbookEntryLocalServiceImpl.java
License:Open Source License
@Indexable(type = IndexableType.REINDEX) public GuestbookEntry updateGuestbookEntry(long userId, long guestbookId, long entryId, String name, String email, String message, ServiceContext serviceContext) throws PortalException, SystemException { Date now = new Date(); validate(name, email, message);// ww w . jav a 2 s. c o m GuestbookEntry entry = guestbookEntryPersistence.findByPrimaryKey(entryId); User user = userLocalService.getUserById(userId); entry.setUserId(userId); entry.setUserName(user.getFullName()); entry.setModifiedDate(serviceContext.getModifiedDate(now)); entry.setName(name); entry.setEmail(email); entry.setMessage(message); entry.setExpandoBridgeAttributes(serviceContext); guestbookEntryPersistence.update(entry); // Integrate with Liferay frameworks here. resourceLocalService.updateResources(user.getCompanyId(), serviceContext.getScopeGroupId(), GuestbookEntry.class.getName(), entryId, serviceContext.getModelPermissions()); return entry; }
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);//w w w. j av a 2s .co 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.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. j a v a 2s . co 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//from w w w.ja va2s.co 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; }