@Test public void upsertOrganizationExisting() throws Exception { ObjectMapper mapper = new ObjectMapper(); String ipAddress = "192.168.56.1"; String user = "USER"; mockHttpSession.setAttribute("acm_ip_address", ipAddress); Organization body = new Organization(); body.setOrganizationId(-1L); body.setOrganizationValue("Armedia LLC."); Capture<Organization> orgCapture = EasyMock.newCapture(); Capture<Organization> orgCaptureOld = EasyMock.newCapture(); expect(mockOrganizationService.getOrganization(body.getOrganizationId())).andReturn(body); expect(mockAuthentication.getName()).andReturn(user).anyTimes(); expect(mockOrganizationService.saveOrganization(anyObject(Organization.class), eq(mockAuthentication), eq(ipAddress))) .andReturn(body); mockOrganizationEventPublisher.publishOrganizationUpsertEvent(capture(orgCapture), capture(orgCaptureOld), eq(false), eq(true)); expectLastCall(); replayAll(); MvcResult result = mockMvc .perform(post("/api/latest/plugin/organizations").accept(MediaType.APPLICATION_JSON).contentType(MediaType.APPLICATION_JSON) .content(mapper.writeValueAsString(body)).principal(mockAuthentication).session(mockHttpSession)) .andExpect(status().isOk()).andReturn(); verifyAll(); Organization retval = mapper.readValue(result.getResponse().getContentAsString(), Organization.class); assertEquals(body.getOrganizationValue(), retval.getOrganizationValue()); assertEquals(body.getOrganizationValue(), orgCapture.getValue().getOrganizationValue()); assertEquals(body.getOrganizationId(), orgCapture.getValue().getOrganizationId()); }
@PreAuthorize("hasPermission(#organizationId, 'ORGANIZATION', 'viewOrganizationPage')") @RequestMapping(value = "/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @DecoratedAssignedObjectParticipants @ResponseBody public Organization getOrganization(@PathVariable("id") Long organizationId) throws AcmObjectNotFoundException { try { Organization organization = organizationService.getOrganization(organizationId); organizationEventPublisher.publishOrganizationViewedEvent(organization, true); return organization; } catch (Exception e) { log.error("Error while retrieving Organization with id: [{}]", organizationId, e); throw new AcmObjectNotFoundException("Organization", null, "Could not retrieve organization.", e); } }
OrganizationAPIController { @PreAuthorize("hasPermission(#organizationId, 'ORGANIZATION', 'viewOrganizationPage')") @RequestMapping(value = "/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @DecoratedAssignedObjectParticipants @ResponseBody public Organization getOrganization(@PathVariable("id") Long organizationId) throws AcmObjectNotFoundException { try { Organization organization = organizationService.getOrganization(organizationId); organizationEventPublisher.publishOrganizationViewedEvent(organization, true); return organization; } catch (Exception e) { log.error("Error while retrieving Organization with id: [{}]", organizationId, e); throw new AcmObjectNotFoundException("Organization", null, "Could not retrieve organization.", e); } } }
OrganizationAPIController { @PreAuthorize("hasPermission(#organizationId, 'ORGANIZATION', 'viewOrganizationPage')") @RequestMapping(value = "/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @DecoratedAssignedObjectParticipants @ResponseBody public Organization getOrganization(@PathVariable("id") Long organizationId) throws AcmObjectNotFoundException { try { Organization organization = organizationService.getOrganization(organizationId); organizationEventPublisher.publishOrganizationViewedEvent(organization, true); return organization; } catch (Exception e) { log.error("Error while retrieving Organization with id: [{}]", organizationId, e); throw new AcmObjectNotFoundException("Organization", null, "Could not retrieve organization.", e); } }  }
OrganizationAPIController { @PreAuthorize("hasPermission(#organizationId, 'ORGANIZATION', 'viewOrganizationPage')") @RequestMapping(value = "/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @DecoratedAssignedObjectParticipants @ResponseBody public Organization getOrganization(@PathVariable("id") Long organizationId) throws AcmObjectNotFoundException { try { Organization organization = organizationService.getOrganization(organizationId); organizationEventPublisher.publishOrganizationViewedEvent(organization, true); return organization; } catch (Exception e) { log.error("Error while retrieving Organization with id: [{}]", organizationId, e); throw new AcmObjectNotFoundException("Organization", null, "Could not retrieve organization.", e); } }  @PreAuthorize("#in.organizationId == null or hasPermission(#in.organizationId, 'ORGANIZATION', 'editOrganization')") @RequestMapping(method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @DecoratedAssignedObjectParticipants @ResponseBody Organization upsertOrganization(@RequestBody Organization in, Authentication auth, HttpSession httpSession); @RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody String getOrganizations(Authentication auth, @RequestParam(value = "start", required = false, defaultValue = "0") int start,
            @RequestParam(value = "n", required = false, defaultValue = "10") int n,
            @RequestParam(value = "s", required = false, defaultValue = "ASC") String s); @PreAuthorize("hasPermission(#organizationId, 'ORGANIZATION', 'viewOrganizationPage')") @RequestMapping(value = "/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @DecoratedAssignedObjectParticipants @ResponseBody Organization getOrganization(@PathVariable("id") Long organizationId); @RequestMapping(value = "/{organizationId}/associations/{objectType}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody String getChildObjects(Authentication auth, @PathVariable("organizationId") Long organizationId,
            @PathVariable("objectType") String objectType, @RequestParam(value = "start", required = false, defaultValue = "0") int start,
            @RequestParam(value = "n", required = false, defaultValue = "10") int n); @RequestMapping(value = "/search/{organizationId}", method = RequestMethod.GET) String searchOrganizations(@PathVariable("organizationId") Long organizationId); void setOrganizationService(OrganizationService organizationService); void setExecuteSolrQuery(ExecuteSolrQuery executeSolrQuery); void setOrganizationEventPublisher(OrganizationEventPublisher organizationEventPublisher); void setFacetedSearchPath(String facetedSearchPath); ObjectConverter getObjectConverter(); void setObjectConverter(ObjectConverter objectConverter); }
OrganizationAPIController { @PreAuthorize("hasPermission(#organizationId, 'ORGANIZATION', 'viewOrganizationPage')") @RequestMapping(value = "/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @DecoratedAssignedObjectParticipants @ResponseBody public Organization getOrganization(@PathVariable("id") Long organizationId) throws AcmObjectNotFoundException { try { Organization organization = organizationService.getOrganization(organizationId); organizationEventPublisher.publishOrganizationViewedEvent(organization, true); return organization; } catch (Exception e) { log.error("Error while retrieving Organization with id: [{}]", organizationId, e); throw new AcmObjectNotFoundException("Organization", null, "Could not retrieve organization.", e); } }  @PreAuthorize("#in.organizationId == null or hasPermission(#in.organizationId, 'ORGANIZATION', 'editOrganization')") @RequestMapping(method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @DecoratedAssignedObjectParticipants @ResponseBody Organization upsertOrganization(@RequestBody Organization in, Authentication auth, HttpSession httpSession); @RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody String getOrganizations(Authentication auth, @RequestParam(value = "start", required = false, defaultValue = "0") int start,
            @RequestParam(value = "n", required = false, defaultValue = "10") int n,
            @RequestParam(value = "s", required = false, defaultValue = "ASC") String s); @PreAuthorize("hasPermission(#organizationId, 'ORGANIZATION', 'viewOrganizationPage')") @RequestMapping(value = "/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @DecoratedAssignedObjectParticipants @ResponseBody Organization getOrganization(@PathVariable("id") Long organizationId); @RequestMapping(value = "/{organizationId}/associations/{objectType}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody String getChildObjects(Authentication auth, @PathVariable("organizationId") Long organizationId,
            @PathVariable("objectType") String objectType, @RequestParam(value = "start", required = false, defaultValue = "0") int start,
            @RequestParam(value = "n", required = false, defaultValue = "10") int n); @RequestMapping(value = "/search/{organizationId}", method = RequestMethod.GET) String searchOrganizations(@PathVariable("organizationId") Long organizationId); void setOrganizationService(OrganizationService organizationService); void setExecuteSolrQuery(ExecuteSolrQuery executeSolrQuery); void setOrganizationEventPublisher(OrganizationEventPublisher organizationEventPublisher); void setFacetedSearchPath(String facetedSearchPath); ObjectConverter getObjectConverter(); void setObjectConverter(ObjectConverter objectConverter);  }