List of usage examples for com.liferay.portal.kernel.service ServiceContext ServiceContext
public ServiceContext()
From source file:at.graz.meduni.bibbox.liferay.portlet.service.impl.ApplicationInstanceServiceImpl.java
License:Open Source License
private JSONObject installApplication(String applicationname, String version, String instanceid, String instancename, String data) { JSONObject returnobject = JSONFactoryUtil.createJSONObject(); if (ApplicationInstanceLocalServiceUtil.checkInstanceNameAvailable(instanceid)) { returnobject.put("status", "error"); returnobject.put("error", "InstanceId alredy exists!"); return returnobject; }// ww w .j a v a 2s . c om ApplicationInstanceLocalServiceUtil.registerApplication(applicationname, version, instanceid, instancename); long userId = 0; long groupId = 0; try { User user = this.getGuestOrUser(); Company company = CompanyLocalServiceUtil.getCompany(user.getCompanyId()); groupId = company.getGroupId(); userId = user.getUserId(); } catch (Exception e) { System.err.println(FormatExceptionMessage.formatExceptionMessage("error", log_portlet_, log_classname_, "installApplication(String applicationname, String version, String instanceid, String instancename, String data)", "Error getting user from api call.")); e.printStackTrace(); } Map<String, Serializable> taskContextMap = new HashMap<>(); taskContextMap.put("instanceId", instanceid); taskContextMap.put("data", data); try { BackgroundTaskManagerUtil.addBackgroundTask(userId, groupId, BibboxBackgroundTaskExecutorNames.BIBBOX_INSTANCE_INSTALLER_BACKGROUND_TASK_EXECUTOR, new String[] { "BIBBOXDocker-portlet" }, InstallApplicationBG.class, taskContextMap, new ServiceContext()); } catch (PortalException e) { System.err.println(FormatExceptionMessage.formatExceptionMessage("error", log_portlet_, log_classname_, "installApplication(String applicationname, String version, String instanceid, String instancename, String data)", "Error starting Background Task. For instance: " + instanceid)); e.printStackTrace(); } returnobject.put("status", "installing"); returnobject.put("instanceid", instanceid); return returnobject; }
From source file:at.graz.meduni.bibbox.liferay.portlet.service.impl.ApplicationInstanceServiceImpl.java
License:Open Source License
private JSONObject deleteInstance(String instanceId) { JSONObject returnobject = JSONFactoryUtil.createJSONObject(); ApplicationInstance applicationinstance = ApplicationInstanceLocalServiceUtil .getApplicationInstance(instanceId); if (applicationinstance == null) { returnobject.put("status", "error"); returnobject.put("error", "InstanceId dose not exist!"); } else {/*from ww w .j a v a 2s .co m*/ applicationinstance.setDeleted(true); applicationinstance.setStatus("deleting"); ApplicationInstanceLocalServiceUtil.updateApplicationInstance(applicationinstance); long userId = 0; long groupId = 0; try { User user = this.getGuestOrUser(); Company company = CompanyLocalServiceUtil.getCompany(user.getCompanyId()); groupId = company.getGroupId(); userId = user.getUserId(); } catch (Exception e) { System.err.println(FormatExceptionMessage.formatExceptionMessage("error", log_portlet_, log_classname_, "getUserObject()", "Error getting user from api call")); e.printStackTrace(); } Map<String, Serializable> taskContextMap = new HashMap<>(); taskContextMap.put("instanceId", instanceId); try { BackgroundTaskManagerUtil.addBackgroundTask(userId, groupId, BibboxBackgroundTaskExecutorNames.BIBBOX_INSTANCE_DELETE_BACKGROUND_TASK_EXECUTOR, new String[] { "BIBBOXDocker-portlet" }, DeleteApplication.class, taskContextMap, new ServiceContext()); } catch (PortalException e) { System.err.println(FormatExceptionMessage.formatExceptionMessage("error", log_portlet_, log_classname_, "getUserObject()", "Error starting delete Task.")); e.printStackTrace(); } returnobject.put("status", "installing"); returnobject.put("instanceid", instanceId); } return returnobject; }
From source file:at.graz.meduni.bibbox.liferay.portlet.service.impl.ApplicationInstanceServiceImpl.java
License:Open Source License
private JSONObject startInstance(String instanceId) { JSONObject returnobject = JSONFactoryUtil.createJSONObject(); ApplicationInstance applicationinstance = ApplicationInstanceLocalServiceUtil .getApplicationInstance(instanceId); if (applicationinstance == null) { returnobject.put("status", "error"); returnobject.put("error", "InstanceId dose not exist!"); String activityId = addMessageActivity("Starting Instance " + instanceId, "STARTAPP", "RUNNING", "UNKNOWN"); ActivitiesProtocol.addActivityLogEntry(activityId, "ERROR", "InstanceId dose not exist!"); finishActivity(activityId, "FINISHED", "ERROR"); } else {// www.j ava 2 s .c om ApplicationInstanceStatus applicationinstancestatus = ApplicationInstanceStatusLocalServiceUtil .getApplicationInstanceStatusByInstanceId(applicationinstance.getApplicationInstanceId()); applicationinstancestatus.setStatus("starting"); applicationinstancestatus = ApplicationInstanceStatusLocalServiceUtil .updateApplicationInstanceStatus(applicationinstancestatus); long userId = 0; long groupId = 0; try { User user = this.getGuestOrUser(); Company company = CompanyLocalServiceUtil.getCompany(user.getCompanyId()); groupId = company.getGroupId(); userId = user.getUserId(); } catch (Exception e) { System.err.println(FormatExceptionMessage.formatExceptionMessage("error", log_portlet_, log_classname_, "startInstance(String instanceId)", "Error getting user from api call.")); e.printStackTrace(); } Map<String, Serializable> taskContextMap = new HashMap<>(); taskContextMap.put("instanceId", instanceId); taskContextMap.put("command", "start"); try { BackgroundTaskManagerUtil.addBackgroundTask(userId, groupId, BibboxBackgroundTaskExecutorNames.BIBBOX_INSTANCE_CONTROLE_BACKGROUND_TASK_EXECUTOR, new String[] { "BIBBOXDocker-portlet" }, ControleApplication.class, taskContextMap, new ServiceContext()); } catch (PortalException e) { System.err.println(FormatExceptionMessage.formatExceptionMessage("error", log_portlet_, log_classname_, "startInstance(String instanceId)", "Error starting Background Task. For instance: " + instanceId)); e.printStackTrace(); } } applicationinstance = null; returnobject.put("status", "starting"); return returnobject; }
From source file:at.graz.meduni.bibbox.liferay.portlet.service.impl.ApplicationInstanceServiceImpl.java
License:Open Source License
private JSONObject stopInstance(String instanceId) { JSONObject returnobject = JSONFactoryUtil.createJSONObject(); ApplicationInstance applicationinstance = ApplicationInstanceLocalServiceUtil .getApplicationInstance(instanceId); if (applicationinstance == null) { returnobject.put("status", "error"); returnobject.put("error", "InstanceId dose not exist!"); String activityId = addMessageActivity("Stopping Instance " + instanceId, "STOPAPP", "RUNNING", "UNKNOWN"); ActivitiesProtocol.addActivityLogEntry(activityId, "ERROR", "InstanceId dose not exist!"); finishActivity(activityId, "FINISHED", "ERROR"); } else {//from w w w . java 2 s .co m ApplicationInstanceStatus applicationinstancestatus = ApplicationInstanceStatusLocalServiceUtil .getApplicationInstanceStatusByInstanceId(applicationinstance.getApplicationInstanceId()); applicationinstancestatus.setStatus("stopping"); applicationinstancestatus = ApplicationInstanceStatusLocalServiceUtil .updateApplicationInstanceStatus(applicationinstancestatus); long userId = 0; long groupId = 0; try { User user = this.getGuestOrUser(); Company company = CompanyLocalServiceUtil.getCompany(user.getCompanyId()); groupId = company.getGroupId(); userId = user.getUserId(); } catch (Exception e) { System.err.println(FormatExceptionMessage.formatExceptionMessage("error", log_portlet_, log_classname_, "stopInstance(String instanceId)", "Error getting user from api call.")); e.printStackTrace(); } Map<String, Serializable> taskContextMap = new HashMap<>(); taskContextMap.put("instanceId", instanceId); taskContextMap.put("command", "stop"); try { BackgroundTaskManagerUtil.addBackgroundTask(userId, groupId, BibboxBackgroundTaskExecutorNames.BIBBOX_INSTANCE_CONTROLE_BACKGROUND_TASK_EXECUTOR, new String[] { "BIBBOXDocker-portlet" }, ControleApplication.class, taskContextMap, new ServiceContext()); } catch (PortalException e) { System.err.println(FormatExceptionMessage.formatExceptionMessage("error", log_portlet_, log_classname_, "stopInstance(String instanceId)", "Error starting Background Task. For instance: " + instanceId)); e.printStackTrace(); } } returnobject.put("status", "stopping"); return returnobject; }
From source file:at.graz.meduni.bibbox.liferay.portlet.service.impl.ApplicationInstanceServiceImpl.java
License:Open Source License
private JSONObject restartInstance(String instanceId) { JSONObject returnobject = JSONFactoryUtil.createJSONObject(); ApplicationInstance applicationinstance = ApplicationInstanceLocalServiceUtil .getApplicationInstance(instanceId); if (applicationinstance == null) { returnobject.put("status", "error"); returnobject.put("error", "InstanceId dose not exist!"); String activityId = addMessageActivity("Restart Instance " + instanceId, "RESTARTAPP", "RUNNING", "UNKNOWN"); ActivitiesProtocol.addActivityLogEntry(activityId, "ERROR", "InstanceId dose not exist!"); finishActivity(activityId, "FINISHED", "ERROR"); } else {/*from ww w. ja v a 2s.co m*/ ApplicationInstanceStatus applicationinstancestatus = ApplicationInstanceStatusLocalServiceUtil .getApplicationInstanceStatusByInstanceId(applicationinstance.getApplicationInstanceId()); applicationinstancestatus.setStatus("restarting"); applicationinstancestatus = ApplicationInstanceStatusLocalServiceUtil .updateApplicationInstanceStatus(applicationinstancestatus); long userId = 0; long groupId = 0; try { User user = this.getGuestOrUser(); Company company = CompanyLocalServiceUtil.getCompany(user.getCompanyId()); groupId = company.getGroupId(); userId = user.getUserId(); } catch (Exception e) { System.err.println(FormatExceptionMessage.formatExceptionMessage("error", log_portlet_, log_classname_, "restartInstance(String instanceId)", "Error getting user from api call.")); e.printStackTrace(); } Map<String, Serializable> taskContextMap = new HashMap<>(); taskContextMap.put("instanceId", instanceId); taskContextMap.put("command", "restart"); try { BackgroundTaskManagerUtil.addBackgroundTask(userId, groupId, BibboxBackgroundTaskExecutorNames.BIBBOX_INSTANCE_CONTROLE_BACKGROUND_TASK_EXECUTOR, new String[] { "BIBBOXDocker-portlet" }, ControleApplication.class, taskContextMap, new ServiceContext()); } catch (PortalException e) { System.err.println(FormatExceptionMessage.formatExceptionMessage("error", log_portlet_, log_classname_, "restartInstance(String instanceId)", "Error starting Background Task. For instance: " + instanceId)); e.printStackTrace(); } } returnobject.put("status", "restarting"); return returnobject; }
From source file:ch.inofix.contact.service.impl.ContactLocalServiceImpl.java
License:Open Source License
@Override public long exportContactsAsFileInBackground(long userId, ExportImportConfiguration exportImportConfiguration) throws PortalException { // TODO: The export may have different file types / extensions: // - .csv/* ww w . j av a 2 s . co m*/ // - .xml // - .txt // - .json // if // (!DLValidatorUtil.isValidName(exportImportConfiguration.getName())) { // throw new LARFileNameException(exportImportConfiguration.getName()); // } Map<String, Serializable> taskContextMap = new HashMap<>(); taskContextMap.put("exportImportConfigurationId", exportImportConfiguration.getExportImportConfigurationId()); BackgroundTask backgroundTask = BackgroundTaskManagerUtil.addBackgroundTask(userId, exportImportConfiguration.getGroupId(), exportImportConfiguration.getName(), ContactExportBackgroundTaskExecutor.class.getName(), taskContextMap, new ServiceContext()); return backgroundTask.getBackgroundTaskId(); }
From source file:ch.inofix.contact.service.impl.ContactLocalServiceImpl.java
License:Open Source License
@Override public long importContactsInBackground(long userId, ExportImportConfiguration exportImportConfiguration, File file) throws PortalException { Map<String, Serializable> taskContextMap = new HashMap<>(); taskContextMap.put("exportImportConfigurationId", exportImportConfiguration.getExportImportConfigurationId()); BackgroundTask backgroundTask = BackgroundTaskManagerUtil.addBackgroundTask(userId, exportImportConfiguration.getGroupId(), exportImportConfiguration.getName(), ContactImportBackgroundTaskExecutor.class.getName(), taskContextMap, new ServiceContext()); backgroundTask.addAttachment(userId, file.getName(), file); return backgroundTask.getBackgroundTaskId(); }
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()); }/*from ww w. j a v a 2s . c om*/ }
From source file:com.bemis.portal.customer.service.impl.CustomerLocationLocalServiceImpl.java
License:Open Source License
@Override public void updateOrAddCustomerLocation(List<CustomerLocation> customerLocations) throws PortalException { for (CustomerLocation customerLocation : customerLocations) { long companyId = _bemisPortalService.getDefaultCompanyId(); User user = _bemisPortalService.getDefaultUser(); ServiceContext serviceContext = new ServiceContext(); serviceContext.setCompanyId(companyId); serviceContext.setUserId(user.getUserId()); CustomerLocation storedCustomerLocation = customerLocationPersistence .fetchByBemisCustomerId(customerLocation.getBemisCustomerId()); if (storedCustomerLocation == null) { storedCustomerLocation = addCustomerLocation(customerLocation.getBemisCustomerId(), customerLocation.getBemisParentId(), customerLocation.getCustomerName(), customerLocation.getCustomerAddress1(), customerLocation.getCustomerAddress2(), customerLocation.getCustomerAddress3(), customerLocation.getCustomerCity(), customerLocation.getCustomerState(), customerLocation.getCustomerPostalCde(), customerLocation.getCustomerCountry(), customerLocation.getCustomerPhoneNbr(), customerLocation.getCustomerPoBox(), customerLocation.getCustomerPoCity(), customerLocation.getCustomerPoState(), customerLocation.getCustomerPoPostalCde(), customerLocation.getCustomerActiveStatusCde(), serviceContext); } else {// w w w. j ava 2 s .c om storedCustomerLocation = updateCustomerLocation(storedCustomerLocation.getCustomerLocationId(), customerLocation.getBemisParentId(), customerLocation.getCustomerName(), customerLocation.getCustomerAddress1(), customerLocation.getCustomerAddress2(), customerLocation.getCustomerAddress3(), customerLocation.getCustomerCity(), customerLocation.getCustomerState(), customerLocation.getCustomerPostalCde(), customerLocation.getCustomerCountry(), customerLocation.getCustomerPhoneNbr(), customerLocation.getCustomerPoBox(), customerLocation.getCustomerPoCity(), customerLocation.getCustomerPoState(), customerLocation.getCustomerPoPostalCde(), customerLocation.getCustomerActiveStatusCde(), serviceContext); } } }
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 companyId//from w ww . j a va2 s . c o m * @param groupId * @param userId * @param file * @param fileDescription * @param title * @param folderId * @param changeLog * @param assetTagNames * @return FileEntry * @throws PortalException */ public FileEntry uploadFile(long companyId, long groupId, long userId, File file, String fileDescription, String title, long folderId, String changeLog, String[] assetTagNames) throws PortalException { ServiceContext serviceContext = new ServiceContext(); serviceContext.setCompanyId(companyId); serviceContext.setScopeGroupId(groupId); serviceContext.setUserId(userId); serviceContext.setAssetTagNames(assetTagNames); serviceContext.setAttribute(FileUploaderConstants.DESTINATION_FOLDER_ID, folderId); return uploadFile(file, fileDescription, title, changeLog, serviceContext); }