@Test public void testUpdateCompany() { when(accountClient.trackEvent(any(TrackEventRequest.class))).thenReturn(BaseResponse.builder().message("company created").build()); CompanyDto companyDto = CompanyDto.builder() .name("test_company001") .defaultDayWeekStarts("Monday") .defaultTimezone(TimeZone.getDefault().getID()) .build(); GenericCompanyResponse genericCompanyResponse = companyClient.createCompany(AuthConstant.AUTHORIZATION_SUPPORT_USER, companyDto); CompanyDto createdCompany = genericCompanyResponse.getCompany(); assertThat(genericCompanyResponse.isSuccess()).isTrue(); companyDto.setId(createdCompany.getId()); companyDto.setName("test_company_update001"); companyDto.setArchived(true); genericCompanyResponse = companyClient.updateCompany(AuthConstant.AUTHORIZATION_SUPPORT_USER, companyDto); log.info(genericCompanyResponse.toString()); assertThat(genericCompanyResponse.isSuccess()).isTrue(); CompanyDto updatedCompany = genericCompanyResponse.getCompany(); assertThat(updatedCompany).isEqualTo(companyDto); companyDto.setId(UUID.randomUUID().toString()); companyDto.setName("test_company_update002"); companyDto.setArchived(true); genericCompanyResponse = companyClient.updateCompany(AuthConstant.AUTHORIZATION_SUPPORT_USER, companyDto); log.info(genericCompanyResponse.toString()); assertThat(genericCompanyResponse.isSuccess()).isFalse(); assertThat(genericCompanyResponse.getCode()).isEqualTo(ResultCode.NOT_FOUND); }
@PutMapping(path= "/update") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER }) public GenericCompanyResponse updateCompany(@RequestBody @Validated({Group1.class}) CompanyDto companyDto) { if (AuthConstant.AUTHORIZATION_AUTHENTICATED_USER.equals(AuthContext.getAuthz())) { permissionService.checkPermissionCompanyAdmin(companyDto.getId()); } CompanyDto updatedCompanyDto = companyService.updateCompany(companyDto); return new GenericCompanyResponse(updatedCompanyDto); }
CompanyController { @PutMapping(path= "/update") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER }) public GenericCompanyResponse updateCompany(@RequestBody @Validated({Group1.class}) CompanyDto companyDto) { if (AuthConstant.AUTHORIZATION_AUTHENTICATED_USER.equals(AuthContext.getAuthz())) { permissionService.checkPermissionCompanyAdmin(companyDto.getId()); } CompanyDto updatedCompanyDto = companyService.updateCompany(companyDto); return new GenericCompanyResponse(updatedCompanyDto); } }
CompanyController { @PutMapping(path= "/update") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER }) public GenericCompanyResponse updateCompany(@RequestBody @Validated({Group1.class}) CompanyDto companyDto) { if (AuthConstant.AUTHORIZATION_AUTHENTICATED_USER.equals(AuthContext.getAuthz())) { permissionService.checkPermissionCompanyAdmin(companyDto.getId()); } CompanyDto updatedCompanyDto = companyService.updateCompany(companyDto); return new GenericCompanyResponse(updatedCompanyDto); }  }
CompanyController { @PutMapping(path= "/update") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER }) public GenericCompanyResponse updateCompany(@RequestBody @Validated({Group1.class}) CompanyDto companyDto) { if (AuthConstant.AUTHORIZATION_AUTHENTICATED_USER.equals(AuthContext.getAuthz())) { permissionService.checkPermissionCompanyAdmin(companyDto.getId()); } CompanyDto updatedCompanyDto = companyService.updateCompany(companyDto); return new GenericCompanyResponse(updatedCompanyDto); }  @PostMapping(path = "/create") @Authorize(value = { AuthConstant.AUTHORIZATION_SUPPORT_USER, AuthConstant.AUTHORIZATION_WWW_SERVICE }) GenericCompanyResponse createCompany(@RequestBody @Validated({Group2.class}) CompanyDto companyDto); @GetMapping(path = "/list") @Authorize(value = {AuthConstant.AUTHORIZATION_SUPPORT_USER}) ListCompanyResponse listCompanies(@RequestParam int offset, @RequestParam int limit); @GetMapping(path= "/get") @Authorize(value = { AuthConstant.AUTHORIZATION_ACCOUNT_SERVICE, AuthConstant.AUTHORIZATION_BOT_SERVICE, AuthConstant.AUTHORIZATION_WHOAMI_SERVICE, AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER, AuthConstant.AUTHORIZATION_WWW_SERVICE, AuthConstant.AUTHORIZATION_ICAL_SERVICE }) GenericCompanyResponse getCompany(@RequestParam("company_id") String companyId); @PutMapping(path= "/update") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER }) GenericCompanyResponse updateCompany(@RequestBody @Validated({Group1.class}) CompanyDto companyDto); }
CompanyController { @PutMapping(path= "/update") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER }) public GenericCompanyResponse updateCompany(@RequestBody @Validated({Group1.class}) CompanyDto companyDto) { if (AuthConstant.AUTHORIZATION_AUTHENTICATED_USER.equals(AuthContext.getAuthz())) { permissionService.checkPermissionCompanyAdmin(companyDto.getId()); } CompanyDto updatedCompanyDto = companyService.updateCompany(companyDto); return new GenericCompanyResponse(updatedCompanyDto); }  @PostMapping(path = "/create") @Authorize(value = { AuthConstant.AUTHORIZATION_SUPPORT_USER, AuthConstant.AUTHORIZATION_WWW_SERVICE }) GenericCompanyResponse createCompany(@RequestBody @Validated({Group2.class}) CompanyDto companyDto); @GetMapping(path = "/list") @Authorize(value = {AuthConstant.AUTHORIZATION_SUPPORT_USER}) ListCompanyResponse listCompanies(@RequestParam int offset, @RequestParam int limit); @GetMapping(path= "/get") @Authorize(value = { AuthConstant.AUTHORIZATION_ACCOUNT_SERVICE, AuthConstant.AUTHORIZATION_BOT_SERVICE, AuthConstant.AUTHORIZATION_WHOAMI_SERVICE, AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER, AuthConstant.AUTHORIZATION_WWW_SERVICE, AuthConstant.AUTHORIZATION_ICAL_SERVICE }) GenericCompanyResponse getCompany(@RequestParam("company_id") String companyId); @PutMapping(path= "/update") @Authorize(value = { AuthConstant.AUTHORIZATION_AUTHENTICATED_USER, AuthConstant.AUTHORIZATION_SUPPORT_USER }) GenericCompanyResponse updateCompany(@RequestBody @Validated({Group1.class}) CompanyDto companyDto);  }