@BeforeClass @Atomic(mode = TxMode.WRITE) public static void setupUsers() { ManualGroupRegister.ensure(); user1 = User.findByUsername("user1"); if (user1 == null) { user1 = new User("user1", ManualGroupRegister.newProfile()); } }
@POST @Produces(JSON_UTF8) @Path("disconnectMissionProcess") public Response disconnectMissionProcess( @QueryParam("processNumber") String processNumber, @QueryParam("hostname") String hostname, @QueryParam("remoteProcessNumber") String remoteProcessNumber, @QueryParam("username") String username, @QueryParam("access_token") String access_token) { checkToken(access_token); login(User.findByUsername(username)); try { final Mission mission = findMission(remoteProcessNumber); if (mission == null) { return respondWithError(Status.BAD_REQUEST, "bad.mission.number"); } else { final MissionProcess missionProcess = mission.getMissionProcess(); final RemoteMissionSystem remoteMissionSystem = RemoteMissionSystem.find(hostname); if (remoteMissionSystem == null) { return respondWithError(Status.NOT_ACCEPTABLE, "remote.host.not.configured"); } for (final RemoteMissionProcess remoteMissionProcess : missionProcess.getRemoteMissionProcessSet()) { if (remoteMissionProcess.getRemoteMissionSystem() == remoteMissionSystem && remoteMissionProcess.getProcessNumber().equals(processNumber)) { final DisassociateMissionProcessActivity activity = (DisassociateMissionProcessActivity) missionProcess.getActivity(DisassociateMissionProcessActivity.class); final DisassociateMissionProcessActivityInfo information = activity.getActivityInformation(missionProcess); information.setRemoteMissionProcess(remoteMissionProcess); information.setConnect(false); activity.execute(information); } } return Response.ok().build(); } } finally { logout(); } }
@POST @Produces(JSON_UTF8) @Path("connectMissionProcess") public Response connectMissionProcess( @QueryParam("processNumber") String processNumber, @QueryParam("externalId") String externalId, @QueryParam("hostname") String hostname, @QueryParam("remoteProcessNumber") String remoteProcessNumber, @QueryParam("username") String username, @QueryParam("access_token") String access_token) { checkToken(access_token); try { login(User.findByUsername(username)); final Mission mission = findMission(remoteProcessNumber); if (mission == null) { return respondWithError(Status.BAD_REQUEST, "bad.mission.number"); } else { final MissionProcess missionProcess = mission.getMissionProcess(); final RemoteMissionSystem remoteMissionSystem = RemoteMissionSystem.find(hostname); if (remoteMissionSystem == null) { return respondWithError(Status.NOT_ACCEPTABLE, "remote.host.not.configured"); } final AssociateMissionProcessActivity activity = (AssociateMissionProcessActivity) missionProcess.getActivity(AssociateMissionProcessActivity.class); final AssociateMissionProcessActivityInfo information = activity.getActivityInformation(missionProcess); information.setProcessNumber(processNumber); information.setExternalId(externalId); information.setRemoteMissionSystem(remoteMissionSystem); information.setConnect(false); activity.execute(information); final JsonObject obj = new JsonObject(); obj.addProperty("processID", missionProcess.getProcessNumber()); obj.addProperty("externalId", missionProcess.getExternalId()); return Response.ok().entity(gson.toJson(obj)).build(); } } finally { logout(); } }
// change to put @PUT @Produces(JSON_UTF8) @Path("cancelFundAllocation") public String cancelFundAllocation( @QueryParam("processID") String processID, @QueryParam("userID") String userID, @QueryParam("access_token") String access_token) { checkToken(access_token); login(User.findByUsername(userID)); try { WorkflowSystem ws = WorkflowSystem.getInstance(); Set<WorkflowProcess> processes = ws.getProcessesSet(); for (WorkflowProcess workflowProcess : processes) { if (workflowProcess.getProcessNumber() != null) { if (workflowProcess.getProcessNumber().equals(processID)) { WorkflowActivity<WorkflowProcess, ActivityInformation<WorkflowProcess>> cancelAcquisitionRequest = workflowProcess.getActivity( DeleteAfterTheFactAcquisitionProcess.class.getSimpleName()); if (cancelAcquisitionRequest == null) { // is not after the fact cancelAcquisitionRequest = workflowProcess.getActivity(CancelAcquisitionRequest.class.getSimpleName()); } try { cancelAcquisitionRequest.execute( new ActivityInformation<WorkflowProcess>( workflowProcess, cancelAcquisitionRequest)); } catch (Exception e) { throw newApplicationError(Status.NOT_ACCEPTABLE, "cancelation_not_acceptable"); } JsonObject obj = new JsonObject(); obj.addProperty("status", Status.OK.toString()); return gson.toJson(obj); } } } // No process was found throw newApplicationError(Status.NOT_FOUND, "resource_not_found"); } finally { logout(); } }
public ActionForward showPaymentsForEvent( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { final Event event = getEvent(request); request.setAttribute("event", event); if (!StringUtils.isEmpty(event.getCreatedBy())) { User responsible = User.findByUsername(event.getCreatedBy()); request.setAttribute("responsible", responsible.getPerson()); } if (event.isOpen()) { request.setAttribute("entryDTOs", event.calculateEntries()); request.setAttribute("accountingEventPaymentCodes", event.getNonProcessedPaymentCodes()); } return mapping.findForward("showPaymentsForEvent"); }
@POST @Produces(JSON_UTF8) @Path("allocateFunds") public Response allocateFunds( @QueryParam("supplierID") String supplierID, @QueryParam("value") String value, @QueryParam("valueVat") String valueVAT, @QueryParam("cpvCode") String cpvcode, @QueryParam("goodsOrService") String goodsOrServices, @QueryParam("description") String description, @QueryParam("userID") String userID, @QueryParam("access_token") String access_token) { checkToken(access_token); login(User.findByUsername(userID)); try { AfterTheFactAcquisitionProcessBean bean = new AfterTheFactAcquisitionProcessBean(); Set<Supplier> suppliers = Bennu.getInstance().getSuppliersSet(); Supplier supplier = null; for (Supplier sup : suppliers) { if (sup.getExternalId().equals(supplierID)) { supplier = sup; break; } } if (supplier == null) { return respondWithError(Status.NOT_FOUND, "supplier.not.found"); } bean.setSupplier(supplier); bean.setAfterTheFactAcquisitionType(AfterTheFactAcquisitionType.PURCHASE); Money itemValue = new Money(value); bean.setValue(itemValue); double VAT = Double.parseDouble(valueVAT); bean.setVatValue(new BigDecimal(VAT)); bean.setYear(new LocalDate().getYear()); bean.setDescription(description); bean.setClassification(AcquisitionItemClassification.valueOf(goodsOrServices.toUpperCase())); CPVReference cpvReference = CPVReference.getCPVCode(cpvcode); if (cpvReference == null) { return respondWithError(Status.NOT_FOUND, "cpv.reference.not.found"); } bean.setCpvReference(cpvReference); AfterTheFactAcquisitionProcess process; try { process = AfterTheFactAcquisitionProcess.createNewAfterTheFactAcquisitionProcess(bean); } catch (DomainException e) { throw newApplicationError(Status.PRECONDITION_FAILED, "precondition_failed"); } JsonObject obj = new JsonObject(); obj.addProperty("processID", process.getProcessNumber()); return Response.ok().entity(gson.toJson(obj)).build(); } finally { logout(); } }