use of com.liferay.portal.service.ServiceContext in project liferay-ide by liferay.
the class EditorPortlet method serveUpdateFileEntryContent.
protected void serveUpdateFileEntryContent(ResourceRequest resourceRequest, ResourceResponse resourceResponse) throws Exception {
long fileEntryId = ParamUtil.getLong(resourceRequest, "fileEntryId");
FileEntry fileEntry = DLAppServiceUtil.getFileEntry(fileEntryId);
String content = ParamUtil.getString(resourceRequest, "content");
byte[] bytes = content.getBytes(StringPool.UTF8);
ServiceContext serviceContext = ServiceContextFactory.getInstance(resourceRequest);
DLAppServiceUtil.updateFileEntry(fileEntryId, fileEntry.getTitle(), resourceRequest.getContentType(), fileEntry.getTitle(), fileEntry.getDescription(), StringPool.BLANK, false, bytes, serviceContext);
JSONObject jsonObject = JSONFactoryUtil.createJSONObject();
writeJSON(resourceRequest, resourceResponse, jsonObject);
}
use of com.liferay.portal.service.ServiceContext in project liferay-ide by liferay.
the class ShindigUtil method getGadgetEditorRootFolder.
public static Folder getGadgetEditorRootFolder(long repositoryId) throws Exception {
Folder folder = null;
try {
folder = DLAppServiceUtil.getFolder(repositoryId, DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, _GADGET_EDITOR_ROOT_FOLDER_NAME);
} catch (Exception e) {
}
if (folder == null) {
ServiceContext serviceContext = new ServiceContext();
serviceContext.setGroupPermissions(new String[] { ActionKeys.ADD_DOCUMENT, ActionKeys.DELETE, ActionKeys.UPDATE, ActionKeys.VIEW });
serviceContext.setGuestPermissions(new String[] { ActionKeys.VIEW });
serviceContext.setScopeGroupId(repositoryId);
folder = DLAppServiceUtil.addFolder(repositoryId, DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, _GADGET_EDITOR_ROOT_FOLDER_NAME, StringPool.BLANK, serviceContext);
}
return folder;
}
use of com.liferay.portal.service.ServiceContext in project liferay-ide by liferay.
the class KBArticleStagedModelDataHandler method doImportStagedModel.
@Override
protected void doImportStagedModel(PortletDataContext portletDataContext, KBArticle kbArticle) throws Exception {
long userId = portletDataContext.getUserId(kbArticle.getUserUuid());
if (kbArticle.getParentResourcePrimKey() != KBFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
if (kbArticle.getClassNameId() == kbArticle.getParentResourceClassNameId()) {
StagedModelDataHandlerUtil.importReferenceStagedModels(portletDataContext, kbArticle, KBArticle.class);
} else {
StagedModelDataHandlerUtil.importReferenceStagedModels(portletDataContext, kbArticle, KBFolder.class);
}
}
Map<Long, Long> kbArticleResourcePrimKeys = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(KBArticle.class);
long parentResourcePrimKey = MapUtil.getLong(kbArticleResourcePrimKeys, kbArticle.getParentResourcePrimKey(), KBFolderConstants.DEFAULT_PARENT_FOLDER_ID);
long resourcePrimaryKey = MapUtil.getLong(kbArticleResourcePrimKeys, kbArticle.getResourcePrimKey(), 0);
if (parentResourcePrimKey == KBFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
Map<Long, Long> kbFolderResourcePrimKeys = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(KBFolder.class);
parentResourcePrimKey = MapUtil.getLong(kbFolderResourcePrimKeys, kbArticle.getParentResourcePrimKey(), KBFolderConstants.DEFAULT_PARENT_FOLDER_ID);
}
String[] sections = AdminUtil.unescapeSections(kbArticle.getSections());
ServiceContext serviceContext = portletDataContext.createServiceContext(kbArticle);
KBArticle importedKBArticle = null;
if (portletDataContext.isDataStrategyMirror()) {
KBArticle existingKBArticle = KBArticleUtil.fetchByR_V(resourcePrimaryKey, kbArticle.getVersion());
if (existingKBArticle == null) {
existingKBArticle = KBArticleUtil.fetchByUUID_G(kbArticle.getUuid(), portletDataContext.getScopeGroupId());
}
if (existingKBArticle == null) {
serviceContext.setUuid(kbArticle.getUuid());
existingKBArticle = KBArticleLocalServiceUtil.fetchLatestKBArticle(resourcePrimaryKey, WorkflowConstants.STATUS_ANY);
if (existingKBArticle == null) {
importedKBArticle = KBArticleLocalServiceUtil.addKBArticle(userId, kbArticle.getParentResourceClassNameId(), parentResourcePrimKey, kbArticle.getTitle(), kbArticle.getUrlTitle(), kbArticle.getContent(), kbArticle.getDescription(), kbArticle.getSourceURL(), sections, null, serviceContext);
KBArticleLocalServiceUtil.updatePriority(importedKBArticle.getResourcePrimKey(), kbArticle.getPriority());
} else {
KBArticleLocalServiceUtil.updateKBArticle(userId, existingKBArticle.getResourcePrimKey(), kbArticle.getTitle(), kbArticle.getContent(), kbArticle.getDescription(), kbArticle.getSourceURL(), sections, null, null, serviceContext);
KBArticleLocalServiceUtil.moveKBArticle(userId, existingKBArticle.getResourcePrimKey(), existingKBArticle.getParentResourceClassNameId(), parentResourcePrimKey, kbArticle.getPriority());
importedKBArticle = KBArticleLocalServiceUtil.getLatestKBArticle(existingKBArticle.getResourcePrimKey(), WorkflowConstants.STATUS_APPROVED);
}
} else {
importedKBArticle = existingKBArticle;
}
} else {
importedKBArticle = KBArticleLocalServiceUtil.addKBArticle(userId, kbArticle.getParentResourceClassNameId(), parentResourcePrimKey, kbArticle.getTitle(), kbArticle.getUrlTitle(), kbArticle.getContent(), kbArticle.getDescription(), kbArticle.getSourceURL(), sections, null, serviceContext);
KBArticleLocalServiceUtil.updatePriority(importedKBArticle.getResourcePrimKey(), kbArticle.getPriority());
}
importKBArticleAttachments(portletDataContext, kbArticle, importedKBArticle);
portletDataContext.importClassedModel(kbArticle, importedKBArticle);
if (!kbArticle.isMain()) {
kbArticleResourcePrimKeys.put(kbArticle.getResourcePrimKey(), importedKBArticle.getResourcePrimKey());
}
}
use of com.liferay.portal.service.ServiceContext in project liferay-ide by liferay.
the class KBArticleWorkflowHandler method updateStatus.
@Override
public KBArticle updateStatus(int status, Map<String, Serializable> workflowContext) throws PortalException, SystemException {
long userId = GetterUtil.getLong((String) workflowContext.get(WorkflowConstants.CONTEXT_USER_ID));
long resourcePrimKey = GetterUtil.getLong((String) workflowContext.get(WorkflowConstants.CONTEXT_ENTRY_CLASS_PK));
ServiceContext serviceContext = (ServiceContext) workflowContext.get("serviceContext");
return KBArticleLocalServiceUtil.updateStatus(userId, resourcePrimKey, status, serviceContext);
}
use of com.liferay.portal.service.ServiceContext in project liferay-ide by liferay.
the class AddGoogleDocsFileEntryTypeAction method addGoogleDocsFileEntryType.
protected void addGoogleDocsFileEntryType(long userId, long groupId) throws PortalException, SystemException {
Map<Locale, String> nameMap = new HashMap<Locale, String>();
Locale locale = LocaleUtil.getDefault();
nameMap.put(locale, GoogleDocsConstants.GOOGLE_DOCS_FILE_ENTRY_TYPE_NAME);
Map<Locale, String> descriptionMap = new HashMap<Locale, String>();
descriptionMap.put(locale, GoogleDocsConstants.GOOGLE_DOCS_FILE_ENTRY_TYPE_NAME);
ServiceContext serviceContext = new ServiceContext();
Class<?> clazz = getClass();
String xsd = ContentUtil.get(clazz.getClassLoader(), "com/liferay/google/docs/hook/event/dependencies" + "/google-docs-file-entry-type-xsd.xml");
serviceContext.setAttribute("xsd", xsd);
DLFileEntryTypeLocalServiceUtil.addFileEntryType(userId, groupId, GoogleDocsConstants.GOOGLE_DOCS_FILE_ENTRY_TYPE_KEY, nameMap, descriptionMap, new long[0], serviceContext);
}
Aggregations