List of usage examples for com.liferay.portal.kernel.util GetterUtil getLong
public static long getLong(String value)
From source file:au.com.permeance.liferay.util.workflow.WebContentWorkflowHandler.java
License:Open Source License
/** * This implementation puts out a stack trace for any exception because Liferay can swallow them * and this is where potential PACL-related exceptions can occur. *//*from w ww . ja v a 2s. c om*/ @Override public JournalArticle updateStatus(int status, Map<String, Serializable> workflowContext) throws PortalException { try { long userId = GetterUtil.getLong((String) workflowContext.get(WorkflowConstants.CONTEXT_USER_ID)); long classPK = GetterUtil .getLong((String) workflowContext.get(WorkflowConstants.CONTEXT_ENTRY_CLASS_PK)); JournalArticle article = JournalArticleLocalServiceUtil.getArticle(classPK); ServiceContext serviceContext = (ServiceContext) workflowContext.get("serviceContext"); String articleURL = PortalUtil.getControlPanelFullURL(serviceContext.getScopeGroupId(), PortletKeys.JOURNAL, null); return JournalArticleLocalServiceUtil.updateStatus(userId, article, status, articleURL, serviceContext, workflowContext); } catch (RuntimeException e) { _log.error("Error updating status: " + e.getMessage(), e); throw e; } catch (PortalException e) { _log.error("Error updating status: " + e.getMessage(), e); throw e; } }
From source file:br.com.thiagomoreira.liferay.plugins.fixvirtualhost.FixVirtualHostAction.java
License:Apache License
@Override public void run(String[] ids) throws ActionException { try {// w ww .j a v a2s . c o m doRun(GetterUtil.getLong(ids[0])); } catch (Exception e) { throw new ActionException(e); } }
From source file:ca.efendi.datafeeds.search.CJProductIndexer.java
License:Apache License
@Override protected void doReindex(final String[] ids) throws Exception { final long companyId = GetterUtil.getLong(ids[0]); reindexEntries(companyId);/* w w w. j a va 2 s.com*/ }
From source file:ch.inofix.referencemanager.service.impl.ReferenceLocalServiceImpl.java
License:Open Source License
@Indexable(type = IndexableType.REINDEX) @Override// w ww.j av a 2s.c o m public Reference addReference(long userId, String bibTeX, long[] bibliographyIds, ServiceContext serviceContext) throws PortalException { // Reference User user = userPersistence.findByPrimaryKey(userId); long groupId = serviceContext.getScopeGroupId(); long companyId = user.getCompanyId(); long referenceId = counterLocalService.increment(); Reference reference = referencePersistence.create(referenceId); reference.setUuid(serviceContext.getUuid()); reference.setGroupId(groupId); reference.setCompanyId(companyId); reference.setUserId(user.getUserId()); reference.setUserName(user.getFullName()); reference.setExpandoBridgeAttributes(serviceContext); BibTeXEntry bibTeXEntry = BibTeXUtil.getBibTeXEntry(bibTeX); if (bibTeXEntry != null) { Key key = new Key("bibshare-id"); Value value = new StringValue(String.valueOf(referenceId), Style.QUOTED); bibTeXEntry.addField(key, value); } else { // TODO: raise an error and report to the user that something is // wrong with the bibtex-src. } bibTeX = BibTeXUtil.format(bibTeXEntry); reference.setBibTeX(bibTeX); referencePersistence.update(reference); // Match user and group references against common references long defaultGroupId = GetterUtil.getLong(PropsUtil.get("default.group.id")); if (reference.getGroupId() != defaultGroupId) { match(reference); } // BibRefRelation for (long bibliographyId : bibliographyIds) { Bibliography bibliography = bibliographyLocalService.getBibliography(bibliographyId); long bibRefRelationId = counterLocalService.increment(); BibRefRelation bibRefRelation = bibRefRelationPersistence.create(bibRefRelationId); bibRefRelation.setGroupId(bibliography.getGroupId()); bibRefRelation.setCompanyId(bibliography.getCompanyId()); bibRefRelation.setUserId(bibliography.getUserId()); bibRefRelation.setUserName(bibliography.getUserName()); bibRefRelation.setBibliographyId(bibliography.getBibliographyId()); bibRefRelation.setReferenceId(referenceId); bibRefRelationPersistence.update(bibRefRelation); } // Resources resourceLocalService.addModelResources(reference, serviceContext); // Asset updateAsset(userId, reference, serviceContext.getAssetCategoryIds(), serviceContext.getAssetTagNames(), serviceContext.getAssetLinkEntryIds(), serviceContext.getAssetPriority()); // Social JSONObject extraDataJSONObject = JSONFactoryUtil.createJSONObject(); extraDataJSONObject.put("title", reference.getCitation()); socialActivityLocalService.addActivity(userId, groupId, Reference.class.getName(), referenceId, ReferenceActivityKeys.ADD_REFERENCE, extraDataJSONObject.toString(), 0); return reference; }
From source file:ch.inofix.referencemanager.service.impl.ReferenceLocalServiceImpl.java
License:Open Source License
public void match(Reference reference) throws PortalException { _log.info("match"); long defaultGroupId = GetterUtil.getLong(PropsUtil.get("default.group.id")); Hits hits = search(reference.getUserId(), defaultGroupId, -1, null, reference.getTitle(), null, WorkflowConstants.STATUS_ANY, null, false, 0, 20, null); _log.info("hits.getLength() = " + hits.getLength()); if (hits.getLength() == 0) { // not yet in the pool of common references _log.info("not yet in the global references "); // TODO: strip the private fields from the reference String bibTeX = reference.getBibTeX(); ServiceContext serviceContext = new ServiceContext(); serviceContext.setScopeGroupId(defaultGroupId); Reference globalReference = addReference(reference.getUserId(), bibTeX, serviceContext); refRefRelationLocalService.addRefRefRelation(reference.getUserId(), globalReference.getReferenceId(), reference.getReferenceId(), new ServiceContext()); }/* w ww . j a v a 2s. co m*/ }
From source file:ch.inofix.referencemanager.service.impl.ReferenceLocalServiceImpl.java
License:Open Source License
@Indexable(type = IndexableType.REINDEX) public Reference updateReference(long referenceId, long userId, String bibTeX, long[] bibliographyIds, ServiceContext serviceContext) throws PortalException { // Reference//from w w w .jav a 2s .c o m User user = userPersistence.findByPrimaryKey(userId); Reference reference = referencePersistence.findByPrimaryKey(referenceId); long groupId = serviceContext.getScopeGroupId(); long companyId = user.getCompanyId(); reference.setUuid(serviceContext.getUuid()); reference.setGroupId(groupId); reference.setCompanyId(companyId); reference.setUserId(user.getUserId()); reference.setUserName(user.getFullName()); reference.setExpandoBridgeAttributes(serviceContext); BibTeXEntry bibTeXEntry = BibTeXUtil.getBibTeXEntry(bibTeX); if (bibTeXEntry != null) { Key key = new Key("bibshare-last-modified"); Value value = new StringValue(String.valueOf(new Date().getTime()), Style.QUOTED); bibTeXEntry.addField(key, value); } else { // TODO: raise an error and report to the user that something is // wrong with the bibtex-src. } bibTeX = BibTeXUtil.format(bibTeXEntry); reference.setBibTeX(bibTeX); reference = referencePersistence.update(reference); // Match user and group references against common references long defaultGroupId = GetterUtil.getLong(PropsUtil.get("default.group.id")); if (reference.getGroupId() != defaultGroupId) { match(reference); } // BibRefRelation for (long bibliographyId : bibliographyIds) { Bibliography bibliography = bibliographyLocalService.getBibliography(bibliographyId); long bibRefRelationId = counterLocalService.increment(); BibRefRelation bibRefRelation = bibRefRelationPersistence.create(bibRefRelationId); bibRefRelation.setGroupId(bibliography.getGroupId()); bibRefRelation.setCompanyId(bibliography.getCompanyId()); bibRefRelation.setUserId(bibliography.getUserId()); bibRefRelation.setUserName(bibliography.getUserName()); bibRefRelation.setBibliographyId(bibliography.getBibliographyId()); bibRefRelation.setReferenceId(referenceId); bibRefRelationPersistence.update(bibRefRelation); } // Resources resourceLocalService.addModelResources(reference, serviceContext); // Asset updateAsset(userId, reference, serviceContext.getAssetCategoryIds(), serviceContext.getAssetTagNames(), serviceContext.getAssetLinkEntryIds(), serviceContext.getAssetPriority()); // Social JSONObject extraDataJSONObject = JSONFactoryUtil.createJSONObject(); extraDataJSONObject.put("title", reference.getCitation()); socialActivityLocalService.addActivity(userId, groupId, Reference.class.getName(), referenceId, ReferenceActivityKeys.UPDATE_REFERENCE, extraDataJSONObject.toString(), 0); return reference; }
From source file:com.bemis.portal.customer.service.impl.CustomerProfileLocalServiceImpl.java
License:Open Source License
@Override public List<CustomerProfile> searchCustomer(String criteria, int start, int end) throws PortalException { long companyId = _bemisPortalService.getDefaultCompanyId(); List<CustomerProfile> customerProfiles = new ArrayList<>(); LinkedHashMap<String, Object> params = new LinkedHashMap<>(); params.put(_EXPANDO_ATTRIBUTES, criteria); Hits hits = _organizationLocalService.search(companyId, OrganizationConstants.DEFAULT_PARENT_ORGANIZATION_ID, criteria, params, start, end, null); Document[] documents = hits.getDocs(); for (Document doc : documents) { long orgId = GetterUtil.getLong(doc.get(Field.ORGANIZATION_ID)); Organization org = _organizationLocalService.getOrganization(orgId); customerProfiles.add(asCustomerProfile(org)); }/* w ww .ja va 2s. com*/ return customerProfiles; }
From source file:com.bemis.portal.fileuploader.service.impl.FileUploaderLocalServiceImpl.java
License:Open Source License
/** * Uploads the file into the destination folder * If the file does not exist, adds the file. If exists, updates the existing file * Adds tags and categories to documents * * @param file/*from www.ja v a 2s.c om*/ * @param fileDescription * @param fileName * @param changeLog * @param serviceContext * @return FileEntry * @throws PortalException */ public FileEntry uploadFile(File file, String fileDescription, String fileName, String changeLog, ServiceContext serviceContext) throws PortalException { if (_log.isDebugEnabled()) { _log.debug("Invoking uploadFile...."); } long companyId = serviceContext.getCompanyId(); long groupId = serviceContext.getScopeGroupId(); long userId = serviceContext.getUserId(); // see https://issues.liferay.com/browse/LPS-66607 User user = userLocalService.getUser(userId); // Check permissions _fileUploadHelper.checkPermission(companyId, groupId, userId); String title = FilenameUtils.removeExtension(fileName); long folderId = GetterUtil.getLong(serviceContext.getAttribute(DESTINATION_FOLDER_ID)); fileName = file.getName(); String mimeType = MimeTypesUtil.getContentType(fileName); boolean majorVersion = true; DLFileEntry dlFileEntry = _dlFileEntryLocalService.fetchFileEntry(groupId, folderId, title); FileEntry fileEntry = null; if (Validator.isNull(dlFileEntry)) { fileEntry = addFileEntry(userId, groupId, folderId, fileName, mimeType, title, fileDescription, changeLog, file, serviceContext); } else { fileEntry = updateFileEntry(userId, dlFileEntry, fileName, mimeType, title, fileDescription, changeLog, majorVersion, file, serviceContext); } FileVersion fileVersion = fileEntry.getFileVersion(); long[] assetCategoryIds = _fileUploadHelper.getAssetCategoryIds(groupId, title, serviceContext); String[] assetTagNames = serviceContext.getAssetTagNames(); if (_log.isDebugEnabled()) { _log.debug(">>> Updating FileEntry with tags and categories"); } _dlAppLocalService.updateAsset(userId, fileEntry, fileVersion, assetCategoryIds, assetTagNames, null); // Post processing uploaded file _fileUploadHelper.postProcessUpload(file, fileEntry.getFileEntryId(), serviceContext); return fileEntry; }
From source file:com.beorn.onlinepayment.shopping.action.BtopCheckoutAction.java
License:Open Source License
@Override public void processAction(StrutsPortletAction originalStrutsPortletAction, PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); long companyId = themeDisplay.getCompanyId(); long ownerId = themeDisplay.getScopeGroupId(); int ownerType = PortletKeys.PREFS_OWNER_TYPE_GROUP; long plid = PortletKeys.PREFS_PLID_SHARED; String portletId = PortletKeys.SHOPPING; PortletPreferences preferences = PortletPreferencesLocalServiceUtil.getPreferences(companyId, ownerId, ownerType, plid, portletId); String paymentType = PrefsParamUtil.getString(preferences, actionRequest, "paymentType"); String cmd = ParamUtil.getString(actionRequest, Constants.CMD); if (cmd.equals(Constants.SAVE) && paymentType.equals("Betop")) { processSaveCheckoutActionWithoutForwarding(originalStrutsPortletAction, actionRequest, actionResponse); PaymentAppSender paymentAppSender = PaymentAppUtil.getPaymentAppSender(); ShoppingCart cart = ShoppingUtil.getCart(actionRequest); ShoppingOrder order = (ShoppingOrder) actionRequest.getAttribute("SHOPPING_ORDER"); long sellerId = GetterUtil.getLong(preferences.getValue("sellerId", "0")); double amount = ShoppingUtil.calculateTotal(cart.getItems(), order.getBillingState(), cart.getCoupon(), cart.getAltShipping(), cart.isInsure()); String currencyCode = preferences.getValue("currencyId", "USD"); Long transactionId = paymentAppSender.addTransaction(sellerId, amount, currencyCode); OrderTransactionLocalServiceUtil.addOrderTransaction(order.getOrderId(), transactionId); HttpServletRequest request = PortalUtil.getHttpServletRequest(actionRequest); String remoteIp = request.getRemoteAddr(); String forwardedForIp = StringUtil.extractFirst(request.getHeader("X-Forwarded-For"), StringPool.COMMA_AND_SPACE); if (forwardedForIp != null) remoteIp = forwardedForIp;//from www . j a v a 2s . c om List<ApiPaymentMethod> paymentMethods = paymentAppSender.getPaymentMethods(transactionId, paymentAppSender.geolocalizeIp(remoteIp)); Long[] paymentMethodIds = new Long[paymentMethods.size()]; String[] paymentMethodNames = new String[paymentMethods.size()]; for (int i = 0; i < paymentMethods.size(); ++i) { paymentMethodIds[i] = paymentMethods.get(i).getPaymentMethodId(); paymentMethodNames[i] = paymentMethods.get(i).getName(themeDisplay.getLocale()); } actionRequest.setAttribute("orderId", order.getOrderId()); actionRequest.setAttribute("paymentMethodIds", paymentMethodIds); actionRequest.setAttribute("paymentMethodNames", paymentMethodNames); } else { originalStrutsPortletAction.processAction(originalStrutsPortletAction, portletConfig, actionRequest, actionResponse); } }
From source file:com.cd.learning.hook.MBUtil.java
License:Open Source License
public static List<Object> getEntries(Hits hits) { List<Object> entries = new ArrayList<Object>(); for (Document document : hits.getDocs()) { long categoryId = GetterUtil.getLong(document.get(Field.CATEGORY_ID)); try {//from ww w . ja v a2 s . c om MBCategoryLocalServiceUtil.getCategory(categoryId); } catch (Exception e) { if (_log.isWarnEnabled()) { _log.warn("Message boards search index is stale and contains " + "category " + categoryId); } continue; } long threadId = GetterUtil.getLong(document.get("threadId")); try { MBThreadLocalServiceUtil.getThread(threadId); } catch (Exception e) { if (_log.isWarnEnabled()) { _log.warn("Message boards search index is stale and contains " + "thread " + threadId); } continue; } String entryClassName = document.get(Field.ENTRY_CLASS_NAME); long entryClassPK = GetterUtil.getLong(document.get(Field.ENTRY_CLASS_PK)); Object obj = null; try { if (entryClassName.equals(DLFileEntry.class.getName())) { long classPK = GetterUtil.getLong(document.get(Field.CLASS_PK)); MBMessageLocalServiceUtil.getMessage(classPK); obj = DLFileEntryLocalServiceUtil.getDLFileEntry(entryClassPK); } else if (entryClassName.equals(MBMessage.class.getName())) { obj = MBMessageLocalServiceUtil.getMessage(entryClassPK); } entries.add(obj); } catch (Exception e) { if (_log.isWarnEnabled()) { _log.warn("Message boards search index is stale and contains " + "entry {className=" + entryClassName + ", " + "classPK=" + entryClassPK + "}"); } continue; } } return entries; }