List of usage examples for org.springframework.http HttpStatus UNPROCESSABLE_ENTITY
HttpStatus UNPROCESSABLE_ENTITY
To view the source code for org.springframework.http HttpStatus UNPROCESSABLE_ENTITY.
Click Source Link
From source file:org.kuali.mobility.events.controllers.CalendarController.java
@RequestMapping(value = "/saveEvent", method = RequestMethod.POST) public String saveEvent(HttpServletRequest request, @ModelAttribute("event") EditEvent event, BindingResult result, SessionStatus status, Model uiModel) { User user = (User) request.getSession().getAttribute(Constants.KME_USER_KEY); EditEvent eventReturned = null;/*from w w w . j a va 2 s . c o m*/ try { eventReturned = calendarEventOAuthService.saveEvent(user.getUserId(), event, event.getEventId()); if (eventReturned.getResponseCode() == HttpStatus.UNPROCESSABLE_ENTITY.value()) { Errors errors = ((Errors) result); for (Iterator iterator = eventReturned.getErrors().entrySet().iterator(); iterator.hasNext();) { Map.Entry<String, List<String>> entry = (Map.Entry<String, List<String>>) iterator.next(); for (String error : entry.getValue()) { errors.rejectValue(entry.getKey(), "", error); } } event.setDefaultCategories(eventReturned.getDefaultCategories()); return "calendar/editEvent"; } } catch (PageLevelException pageLevelException) { uiModel.addAttribute("message", pageLevelException.getMessage()); return "calendar/message"; } return "redirect:/calendar/month"; }
From source file:com.ge.predix.integration.test.PrivilegeManagementAccessControlServiceIT.java
public void testPutSubjectMismatchURI() { try {/*from w w w. ja va2 s . co m*/ String subjectIdentifier = "marcia"; URI subjectUri = URI.create(this.acsUrl + PrivilegeHelper.ACS_SUBJECT_API_PATH + URLEncoder.encode(subjectIdentifier, "UTF-8")); this.acsAdminRestTemplate.put(subjectUri, new HttpEntity<>(BOB_V1, this.zone1Headers)); Assert.fail("Subject " + subjectIdentifier + " was not supposed to be created"); } catch (HttpClientErrorException e) { Assert.assertEquals(e.getStatusCode(), HttpStatus.UNPROCESSABLE_ENTITY); return; } catch (Exception e) { Assert.fail("Unable to create subject."); } Assert.fail("Expected Unprocessible Entity status code in testPutSubjectMismatchURIV1"); }
From source file:com.ge.predix.integration.test.PrivilegeManagementAccessControlServiceIT.java
@Test(dataProvider = "invalidSubjectPostProvider") public void testPostSubjectNegativeCases(final BaseSubject subject, final String endpoint) { try {/*from www . ja va 2s . co m*/ this.privilegeHelper.postMultipleSubjects(this.acsAdminRestTemplate, endpoint, this.zone1Headers, subject); } catch (HttpClientErrorException e) { Assert.assertEquals(e.getStatusCode(), HttpStatus.UNPROCESSABLE_ENTITY); return; } catch (Exception e) { Assert.fail("Unable to create subject."); } Assert.fail("Expected Unprocessible Entity status code in testPostSubjectNegativeCases"); }
From source file:com.ge.predix.integration.test.PrivilegeManagementAccessControlServiceIT.java
@Test(dataProvider = "invalidResourcePostProvider") public void testPostResourceNegativeCases(final BaseResource resource, final String endpoint) { try {/*w ww. j a va 2s . c o m*/ this.privilegeHelper.postResources(this.acsAdminRestTemplate, endpoint, this.zone1Headers, resource); } catch (HttpClientErrorException e) { Assert.assertEquals(e.getStatusCode(), HttpStatus.UNPROCESSABLE_ENTITY); return; } catch (Exception e) { Assert.fail("Unable to create resource."); } Assert.fail("Expected UnprocessibleEntity status code in testPostResourceNegativeCases"); }
From source file:com.ge.predix.integration.test.PrivilegeManagementAccessControlServiceIT.java
public void testUpdateResourceURIMismatch() throws Exception { try {//from w w w .ja v a 2 s.c om this.privilegeHelper.putResource(this.acsAdminRestTemplate, SANRAMON, this.acsUrl, this.zone1Headers, this.privilegeHelper.getDefaultAttribute()); URI resourceUri = URI.create(this.acsUrl + PrivilegeHelper.ACS_RESOURCE_API_PATH + URLEncoder.encode("/different/resource", "UTF-8")); this.acsAdminRestTemplate.put(resourceUri, new HttpEntity<>(SANRAMON, this.zone1Headers)); } catch (HttpClientErrorException e) { Assert.assertEquals(e.getStatusCode(), HttpStatus.UNPROCESSABLE_ENTITY); return; } Assert.fail("Expected Unprocessible Entity status code in testUpdateResourceURIMismatchV1"); }
From source file:com.ephesoft.dcma.webservice.util.WebServiceHelper.java
/** * This Web service helper will create the new document type for the specified Batch Class. If it cant create the Document type it * raises an Exception//from www. jav a 2s .com * * @param req the {@link HttpServletRequest} The request made by the client encapsulated as an Object * @throws InternalServerException When an uncaught Exception occurs * @throws ValidationException When the Input Parameters cannot be validated */ public void documentTypeCreation(final HttpServletRequest req) throws InternalServerException, ValidationException { String respStr = WebServiceConstants.EMPTY_STRING; String workingDir = WebServiceConstants.EMPTY_STRING; if (req instanceof DefaultMultipartHttpServletRequest) { try { final String webServiceFolderPath = batchSchemaService.getWebServicesFolderPath(); workingDir = WebServiceUtil.createWebServiceWorkingDir(webServiceFolderPath); final DefaultMultipartHttpServletRequest multiPartRequest = (DefaultMultipartHttpServletRequest) req; final MultiValueMap<String, MultipartFile> fileMap = multiPartRequest.getMultiFileMap(); LOGGER.info("Retreiving xml file."); String xmlFileName = WebServiceConstants.EMPTY_STRING; xmlFileName = getXMLFile(workingDir, multiPartRequest, fileMap); WebServiceParams webServiceParams = null; final File xmlFile = new File(workingDir + File.separator + xmlFileName); if (xmlFile.exists()) { LOGGER.info("Input xml file found, retrieving the parameters from it."); final FileInputStream inputStream = new FileInputStream(xmlFile); final Source source = XMLUtil.createSourceFromStream(inputStream); webServiceParams = (WebServiceParams) batchSchemaDao.getJAXB2Template().getJaxb2Marshaller() .unmarshal(source); } else { respStr = WebServiceConstants.INPUT_FILES_NOT_FOUND_MESSAGE; final RestError restError = createUnprocessableEntityRestError(respStr, WebServiceConstants.INVALID_PARAMETERS_CODE); LOGGER.error(WebServiceConstants.INPUT_FILES_NOT_FOUND_MESSAGE + WebServiceConstants.HTTP_STATUS + HttpStatus.UNPROCESSABLE_ENTITY); throw new ValidationException(WebServiceConstants.INPUT_FILES_NOT_FOUND_MESSAGE, restError); } if (null != webServiceParams.getParams()) { final List<Param> paramList = webServiceParams.getParams().getParam(); if (paramList == null || paramList.isEmpty()) { respStr = WebServiceConstants.PARAMETER_XML_INCORRECT_MESSAGE; final RestError restError = createUnprocessableEntityRestError(respStr, WebServiceConstants.INVALID_PARAMETERS_CODE); LOGGER.error(WebServiceConstants.PARAMETER_XML_INCORRECT_MESSAGE + WebServiceConstants.HTTP_STATUS + HttpStatus.UNPROCESSABLE_ENTITY); throw new InternalServerException(WebServiceConstants.PARAMETER_XML_INCORRECT_MESSAGE, restError); } else { LOGGER.info("Initializing input parameters."); String documentTypeName = WebServiceConstants.EMPTY_STRING; String documentTypeDescription = WebServiceConstants.EMPTY_STRING; String minConfidenceThreshold = WebServiceConstants.EMPTY_STRING; String formProcessingFile = WebServiceConstants.EMPTY_STRING; String secondPageProjectFile = WebServiceConstants.EMPTY_STRING; String thirdPageProjectFile = WebServiceConstants.EMPTY_STRING; String lastPageProjectFile = WebServiceConstants.EMPTY_STRING; String batchClassIdentifier = WebServiceConstants.EMPTY_STRING; String hidden = WebServiceConstants.EMPTY_STRING; for (final Param param : paramList) { if (WebServiceConstants.DOCUMENT_TYPE_NAME.equalsIgnoreCase(param.getName())) { documentTypeName = param.getValue().trim(); LOGGER.info("Document type name entered is :" + documentTypeName); continue; } if (WebServiceConstants.DOCUMENT_TYPE_DESCRIPTION.equalsIgnoreCase(param.getName())) { documentTypeDescription = param.getValue().trim(); LOGGER.info("Document type description given is :" + documentTypeDescription); continue; } if (WebServiceConstants.MIN_CONFIDENCE_THRESHOLD.equalsIgnoreCase(param.getName())) { minConfidenceThreshold = param.getValue().trim(); LOGGER.info("Document type minimum confidence threshold entered is :" + minConfidenceThreshold); continue; } if (WebServiceConstants.FIRST_PAGE_PROJECT_FILE.equalsIgnoreCase(param.getName())) { formProcessingFile = param.getValue().trim(); LOGGER.info(EphesoftStringUtil.concatenate( "Document type form processing file entered is : ", formProcessingFile)); continue; } if (WebServiceConstants.SECOND_PAGE_PROJECT_FILE.equalsIgnoreCase(param.getName())) { secondPageProjectFile = param.getValue().trim(); LOGGER.info(EphesoftStringUtil.concatenate( "Document type second page form processing file entered is : ", secondPageProjectFile)); continue; } if (WebServiceConstants.THIRD_PAGE_PROJECT_FILE.equalsIgnoreCase(param.getName())) { thirdPageProjectFile = param.getValue().trim(); LOGGER.info(EphesoftStringUtil.concatenate( "Document type third page form processing file entered is : ", thirdPageProjectFile)); continue; } if (WebServiceConstants.LAST_PAGE_PROJECT_FILE.equalsIgnoreCase(param.getName())) { lastPageProjectFile = param.getValue().trim(); LOGGER.info(EphesoftStringUtil.concatenate( "Document type last page form processing file entered is : ", lastPageProjectFile)); continue; } if (WebServiceUtil.BATCH_CLASS_IDENTIFIER.equalsIgnoreCase(param.getName())) { batchClassIdentifier = param.getValue().trim(); LOGGER.info("Batch class identifier used for copying batch class is :" + batchClassIdentifier); continue; } if (WebServiceConstants.HIDDEN.equalsIgnoreCase(param.getName())) { hidden = param.getValue().trim(); LOGGER.info("Document type hidden field parameter value entered is :" + hidden); continue; } } final List<String> formProcessingFileList = new ArrayList<String>(); formProcessingFileList.add(formProcessingFile); formProcessingFileList.add(secondPageProjectFile); formProcessingFileList.add(thirdPageProjectFile); formProcessingFileList.add(lastPageProjectFile); // Validation for document type creation parameters // provided. LOGGER.info("Validating parameters."); respStr = validateDocumentTypeCreationParameters(documentTypeName, documentTypeDescription, minConfidenceThreshold, formProcessingFileList, batchClassIdentifier, hidden); // verify for unique entries for batch class and unc // folders. if (respStr.isEmpty()) { // creating a new document type. final DocumentType newDocumentType = new DocumentType(); newDocumentType.setName(documentTypeName); newDocumentType.setDescription(documentTypeDescription); newDocumentType.setMinConfidenceThreshold(Float.parseFloat(minConfidenceThreshold)); newDocumentType.setFirstPageProjectFileName(formProcessingFile); newDocumentType.setSecondPageProjectFileName(secondPageProjectFile); newDocumentType.setThirdPageProjectFileName(thirdPageProjectFile); newDocumentType.setFourthPageProjectFileName(lastPageProjectFile); final List<PageType> pages = getListOfPageTypes(documentTypeName); newDocumentType.setPages(pages); if (hidden.equalsIgnoreCase(TRUE)) { newDocumentType.setHidden(true); } else { newDocumentType.setHidden(false); } final BatchClass batchClass = batchClassService .getBatchClassByIdentifier(batchClassIdentifier); // adding the document type to the requested batch // class. batchClass.addDocumentType(newDocumentType); // merging the batch class for persisting the // database state for new document type entry. batchClassService.merge(batchClass); } else { // if the parameters provided didn't validate. final HttpStatus status = HttpStatus.UNPROCESSABLE_ENTITY; final RestError restError = createUnprocessableEntityRestError(respStr, WebServiceConstants.INVALID_ARGUMENTS_IN_XML_INPUT_CODE); LOGGER.error(respStr + WebServiceConstants.HTTP_STATUS + status); throw new ValidationException(respStr, restError); } } } else { respStr = WebServiceConstants.INVALID_ARGUMENTS_IN_XML_INPUT_MESSAGE; throw new ValidationException(respStr, createUnprocessableEntityRestError(respStr, WebServiceConstants.INVALID_ARGUMENTS_IN_XML_INPUT_CODE)); } } catch (final ValidationException validationException) { throw validationException; } catch (final InternalServerException internalServerError) { throw internalServerError; } catch (final Exception exception) { // to handle any other kind of exception that has occurred // during creation. final HttpStatus status = HttpStatus.INTERNAL_SERVER_ERROR; respStr = WebServiceConstants.INTERNAL_SERVER_ERROR_MESSAGE + exception; final RestError restError = createUnprocessableEntityRestError( WebServiceConstants.INTERNAL_SERVER_ERROR_MESSAGE + exception.getMessage(), WebServiceConstants.INTERNAL_SERVER_ERROR_CODE); LOGGER.error("Error response at server:" + respStr); final InternalServerException internalServerExcpetion = new InternalServerException( WebServiceConstants.INTERNAL_SERVER_ERROR_MESSAGE, restError); LOGGER.error(respStr + WebServiceConstants.HTTP_STATUS + status); throw internalServerExcpetion; } finally { if (!workingDir.isEmpty()) { FileUtils.deleteDirectoryAndContentsRecursive(new File(workingDir).getParentFile()); } } } else { respStr = WebServiceConstants.INVALID_MULTIPART_REQUEST; final RestError restError = createUnprocessableEntityRestError(respStr, WebServiceConstants.INVALID_PARAMETERS_CODE); throw new InternalServerException(respStr, restError); } }
From source file:com.ephesoft.dcma.webservice.util.WebServiceHelper.java
/** * Method to extract all required fields and process request. * /*from w w w .j a v a2 s . c o m*/ * @param req {@link HttpServletRequest} the request header for web service hit. * @throws InternalServerException * @throws ValidationException */ public void processCopyBatchClass(final HttpServletRequest req) throws InternalServerException, ValidationException { String respStr = WebServiceConstants.EMPTY_STRING; String workingDir = WebServiceConstants.EMPTY_STRING; if (req instanceof DefaultMultipartHttpServletRequest) { try { final String webServiceFolderPath = batchSchemaService.getWebServicesFolderPath(); workingDir = WebServiceUtil.createWebServiceWorkingDir(webServiceFolderPath); final DefaultMultipartHttpServletRequest multiPartRequest = (DefaultMultipartHttpServletRequest) req; final MultiValueMap<String, MultipartFile> fileMap = multiPartRequest.getMultiFileMap(); LOGGER.info("Retreiving xml file."); if (respStr.isEmpty()) { String xmlFileName = WebServiceConstants.EMPTY_STRING; xmlFileName = getXMLFile(workingDir, multiPartRequest, fileMap); WebServiceParams webServiceParams = null; final File xmlFile = new File(workingDir + File.separator + xmlFileName); if (xmlFile.exists()) { LOGGER.info("Input xml file found, retrieving the parameters from it."); final FileInputStream inputStream = new FileInputStream(xmlFile); final Source source = XMLUtil.createSourceFromStream(inputStream); webServiceParams = (WebServiceParams) batchSchemaDao.getJAXB2Template().getJaxb2Marshaller() .unmarshal(source); } else { createAndThrowMissingXmlException(WebServiceConstants.INPUT_XML_NOT_FOUND_CODE, WebServiceConstants.INPUT_XML_NOT_FOUND_MESSAGE); } final List<Param> paramList = webServiceParams.getParams().getParam(); if (paramList == null || paramList.isEmpty()) { final HttpStatus status = HttpStatus.INTERNAL_SERVER_ERROR; final RestError restError = new RestError(status, WebServiceConstants.PARAMETER_XML_INCORRECT_CODE, WebServiceConstants.PARAMETER_XML_INCORRECT_MESSAGE, WebServiceConstants.PARAMETER_XML_INCORRECT_MESSAGE + WebServiceConstants.CLASS_WEB_SERVICE_UTILITY, WebServiceConstants.DEFAULT_URL); LOGGER.error(status + WebServiceConstants.PARAMETER_XML_INCORRECT_MESSAGE); throw new ValidationException(WebServiceConstants.PARAMETER_XML_INCORRECT_MESSAGE, restError); } else { LOGGER.info("Initializing input parameters."); String batchClassName = WebServiceConstants.EMPTY_STRING; String batchClassDescription = WebServiceConstants.EMPTY_STRING; String batchClassPriority = WebServiceConstants.EMPTY_STRING; String uncFolderName = WebServiceConstants.EMPTY_STRING; String batchClassIdentifier = WebServiceConstants.EMPTY_STRING; String gridWorkflow = WebServiceConstants.EMPTY_STRING; for (final Param param : paramList) { if ((WebServiceConstants.BATCH_CLASS_NAME).equalsIgnoreCase(param.getName())) { batchClassName = param.getValue().trim(); LOGGER.info("Batch class name entered is :" + batchClassName); continue; } if ((WebServiceConstants.BATCH_CLASS_DESCRIPTION).equalsIgnoreCase(param.getName())) { batchClassDescription = param.getValue().trim(); LOGGER.info("Batch class description given is :" + batchClassDescription); continue; } if ((WebServiceConstants.BATCH_CLASS_PRIORITY).equalsIgnoreCase(param.getName())) { batchClassPriority = param.getValue().trim(); LOGGER.info("Batch class priority entered is :" + batchClassPriority); continue; } if ((WebServiceConstants.BATCH_UNC_FOLDER_NAME).equalsIgnoreCase(param.getName())) { uncFolderName = param.getValue().trim(); LOGGER.info("UNC folder path entered is : " + uncFolderName); continue; } if ((WebServiceConstants.COPY_BATCH_CLASS_IDENTIFIER) .equalsIgnoreCase(param.getName())) { batchClassIdentifier = param.getValue().trim(); LOGGER.info("Batch class identifier used for copying batch class is :" + batchClassIdentifier); continue; } if ((WebServiceConstants.IS_GRIDWORKFLOW).equalsIgnoreCase(param.getName())) { gridWorkflow = param.getValue().trim(); LOGGER.info("Grid workflow is :" + gridWorkflow); continue; } } // Validation for batch class creation parameters // provided. LOGGER.info("Validating parameters."); respStr = validateCreateBatchClassParameters(batchClassName, batchClassDescription, batchClassPriority, uncFolderName, batchClassIdentifier, gridWorkflow); // verify for unique entries for batch class and unc // folders. if (respStr.isEmpty()) { respStr = validateBatchClassAndUNC(batchClassName, uncFolderName, batchClassIdentifier); if (respStr.isEmpty()) { // After validation creating batch class. Set<String> superAdminGroups = userConnectivityService.getAllSuperAdminGroups(); if (superAdminGroups != null && !superAdminGroups.isEmpty()) { performBatchClassCreation(batchClassName, batchClassDescription, batchClassPriority, uncFolderName, batchClassIdentifier, superAdminGroups.toArray()[0].toString()); BatchClass batchClass = batchClassService .getBatchClassbyUncFolder(uncFolderName); List<BatchClassGroups> assignedRoles = new ArrayList<BatchClassGroups>(); BatchClassGroups bcGrup = new BatchClassGroups(); bcGrup.setBatchClass(batchClass); for (int itr = 1; itr < superAdminGroups.size(); itr++) { bcGrup.setGroupName(superAdminGroups.toArray()[itr].toString()); } assignedRoles.add(bcGrup); // batchClass.setAssignedGroups(assignedRoles); batchClassService.saveOrUpdate(batchClass); // JIRA-BUG-ID-11125 deploymentService.createAndDeployProcessDefinition(batchClass, false); } else { respStr = "Error in retreving admin groups.Please check user-connectivity settings."; final HttpStatus status = HttpStatus.FORBIDDEN; final RestError restError = new RestError(status, WebServiceConstants.ADMIN_ROLES_NOT_FOUND, respStr, WebServiceConstants.CLASS_WEB_SERVICE_UTILITY, WebServiceConstants.DEFAULT_URL); LOGGER.error( "Error in retreving admin groups.Please check user-connectivity settings" + status); throw new ValidationException(respStr, restError); } } else { final HttpStatus status = HttpStatus.UNPROCESSABLE_ENTITY; final RestError restError = new RestError(status, WebServiceConstants.VALIDATION_EXCEPTION_CODE, respStr, WebServiceConstants.VALIDATION_EXCEPTION_MESSAGE + WebServiceConstants.CLASS_WEB_SERVICE_UTILITY, WebServiceConstants.DEFAULT_URL); LOGGER.error(respStr + WebServiceConstants.HTTP_STATUS + status); throw new ValidationException(respStr, restError); } } else { final HttpStatus status = HttpStatus.UNPROCESSABLE_ENTITY; final RestError restError = new RestError(status, WebServiceConstants.VALIDATION_EXCEPTION_CODE, respStr, WebServiceConstants.CLASS_WEB_SERVICE_UTILITY, WebServiceConstants.DEFAULT_URL); LOGGER.error("Error in Validating Input XML " + respStr + status); throw new ValidationException(respStr, restError); } } } } catch (org.xml.sax.SAXParseException Ex) { respStr = "Error in Parsing Input XML.Please try again"; final RestError restError = new RestError(HttpStatus.UNPROCESSABLE_ENTITY, WebServiceConstants.INPUT_XML_NOT_ABLE_TO_PARSE_CODE, respStr, WebServiceConstants.INPUT_XML_NOT_ABLE_TO_PARSE_MESSAGE + WebServiceConstants.CLASS_WEB_SERVICE_UTILITY, WebServiceConstants.DEFAULT_URL); LOGGER.error("Error response at server:" + respStr); throw new ValidationException(respStr, restError); } catch (final FileNotFoundException fe) { respStr = "Input XMl file is not found.Please try again"; final RestError restError = new RestError(HttpStatus.NOT_FOUND, WebServiceConstants.INPUT_XML_NOT_FOUND_CODE, respStr, WebServiceConstants.INPUT_XML_NOT_FOUND_MESSAGE + WebServiceConstants.CLASS_WEB_SERVICE_UTILITY, WebServiceConstants.DEFAULT_URL); LOGGER.error("Error response at server:" + respStr + fe); throw new ValidationException(WebServiceConstants.INTERNAL_SERVER_ERROR_MESSAGE, restError); } catch (ValidationException validationException) { throw validationException; } catch (InternalServerException validationException) { throw validationException; } catch (final Exception exception) { final HttpStatus status = HttpStatus.INTERNAL_SERVER_ERROR; respStr = WebServiceConstants.INTERNAL_SERVER_ERROR_MESSAGE + exception; final RestError restError = new RestError(status, WebServiceConstants.INTERNAL_SERVER_ERROR_CODE, respStr, respStr + WebServiceConstants.CLASS_WEB_SERVICE_UTILITY, WebServiceConstants.DEFAULT_URL); LOGGER.error("Error response at server:" + respStr + exception); throw new InternalServerException(respStr, restError); } finally { if (!workingDir.isEmpty()) { FileUtils.deleteDirectoryAndContentsRecursive(new File(workingDir).getParentFile()); } } } else { final HttpStatus status = HttpStatus.UNPROCESSABLE_ENTITY; final RestError restError = new RestError(status, WebServiceConstants.VALIDATION_EXCEPTION_CODE, WebServiceConstants.INPUT_FILES_NOT_FOUND_MESSAGE, respStr + WebServiceConstants.CLASS_WEB_SERVICE_UTILITY, WebServiceConstants.DEFAULT_URL); LOGGER.error(respStr + WebServiceConstants.HTTP_STATUS + status); throw new ValidationException(respStr, restError); } }
From source file:com.ephesoft.dcma.webservice.util.WebServiceHelper.java
/** * Perform the learning for provided batch class identifier. * //from ww w. ja v a 2s .c o m * @param batchClassIdentifier {@link String} the identifier for the batch class for which learning has to be done. * @throws InternalServerException * @throws ValidationException */ public void performLearningForBatchClass(final String batchClassIdentifier) throws InternalServerException, ValidationException { String respStr = WebServiceConstants.EMPTY_STRING; // validating the input for batch class identifier. respStr = validateBatchClassIdentifier(batchClassIdentifier); if (respStr.isEmpty()) { try { learnFileForBatchClass(batchClassIdentifier); } catch (final Exception e) { final HttpStatus status = HttpStatus.INTERNAL_SERVER_ERROR; respStr = WebServiceConstants.IMPROPER_INPUT_TO_SERVER_MESSAGE; final RestError restError = new RestError(status, WebServiceConstants.IMPROPER_INPUT_TO_SERVER_CODE, WebServiceConstants.IMPROPER_INPUT_TO_SERVER_MESSAGE, WebServiceConstants.IMPROPER_INPUT_TO_SERVER_MESSAGE + WebServiceConstants.CLASS_WEB_SERVICE_UTILITY, WebServiceConstants.DEFAULT_URL); LOGGER.error(respStr + WebServiceConstants.HTTP_STATUS + status); throw new InternalServerException(WebServiceConstants.IMPROPER_INPUT_TO_SERVER_MESSAGE, restError); } } else { final HttpStatus status = HttpStatus.UNPROCESSABLE_ENTITY; final RestError restError = new RestError(status, WebServiceConstants.VALIDATION_EXCEPTION_CODE, respStr, respStr + WebServiceConstants.CLASS_WEB_SERVICE_UTILITY, WebServiceConstants.DEFAULT_URL); LOGGER.error(respStr + WebServiceConstants.HTTP_STATUS + status); throw new ValidationException(respStr, restError); } }
From source file:com.ephesoft.dcma.webservice.util.WebServiceHelper.java
/** * Gets the batch instance list on the basis of passed status, roles of the logged in user and flag whether the user is super admin * or not./*from w w w. j a v a 2s. c o m*/ * * @param statusParam the batch instance status * @param loggedInUserRole the logged in user role * @param isSuperAdmin the flag if the user is super admin * @return the batch instance list * @throws ValidationException * @throws ValidationException the validation exception */ public BatchInstances getBatchInstanceList(final String statusParam, final Set<String> loggedInUserRole, final boolean isSuperAdmin) throws ValidationException { final BatchInstances batchInstances = new BatchInstances(); boolean isStatusValid = false; String status = null; final List<String> statusList = BatchInstanceStatus.valuesAsStringList(); for (final String statusItem : statusList) { if (statusItem.equalsIgnoreCase(statusParam)) { status = statusItem; isStatusValid = true; break; } } if (!isStatusValid) { throw new ValidationException(WebServiceConstants.INVALID_BATCH_INSTANCE_STATUS_MESSAGE, new RestError(HttpStatus.UNPROCESSABLE_ENTITY, WebServiceConstants.INVALID_BATCH_INSTANCE_STATUS_CODE, WebServiceConstants.INVALID_BATCH_INSTANCE_STATUS_MESSAGE, WebServiceConstants.INVALID_BATCH_INSTANCE_STATUS_MESSAGE + WebServiceConstants.CLASS_WEB_SERVICE_UTILITY, WebServiceConstants.DEFAULT_URL)); } else { final Set<String> batchInstancesId = new TreeSet<String>(); final BatchInstanceStatus batchInstanceStatus = BatchInstanceStatus.valueOf(status); LOGGER.info("Batch instance status is " + status); LOGGER.info("Fetching batch instance list from the database"); final List<BatchInstance> batchInstance = batchInstanceService .getBatchInstByStatus(batchInstanceStatus); if (CollectionUtils.isNotEmpty(batchInstance)) { if (!isSuperAdmin) { // fetch the batch instances from batch instance groups final Set<String> batchInstancesIdentifiers = batchInstanceGroupsService .getBatchInstanceIdentifierForUserRoles(loggedInUserRole); if (CollectionUtils.isNotEmpty(batchInstancesIdentifiers)) { batchInstancesId.addAll(batchInstancesIdentifiers); } // fetch the list of batch instances from the batch instance // table for batch classes having the given role. final List<BatchClass> batchClasses = batchClassService .getAllBatchClassesByUserRoles(loggedInUserRole); List<BatchInstance> eachBatchInstance; for (final BatchClass batchClass : batchClasses) { // TODO : service hit should not be inside a loop. // Modify the API to return list of Identifiers // only, rather than complete objects. eachBatchInstance = batchInstanceService.getBatchInstByBatchClass(batchClass); for (final BatchInstance bi : eachBatchInstance) { batchInstancesId.add(bi.getIdentifier()); } } } else { for (final BatchInstance bi : batchInstance) { batchInstancesId.add(bi.getIdentifier()); } } LOGGER.info("Fetched list of batch instances from the batch instance table" + " for batch classes having the given role:"); LOGGER.info(batchInstancesId.toString()); final List<com.ephesoft.dcma.batch.schema.BatchInstances.BatchInstance> batchInstanceList = batchInstances .getBatchInstance(); com.ephesoft.dcma.batch.schema.BatchInstances.BatchInstance batchLocal; for (final BatchInstance eachBatchInstance : batchInstance) { if (batchInstancesId.contains(eachBatchInstance.getIdentifier())) { batchLocal = new com.ephesoft.dcma.batch.schema.BatchInstances.BatchInstance(); batchLocal.setIdentifier(eachBatchInstance.getIdentifier()); batchLocal.setBatchName(eachBatchInstance.getBatchName()); batchLocal.setCurrentUser(eachBatchInstance.getCurrentUser()); batchLocal.setExecutedModules(eachBatchInstance.getExecutedModules()); batchLocal.setLocalFolder(eachBatchInstance.getLocalFolder()); batchLocal.setRemoteBatchInstanceId(eachBatchInstance.getRemoteBatchInstance() != null ? eachBatchInstance.getRemoteBatchInstance().getRemoteBatchInstanceIdentifier() : null); batchLocal.setReviewOperatorName(eachBatchInstance.getReviewUserName()); batchLocal.setServerIP(eachBatchInstance.getServerIP()); batchLocal.setUncSubFolder(eachBatchInstance.getUncSubfolder()); batchLocal.setValidateOperatorName(eachBatchInstance.getValidationUserName()); batchInstanceList.add(batchLocal); } } } } return batchInstances; }
From source file:com.ephesoft.dcma.webservice.util.WebServiceHelper.java
/** * Adds the user roles to batch instance. * //from w ww . j a va 2 s .com * @param identifier the batch class identifier * @param userRole the user role to add * @param isSuperAdmin the flag if user is super admin * @return the success or failure message. * @throws ValidationException the validation exception * @throws UnAuthorisedAccessException the un authorised access exception */ public String addUserRolesToBatchInstance(final String identifier, final String userRole, final Boolean isSuperAdmin) throws ValidationException, UnAuthorisedAccessException { boolean isRoleAdded = false; final BatchInstance batchInstance = batchInstanceService.getBatchInstanceByIdentifier(identifier); final Set<String> allRoles = userConnectivityService.getAllGroups(); if (CollectionUtils.isNotEmpty(allRoles) && allRoles.contains(userRole)) { if (batchInstance != null) { if (isSuperAdmin) { batchInstanceGroupsService.addUserRolesToBatchInstanceIdentifier(identifier, userRole); isRoleAdded = true; } else { throw new UnAuthorisedAccessException(); } } else { createAndThrowValidationException(identifier, WebServiceConstants.INVALID_BATCH_INSTANCE_IDENTIFIER_CODE, WebServiceConstants.INVALID_BATCH_INSTANCE_IDENTIFIER_MESSAGE); } } else { throw new ValidationException(WebServiceConstants.INVALID_ROLE_ERROR_MESSAGE, new RestError(HttpStatus.UNPROCESSABLE_ENTITY, WebServiceConstants.INVALID_ROLE_ERROR_CODE, WebServiceConstants.INVALID_ROLE_ERROR_MESSAGE, WebServiceConstants.INVALID_ROLE_ERROR_MESSAGE + WebServiceConstants.CLASS_WEB_SERVICE_UTILITY, WebServiceConstants.DEFAULT_URL)); } return isRoleAdded ? WebServiceConstants.USER_ROLE_ADDED_SUCCESS_MESSAGE + getAdditionalInfo(userRole + " added to " + identifier) : WebServiceConstants.USER_ROLE_ADDED_FAILURE_MESSAGE + identifier; }