@Override public Response getStatisticByAgency(HttpServletRequest request, HttpHeaders header, Company company, Locale locale, User user, ServiceContext serviceContext) { ServiceInfoActions actions = new ServiceInfoActionsImpl(); long groupId = GetterUtil.getLong(header.getHeaderString("groupId")); JSONObject results = JSONFactoryUtil.createJSONObject(); try { results = actions.getStatisticByAdministration(serviceContext, groupId); _log.info(results); return Response.status(200).entity(JSONFactoryUtil.looseSerialize(results)).build(); } catch (Exception e) { ErrorMsg error = new ErrorMsg(); error.setMessage("Forbidden."); error.setCode(HttpURLConnection.HTTP_FORBIDDEN); error.setDescription("Forbidden."); return Response.status(HttpURLConnection.HTTP_FORBIDDEN).entity(error).build(); } }
@Override public Response getStatisticByDomain(HttpServletRequest request, HttpHeaders header, Company company, Locale locale, User user, ServiceContext serviceContext) { ServiceInfoActions actions = new ServiceInfoActionsImpl(); long groupId = GetterUtil.getLong(header.getHeaderString("groupId")); JSONObject results = JSONFactoryUtil.createJSONObject(); try { results = actions.getStatisticByDomain(serviceContext, groupId); _log.info(results); return Response.status(200).entity(JSONFactoryUtil.looseSerialize(results)).build(); } catch (Exception e) { ErrorMsg error = new ErrorMsg(); error.setMessage("Forbidden."); error.setCode(HttpURLConnection.HTTP_FORBIDDEN); error.setDescription("Forbidden."); return Response.status(HttpURLConnection.HTTP_FORBIDDEN).entity(error).build(); } }
@Override public Response deleteFormbyRegId(HttpServletRequest request, HttpHeaders header, Company company, Locale locale, User user, ServiceContext serviceContext, long id, String referenceUid) { BackendAuth auth = new BackendAuthImpl(); try { if (!auth.isAuth(serviceContext)) { throw new UnauthenticationException(); } long groupId = GetterUtil.getLong(header.getHeaderString("groupId")); RegistrationFormActions action = new RegistrationFormActionsImpl(); action.deleteRegistrationForm(groupId, id, referenceUid); return Response.status(HttpURLConnection.HTTP_NO_CONTENT).build(); } catch (Exception e) { return processException(e); } }
private Response processException(Exception e) { ErrorMsg error = new ErrorMsg(); if (e instanceof UnauthenticationException) { error.setMessage("Non-Authoritative Information."); error.setCode(HttpURLConnection.HTTP_NOT_AUTHORITATIVE); error.setDescription("Non-Authoritative Information."); return Response.status(HttpURLConnection.HTTP_NOT_AUTHORITATIVE).entity(error).build(); } else { if (e instanceof UnauthorizationException) { error.setMessage("Unauthorized."); error.setCode(HttpURLConnection.HTTP_NOT_AUTHORITATIVE); error.setDescription("Unauthorized."); return Response.status(HttpURLConnection.HTTP_UNAUTHORIZED).entity(error).build(); } else { error.setMessage("No Content."); error.setCode(HttpURLConnection.HTTP_FORBIDDEN); error.setDescription("No Content."); return Response.status(HttpURLConnection.HTTP_FORBIDDEN).entity(error).build(); } } }
private Response processException(Exception e) { ErrorMsg error = new ErrorMsg(); if (e instanceof UnauthenticationException) { error.setMessage("Non-Authoritative Information."); error.setCode(HttpURLConnection.HTTP_NOT_AUTHORITATIVE); error.setDescription("Non-Authoritative Information."); return Response.status(HttpURLConnection.HTTP_NOT_AUTHORITATIVE).entity(error).build(); } else { if (e instanceof UnauthorizationException) { error.setMessage("Unauthorized."); error.setCode(HttpURLConnection.HTTP_NOT_AUTHORITATIVE); error.setDescription("Unauthorized."); return Response.status(HttpURLConnection.HTTP_UNAUTHORIZED).entity(error).build(); } else { _log.error(e); error.setMessage("No Content."); error.setCode(HttpURLConnection.HTTP_FORBIDDEN); error.setDescription("No Content."); return Response.status(HttpURLConnection.HTTP_FORBIDDEN).entity(error).build(); } } }
private Response processException(Exception e) { ErrorMsg error = new ErrorMsg(); if (e instanceof UnauthenticationException) { error.setMessage("Non-Authoritative Information."); error.setCode(HttpURLConnection.HTTP_NOT_AUTHORITATIVE); error.setDescription("Non-Authoritative Information."); return Response.status(HttpURLConnection.HTTP_NOT_AUTHORITATIVE).entity(error).build(); } else { if (e instanceof UnauthorizationException) { error.setMessage("Unauthorized."); error.setCode(HttpURLConnection.HTTP_NOT_AUTHORITATIVE); error.setDescription("Unauthorized."); return Response.status(HttpURLConnection.HTTP_UNAUTHORIZED).entity(error).build(); } else { error.setMessage("No Content."); error.setCode(HttpURLConnection.HTTP_FORBIDDEN); error.setDescription(e.getMessage()); return Response.status(HttpURLConnection.HTTP_FORBIDDEN).entity(error).build(); } } }
@Override public Response previewFile(HttpServletRequest request, HttpHeaders header, Company company, Locale locale, User user, ServiceContext serviceContext, long registrationId, String referenceUid) { BackendAuth auth = new BackendAuthImpl(); try { if (!auth.isAuth(serviceContext)) { throw new UnauthenticationException(); } long groupId = GetterUtil.getLong(header.getHeaderString("groupId")); RegistrationForm registrationForm = RegistrationFormLocalServiceUtil.findFormbyRegidRefid(groupId, registrationId, referenceUid); if (registrationForm != null && registrationForm.getFileEntryId() > 0) { FileEntry fileEntry = DLAppLocalServiceUtil.getFileEntry(registrationForm.getFileEntryId()); File file = DLFileEntryLocalServiceUtil.getFile(fileEntry.getFileEntryId(), fileEntry.getVersion(), true); ResponseBuilder responseBuilder = Response.ok((Object) file); responseBuilder.header("Content-Disposition", "attachment; filename=\"" + fileEntry.getFileName() + "\""); responseBuilder.header("Content-Type", fileEntry.getMimeType()); return responseBuilder.build(); } else { return Response.status(HttpURLConnection.HTTP_NO_CONTENT).build(); } } catch (Exception e) { return processException(e); } }
@Override public Response getServiceConfig(HttpServletRequest request, HttpHeaders header, Company company, Locale locale, User user, ServiceContext serviceContext, long id) { ServiceConfigActions actions = new ServiceConfigActionImpl(); ServiceConfigDetailModel returnModel = new ServiceConfigDetailModel(); try { ServiceConfig serviceConfig = actions.getServiceConfigDetail(id); returnModel = ServiceConfigUtils.mapptingToServiceConfig(serviceConfig); return Response.status(200).entity(returnModel).build(); } catch (Exception e) { ErrorMsg error = new ErrorMsg(); if (e instanceof NotFoundException) { error.setMessage("Non-Authoritative Information."); error.setCode(HttpURLConnection.HTTP_NOT_FOUND); error.setDescription("Non-Authoritative Information."); return Response.status(HttpURLConnection.HTTP_NOT_FOUND).entity(error).build(); } else { error.setMessage("Internal Server Error"); error.setCode(HttpURLConnection.HTTP_FORBIDDEN); error.setDescription(e.getMessage()); return Response.status(HttpURLConnection.HTTP_INTERNAL_ERROR).entity(error).build(); } } }
@Override public Response getConfig(HttpServletRequest request, HttpHeaders header, Company company, Locale locale, User user, ServiceContext serviceContext, long id) { BackendAuth auth = new BackendAuthImpl(); try { if (!auth.isAuth(serviceContext)) { throw new UnauthenticationException(); } ServerConfig config = ServerConfigLocalServiceUtil.getServerConfig(id); String configStr = config.getConfigs(); ServerConfigSingleInputModel result = new ServerConfigSingleInputModel(); result.setValue(configStr); return Response.status(200).entity(result).build(); } catch (Exception e) { ErrorMsg error = new ErrorMsg(); if (e instanceof UnauthenticationException) { error.setMessage("Non-Authoritative Information."); error.setCode(HttpURLConnection.HTTP_NOT_AUTHORITATIVE); error.setDescription("Non-Authoritative Information."); return Response.status(HttpURLConnection.HTTP_NOT_AUTHORITATIVE).entity(error).build(); } else { error.setMessage("Internal Server Error"); error.setCode(HttpURLConnection.HTTP_FORBIDDEN); error.setDescription(e.getMessage()); return Response.status(HttpURLConnection.HTTP_INTERNAL_ERROR).entity(error).build(); } } }
@Override public Response getDeliverableLog(Long id) { try { DeliverableLogActions action = new DeliverableLogActionsImpl(); DeliverableLog log = action.getDeliverableLog(id); return Response.status(200).entity(log).build(); } catch (Exception e) { return Response.status(HttpURLConnection.HTTP_INTERNAL_ERROR).entity(e).build(); } }
@Override public Response deleteServiceInfo(HttpServletRequest request, HttpHeaders header, Company company, Locale locale, User user, ServiceContext serviceContext, String id) { BackendAuth auth = new BackendAuthImpl(); ServiceInfoActions actions = new ServiceInfoActionsImpl(); ServiceInfoInputModel serviceInfoInput = new ServiceInfoInputModel(); try { if (!auth.isAuth(serviceContext)) { throw new UnauthenticationException(); } if (!auth.hasResource(serviceContext, ServiceInfo.class.getName(), ActionKeys.ADD_ENTRY)) { throw new UnauthorizationException(); } ServiceInfo serviceInfo = actions.removeServiceInfo(GetterUtil.getLong(id)); if (Validator.isNotNull(serviceInfo)) { serviceInfoInput = ServiceInfoUtils.mappingToServiceInfoInputModel(serviceInfo); return Response.status(200).entity(serviceInfoInput).build(); } else { throw new Exception(); } } catch (Exception e) { ErrorMsg error = new ErrorMsg(); if (e instanceof UnauthenticationException) { error.setMessage("Non-Authoritative Information."); error.setCode(HttpURLConnection.HTTP_NOT_AUTHORITATIVE); error.setDescription("Non-Authoritative Information."); return Response.status(HttpURLConnection.HTTP_NOT_AUTHORITATIVE).entity(error).build(); } else { if (e instanceof UnauthorizationException) { error.setMessage("Unauthorized."); error.setCode(HttpURLConnection.HTTP_NOT_AUTHORITATIVE); error.setDescription("Unauthorized."); return Response.status(HttpURLConnection.HTTP_UNAUTHORIZED).entity(error).build(); } else { error.setMessage("No Content."); error.setCode(HttpURLConnection.HTTP_NOT_ACCEPTABLE); error.setDescription("No Content."); return Response.status(HttpURLConnection.HTTP_NO_CONTENT).entity(error).build(); } } } }
@Override public Response deleteFileTemplateOfServiceInfo(HttpServletRequest request, HttpHeaders header, Company company, Locale locale, User user, ServiceContext serviceContext, String id, String templateNo) { BackendAuth auth = new BackendAuthImpl(); ServiceInfoActions actions = new ServiceInfoActionsImpl(); ServiceFileTemplate serviceFileTemplate = null; try { if (!auth.isAuth(serviceContext)) { throw new UnauthenticationException(); } if (!auth.hasResource(serviceContext, ServiceInfo.class.getName(), ActionKeys.ADD_ENTRY)) { throw new UnauthorizationException(); } serviceFileTemplate = actions.removeServiceFileTemplate(GetterUtil.getLong(id), templateNo); FileTemplateModel result = ServiceInfoUtils.mappingToFileTemplateModel(serviceFileTemplate); return Response.status(200).entity(result).build(); } catch (Exception e) { ErrorMsg error = new ErrorMsg(); if (e instanceof UnauthenticationException) { error.setMessage("Non-Authoritative Information."); error.setCode(HttpURLConnection.HTTP_NOT_AUTHORITATIVE); error.setDescription("Non-Authoritative Information."); return Response.status(HttpURLConnection.HTTP_NOT_AUTHORITATIVE).entity(error).build(); } else { if (e instanceof UnauthorizationException) { error.setMessage("Unauthorized."); error.setCode(HttpURLConnection.HTTP_NOT_AUTHORITATIVE); error.setDescription("Unauthorized."); return Response.status(HttpURLConnection.HTTP_UNAUTHORIZED).entity(error).build(); } else { error.setMessage("No Content."); error.setCode(HttpURLConnection.HTTP_NO_CONTENT); error.setDescription("No Content."); return Response.status(HttpURLConnection.HTTP_NO_CONTENT).entity(error).build(); } } } }
@Override public Response getApplicants(HttpServletRequest request, HttpHeaders header, Company company, Locale locale, User user, ServiceContext serviceContext, ApplicantSearchModel query) { ApplicantActions actions = new ApplicantActionsImpl(); ApplicantResultsModel results = new ApplicantResultsModel(); BackendAuth auth = new BackendAuthImpl(); try { if (!auth.isAuth(serviceContext)) { throw new UnauthenticationException(); } if (!auth.hasResource(serviceContext, ServiceInfo.class.getName(), ActionKeys.ADD_ENTRY)) { throw new UnauthorizationException(); } if (query.getEnd() == 0) { query.setStart(-1); query.setEnd(-1); } long groupId = GetterUtil.getLong(header.getHeaderString("groupId")); LinkedHashMap<String, Object> params = new LinkedHashMap<String, Object>(); params.put("groupId", String.valueOf(groupId)); params.put("keywords", query.getKeywords()); params.put("type", query.getType()); params.put("lock", query.getLock()); Sort[] sorts = new Sort[] { SortFactoryUtil.create(query.getSort() + "_sortable", Sort.STRING_TYPE, GetterUtil.getBoolean(query.getOrder())) }; JSONObject jsonData = actions.getApplicants(serviceContext, serviceContext.getUserId(), serviceContext.getCompanyId(), groupId, params, sorts, query.getStart(), query.getEnd(), serviceContext); results.setTotal(jsonData.getInt("total")); results.getData().addAll(ApplicantUtils.mappingToApplicantResults((List<Document>) jsonData.get("data"))); return Response.status(200).entity(results).build(); } catch (Exception e) { ErrorMsg error = new ErrorMsg(); if (e instanceof UnauthenticationException) { error.setMessage("Non-Authoritative Information."); error.setCode(HttpURLConnection.HTTP_NOT_AUTHORITATIVE); error.setDescription("Non-Authoritative Information."); return Response.status(HttpURLConnection.HTTP_NOT_AUTHORITATIVE).entity(error).build(); } else { if (e instanceof UnauthorizationException) { error.setMessage("Unauthorized."); error.setCode(HttpURLConnection.HTTP_NOT_AUTHORITATIVE); error.setDescription("Unauthorized."); return Response.status(HttpURLConnection.HTTP_UNAUTHORIZED).entity(error).build(); } else { error.setMessage("Internal Server Error"); error.setCode(HttpURLConnection.HTTP_FORBIDDEN); error.setDescription(e.getMessage()); return Response.status(HttpURLConnection.HTTP_INTERNAL_ERROR).entity(error).build(); } } } }
@Override public Response getApplicantDetail(HttpServletRequest request, HttpHeaders header, Company company, Locale locale, User user, ServiceContext serviceContext, long id) { ApplicantActions actions = new ApplicantActionsImpl(); ApplicantModel results = new ApplicantModel(); BackendAuth auth = new BackendAuthImpl(); Applicant applicant = null; try { if (!auth.isAuth(serviceContext)) { throw new UnauthenticationException(); } User requestUser = ApplicantUtils.getUser(id); boolean isAllowed = false; if (auth.hasResource(serviceContext, Applicant.class.getName(), ActionKeys.ADD_ENTRY)) { isAllowed = true; } else { if (Validator.isNull(requestUser)) { throw new NoSuchUserException(); } else { // check userLogin is equal userRequest get detail if (requestUser.getUserId() == user.getUserId()) { isAllowed = true; } } } if (isAllowed) { applicant = actions.getApplicantDetail(serviceContext, id); results = ApplicantUtils.mappingToApplicantModel(applicant); return Response.status(200).entity(results).build(); } else { throw new UnauthorizationException(); } } catch (Exception e) { ErrorMsg error = new ErrorMsg(); if (e instanceof UnauthenticationException) { error.setMessage("Non-Authoritative Information."); error.setCode(HttpURLConnection.HTTP_NOT_AUTHORITATIVE); error.setDescription("Non-Authoritative Information."); return Response.status(HttpURLConnection.HTTP_NOT_AUTHORITATIVE).entity(error).build(); } else { if (e instanceof UnauthorizationException) { error.setMessage("Unauthorized."); error.setCode(HttpURLConnection.HTTP_NOT_AUTHORITATIVE); error.setDescription("Unauthorized."); return Response.status(HttpURLConnection.HTTP_UNAUTHORIZED).entity(error).build(); } else { if (e instanceof NoSuchUserException) { error.setMessage("Not Found"); error.setCode(HttpURLConnection.HTTP_NOT_FOUND); error.setDescription("Not Found"); return Response.status(HttpURLConnection.HTTP_NOT_FOUND).entity(error).build(); } else { error.setMessage("Internal Server Error"); error.setCode(HttpURLConnection.HTTP_INTERNAL_ERROR); error.setDescription(e.getMessage()); return Response.status(HttpURLConnection.HTTP_INTERNAL_ERROR).entity(error).build(); } } } } }
@Override public Response updateApplicant(HttpServletRequest request, HttpHeaders header, Company company, Locale locale, User user, ServiceContext serviceContext, long id, ApplicantInputUpdateModel input) { ApplicantActions actions = new ApplicantActionsImpl(); ApplicantModel results = new ApplicantModel(); BackendAuth auth = new BackendAuthImpl(); Applicant applicant = null; long groupId = GetterUtil.getLong(header.getHeaderString("groupId")); try { if (!auth.isAuth(serviceContext)) { throw new UnauthenticationException(); } User requestUser = ApplicantUtils.getUser(id); boolean isAllowed = false; if (auth.hasResource(serviceContext, Applicant.class.getName(), ActionKeys.ADD_ENTRY)) { isAllowed = true; } else { if (Validator.isNull(requestUser)) { throw new NoSuchUserException(); } else { // check userLogin is equal userRequest get detail if (requestUser.getUserId() == user.getUserId()) { isAllowed = true; } } } if (isAllowed) { applicant = actions.updateApplicant(serviceContext,groupId, id, input.getApplicantName(), input.getAddress(), input.getCityCode(), input.getCityName(), input.getDistrictCode(), input.getDistrictName(), input.getWardCode(), input.getWardName(), input.getContactName(), input.getContactTelNo(), input.getContactEmail()); results = ApplicantUtils.mappingToApplicantModel(applicant); return Response.status(200).entity(results).build(); } else { throw new UnauthorizationException(); } } catch (Exception e) { ErrorMsg error = new ErrorMsg(); if (e instanceof UnauthenticationException) { error.setMessage("Non-Authoritative Information."); error.setCode(HttpURLConnection.HTTP_NOT_AUTHORITATIVE); error.setDescription("Non-Authoritative Information."); return Response.status(HttpURLConnection.HTTP_NOT_AUTHORITATIVE).entity(error).build(); } else { if (e instanceof UnauthorizationException) { error.setMessage("Unauthorized."); error.setCode(HttpURLConnection.HTTP_NOT_AUTHORITATIVE); error.setDescription("Unauthorized."); return Response.status(HttpURLConnection.HTTP_UNAUTHORIZED).entity(error).build(); } else { if (e instanceof NoSuchUserException) { error.setMessage("Not Found"); error.setCode(HttpURLConnection.HTTP_NOT_FOUND); error.setDescription("Not Found"); return Response.status(HttpURLConnection.HTTP_NOT_FOUND).entity(error).build(); } else { error.setMessage("Internal Server Error"); error.setCode(HttpURLConnection.HTTP_INTERNAL_ERROR); error.setDescription(e.getMessage()); return Response.status(HttpURLConnection.HTTP_INTERNAL_ERROR).entity(error).build(); } } } } }
@Override public Response deleteApplicant(HttpServletRequest request, HttpHeaders header, Company company, Locale locale, User user, ServiceContext serviceContext, long id) { ApplicantActions actions = new ApplicantActionsImpl(); ApplicantModel results = new ApplicantModel(); BackendAuth auth = new BackendAuthImpl(); Applicant applicant = null; try { if (!auth.isAuth(serviceContext)) { throw new UnauthenticationException(); } boolean isAllowed = false; if (auth.hasResource(serviceContext, Applicant.class.getName(), ActionKeys.ADD_ENTRY)) { isAllowed = true; } if (isAllowed) { applicant = actions.removeApplicant(serviceContext, id); results = ApplicantUtils.mappingToApplicantModel(applicant); return Response.status(200).entity(results).build(); } else { throw new UnauthorizationException(); } } catch (Exception e) { ErrorMsg error = new ErrorMsg(); if (e instanceof UnauthenticationException) { error.setMessage("Non-Authoritative Information."); error.setCode(HttpURLConnection.HTTP_NOT_AUTHORITATIVE); error.setDescription("Non-Authoritative Information."); return Response.status(HttpURLConnection.HTTP_NOT_AUTHORITATIVE).entity(error).build(); } else { if (e instanceof UnauthorizationException) { error.setMessage("Unauthorized."); error.setCode(HttpURLConnection.HTTP_NOT_AUTHORITATIVE); error.setDescription("Unauthorized."); return Response.status(HttpURLConnection.HTTP_UNAUTHORIZED).entity(error).build(); } else { if (e instanceof NoSuchUserException) { error.setMessage("Not Found"); error.setCode(HttpURLConnection.HTTP_NOT_FOUND); error.setDescription("Not Found"); return Response.status(HttpURLConnection.HTTP_NOT_FOUND).entity(error).build(); } else { error.setMessage("Internal Server Error"); error.setCode(HttpURLConnection.HTTP_INTERNAL_ERROR); error.setDescription(e.getMessage()); return Response.status(HttpURLConnection.HTTP_INTERNAL_ERROR).entity(error).build(); } } } } }
@Override public Response getApplicantProfile(HttpServletRequest request, HttpHeaders header, Company company, Locale locale, User user, ServiceContext serviceContext, long id) { ApplicantActions actions = new ApplicantActionsImpl(); BackendAuth auth = new BackendAuthImpl(); Applicant applicant = null; try { if (!auth.isAuth(serviceContext)) { throw new UnauthenticationException(); } User requestUser = ApplicantUtils.getUser(id); boolean isAllowed = false; if (auth.hasResource(serviceContext, Applicant.class.getName(), ActionKeys.ADD_ENTRY)) { isAllowed = true; } else { if (Validator.isNull(requestUser)) { throw new NoSuchUserException(); } else { // check userLogin is equal userRequest get detail if (requestUser.getUserId() == user.getUserId()) { isAllowed = true; } } } if (isAllowed) { applicant = actions.getApplicantDetail (serviceContext, id); JSONObject result = JSONFactoryUtil.createJSONObject(applicant.getProfile()); return Response.status(200).entity(JSONFactoryUtil.looseSerialize(result)).build(); } else { throw new UnauthorizationException(); } } catch (Exception e) { ErrorMsg error = new ErrorMsg(); if (e instanceof UnauthenticationException) { error.setMessage("Non-Authoritative Information."); error.setCode(HttpURLConnection.HTTP_NOT_AUTHORITATIVE); error.setDescription("Non-Authoritative Information."); return Response.status(HttpURLConnection.HTTP_NOT_AUTHORITATIVE).entity(error).build(); } else { if (e instanceof UnauthorizationException) { error.setMessage("Unauthorized."); error.setCode(HttpURLConnection.HTTP_NOT_AUTHORITATIVE); error.setDescription("Unauthorized."); return Response.status(HttpURLConnection.HTTP_UNAUTHORIZED).entity(error).build(); } else { if (e instanceof NoSuchUserException) { error.setMessage("Not Found"); error.setCode(HttpURLConnection.HTTP_NOT_FOUND); error.setDescription("Not Found"); return Response.status(HttpURLConnection.HTTP_NOT_FOUND).entity(error).build(); } else { error.setMessage("Internal Server Error"); error.setCode(HttpURLConnection.HTTP_INTERNAL_ERROR); error.setDescription(e.getMessage()); return Response.status(HttpURLConnection.HTTP_INTERNAL_ERROR).entity(error).build(); } } } } }
@Override public Response addApplicantProfile(HttpServletRequest request, HttpHeaders header, Company company, Locale locale, User user, ServiceContext serviceContext, long id, ProfileInputModel input) { ApplicantActions actions = new ApplicantActionsImpl(); BackendAuth auth = new BackendAuthImpl(); Applicant applicant = null; long groupId = GetterUtil.getLong(header.getHeaderString("groupId")); try { if (!auth.isAuth(serviceContext)) { throw new UnauthenticationException(); } User requestUser = ApplicantUtils.getUser(id); boolean isAllowed = false; if (auth.hasResource(serviceContext, Applicant.class.getName(), ActionKeys.ADD_ENTRY)) { isAllowed = true; } else { if (Validator.isNull(requestUser)) { throw new NoSuchUserException(); } else { // check userLogin is equal userRequest get detail if (requestUser.getUserId() == user.getUserId()) { isAllowed = true; } } } if (isAllowed) { applicant = actions.updateProfile(serviceContext,groupId, id, input.getValue()); JSONObject result = JSONFactoryUtil.createJSONObject(applicant.getProfile()); return Response.status(200).entity(JSONFactoryUtil.looseSerialize(result)).build(); } else { throw new UnauthorizationException(); } } catch (Exception e) { ErrorMsg error = new ErrorMsg(); if (e instanceof UnauthenticationException) { error.setMessage("Non-Authoritative Information."); error.setCode(HttpURLConnection.HTTP_NOT_AUTHORITATIVE); error.setDescription("Non-Authoritative Information."); return Response.status(HttpURLConnection.HTTP_NOT_AUTHORITATIVE).entity(error).build(); } else { if (e instanceof UnauthorizationException) { error.setMessage("Unauthorized."); error.setCode(HttpURLConnection.HTTP_NOT_AUTHORITATIVE); error.setDescription("Unauthorized."); return Response.status(HttpURLConnection.HTTP_UNAUTHORIZED).entity(error).build(); } else { if (e instanceof NoSuchUserException) { error.setMessage("Not Found"); error.setCode(HttpURLConnection.HTTP_NOT_FOUND); error.setDescription("Not Found"); return Response.status(HttpURLConnection.HTTP_NOT_FOUND).entity(error).build(); } else { error.setMessage("Internal Server Error."); error.setCode(HttpURLConnection.HTTP_INTERNAL_ERROR); error.setDescription(e.getMessage()); return Response.status(HttpURLConnection.HTTP_INTERNAL_ERROR).entity(error).build(); } } } } }
@Override public Response lockApplicant(HttpServletRequest request, HttpHeaders header, Company company, Locale locale, User user, ServiceContext serviceContext, long id) { ApplicantActions actions = new ApplicantActionsImpl(); BackendAuth auth = new BackendAuthImpl(); ApplicantModel results = new ApplicantModel(); Applicant applicant = null; try { if (!auth.isAuth(serviceContext)) { throw new UnauthenticationException(); } User requestUser = ApplicantUtils.getUser(id); boolean isAllowed = false; if (auth.hasResource(serviceContext, Applicant.class.getName(), ActionKeys.ADD_ENTRY)) { isAllowed = true; } else { if (Validator.isNull(requestUser)) { throw new NoSuchUserException(); } else { // check userLogin is equal userRequest get detail if (requestUser.getUserId() == user.getUserId()) { isAllowed = true; } } } if (isAllowed) { applicant = actions.lockApplicant(serviceContext, id); results = ApplicantUtils.mappingToApplicantModel(applicant); return Response.status(200).entity(results).build(); } else { throw new UnauthorizationException(); } } catch (Exception e) { ErrorMsg error = new ErrorMsg(); if (e instanceof UnauthenticationException) { error.setMessage("Non-Authoritative Information."); error.setCode(HttpURLConnection.HTTP_NOT_AUTHORITATIVE); error.setDescription("Non-Authoritative Information."); return Response.status(HttpURLConnection.HTTP_NOT_AUTHORITATIVE).entity(error).build(); } else { if (e instanceof UnauthorizationException) { error.setMessage("Unauthorized."); error.setCode(HttpURLConnection.HTTP_NOT_AUTHORITATIVE); error.setDescription("Unauthorized."); return Response.status(HttpURLConnection.HTTP_UNAUTHORIZED).entity(error).build(); } else { if (e instanceof NoSuchUserException) { error.setMessage("Not Found"); error.setCode(HttpURLConnection.HTTP_NOT_FOUND); error.setDescription("Not Found"); return Response.status(HttpURLConnection.HTTP_NOT_FOUND).entity(error).build(); } else { error.setMessage("Internal Server Error"); error.setCode(HttpURLConnection.HTTP_INTERNAL_ERROR); error.setDescription(e.getMessage()); return Response.status(HttpURLConnection.HTTP_INTERNAL_ERROR).entity(error).build(); } } } } }
/** * Download payment File Confirm * * @param * @return Response */ @Override public Response downloadConfirmFile(HttpServletRequest request, HttpHeaders header, Company company, Locale locale, User user, ServiceContext serviceContext, String id, String referenceUid) { BackendAuth auth = new BackendAuthImpl(); long dossierId = GetterUtil.getLong(id); // TODO get Dossier by referenceUid if dossierId = 0 // String referenceUid = dossierId == 0 ? id : StringPool.BLANK; try { if (!auth.isAuth(serviceContext)) { throw new UnauthenticationException(); } PaymentFileActions action = new PaymentFileActionsImpl(); PaymentFile paymentFile = action.getPaymentFileByReferenceUid(dossierId, referenceUid); if (paymentFile.getConfirmFileEntryId() > 0) { FileEntry fileEntry = DLAppLocalServiceUtil.getFileEntry(paymentFile.getConfirmFileEntryId()); File file = DLFileEntryLocalServiceUtil.getFile(fileEntry.getFileEntryId(), fileEntry.getVersion(), true); ResponseBuilder responseBuilder = Response.ok((Object) file); responseBuilder.header("Content-Disposition", "attachment; filename=\"" + fileEntry.getFileName() + "\""); responseBuilder.header("Content-Type", fileEntry.getMimeType()); return responseBuilder.build(); } else { return Response.status(HttpURLConnection.HTTP_NO_CONTENT).build(); } } catch (Exception e) { return processException(e); } }
/** * Download Invoice File Confirm * * @param * @return Response */ @Override public Response downloadInvoiceFile(HttpServletRequest request, HttpHeaders header, Company company, Locale locale, User user, ServiceContext serviceContext, String id, String referenceUid) { BackendAuth auth = new BackendAuthImpl(); long dossierId = GetterUtil.getLong(id); // TODO get Dossier by referenceUid if dossierId = 0 // String referenceUid = dossierId == 0 ? id : StringPool.BLANK; try { if (!auth.isAuth(serviceContext)) { throw new UnauthenticationException(); } PaymentFileActions action = new PaymentFileActionsImpl(); PaymentFile paymentFile = action.getPaymentFileByReferenceUid(dossierId, referenceUid); if (paymentFile.getInvoiceFileEntryId() > 0) { FileEntry fileEntry = DLAppLocalServiceUtil.getFileEntry(paymentFile.getInvoiceFileEntryId()); File file = DLFileEntryLocalServiceUtil.getFile(fileEntry.getFileEntryId(), fileEntry.getVersion(), true); ResponseBuilder responseBuilder = Response.ok((Object) file); responseBuilder.header("Content-Disposition", "attachment; filename=\"" + fileEntry.getFileName() + "\""); responseBuilder.header("Content-Type", fileEntry.getMimeType()); return responseBuilder.build(); } else { return Response.status(HttpURLConnection.HTTP_NO_CONTENT).build(); } } catch (Exception e) { return processException(e); } }
@Override public Response downloadByDossierId_ReferenceUid(HttpServletRequest request, HttpHeaders header, Company company, Locale locale, User user, ServiceContext serviceContext, long id, String referenceUid, String password) { // TODO: check user is loged or password for access dossier file BackendAuth auth = new BackendAuthImpl(); try { if (!auth.isAuth(serviceContext)) { throw new UnauthenticationException(); } DossierFile dossierFile = DossierFileLocalServiceUtil.getDossierFileByReferenceUid(id, referenceUid); // TODO download file with dossierFileID if (Validator.isNull(dossierFile) && Validator.isNumber(referenceUid)) { dossierFile = DossierFileLocalServiceUtil.fetchDossierFile(Long.valueOf(referenceUid)); } if (dossierFile.getFileEntryId() > 0) { FileEntry fileEntry = DLAppLocalServiceUtil.getFileEntry(dossierFile.getFileEntryId()); File file = DLFileEntryLocalServiceUtil.getFile(fileEntry.getFileEntryId(), fileEntry.getVersion(), true); ResponseBuilder responseBuilder = Response.ok((Object) file); responseBuilder.header("Content-Disposition", "attachment; filename=\"" + fileEntry.getFileName() + "\""); responseBuilder.header("Content-Type", fileEntry.getMimeType()); return responseBuilder.build(); } else { return Response.status(HttpURLConnection.HTTP_NO_CONTENT).build(); } } catch (Exception e) { return processException(e); } }
@Override public Response addPaymentConfig(HttpServletRequest request, HttpHeaders header, Company company, Locale locale, User user, ServiceContext serviceContext, PaymentConfigInputModel input) { long groupId = GetterUtil.getLong(header.getHeaderString("groupId")); BackendAuth auth = new BackendAuthImpl(); try { if (!auth.isAuth(serviceContext)) { throw new UnauthenticationException(); } if (!auth.hasResource(serviceContext, PaymentConfig.class.getName(), ActionKeys.ADD_ENTRY)) { throw new UnauthorizationException(); } PaymentConfig paymentConfig = PaymentConfigLocalServiceUtil.updatePaymentConfig(groupId, 0, input.getGovAgencyCode(), input.getGovAgencyName(), input.getGovAgencyTaxNo(), input.getInvoiceTemplateNo(), input.getInvoiceIssueNo(), input.getInvoiceLastNo(), StringPool.BLANK, input.getBankInfo(), StringPool.BLANK, serviceContext); PaymentConfigInputModel result = PaymentConfigUtils.mappingToModel(paymentConfig); return Response.status(200).entity(result).build(); } catch (Exception e) { ErrorMsg error = new ErrorMsg(); if (e instanceof UnauthenticationException) { error.setMessage("Non-Authoritative Information."); error.setCode(HttpURLConnection.HTTP_NOT_AUTHORITATIVE); error.setDescription("Non-Authoritative Information."); return Response.status(HttpURLConnection.HTTP_NOT_AUTHORITATIVE).entity(error).build(); } else { if (e instanceof UnauthorizationException) { error.setMessage("Unauthorized."); error.setCode(HttpURLConnection.HTTP_NOT_AUTHORITATIVE); error.setDescription("Unauthorized."); return Response.status(HttpURLConnection.HTTP_UNAUTHORIZED).entity(error).build(); } else { error.setMessage("Internal Server Error"); error.setCode(HttpURLConnection.HTTP_FORBIDDEN); error.setDescription(e.getMessage()); return Response.status(HttpURLConnection.HTTP_INTERNAL_ERROR).entity(error).build(); } } } }
@Override public Response updatePaymentConfig(HttpServletRequest request, HttpHeaders header, Company company, Locale locale, User user, ServiceContext serviceContext, long id, PaymentConfigInputModel input) { long groupId = GetterUtil.getLong(header.getHeaderString("groupId")); BackendAuth auth = new BackendAuthImpl(); try { if (!auth.isAuth(serviceContext)) { throw new UnauthenticationException(); } if (!auth.hasResource(serviceContext, PaymentConfig.class.getName(), ActionKeys.ADD_ENTRY)) { throw new UnauthorizationException(); } PaymentConfig paymentConfig = PaymentConfigLocalServiceUtil.updatePaymentConfig(groupId, id, input.getGovAgencyCode(), input.getGovAgencyName(), input.getGovAgencyTaxNo(), input.getInvoiceTemplateNo(), input.getInvoiceIssueNo(), input.getInvoiceLastNo(), StringPool.BLANK, input.getBankInfo(), StringPool.BLANK, serviceContext); PaymentConfigInputModel result = PaymentConfigUtils.mappingToModel(paymentConfig); return Response.status(200).entity(result).build(); } catch (Exception e) { ErrorMsg error = new ErrorMsg(); if (e instanceof UnauthenticationException) { error.setMessage("Non-Authoritative Information."); error.setCode(HttpURLConnection.HTTP_NOT_AUTHORITATIVE); error.setDescription("Non-Authoritative Information."); return Response.status(HttpURLConnection.HTTP_NOT_AUTHORITATIVE).entity(error).build(); } else { if (e instanceof UnauthorizationException) { error.setMessage("Unauthorized."); error.setCode(HttpURLConnection.HTTP_NOT_AUTHORITATIVE); error.setDescription("Unauthorized."); return Response.status(HttpURLConnection.HTTP_UNAUTHORIZED).entity(error).build(); } else { error.setMessage("Internal Server Error"); error.setCode(HttpURLConnection.HTTP_FORBIDDEN); error.setDescription(e.getMessage()); return Response.status(HttpURLConnection.HTTP_INTERNAL_ERROR).entity(error).build(); } } } }
@Override public Response removePaymentConfig(HttpServletRequest request, HttpHeaders header, Company company, Locale locale, User user, ServiceContext serviceContext, long id) { BackendAuth auth = new BackendAuthImpl(); try { if (!auth.isAuth(serviceContext)) { throw new UnauthenticationException(); } if (!auth.hasResource(serviceContext, PaymentConfig.class.getName(), ActionKeys.ADD_ENTRY)) { throw new UnauthorizationException(); } PaymentConfig paymentConfig = PaymentConfigLocalServiceUtil.removePaymentConfig(id); PaymentConfigInputModel result = PaymentConfigUtils.mappingToModel(paymentConfig); return Response.status(200).entity(result).build(); } catch (Exception e) { ErrorMsg error = new ErrorMsg(); if (e instanceof UnauthenticationException) { error.setMessage("Non-Authoritative Information."); error.setCode(HttpURLConnection.HTTP_NOT_AUTHORITATIVE); error.setDescription("Non-Authoritative Information."); return Response.status(HttpURLConnection.HTTP_NOT_AUTHORITATIVE).entity(error).build(); } else { if (e instanceof UnauthorizationException) { error.setMessage("Unauthorized."); error.setCode(HttpURLConnection.HTTP_NOT_AUTHORITATIVE); error.setDescription("Unauthorized."); return Response.status(HttpURLConnection.HTTP_UNAUTHORIZED).entity(error).build(); } else { error.setMessage("Internal Server Error"); error.setCode(HttpURLConnection.HTTP_FORBIDDEN); error.setDescription(e.getMessage()); return Response.status(HttpURLConnection.HTTP_INTERNAL_ERROR).entity(error).build(); } } } }
@Override public Response addInvoiceForm(HttpServletRequest request, HttpHeaders header, Company company, Locale locale, User user, ServiceContext serviceContext, long id, PaymentConfigSingleInputModel input) { BackendAuth auth = new BackendAuthImpl(); try { if (!auth.isAuth(serviceContext)) { throw new UnauthenticationException(); } if (!auth.hasResource(serviceContext, PaymentConfig.class.getName(), ActionKeys.ADD_ENTRY)) { throw new UnauthorizationException(); } PaymentConfig paymentConfig = PaymentConfigLocalServiceUtil.updateInvoidForm(id, input.getValue(), serviceContext); PaymentConfigSingleInputModel result = new PaymentConfigSingleInputModel(); result.setValue(paymentConfig.getInvoiceForm()); return Response.status(200).entity(result).build(); } catch (Exception e) { ErrorMsg error = new ErrorMsg(); if (e instanceof UnauthenticationException) { error.setMessage("Non-Authoritative Information."); error.setCode(HttpURLConnection.HTTP_NOT_AUTHORITATIVE); error.setDescription("Non-Authoritative Information."); return Response.status(HttpURLConnection.HTTP_NOT_AUTHORITATIVE).entity(error).build(); } else { if (e instanceof UnauthorizationException) { error.setMessage("Unauthorized."); error.setCode(HttpURLConnection.HTTP_NOT_AUTHORITATIVE); error.setDescription("Unauthorized."); return Response.status(HttpURLConnection.HTTP_UNAUTHORIZED).entity(error).build(); } else { error.setMessage("Internal Server Error"); error.setCode(HttpURLConnection.HTTP_FORBIDDEN); error.setDescription(e.getMessage()); return Response.status(HttpURLConnection.HTTP_INTERNAL_ERROR).entity(error).build(); } } } }
@Override public Response updateInvoiceForm(HttpServletRequest request, HttpHeaders header, Company company, Locale locale, User user, ServiceContext serviceContext, long id, PaymentConfigSingleInputModel input) { BackendAuth auth = new BackendAuthImpl(); try { if (!auth.isAuth(serviceContext)) { throw new UnauthenticationException(); } if (!auth.hasResource(serviceContext, PaymentConfig.class.getName(), ActionKeys.ADD_ENTRY)) { throw new UnauthorizationException(); } PaymentConfig paymentConfig = PaymentConfigLocalServiceUtil.updateInvoidForm(id, input.getValue(), serviceContext); PaymentConfigSingleInputModel result = new PaymentConfigSingleInputModel(); result.setValue(paymentConfig.getInvoiceForm()); return Response.status(200).entity(result).build(); } catch (Exception e) { ErrorMsg error = new ErrorMsg(); if (e instanceof UnauthenticationException) { error.setMessage("Non-Authoritative Information."); error.setCode(HttpURLConnection.HTTP_NOT_AUTHORITATIVE); error.setDescription("Non-Authoritative Information."); return Response.status(HttpURLConnection.HTTP_NOT_AUTHORITATIVE).entity(error).build(); } else { if (e instanceof UnauthorizationException) { error.setMessage("Unauthorized."); error.setCode(HttpURLConnection.HTTP_NOT_AUTHORITATIVE); error.setDescription("Unauthorized."); return Response.status(HttpURLConnection.HTTP_UNAUTHORIZED).entity(error).build(); } else { error.setMessage("Internal Server Error"); error.setCode(HttpURLConnection.HTTP_FORBIDDEN); error.setDescription(e.getMessage()); return Response.status(HttpURLConnection.HTTP_INTERNAL_ERROR).entity(error).build(); } } } }
@Override public Response addEpaymentconfig(HttpServletRequest request, HttpHeaders header, Company company, Locale locale, User user, ServiceContext serviceContext, long id, PaymentConfigSingleInputModel input) { BackendAuth auth = new BackendAuthImpl(); try { if (!auth.isAuth(serviceContext)) { throw new UnauthenticationException(); } if (!auth.hasResource(serviceContext, PaymentConfig.class.getName(), ActionKeys.ADD_ENTRY)) { throw new UnauthorizationException(); } PaymentConfig paymentConfig = PaymentConfigLocalServiceUtil.updateEConfig(id, input.getValue(), serviceContext); PaymentConfigSingleInputModel result = new PaymentConfigSingleInputModel(); result.setValue(paymentConfig.getEpaymentConfig()); return Response.status(200).entity(result).build(); } catch (Exception e) { ErrorMsg error = new ErrorMsg(); if (e instanceof UnauthenticationException) { error.setMessage("Non-Authoritative Information."); error.setCode(HttpURLConnection.HTTP_NOT_AUTHORITATIVE); error.setDescription("Non-Authoritative Information."); return Response.status(HttpURLConnection.HTTP_NOT_AUTHORITATIVE).entity(error).build(); } else { if (e instanceof UnauthorizationException) { error.setMessage("Unauthorized."); error.setCode(HttpURLConnection.HTTP_NOT_AUTHORITATIVE); error.setDescription("Unauthorized."); return Response.status(HttpURLConnection.HTTP_UNAUTHORIZED).entity(error).build(); } else { error.setMessage("Internal Server Error"); error.setCode(HttpURLConnection.HTTP_FORBIDDEN); error.setDescription(e.getMessage()); return Response.status(HttpURLConnection.HTTP_INTERNAL_ERROR).entity(error).build(); } } } }
@Override public Response updateEpaymentconfig(HttpServletRequest request, HttpHeaders header, Company company, Locale locale, User user, ServiceContext serviceContext, long id, String key, PaymentConfigSingleInputModel input) { BackendAuth auth = new BackendAuthImpl(); try { if (!auth.isAuth(serviceContext)) { throw new UnauthenticationException(); } if (!auth.hasResource(serviceContext, PaymentConfig.class.getName(), ActionKeys.ADD_ENTRY)) { throw new UnauthorizationException(); } String eConfig = PaymentConfigLocalServiceUtil.getPaymentConfig(id).getEpaymentConfig(); JSONObject jsEConfig = JSONFactoryUtil.createJSONObject(eConfig); jsEConfig.put(key, input.getValue()); PaymentConfig paymentConfig = PaymentConfigLocalServiceUtil.updateEConfig(id, jsEConfig.toString(), serviceContext); PaymentConfigSingleInputModel result = new PaymentConfigSingleInputModel(); result.setValue(paymentConfig.getEpaymentConfig()); return Response.status(200).entity(result).build(); } catch (Exception e) { ErrorMsg error = new ErrorMsg(); if (e instanceof UnauthenticationException) { error.setMessage("Non-Authoritative Information."); error.setCode(HttpURLConnection.HTTP_NOT_AUTHORITATIVE); error.setDescription("Non-Authoritative Information."); return Response.status(HttpURLConnection.HTTP_NOT_AUTHORITATIVE).entity(error).build(); } else { if (e instanceof UnauthorizationException) { error.setMessage("Unauthorized."); error.setCode(HttpURLConnection.HTTP_NOT_AUTHORITATIVE); error.setDescription("Unauthorized."); return Response.status(HttpURLConnection.HTTP_UNAUTHORIZED).entity(error).build(); } else { error.setMessage("Internal Server Error"); error.setCode(HttpURLConnection.HTTP_FORBIDDEN); error.setDescription(e.getMessage()); return Response.status(HttpURLConnection.HTTP_INTERNAL_ERROR).entity(error).build(); } } } }
@Override public Response addServiceProcesses(HttpServletRequest request, HttpHeaders header, Company company, Locale locale, User user, ServiceContext serviceContext, ServiceProcessInputModel input) { ServiceProcessActions actions = new ServiceProcessActionsImpl(); long groupId = GetterUtil.getLong(header.getHeaderString("groupId")); BackendAuth auth = new BackendAuthImpl(); try { if (!auth.isAuth(serviceContext)) { throw new UnauthenticationException(); } if (!auth.hasResource(serviceContext, ServiceProcess.class.getName(), ActionKeys.ADD_ENTRY)) { throw new UnauthorizationException(); } ServiceProcess serviceProcess = actions.updateServiceProcess(groupId, 0l, input.getProcessNo(), input.getProcessName(), input.getDescription(), input.getDurationCount(), input.getDurationUnit(), input.getCounter(), GetterUtil.getBoolean(input.getGenerateDossierNo()), input.getDossierNoPattern(), GetterUtil.getBoolean(input.getGenerateDueDate()), input.getDueDatePattern(), GetterUtil.getBoolean(input.getGeneratePassword()), GetterUtil.getBoolean(input.getDirectNotification()), input.getServerNo(), serviceContext); ServiceProcessDetailModel result = ServiceProcessUtils.mappingToDetail(serviceProcess); return Response.status(200).entity(result).build(); } catch (Exception e) { ErrorMsg error = new ErrorMsg(); if (e instanceof UnauthenticationException) { error.setMessage("Non-Authoritative Information."); error.setCode(HttpURLConnection.HTTP_NOT_AUTHORITATIVE); error.setDescription("Non-Authoritative Information."); return Response.status(HttpURLConnection.HTTP_NOT_AUTHORITATIVE).entity(error).build(); } else { if (e instanceof UnauthorizationException) { error.setMessage("Unauthorized."); error.setCode(HttpURLConnection.HTTP_NOT_AUTHORITATIVE); error.setDescription("Unauthorized."); return Response.status(HttpURLConnection.HTTP_UNAUTHORIZED).entity(error).build(); } else { error.setMessage("Internal Server Error"); error.setCode(HttpURLConnection.HTTP_FORBIDDEN); error.setDescription(e.getMessage()); return Response.status(HttpURLConnection.HTTP_INTERNAL_ERROR).entity(error).build(); } } } }
@Override public Response updateServiceProcess(HttpServletRequest request, HttpHeaders header, Company company, Locale locale, User user, ServiceContext serviceContext, long id, ServiceProcessInputModel input) { ServiceProcessActions actions = new ServiceProcessActionsImpl(); long groupId = GetterUtil.getLong(header.getHeaderString("groupId")); BackendAuth auth = new BackendAuthImpl(); try { if (!auth.isAuth(serviceContext)) { throw new UnauthenticationException(); } if (!auth.hasResource(serviceContext, ServiceProcess.class.getName(), ActionKeys.ADD_ENTRY)) { throw new UnauthorizationException(); } ServiceProcess serviceProcess = actions.updateServiceProcess(groupId, id, input.getProcessNo(), input.getProcessName(), input.getDescription(), input.getDurationCount(), input.getDurationUnit(), input.getCounter(), GetterUtil.getBoolean(input.getGenerateDossierNo()), input.getDossierNoPattern(), GetterUtil.getBoolean(input.getGenerateDueDate()), input.getDueDatePattern(), GetterUtil.getBoolean(input.getGeneratePassword()), GetterUtil.getBoolean(input.getDirectNotification()), input.getServerNo(), serviceContext); ServiceProcessDetailModel result = ServiceProcessUtils.mappingToDetail(serviceProcess); return Response.status(200).entity(result).build(); } catch (Exception e) { ErrorMsg error = new ErrorMsg(); if (e instanceof UnauthenticationException) { error.setMessage("Non-Authoritative Information."); error.setCode(HttpURLConnection.HTTP_NOT_AUTHORITATIVE); error.setDescription("Non-Authoritative Information."); return Response.status(HttpURLConnection.HTTP_NOT_AUTHORITATIVE).entity(error).build(); } else { if (e instanceof UnauthorizationException) { error.setMessage("Unauthorized."); error.setCode(HttpURLConnection.HTTP_NOT_AUTHORITATIVE); error.setDescription("Unauthorized."); return Response.status(HttpURLConnection.HTTP_UNAUTHORIZED).entity(error).build(); } else { error.setMessage("Internal Server Error"); error.setCode(HttpURLConnection.HTTP_FORBIDDEN); error.setDescription(e.getMessage()); return Response.status(HttpURLConnection.HTTP_INTERNAL_ERROR).entity(error).build(); } } } }
@Override public Response addServiceProcessRole(HttpServletRequest request, HttpHeaders header, Company company, Locale locale, User user, ServiceContext serviceContext, long id, RoleInputModel input) { ServiceProcessActions actions = new ServiceProcessActionsImpl(); long groupId = GetterUtil.getLong(header.getHeaderString("groupId")); BackendAuth auth = new BackendAuthImpl(); try { if (!auth.isAuth(serviceContext)) { throw new UnauthenticationException("UnauthenticationException"); } if (!auth.hasResource(serviceContext, ServiceProcess.class.getName(), ActionKeys.ADD_ENTRY)) { throw new UnauthorizationException("UnauthorizationException"); } ServiceProcessRole role = actions.updateServiceProcessRole(groupId, id, input.getRoleId(), GetterUtil.getBoolean(input.getModerator()), input.getCondition()); RoleInputModel result = ServiceProcessUtils.mappingToServiceRoleInput(role); return Response.status(200).entity(result).build(); } catch (Exception e) { ErrorMsg error = new ErrorMsg(); if (e instanceof UnauthenticationException) { error.setMessage("Non-Authoritative Information."); error.setCode(HttpURLConnection.HTTP_NOT_AUTHORITATIVE); error.setDescription("Non-Authoritative Information."); return Response.status(HttpURLConnection.HTTP_NOT_AUTHORITATIVE).entity(error).build(); } else { if (e instanceof UnauthorizationException) { error.setMessage("Unauthorized."); error.setCode(HttpURLConnection.HTTP_NOT_AUTHORITATIVE); error.setDescription("Unauthorized."); return Response.status(HttpURLConnection.HTTP_UNAUTHORIZED).entity(error).build(); } else { error.setMessage("Internal Server Error"); error.setCode(HttpURLConnection.HTTP_FORBIDDEN); error.setDescription(e.getMessage()); return Response.status(HttpURLConnection.HTTP_INTERNAL_ERROR).entity(error).build(); } } } }
@Override public Response updateServiceProcessRole(HttpServletRequest request, HttpHeaders header, Company company, Locale locale, User user, ServiceContext serviceContext, long id, long roleid, RoleInputModel input) { ServiceProcessActions actions = new ServiceProcessActionsImpl(); long groupId = GetterUtil.getLong(header.getHeaderString("groupId")); BackendAuth auth = new BackendAuthImpl(); try { if (!auth.isAuth(serviceContext)) { throw new UnauthenticationException("UnauthenticationException"); } if (!auth.hasResource(serviceContext, ServiceProcess.class.getName(), ActionKeys.ADD_ENTRY)) { throw new UnauthorizationException("UnauthorizationException"); } ServiceProcessRole role = actions.updateServiceProcessRole(groupId, id, roleid, GetterUtil.getBoolean(input.getModerator()), input.getCondition()); RoleInputModel result = ServiceProcessUtils.mappingToServiceRoleInput(role); return Response.status(200).entity(result).build(); } catch (Exception e) { ErrorMsg error = new ErrorMsg(); if (e instanceof UnauthenticationException) { error.setMessage("Non-Authoritative Information."); error.setCode(HttpURLConnection.HTTP_NOT_AUTHORITATIVE); error.setDescription("Non-Authoritative Information."); return Response.status(HttpURLConnection.HTTP_NOT_AUTHORITATIVE).entity(error).build(); } else { if (e instanceof UnauthorizationException) { error.setMessage("Unauthorized."); error.setCode(HttpURLConnection.HTTP_NOT_AUTHORITATIVE); error.setDescription("Unauthorized."); return Response.status(HttpURLConnection.HTTP_UNAUTHORIZED).entity(error).build(); } else { error.setMessage("Internal Server Error"); error.setCode(HttpURLConnection.HTTP_FORBIDDEN); error.setDescription(e.getMessage()); return Response.status(HttpURLConnection.HTTP_INTERNAL_ERROR).entity(error).build(); } } } }
@Override public Response removeServiceProcessRole(HttpServletRequest request, HttpHeaders header, Company company, Locale locale, User user, ServiceContext serviceContext, long id, long roleid) { ServiceProcessActions actions = new ServiceProcessActionsImpl(); BackendAuth auth = new BackendAuthImpl(); try { if (!auth.isAuth(serviceContext)) { throw new UnauthenticationException("UnauthenticationException"); } if (!auth.hasResource(serviceContext, ServiceProcess.class.getName(), ActionKeys.ADD_ENTRY)) { throw new UnauthorizationException("UnauthorizationException"); } ServiceProcessRole role = actions.removeServiceProcessRole(id, roleid); RoleInputModel result = ServiceProcessUtils.mappingToServiceRoleInput(role); return Response.status(200).entity(result).build(); } catch (Exception e) { ErrorMsg error = new ErrorMsg(); if (e instanceof UnauthenticationException) { error.setMessage("Non-Authoritative Information."); error.setCode(HttpURLConnection.HTTP_NOT_AUTHORITATIVE); error.setDescription("Non-Authoritative Information."); return Response.status(HttpURLConnection.HTTP_NOT_AUTHORITATIVE).entity(error).build(); } else { if (e instanceof UnauthorizationException) { error.setMessage("Unauthorized."); error.setCode(HttpURLConnection.HTTP_NOT_AUTHORITATIVE); error.setDescription("Unauthorized."); return Response.status(HttpURLConnection.HTTP_UNAUTHORIZED).entity(error).build(); } else { error.setMessage("Internal Server Error"); error.setCode(HttpURLConnection.HTTP_FORBIDDEN); error.setDescription(e.getMessage()); return Response.status(HttpURLConnection.HTTP_INTERNAL_ERROR).entity(error).build(); } } } }
@Override public Response addProcessStep(HttpServletRequest request, HttpHeaders header, Company company, Locale locale, User user, ServiceContext serviceContext, long id, ProcessStepInputModel input) { ServiceProcessActions actions = new ServiceProcessActionsImpl(); long groupId = GetterUtil.getLong(header.getHeaderString("groupId")); BackendAuth auth = new BackendAuthImpl(); try { if (!auth.isAuth(serviceContext)) { throw new UnauthenticationException(); } if (!auth.hasResource(serviceContext, ServiceProcess.class.getName(), ActionKeys.ADD_ENTRY)) { throw new UnauthorizationException(); } ProcessStep addstep = ProcessStepLocalServiceUtil.fetchBySC_GID(input.getStepCode(), groupId, id); if (Validator.isNotNull(addstep)) { throw new DuplicateStepNoException("DuplicateStepNoException"); } ProcessStep step = actions.updateProcessStep(groupId, StringPool.BLANK, input.getStepCode(), input.getStepName(), id, input.getSequenceNo(), input.getDossierStatus(), input.getDossierSubStatus(), GetterUtil.getInteger(input.getDurationCount()), input.getCustomProcessUrl(), input.getStepInstruction(), input.getBriefNote(), GetterUtil.getBoolean(input.getEditable()), serviceContext); ProcessStepInputModel result = ServiceProcessUtils.mapptingToStepPOST(step); return Response.status(200).entity(result).build(); } catch (Exception e) { ErrorMsg error = new ErrorMsg(); if (e instanceof UnauthenticationException) { error.setMessage("Non-Authoritative Information."); error.setCode(HttpURLConnection.HTTP_NOT_AUTHORITATIVE); error.setDescription("Non-Authoritative Information."); return Response.status(HttpURLConnection.HTTP_NOT_AUTHORITATIVE).entity(error).build(); } else { if (e instanceof UnauthorizationException) { error.setMessage("Unauthorized."); error.setCode(HttpURLConnection.HTTP_NOT_AUTHORITATIVE); error.setDescription("Unauthorized."); return Response.status(HttpURLConnection.HTTP_UNAUTHORIZED).entity(error).build(); } else { error.setMessage("Internal Server Error"); error.setCode(HttpURLConnection.HTTP_FORBIDDEN); error.setDescription(e.getMessage()); return Response.status(HttpURLConnection.HTTP_INTERNAL_ERROR).entity(error).build(); } } } }