use of com.liferay.portal.service.ServiceContext in project liferay-ide by liferay.
the class JukeboxPortlet method deleteAlbum.
public void deleteAlbum(ActionRequest request, ActionResponse response) throws Exception {
long albumId = ParamUtil.getLong(request, "albumId");
boolean moveToTrash = ParamUtil.getBoolean(request, "moveToTrash");
ServiceContext serviceContext = ServiceContextFactory.getInstance(Album.class.getName(), request);
try {
if (moveToTrash) {
Album album = AlbumServiceUtil.moveAlbumToTrash(albumId);
Map<String, String[]> data = new HashMap<String, String[]>();
data.put("deleteEntryClassName", new String[] { Album.class.getName() });
data.put("deleteEntryTitle", new String[] { album.getName() });
data.put("restoreEntryIds", new String[] { String.valueOf(albumId) });
SessionMessages.add(request, PortalUtil.getPortletId(request) + SessionMessages.KEY_SUFFIX_DELETE_SUCCESS_DATA, data);
SessionMessages.add(request, PortalUtil.getPortletId(request) + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_SUCCESS_MESSAGE);
} else {
AlbumServiceUtil.deleteAlbum(albumId, serviceContext);
SessionMessages.add(request, "albumDeleted");
}
sendRedirect(request, response);
} catch (Exception e) {
SessionErrors.add(request, e.getClass().getName());
response.setRenderParameter("jspPage", "/html/error.jsp");
}
}
use of com.liferay.portal.service.ServiceContext in project liferay-ide by liferay.
the class BaseKBPortlet method updateKBComment.
public void updateKBComment(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {
ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
if (!themeDisplay.isSignedIn()) {
return;
}
String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
long kbCommentId = ParamUtil.getLong(actionRequest, "kbCommentId");
long classNameId = ParamUtil.getLong(actionRequest, "classNameId");
long classPK = ParamUtil.getLong(actionRequest, "classPK");
String content = ParamUtil.getString(actionRequest, "content");
int status = ParamUtil.getInteger(actionRequest, "status", KBCommentConstants.STATUS_ANY);
ServiceContext serviceContext = ServiceContextFactory.getInstance(KBComment.class.getName(), actionRequest);
if (cmd.equals(Constants.ADD)) {
KBCommentLocalServiceUtil.addKBComment(themeDisplay.getUserId(), classNameId, classPK, content, serviceContext);
} else if (cmd.equals(Constants.UPDATE)) {
if (status == KBCommentConstants.STATUS_ANY) {
KBComment kbComment = KBCommentServiceUtil.getKBComment(kbCommentId);
status = kbComment.getStatus();
}
KBCommentServiceUtil.updateKBComment(kbCommentId, classNameId, classPK, content, status, serviceContext);
}
SessionMessages.add(actionRequest, "suggestionSaved");
}
use of com.liferay.portal.service.ServiceContext in project liferay-ide by liferay.
the class BaseKBPortlet method updateKBCommentStatus.
public void updateKBCommentStatus(ActionRequest actionRequest, ActionResponse actionResponse) throws PortalException, SystemException {
long kbCommentId = ParamUtil.getLong(actionRequest, "kbCommentId");
int status = ParamUtil.getInteger(actionRequest, "kbCommentStatus");
ServiceContext serviceContext = ServiceContextFactory.getInstance(KBComment.class.getName(), actionRequest);
KBCommentServiceUtil.updateStatus(kbCommentId, status, serviceContext);
SessionMessages.add(actionRequest, "suggestionStatusUpdated");
}
use of com.liferay.portal.service.ServiceContext in project liferay-ide by liferay.
the class KBArticleAttachmentsUtil method getFolderId.
public static long getFolderId(long groupId, long userId, long resourcePrimKey) throws PortalException, SystemException {
ServiceContext serviceContext = new ServiceContext();
serviceContext.setAddGroupPermissions(true);
serviceContext.setAddGuestPermissions(true);
Repository repository = PortletFileRepositoryUtil.addPortletRepository(groupId, PortletKeys.KNOWLEDGE_BASE_ARTICLE, serviceContext);
Folder folder = PortletFileRepositoryUtil.addPortletFolder(userId, repository.getRepositoryId(), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, String.valueOf(resourcePrimKey), serviceContext);
return folder.getFolderId();
}
use of com.liferay.portal.service.ServiceContext in project liferay-ide by liferay.
the class AlbumStagedModelDataHandler method doImportStagedModel.
@Override
protected void doImportStagedModel(PortletDataContext portletDataContext, Album album) throws Exception {
long userId = portletDataContext.getUserId(album.getUserUuid());
ServiceContext serviceContext = portletDataContext.createServiceContext(album);
String artistPath = ExportImportPathUtil.getModelPath(portletDataContext, Artist.class.getName(), album.getArtistId());
Artist artist = (Artist) portletDataContext.getZipEntryAsObject(artistPath);
if (artist != null) {
StagedModelDataHandlerUtil.importReferenceStagedModel(portletDataContext, album, Artist.class, album.getArtistId());
}
Map<Long, Long> artistIds = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(Artist.class);
long artistId = MapUtil.getLong(artistIds, album.getArtistId(), album.getArtistId());
Album importedAlbum = null;
if (portletDataContext.isDataStrategyMirror()) {
Album existingAlbum = AlbumLocalServiceUtil.fetchAlbumByUuidAndGroupId(album.getUuid(), portletDataContext.getScopeGroupId());
if (existingAlbum == null) {
serviceContext.setUuid(album.getUuid());
importedAlbum = AlbumLocalServiceUtil.addAlbum(userId, artistId, album.getName(), album.getYear(), null, serviceContext);
} else {
importedAlbum = AlbumLocalServiceUtil.updateAlbum(userId, existingAlbum.getAlbumId(), artistId, album.getName(), album.getYear(), null, serviceContext);
}
} else {
importedAlbum = AlbumLocalServiceUtil.addAlbum(userId, artistId, album.getName(), album.getYear(), null, serviceContext);
}
Element albumElement = portletDataContext.getImportDataStagedModelElement(album);
List<Element> attachmentElements = portletDataContext.getReferenceDataElements(albumElement, FileEntry.class, PortletDataContext.REFERENCE_TYPE_WEAK);
for (Element attachmentElement : attachmentElements) {
String path = attachmentElement.attributeValue("path");
FileEntry fileEntry = (FileEntry) portletDataContext.getZipEntryAsObject(path);
InputStream inputStream = null;
try {
String binPath = attachmentElement.attributeValue("bin-path");
if (Validator.isNull(binPath) && portletDataContext.isPerformDirectBinaryImport()) {
try {
inputStream = _getContentStream(fileEntry);
} catch (NoSuchFileException nsfe) {
}
} else {
inputStream = portletDataContext.getZipEntryAsInputStream(binPath);
}
if (inputStream == null) {
if (_log.isWarnEnabled()) {
_log.warn("Unable to import attachment for file entry " + fileEntry.getFileEntryId());
}
continue;
}
importedAlbum = AlbumLocalServiceUtil.updateAlbum(userId, importedAlbum.getAlbumId(), importedAlbum.getArtistId(), importedAlbum.getName(), importedAlbum.getYear(), inputStream, serviceContext);
} finally {
StreamUtil.cleanUp(inputStream);
}
}
portletDataContext.importClassedModel(album, importedAlbum);
}
Aggregations