protected void importAssetVocabulary( PortletDataContext portletDataContext, Map<Long, Long> assetVocabularyPKs, Element assetVocabularyElement, AssetVocabulary assetVocabulary) throws Exception { long userId = portletDataContext.getUserId(assetVocabulary.getUserUuid()); long groupId = portletDataContext.getScopeGroupId(); ServiceContext serviceContext = new ServiceContext(); serviceContext.setAddGroupPermissions(true); serviceContext.setAddGuestPermissions(true); serviceContext.setCreateDate(assetVocabulary.getCreateDate()); serviceContext.setModifiedDate(assetVocabulary.getModifiedDate()); serviceContext.setScopeGroupId(portletDataContext.getScopeGroupId()); AssetVocabulary importedAssetVocabulary = null; AssetVocabulary existingAssetVocabulary = AssetVocabularyUtil.fetchByG_N(groupId, assetVocabulary.getName()); if (existingAssetVocabulary == null) { Group companyGroup = GroupLocalServiceUtil.getCompanyGroup(portletDataContext.getCompanyId()); existingAssetVocabulary = AssetVocabularyUtil.fetchByG_N(companyGroup.getGroupId(), assetVocabulary.getName()); } if (existingAssetVocabulary == null) { serviceContext.setUuid(assetVocabulary.getUuid()); importedAssetVocabulary = AssetVocabularyLocalServiceUtil.addVocabulary( userId, assetVocabulary.getTitle(), getAssetVocabularyTitleMap(assetVocabulary), assetVocabulary.getDescriptionMap(), assetVocabulary.getSettings(), serviceContext); } else { importedAssetVocabulary = AssetVocabularyLocalServiceUtil.updateVocabulary( existingAssetVocabulary.getVocabularyId(), assetVocabulary.getTitle(), getAssetVocabularyTitleMap(assetVocabulary), assetVocabulary.getDescriptionMap(), assetVocabulary.getSettings(), serviceContext); } assetVocabularyPKs.put( assetVocabulary.getVocabularyId(), importedAssetVocabulary.getVocabularyId()); portletDataContext.importPermissions( AssetVocabulary.class, assetVocabulary.getVocabularyId(), importedAssetVocabulary.getVocabularyId()); }
protected ServiceContext createServiceContext( PortletDataContext portletDataContext, AssetTag assetTag) { ServiceContext serviceContext = new ServiceContext(); serviceContext.setAddGroupPermissions(true); serviceContext.setAddGuestPermissions(true); serviceContext.setCreateDate(assetTag.getCreateDate()); serviceContext.setModifiedDate(assetTag.getModifiedDate()); serviceContext.setScopeGroupId(portletDataContext.getScopeGroupId()); return serviceContext; }
/** * Returns a new service context object identical to this service context object. * * @return a new service context object */ @Override public Object clone() { ServiceContext serviceContext = new ServiceContext(); serviceContext.setAddGroupPermissions(isAddGroupPermissions()); serviceContext.setAddGuestPermissions(isAddGuestPermissions()); serviceContext.setAssetCategoryIds(getAssetCategoryIds()); serviceContext.setAssetEntryVisible(isAssetEntryVisible()); serviceContext.setAssetLinkEntryIds(getAssetLinkEntryIds()); serviceContext.setAssetTagNames(getAssetTagNames()); serviceContext.setAttributes(getAttributes()); serviceContext.setCommand(getCommand()); serviceContext.setCompanyId(getCompanyId()); serviceContext.setCreateDate(getCreateDate()); serviceContext.setCurrentURL(getCurrentURL()); serviceContext.setExpandoBridgeAttributes(getExpandoBridgeAttributes()); serviceContext.setFailOnPortalException(isFailOnPortalException()); serviceContext.setGroupPermissions(getGroupPermissions()); serviceContext.setGuestPermissions(getGuestPermissions()); serviceContext.setHeaders(getHeaders()); serviceContext.setIndexingEnabled(isIndexingEnabled()); serviceContext.setLanguageId(getLanguageId()); serviceContext.setLayoutFullURL(getLayoutFullURL()); serviceContext.setLayoutURL(getLayoutURL()); serviceContext.setModifiedDate(getModifiedDate()); serviceContext.setPathFriendlyURLPrivateGroup(getPathFriendlyURLPrivateGroup()); serviceContext.setPathFriendlyURLPrivateUser(getPathFriendlyURLPrivateUser()); serviceContext.setPathFriendlyURLPublic(getPathFriendlyURLPublic()); serviceContext.setPathMain(getPathMain()); serviceContext.setPlid(getPlid()); serviceContext.setPortalURL(getPortalURL()); serviceContext.setPortletPreferencesIds(getPortletPreferencesIds()); serviceContext.setRemoteAddr(getRemoteAddr()); serviceContext.setRemoteHost(getRemoteHost()); serviceContext.setRequest(getRequest()); serviceContext.setScopeGroupId(getScopeGroupId()); serviceContext.setSignedIn(isSignedIn()); serviceContext.setUserDisplayURL(getUserDisplayURL()); serviceContext.setUserId(getUserId()); serviceContext.setUuid(getUuid()); serviceContext.setWorkflowAction(getWorkflowAction()); return serviceContext; }
public void importRatingsEntries(Class<?> clazz, long classPK, long newClassPK) throws PortalException, SystemException { List<RatingsEntry> ratingsEntries = _ratingsEntriesMap.get(getPrimaryKeyString(clazz, classPK)); if (ratingsEntries == null) { return; } ServiceContext serviceContext = new ServiceContext(); for (RatingsEntry ratingsEntry : ratingsEntries) { long userId = getUserId(ratingsEntry.getUserUuid()); serviceContext.setCreateDate(ratingsEntry.getCreateDate()); serviceContext.setModifiedDate(ratingsEntry.getModifiedDate()); RatingsEntryLocalServiceUtil.updateEntry( userId, clazz.getName(), newClassPK, ratingsEntry.getScore(), serviceContext); } }
@Override protected StagedModel addStagedModel(long groupId, Date createdDate) throws Exception { String title = RandomTestUtil.randomString(); ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(groupId); serviceContext.setCommand(Constants.ADD); serviceContext.setCreateDate(createdDate); serviceContext.setLayoutFullURL("http://localhost"); serviceContext.setModifiedDate(createdDate); return JournalTestUtil.addArticle( groupId, JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID, JournalArticleConstants.CLASSNAME_ID_DEFAULT, title, title, RandomTestUtil.randomString(), LocaleUtil.getSiteDefault(), false, false, serviceContext); }
public void importComments(Class<?> clazz, long classPK, long newClassPK, long groupId) throws PortalException, SystemException { Map<Long, Long> messagePKs = new HashMap<Long, Long>(); Map<Long, Long> threadPKs = new HashMap<Long, Long>(); List<MBMessage> messages = _commentsMap.get(getPrimaryKeyString(clazz, classPK)); if (messages == null) { return; } MBDiscussion discussion = null; try { discussion = MBDiscussionLocalServiceUtil.getDiscussion(clazz.getName(), newClassPK); } catch (NoSuchDiscussionException nsde) { } for (MBMessage message : messages) { long userId = getUserId(message.getUserUuid()); long parentMessageId = MapUtil.getLong(messagePKs, message.getParentMessageId(), message.getParentMessageId()); long threadId = MapUtil.getLong(threadPKs, message.getThreadId(), message.getThreadId()); if ((message.getParentMessageId() == MBMessageConstants.DEFAULT_PARENT_MESSAGE_ID) && (discussion != null)) { MBThread thread = MBThreadLocalServiceUtil.getThread(discussion.getThreadId()); long rootMessageId = thread.getRootMessageId(); messagePKs.put(message.getMessageId(), rootMessageId); threadPKs.put(message.getThreadId(), thread.getThreadId()); } else { ServiceContext serviceContext = new ServiceContext(); serviceContext.setCreateDate(message.getCreateDate()); serviceContext.setModifiedDate(message.getModifiedDate()); serviceContext.setScopeGroupId(groupId); MBMessage importedMessage = null; if (_dataStrategy.equals(PortletDataHandlerKeys.DATA_STRATEGY_MIRROR) || _dataStrategy.equals(PortletDataHandlerKeys.DATA_STRATEGY_MIRROR_OVERWRITE)) { MBMessage existingMessage = MBMessageUtil.fetchByUUID_G(message.getUuid(), groupId); if (existingMessage == null) { serviceContext.setUuid(message.getUuid()); importedMessage = MBMessageLocalServiceUtil.addDiscussionMessage( userId, message.getUserName(), groupId, clazz.getName(), newClassPK, threadId, parentMessageId, message.getSubject(), message.getBody(), serviceContext); } else { serviceContext.setWorkflowAction(WorkflowConstants.ACTION_PUBLISH); importedMessage = MBMessageLocalServiceUtil.updateDiscussionMessage( userId, existingMessage.getMessageId(), clazz.getName(), newClassPK, message.getSubject(), message.getBody(), serviceContext); } } else { importedMessage = MBMessageLocalServiceUtil.addDiscussionMessage( userId, message.getUserName(), groupId, clazz.getName(), newClassPK, threadId, parentMessageId, message.getSubject(), message.getBody(), serviceContext); } messagePKs.put(message.getMessageId(), importedMessage.getMessageId()); threadPKs.put(message.getThreadId(), importedMessage.getThreadId()); } importRatingsEntries( MBDiscussion.class, message.getPrimaryKey(), messagePKs.get(message.getPrimaryKey())); } }
protected ServiceContext createServiceContext( Element element, String path, ClassedModel classedModel, String namespace) { Class<?> clazz = classedModel.getModelClass(); long classPK = getClassPK(classedModel); ServiceContext serviceContext = new ServiceContext(); // Theme display serviceContext.setCompanyId(getCompanyId()); serviceContext.setScopeGroupId(getScopeGroupId()); // Dates if (classedModel instanceof AuditedModel) { AuditedModel auditedModel = (AuditedModel) classedModel; serviceContext.setCreateDate(auditedModel.getCreateDate()); serviceContext.setModifiedDate(auditedModel.getModifiedDate()); } // Permissions if (!MapUtil.getBoolean(_parameterMap, PortletDataHandlerKeys.PERMISSIONS)) { serviceContext.setAddGroupPermissions(true); serviceContext.setAddGuestPermissions(true); } // Asset boolean portletMetadataAll = getBooleanParameter(namespace, PortletDataHandlerKeys.PORTLET_METADATA_ALL); if (isResourceMain(classedModel)) { if (portletMetadataAll || getBooleanParameter(namespace, "categories")) { long[] assetCategoryIds = getAssetCategoryIds(clazz, classPK); serviceContext.setAssetCategoryIds(assetCategoryIds); } if (portletMetadataAll || getBooleanParameter(namespace, "tags")) { String[] assetTagNames = getAssetTagNames(clazz, classPK); serviceContext.setAssetTagNames(assetTagNames); } } // Expando String expandoPath = null; if (element != null) { expandoPath = element.attributeValue("expando-path"); } else { expandoPath = getExpandoPath(path); } if (Validator.isNotNull(expandoPath)) { try { Map<String, Serializable> expandoBridgeAttributes = (Map<String, Serializable>) getZipEntryAsObject(expandoPath); serviceContext.setExpandoBridgeAttributes(expandoBridgeAttributes); } catch (Exception e) { if (_log.isDebugEnabled()) { _log.debug(e, e); } } } return serviceContext; }
public void merge(ServiceContext serviceContext) { setAddGroupPermissions(serviceContext.isAddGroupPermissions()); setAddGuestPermissions(serviceContext.isAddGuestPermissions()); if (serviceContext.getAssetCategoryIds() != null) { setAssetCategoryIds(serviceContext.getAssetCategoryIds()); } if (serviceContext.getAssetLinkEntryIds() != null) { setAssetLinkEntryIds(serviceContext.getAssetLinkEntryIds()); } if (serviceContext.getAssetTagNames() != null) { setAssetTagNames(serviceContext.getAssetTagNames()); } if (serviceContext.getAttributes() != null) { setAttributes(serviceContext.getAttributes()); } if (Validator.isNotNull(serviceContext.getCommand())) { setCommand(serviceContext.getCommand()); } if (serviceContext.getCompanyId() > 0) { setCompanyId(serviceContext.getCompanyId()); } if (serviceContext.getCreateDate() != null) { setCreateDate(serviceContext.getCreateDate()); } if (Validator.isNotNull(serviceContext.getCurrentURL())) { setCurrentURL(serviceContext.getCurrentURL()); } if (serviceContext.getExpandoBridgeAttributes() != null) { setExpandoBridgeAttributes(serviceContext.getExpandoBridgeAttributes()); } if (serviceContext.getGroupPermissions() != null) { setGroupPermissions(serviceContext.getGroupPermissions()); } if (serviceContext.getGuestPermissions() != null) { setGuestPermissions(serviceContext.getGuestPermissions()); } if (serviceContext.getHeaders() != null) { setHeaders(serviceContext.getHeaders()); } setFailOnPortalException(serviceContext.isFailOnPortalException()); setLanguageId(serviceContext.getLanguageId()); if (Validator.isNotNull(serviceContext.getLayoutFullURL())) { setLayoutFullURL(serviceContext.getLayoutFullURL()); } if (Validator.isNotNull(serviceContext.getLayoutURL())) { setLayoutURL(serviceContext.getLayoutURL()); } if (serviceContext.getModifiedDate() != null) { setModifiedDate(serviceContext.getModifiedDate()); } if (Validator.isNotNull(serviceContext.getPathMain())) { setPathMain(serviceContext.getPathMain()); } if (serviceContext.getPlid() > 0) { setPlid(serviceContext.getPlid()); } if (Validator.isNotNull(serviceContext.getPortalURL())) { setPortalURL(serviceContext.getPortalURL()); } if (serviceContext.getPortletPreferencesIds() != null) { setPortletPreferencesIds(serviceContext.getPortletPreferencesIds()); } if (Validator.isNotNull(serviceContext.getRemoteAddr())) { setRemoteAddr(serviceContext.getRemoteAddr()); } if (Validator.isNotNull(serviceContext.getRemoteHost())) { setRemoteHost(serviceContext.getRemoteHost()); } if (serviceContext.getScopeGroupId() > 0) { setScopeGroupId(serviceContext.getScopeGroupId()); } setSignedIn(serviceContext.isSignedIn()); if (Validator.isNotNull(serviceContext.getUserDisplayURL())) { setUserDisplayURL(serviceContext.getUserDisplayURL()); } if (serviceContext.getUserId() > 0) { setUserId(serviceContext.getUserId()); } if (Validator.isNotNull(serviceContext.getUuid())) { setUuid(serviceContext.getUuid()); } if (serviceContext.getWorkflowAction() > 0) { setWorkflowAction(serviceContext.getWorkflowAction()); } }
protected void importAssetCategory( PortletDataContext portletDataContext, Map<Long, Long> assetVocabularyPKs, Map<Long, Long> assetCategoryPKs, Map<String, String> assetCategoryUuids, Element assetCategoryElement, AssetCategory assetCategory) throws Exception { long userId = portletDataContext.getUserId(assetCategory.getUserUuid()); long assetVocabularyId = MapUtil.getLong( assetVocabularyPKs, assetCategory.getVocabularyId(), assetCategory.getVocabularyId()); long parentAssetCategoryId = MapUtil.getLong( assetCategoryPKs, assetCategory.getParentCategoryId(), assetCategory.getParentCategoryId()); if ((parentAssetCategoryId != AssetCategoryConstants.DEFAULT_PARENT_CATEGORY_ID) && (parentAssetCategoryId == assetCategory.getParentCategoryId())) { String path = getAssetCategoryPath(portletDataContext, parentAssetCategoryId); AssetCategory parentAssetCategory = (AssetCategory) portletDataContext.getZipEntryAsObject(path); Node parentCategoryNode = assetCategoryElement.getParent().selectSingleNode("./category[@path='" + path + "']"); if (parentCategoryNode != null) { importAssetCategory( portletDataContext, assetVocabularyPKs, assetCategoryPKs, assetCategoryUuids, (Element) parentCategoryNode, parentAssetCategory); parentAssetCategoryId = MapUtil.getLong( assetCategoryPKs, assetCategory.getParentCategoryId(), assetCategory.getParentCategoryId()); } } ServiceContext serviceContext = new ServiceContext(); serviceContext.setAddGroupPermissions(true); serviceContext.setAddGuestPermissions(true); serviceContext.setCreateDate(assetCategory.getCreateDate()); serviceContext.setModifiedDate(assetCategory.getModifiedDate()); serviceContext.setScopeGroupId(portletDataContext.getScopeGroupId()); AssetCategory importedAssetCategory = null; try { if (parentAssetCategoryId != AssetCategoryConstants.DEFAULT_PARENT_CATEGORY_ID) { AssetCategoryUtil.findByPrimaryKey(parentAssetCategoryId); } List<Element> propertyElements = assetCategoryElement.elements("property"); String[] properties = new String[propertyElements.size()]; for (int i = 0; i < propertyElements.size(); i++) { Element propertyElement = propertyElements.get(i); String key = propertyElement.attributeValue("key"); String value = propertyElement.attributeValue("value"); properties[i] = key.concat(StringPool.COLON).concat(value); } AssetCategory existingAssetCategory = AssetCategoryUtil.fetchByP_N_V( parentAssetCategoryId, assetCategory.getName(), assetVocabularyId); if (existingAssetCategory == null) { serviceContext.setUuid(assetCategory.getUuid()); importedAssetCategory = AssetCategoryLocalServiceUtil.addCategory( userId, parentAssetCategoryId, getAssetCategoryTitleMap(assetCategory), assetCategory.getDescriptionMap(), assetVocabularyId, properties, serviceContext); } else { importedAssetCategory = AssetCategoryLocalServiceUtil.updateCategory( userId, existingAssetCategory.getCategoryId(), parentAssetCategoryId, getAssetCategoryTitleMap(assetCategory), assetCategory.getDescriptionMap(), assetVocabularyId, properties, serviceContext); } assetCategoryPKs.put(assetCategory.getCategoryId(), importedAssetCategory.getCategoryId()); assetCategoryUuids.put(assetCategory.getUuid(), importedAssetCategory.getUuid()); portletDataContext.importPermissions( AssetCategory.class, assetCategory.getCategoryId(), importedAssetCategory.getCategoryId()); } catch (NoSuchCategoryException nsce) { _log.error( "Could not find the parent category for category " + assetCategory.getCategoryId()); } }