use of com.liferay.portal.service.ServiceContext in project liferay-ide by liferay.
the class MediaWikiImporter method readAssetTagNames.
protected String[] readAssetTagNames(long userId, WikiNode node, String content) throws PortalException, SystemException {
Matcher matcher = _categoriesPattern.matcher(content);
List<String> assetTagNames = new ArrayList<String>();
while (matcher.find()) {
String categoryName = matcher.group(1);
categoryName = normalize(categoryName, 75);
AssetTag assetTag = null;
try {
assetTag = AssetTagLocalServiceUtil.getTag(node.getGroupId(), categoryName);
} catch (NoSuchTagException nste) {
ServiceContext serviceContext = new ServiceContext();
serviceContext.setAddGroupPermissions(true);
serviceContext.setAddGuestPermissions(true);
serviceContext.setScopeGroupId(node.getGroupId());
assetTag = AssetTagLocalServiceUtil.addTag(userId, categoryName, null, serviceContext);
}
assetTagNames.add(assetTag.getName());
}
if (content.contains(_WORK_IN_PROGRESS)) {
assetTagNames.add(_WORK_IN_PROGRESS_TAG);
}
return assetTagNames.toArray(new String[assetTagNames.size()]);
}
use of com.liferay.portal.service.ServiceContext in project liferay-ide by liferay.
the class MediaWikiImporter method processImages.
protected void processImages(long userId, WikiNode node, InputStream imagesInputStream) throws Exception {
if (imagesInputStream == null) {
return;
}
ProgressTracker progressTracker = ProgressTrackerThreadLocal.getProgressTracker();
int count = 0;
ZipReader zipReader = ZipReaderFactoryUtil.getZipReader(imagesInputStream);
List<String> entries = zipReader.getEntries();
int total = entries.size();
if (total > 0) {
try {
WikiPageLocalServiceUtil.getPage(node.getNodeId(), SHARED_IMAGES_TITLE);
} catch (NoSuchPageException nspe) {
ServiceContext serviceContext = new ServiceContext();
serviceContext.setAddGroupPermissions(true);
serviceContext.setAddGuestPermissions(true);
WikiPageLocalServiceUtil.addPage(userId, node.getNodeId(), SHARED_IMAGES_TITLE, SHARED_IMAGES_CONTENT, null, true, serviceContext);
}
}
List<ObjectValuePair<String, InputStream>> inputStreamOVPs = new ArrayList<ObjectValuePair<String, InputStream>>();
try {
int percentage = 50;
for (int i = 0; i < entries.size(); i++) {
String entry = entries.get(i);
String key = entry;
InputStream inputStream = zipReader.getEntryAsInputStream(entry);
String[] paths = StringUtil.split(key, CharPool.SLASH);
if (!isValidImage(paths, inputStream)) {
if (_log.isInfoEnabled()) {
_log.info("Ignoring " + key);
}
continue;
}
String fileName = StringUtil.toLowerCase(paths[paths.length - 1]);
ObjectValuePair<String, InputStream> inputStreamOVP = new ObjectValuePair<String, InputStream>(fileName, inputStream);
inputStreamOVPs.add(inputStreamOVP);
count++;
if ((i % 5) == 0) {
WikiPageLocalServiceUtil.addPageAttachments(userId, node.getNodeId(), SHARED_IMAGES_TITLE, inputStreamOVPs);
inputStreamOVPs.clear();
percentage = Math.min(50 + (i * 50) / total, 99);
progressTracker.setPercent(percentage);
}
}
if (!inputStreamOVPs.isEmpty()) {
WikiPageLocalServiceUtil.addPageAttachments(userId, node.getNodeId(), SHARED_IMAGES_TITLE, inputStreamOVPs);
}
} finally {
for (ObjectValuePair<String, InputStream> inputStreamOVP : inputStreamOVPs) {
InputStream inputStream = inputStreamOVP.getValue();
StreamUtil.cleanUp(inputStream);
}
}
zipReader.close();
if (_log.isInfoEnabled()) {
_log.info("Imported " + count + " images into " + node.getName());
}
}
use of com.liferay.portal.service.ServiceContext in project liferay-ide by liferay.
the class MediaWikiImporter method moveFrontPage.
protected void moveFrontPage(long userId, WikiNode node, Map<String, String[]> options) {
String frontPageTitle = MapUtil.getString(options, WikiImporterKeys.OPTIONS_FRONT_PAGE);
if (Validator.isNotNull(frontPageTitle)) {
frontPageTitle = normalizeTitle(frontPageTitle);
try {
if (WikiPageLocalServiceUtil.getPagesCount(node.getNodeId(), frontPageTitle, true) > 0) {
ServiceContext serviceContext = new ServiceContext();
serviceContext.setAddGroupPermissions(true);
serviceContext.setAddGuestPermissions(true);
WikiPageLocalServiceUtil.movePage(userId, node.getNodeId(), frontPageTitle, WikiPageConstants.FRONT_PAGE, false, serviceContext);
}
} catch (Exception e) {
if (_log.isWarnEnabled()) {
StringBundler sb = new StringBundler(4);
sb.append("Could not move ");
sb.append(WikiPageConstants.FRONT_PAGE);
sb.append(" to the title provided: ");
sb.append(frontPageTitle);
_log.warn(sb.toString(), e);
}
}
}
}
use of com.liferay.portal.service.ServiceContext in project liferay-ide by liferay.
the class LiferayActivityService method getActivity.
protected Activity getActivity(ThemeDisplay themeDisplay, SocialActivity socialActivity) throws Exception {
Activity activity = null;
String className = socialActivity.getClassName();
if (className.equals(Activity.class.getName())) {
activity = getExternalActivity(socialActivity);
} else {
activity = new ActivityImpl(String.valueOf(socialActivity.getClassPK()), String.valueOf(socialActivity.getUserId()));
HttpServletRequest request = HttpServletRequestThreadLocal.getHttpServletRequest();
request.setAttribute(WebKeys.THEME_DISPLAY, themeDisplay);
ServiceContext serviceContext = ServiceContextFactory.getInstance(request);
serviceContext.setCompanyId(themeDisplay.getCompanyId());
serviceContext.setUserId(themeDisplay.getUserId());
SocialActivityFeedEntry socialActivityFeedEntry = SocialActivityInterpreterLocalServiceUtil.interpret(StringPool.BLANK, socialActivity, serviceContext);
activity.setBody(socialActivityFeedEntry.getBody());
activity.setTitle(socialActivityFeedEntry.getTitle());
activity.setUrl(socialActivityFeedEntry.getLink());
}
return activity;
}
use of com.liferay.portal.service.ServiceContext in project liferay-ide by liferay.
the class LiferayMediaItemService method doUpdateMediaItem.
protected void doUpdateMediaItem(UserId userId, String appId, String albumId, String mediaItemId, MediaItem mediaItem, SecurityToken securityToken) throws Exception {
long userIdLong = GetterUtil.getLong(userId.getUserId(securityToken));
User user = UserLocalServiceUtil.getUserById(userIdLong);
if (!ShindigUtil.isValidUser(user)) {
return;
}
Group group = user.getGroup();
long groupIdLong = group.getGroupId();
Http.Options options = new Http.Options();
options.setLocation(mediaItem.getUrl());
byte[] byteArray = HttpUtil.URLtoByteArray(options);
String fileName = getFileName(mediaItem, options);
String contentType = MimeTypesUtil.getContentType(fileName);
ServiceContext serviceContext = new ServiceContext();
serviceContext.setAddGroupPermissions(true);
serviceContext.setAddGuestPermissions(true);
serviceContext.setAttribute("sourceFileName", fileName);
serviceContext.setExpandoBridgeAttributes(SerializerUtil.toExpandoAttributes(mediaItem, _MEDIA_ITEM_FIELDS, user.getCompanyId(), DLFileEntry.class.getName()));
serviceContext.setScopeGroupId(groupIdLong);
if (mediaItemId == null) {
long albumIdLong = GetterUtil.getLong(albumId);
DLAppServiceUtil.addFileEntry(groupIdLong, albumIdLong, fileName, contentType, mediaItem.getTitle(), mediaItem.getDescription(), StringPool.BLANK, byteArray, serviceContext);
} else {
long mediaItemIdLong = GetterUtil.getLong(mediaItemId);
FileEntry fileEntry = DLAppLocalServiceUtil.getFileEntry(mediaItemIdLong);
serviceContext.setCreateDate(fileEntry.getCreateDate());
serviceContext.setModifiedDate(fileEntry.getModifiedDate());
DLAppServiceUtil.updateFileEntry(fileEntry.getFileEntryId(), fileName, contentType, mediaItem.getTitle(), mediaItem.getDescription(), StringPool.BLANK, false, byteArray, serviceContext);
}
}
Aggregations