List of usage examples for java.util EnumMap put
public V put(K key, V value)
From source file:org.alfresco.solr.SolrInformationServer.java
private void categorizeNodes(List<Node> nodes, Map<Long, Node> nodeIdsToNodes, EnumMap<SolrApiNodeStatus, List<Long>> nodeStatusToNodeIds) { for (Node node : nodes) { nodeIdsToNodes.put(node.getId(), node); List<Long> nodeIds = nodeStatusToNodeIds.get(node.getStatus()); if (nodeIds == null) { nodeIds = new LinkedList<>(); nodeStatusToNodeIds.put(node.getStatus(), nodeIds); }/*from w w w . ja va 2 s.co m*/ nodeIds.add(node.getId()); } }
From source file:tasly.greathealth.oms.inventory.services.impl.DefaultItemQuantityService.java
@Override @Transactional/*from w ww .jav a 2 s . c o m*/ public EnumMap<HandleReturn, Object> handleUpdateMethod( final List<TaslyItemLocationData> taslyItemLocationDatas, final String sku, final int flag, final int totalNumber) { final EnumMap<HandleReturn, Object> retMap = new EnumMap<HandleReturn, Object>(HandleReturn.class); boolean status = true; boolean flagStatus = false;// insert new itemQuantity flagStatus. int totalOccupy = 0; try { for (int i = 0; i < taslyItemLocationDatas.size(); i++) { final List<ItemQuantityData> itemQuantityDatas = taslyItemLocationDatas.get(i).getItemQuantities(); if (itemQuantityDatas == null || itemQuantityDatas.size() == 0)// no itemQuantityDatas, create! { final CurrentItemQuantityData currentItemQuantityData = getPersistenceManager() .create(CurrentItemQuantityData.class); currentItemQuantityData.setQuantityValue(0); currentItemQuantityData.setStatusCode("ON_HAND"); currentItemQuantityData.setOwner(taslyItemLocationDatas.get(i)); flagStatus = true; } else if (itemQuantityDatas.size() > 0 && flag == 0)// flag=0 itemQuantityData exist,no need update { status = false; } else // itemQuantityDatas exist, check number { final ItemQuantityData iqd = checkItemQuantitySatus(itemQuantityDatas); if (iqd == null) { omsLOG.info("There is no on_hand data!"); status = false; break; } final StockroomLocationData sld = taslyItemLocationDatas.get(i).getStockroomLocation(); final int occupy = iqd.getQuantityValue() - calculateAts(sld, sku); totalOccupy = totalOccupy + occupy; // omsLOG.info("Sku:" + sku + ",LocationId:" + locationId + ",Assign value:" // + (int) Math.round(totalNumber * taslyItemLocationDatas.get(i).getAllocationPercent() / 100.0) // + ",Get value:" + iqd.getQuantityValue() + ",Ats value:" + atsResult.getResult(sku, atsId, // locationId)); // if ((int) Math.round(totalNumber * taslyItemLocationDatas.get(i).getAllocationPercent() / 100.0) < // occupy) // { // omsLOG.error("SKU:" + sku + ",LocationId:" + locationId + // ",occupy number bigger than pre assigned value!"); // // status = false; // }// this sku all ItemLocations skipped! } } } catch (final Exception e) { omsLOG.error("error is " + e); } if (flag == 0 && flagStatus)// flag = 0 and insert new itemQuantity need to be assign. { retMap.put(HandleReturn.handleStatus, true); retMap.put(HandleReturn.availableNumber, 0); retMap.put(HandleReturn.errorStatus, false); return retMap; } else { retMap.put(HandleReturn.handleStatus, status); retMap.put(HandleReturn.availableNumber, totalNumber - totalOccupy); if (totalNumber < totalOccupy) { omsLOG.error("SKU:" + sku + ",totalNumber:" + totalNumber + ",<,totalOccupy:" + totalOccupy); retMap.put(HandleReturn.errorStatus, true); } else { retMap.put(HandleReturn.errorStatus, false); } return retMap; } }
From source file:org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.java
public EnumMap<AuditingFieldsKeysEnum, Object> createArtifactAuditingFields( ArtifactDefinition artifactDefinition, String prevArtifactUuid, String currentArtifactUuid) { EnumMap<AuditingFieldsKeysEnum, Object> auditingFields = new EnumMap<AuditingFieldsKeysEnum, Object>( AuditingFieldsKeysEnum.class); // Putting together artifact info String artifactData = buildAuditingArtifactData(artifactDefinition); auditingFields.put(AuditingFieldsKeysEnum.AUDIT_ARTIFACT_DATA, artifactData); auditingFields.put(AuditingFieldsKeysEnum.AUDIT_PREV_ARTIFACT_UUID, prevArtifactUuid); auditingFields.put(AuditingFieldsKeysEnum.AUDIT_CURR_ARTIFACT_UUID, currentArtifactUuid); return auditingFields; }
From source file:org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.java
public void handleAuditing(AuditingActionEnum auditingActionEnum, Component component, String componentId, User user, ArtifactDefinition artifactDefinition, String prevArtifactUuid, String currentArtifactUuid, ResponseFormat responseFormat, ComponentTypeEnum componentTypeEnum, String resourceInstanceName) { if (auditingActionEnum.getAuditingEsType().equals(AuditingTypesConstants.EXTERNAL_API_EVENT_TYPE)) { return;//from w ww. j a va 2 s .c o m } EnumMap<AuditingFieldsKeysEnum, Object> auditingFields = createArtifactAuditingFields(artifactDefinition, prevArtifactUuid, currentArtifactUuid); if (user == null) { user = new User(); user.setUserId("UNKNOWN"); } switch (componentTypeEnum) { case RESOURCE: Resource resource = (Resource) component; if (resource == null) { // In that case, component ID should be instead of name resource = new Resource(); resource.setName(componentId); } componentsUtils.auditResource(responseFormat, user, resource, null, null, auditingActionEnum, auditingFields); break; case SERVICE: Service service = (Service) component; if (service == null) { // In that case, component ID should be instead of name service = new Service(); service.setName(componentId); } componentsUtils.auditComponent(responseFormat, user, service, null, null, auditingActionEnum, ComponentTypeEnum.SERVICE, auditingFields); break; case RESOURCE_INSTANCE: if (resourceInstanceName == null) { resourceInstanceName = getResourceInstanceNameFromComponent(component, componentId); } auditingFields.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_NAME, resourceInstanceName); componentsUtils.auditComponent(responseFormat, user, component, null, null, auditingActionEnum, ComponentTypeEnum.RESOURCE_INSTANCE, auditingFields); break; default: break; } }
From source file:sg.ncl.MainController.java
@RequestMapping(path = "/password_reset") public String resetPassword(@ModelAttribute("passwordResetForm") PasswordResetForm passwordResetForm) throws IOException { if (!passwordResetForm.isPasswordOk()) { return FORGET_PSWD_NEW_PSWD_PAGE; }/* w w w .ja va 2 s . c o m*/ JSONObject obj = new JSONObject(); obj.put("key", passwordResetForm.getKey()); obj.put("new", passwordResetForm.getPassword1()); log.info("Connecting to sio for password reset, key = {}", passwordResetForm.getKey()); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); HttpEntity<String> request = new HttpEntity<>(obj.toString(), headers); restTemplate.setErrorHandler(new MyResponseErrorHandler()); ResponseEntity response = null; try { response = restTemplate.exchange(properties.getPasswordResetURI(), HttpMethod.PUT, request, String.class); } catch (RestClientException e) { log.warn("Error connecting to sio for password reset! {}", e); passwordResetForm.setErrMsg("Cannot connect to server! Please try again later."); return FORGET_PSWD_NEW_PSWD_PAGE; } if (RestUtil.isError(response.getStatusCode())) { EnumMap<ExceptionState, String> exceptionMessageMap = new EnumMap<>(ExceptionState.class); exceptionMessageMap.put(PASSWORD_RESET_REQUEST_TIMEOUT_EXCEPTION, "Password reset request timed out. Please request a new reset email."); exceptionMessageMap.put(PASSWORD_RESET_REQUEST_NOT_FOUND_EXCEPTION, "Invalid password reset request. Please request a new reset email."); exceptionMessageMap.put(ADAPTER_CONNECTION_EXCEPTION, "Server-side error. Please contact " + CONTACT_EMAIL); MyErrorResource error = objectMapper.readValue(response.getBody().toString(), MyErrorResource.class); ExceptionState exceptionState = ExceptionState.parseExceptionState(error.getError()); final String errMsg = exceptionMessageMap.get(exceptionState) == null ? ERR_SERVER_OVERLOAD : exceptionMessageMap.get(exceptionState); passwordResetForm.setErrMsg(errMsg); log.warn("Server responded error for password reset: {}", exceptionState.toString()); return FORGET_PSWD_NEW_PSWD_PAGE; } log.info("Password was reset, key = {}", passwordResetForm.getKey()); return "password_reset_success"; }
From source file:sg.ncl.MainController.java
@RequestMapping(value = "/teams/join_team", method = RequestMethod.POST) public String checkJoinTeamInfo(@Valid TeamPageJoinTeamForm teamPageJoinForm, BindingResult bindingResult, Model model, HttpSession session, final RedirectAttributes redirectAttributes) throws WebServiceRuntimeException { final String LOG_PREFIX = "Existing user join team: {}"; if (bindingResult.hasErrors()) { log.warn(LOG_PREFIX, "Application form error " + teamPageJoinForm.toString()); return "team_page_join_team"; }//from w w w .j a v a 2s.co m JSONObject mainObject = new JSONObject(); JSONObject teamFields = new JSONObject(); JSONObject userFields = new JSONObject(); mainObject.put("team", teamFields); mainObject.put("user", userFields); userFields.put("id", session.getAttribute("id")); // ncl-id teamFields.put("name", teamPageJoinForm.getTeamName()); log.info(LOG_PREFIX, USER_PREFIX + session.getAttribute("id") + ", team " + teamPageJoinForm.getTeamName()); HttpEntity<String> request = createHttpEntityWithBody(mainObject.toString()); ResponseEntity response; try { restTemplate.setErrorHandler(new MyResponseErrorHandler()); response = restTemplate.exchange(properties.getJoinRequestExistingUser(), HttpMethod.POST, request, String.class); String responseBody = response.getBody().toString(); if (RestUtil.isError(response.getStatusCode())) { // prepare the exception mapping EnumMap<ExceptionState, String> exceptionMessageMap = new EnumMap<>(ExceptionState.class); exceptionMessageMap.put(USER_NOT_FOUND_EXCEPTION, "User not found"); exceptionMessageMap.put(USER_ID_NULL_OR_EMPTY_EXCEPTION, "User id is null or empty"); exceptionMessageMap.put(TEAM_NOT_FOUND_EXCEPTION, "Team name not found"); exceptionMessageMap.put(TEAM_NAME_NULL_OR_EMPTY_EXCEPTION, "Team name is null or empty"); exceptionMessageMap.put(USER_ALREADY_IN_TEAM_EXCEPTION, "User already in team"); exceptionMessageMap.put(TEAM_MEMBER_ALREADY_EXISTS_EXCEPTION, "Team member already exists"); exceptionMessageMap.put(ADAPTER_CONNECTION_EXCEPTION, "Connection to adapter failed"); exceptionMessageMap.put(ADAPTER_INTERNAL_ERROR_EXCEPTION, "Internal server error on adapter"); exceptionMessageMap.put(DETERLAB_OPERATION_FAILED_EXCEPTION, "Operation failed on DeterLab"); MyErrorResource error = objectMapper.readValue(responseBody, MyErrorResource.class); ExceptionState exceptionState = ExceptionState.parseExceptionState(error.getError()); final String errorMessage = exceptionMessageMap.containsKey(exceptionState) ? error.getMessage() : ERR_SERVER_OVERLOAD; log.warn(LOG_PREFIX, responseBody); redirectAttributes.addFlashAttribute(MESSAGE, errorMessage); return "redirect:/teams/join_team"; } else { log.info(LOG_PREFIX, "Application for join team " + teamPageJoinForm.getTeamName() + " submitted"); return "redirect:/teams/join_application_submitted/" + teamPageJoinForm.getTeamName(); } } catch (ResourceAccessException | IOException e) { throw new WebServiceRuntimeException(e.getMessage()); } }
From source file:sg.ncl.MainController.java
@RequestMapping(value = "/teams/apply_team", method = RequestMethod.POST) public String checkApplyTeamInfo(@Valid TeamPageApplyTeamForm teamPageApplyTeamForm, BindingResult bindingResult, HttpSession session, final RedirectAttributes redirectAttributes) throws WebServiceRuntimeException { final String LOG_PREFIX = "Existing user apply for new team: {}"; if (bindingResult.hasErrors()) { log.warn(LOG_PREFIX, "Application form error " + teamPageApplyTeamForm.toString()); return "team_page_apply_team"; }/*from www .j a v a2 s .c om*/ // log data to ensure data has been parsed log.debug(LOG_PREFIX, properties.getRegisterRequestToApplyTeam(session.getAttribute("id").toString())); log.info(LOG_PREFIX, teamPageApplyTeamForm.toString()); JSONObject mainObject = new JSONObject(); JSONObject teamFields = new JSONObject(); mainObject.put("team", teamFields); teamFields.put("name", teamPageApplyTeamForm.getTeamName()); teamFields.put(DESCRIPTION, teamPageApplyTeamForm.getTeamDescription()); teamFields.put(WEBSITE, teamPageApplyTeamForm.getTeamWebsite()); teamFields.put(ORGANISATION_TYPE, teamPageApplyTeamForm.getTeamOrganizationType()); teamFields.put(VISIBILITY, teamPageApplyTeamForm.getIsPublic()); teamFields.put(IS_CLASS, teamPageApplyTeamForm.getIsClass()); String nclUserId = session.getAttribute("id").toString(); HttpEntity<String> request = createHttpEntityWithBody(mainObject.toString()); ResponseEntity response; try { response = restTemplate.exchange(properties.getRegisterRequestToApplyTeam(nclUserId), HttpMethod.POST, request, String.class); String responseBody = response.getBody().toString(); if (RestUtil.isError(response.getStatusCode())) { // prepare the exception mapping EnumMap<ExceptionState, String> exceptionMessageMap = new EnumMap<>(ExceptionState.class); exceptionMessageMap.put(USER_ID_NULL_OR_EMPTY_EXCEPTION, "User id is null or empty "); exceptionMessageMap.put(TEAM_NAME_NULL_OR_EMPTY_EXCEPTION, "Team name is null or empty "); exceptionMessageMap.put(USER_NOT_FOUND_EXCEPTION, "User not found"); exceptionMessageMap.put(TEAM_NAME_ALREADY_EXISTS_EXCEPTION, "Team name already exists"); exceptionMessageMap.put(INVALID_TEAM_NAME_EXCEPTION, "Team name contains invalid characters"); exceptionMessageMap.put(TEAM_MEMBER_ALREADY_EXISTS_EXCEPTION, "Team member already exists"); exceptionMessageMap.put(ADAPTER_CONNECTION_EXCEPTION, "Connection to adapter failed"); exceptionMessageMap.put(ADAPTER_INTERNAL_ERROR_EXCEPTION, "Internal server error on adapter"); exceptionMessageMap.put(DETERLAB_OPERATION_FAILED_EXCEPTION, "Operation failed on DeterLab"); MyErrorResource error = objectMapper.readValue(responseBody, MyErrorResource.class); ExceptionState exceptionState = ExceptionState.parseExceptionState(error.getError()); final String errorMessage = exceptionMessageMap.containsKey(exceptionState) ? error.getMessage() : ERR_SERVER_OVERLOAD; log.warn(LOG_PREFIX, responseBody); redirectAttributes.addFlashAttribute(MESSAGE, errorMessage); return "redirect:/teams/apply_team"; } else { // no errors, everything ok log.info(LOG_PREFIX, "Application for team " + teamPageApplyTeamForm.getTeamName() + " submitted"); return "redirect:/teams/team_application_submitted"; } } catch (ResourceAccessException | IOException e) { log.error(LOG_PREFIX, e); throw new WebServiceRuntimeException(e.getMessage()); } }