Skip to content

Commit

Permalink
Merge pull request apache#7 from crain/develop
Browse files Browse the repository at this point in the history
Looks good to me ...
  • Loading branch information
mgeiss authored May 24, 2017
2 parents d460006 + 5482b43 commit 2b8090d
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 27 deletions.
2 changes: 2 additions & 0 deletions api/src/main/java/io/mifos/customer/PermittableGroupIds.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
public interface PermittableGroupIds {

String CUSTOMER = "customer__v1__customer";
String PORTRAIT = "customer__v1__portrait";
String IDENTIFICATIONS = "customer__v1__identifications";
String TASK = "customer__v1__task";
String CATALOG = "catalog__v1__catalog";
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public interface CustomerEventConstants {
String POST_TASK = "post-task";
String PUT_TASK = "put-task";

String PUT_PORTRAIT = "put-portrait";
String POST_PORTRAIT = "post-portrait";
String DELETE_PORTRAIT = "delete-portrait";

String SELECTOR_INITIALIZE = SELECTOR_NAME + " = '" + INITIALIZE + "'";
Expand All @@ -64,6 +64,6 @@ public interface CustomerEventConstants {
String SELECTOR_POST_TASK = SELECTOR_NAME + " = '" + POST_TASK + "'";
String SELECTOR_PUT_TASK = SELECTOR_NAME + " = '" + PUT_TASK + "'";

String SELECTOR_PUT_PORTRAIT = SELECTOR_NAME + " = '" + PUT_PORTRAIT + "'";
String SELECTOR_PUT_PORTRAIT = SELECTOR_NAME + " = '" + POST_PORTRAIT + "'";
String SELECTOR_DELETE_PORTRAIT = SELECTOR_NAME + " = '" + DELETE_PORTRAIT + "'";
}
Original file line number Diff line number Diff line change
Expand Up @@ -243,15 +243,15 @@ void deleteIdentificationCard(@PathVariable("identifier") final String identifie

@RequestMapping(
value = "/customers/{identifier}/portrait",
method = RequestMethod.PUT,
method = RequestMethod.POST,
produces = MediaType.ALL_VALUE,
consumes = MediaType.MULTIPART_FORM_DATA_VALUE
)
@ThrowsExceptions({
@ThrowsException(status = HttpStatus.NOT_FOUND, exception = CustomerNotFoundException.class),
@ThrowsException(status = HttpStatus.BAD_REQUEST, exception = PortraitValidationException.class),
})
void putPortrait(@PathVariable("identifier") final String identifier,
void postPortrait(@PathVariable("identifier") final String identifier,
@RequestBody final MultipartFile portrait);

@RequestMapping(
Expand Down
23 changes: 12 additions & 11 deletions component-test/src/main/java/io/mifos/customer/TestCustomer.java
Original file line number Diff line number Diff line change
Expand Up @@ -497,9 +497,9 @@ public void shouldUploadPortrait() throws Exception {

final MockMultipartFile file = new MockMultipartFile("portrait", "test.png", MediaType.IMAGE_PNG_VALUE, "i don't care".getBytes());

this.customerManager.putPortrait(customer.getIdentifier(), file);
this.customerManager.postPortrait(customer.getIdentifier(), file);

this.eventRecorder.wait(CustomerEventConstants.PUT_PORTRAIT, customer.getIdentifier());
this.eventRecorder.wait(CustomerEventConstants.POST_PORTRAIT, customer.getIdentifier());

byte[] portrait = this.customerManager.getPortrait(customer.getIdentifier());

Expand All @@ -516,17 +516,18 @@ public void shouldReplacePortrait() throws Exception {

final MockMultipartFile firstFile = new MockMultipartFile("portrait", "test.png", MediaType.IMAGE_PNG_VALUE, "i don't care".getBytes());

this.customerManager.putPortrait(customer.getIdentifier(), firstFile);
this.customerManager.postPortrait(customer.getIdentifier(), firstFile);

this.eventRecorder.wait(CustomerEventConstants.PUT_PORTRAIT, customer.getIdentifier());

this.eventRecorder.clear();
this.eventRecorder.wait(CustomerEventConstants.POST_PORTRAIT, customer.getIdentifier());

final MockMultipartFile secondFile = new MockMultipartFile("portrait", "test.png", MediaType.IMAGE_PNG_VALUE, "i do care".getBytes());

this.customerManager.putPortrait(customer.getIdentifier(), secondFile);
this.customerManager.postPortrait(customer.getIdentifier(), secondFile);

this.eventRecorder.wait(CustomerEventConstants.POST_PORTRAIT, customer.getIdentifier());

this.eventRecorder.wait(CustomerEventConstants.PUT_PORTRAIT, customer.getIdentifier());
// For a unknown reason the wait gets the POST_PORTRAIT event although the the entity has not been written into the database
Thread.sleep(500);

final byte[] portrait = this.customerManager.getPortrait(customer.getIdentifier());

Expand All @@ -543,7 +544,7 @@ public void shouldThrowIfPortraitExceedsMaxSize() throws Exception {

final MockMultipartFile firstFile = new MockMultipartFile("portrait", "test.png", MediaType.IMAGE_PNG_VALUE, RandomStringUtils.randomAlphanumeric(750000).getBytes());

this.customerManager.putPortrait(customer.getIdentifier(), firstFile);
this.customerManager.postPortrait(customer.getIdentifier(), firstFile);
}

@Test(expected = PortraitNotFoundException.class)
Expand All @@ -556,9 +557,9 @@ public void shouldDeletePortrait() throws Exception {

final MockMultipartFile firstFile = new MockMultipartFile("portrait", "test.png", MediaType.IMAGE_PNG_VALUE, "i don't care".getBytes());

this.customerManager.putPortrait(customer.getIdentifier(), firstFile);
this.customerManager.postPortrait(customer.getIdentifier(), firstFile);

this.eventRecorder.wait(CustomerEventConstants.PUT_PORTRAIT, customer.getIdentifier());
this.eventRecorder.wait(CustomerEventConstants.POST_PORTRAIT, customer.getIdentifier());

this.customerManager.deletePortrait(customer.getIdentifier());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public void identificationCardDeletedEvent(@Header(TenantHeaderFilter.TENANT_HEA
)
public void portraitPutEvent(@Header(TenantHeaderFilter.TENANT_HEADER) final String tenant,
final String payload) {
this.eventRecorder.event(tenant, CustomerEventConstants.PUT_PORTRAIT, payload, String.class);
this.eventRecorder.event(tenant, CustomerEventConstants.POST_PORTRAIT, payload, String.class);
}

@JmsListener(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ public String deleteIdentificationCard(final DeleteIdentificationCardCommand del

@Transactional
@CommandHandler
@EventEmitter(selectorName = CustomerEventConstants.SELECTOR_NAME, selectorValue = CustomerEventConstants.PUT_PORTRAIT)
@EventEmitter(selectorName = CustomerEventConstants.SELECTOR_NAME, selectorValue = CustomerEventConstants.POST_PORTRAIT)
public String createPortrait(final CreatePortraitCommand createPortraitCommand) throws IOException {
if(createPortraitCommand.portrait() == null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ ResponseEntity<Void> putContactDetails(@PathVariable("identifier") final String
return ResponseEntity.accepted().build();
}

@Permittable(value = AcceptedTokenType.TENANT, groupId = PermittableGroupIds.CUSTOMER)
@Permittable(value = AcceptedTokenType.TENANT, groupId = PermittableGroupIds.IDENTIFICATIONS)
@RequestMapping(
value = "/customers/{identifier}/identifications",
method = RequestMethod.GET,
Expand All @@ -385,7 +385,7 @@ ResponseEntity<Void> putContactDetails(@PathVariable("identifier") final String
return ResponseEntity.ok(this.customerService.fetchIdentificationCardsByCustomer(identifier));
}

@Permittable(value = AcceptedTokenType.TENANT, groupId = PermittableGroupIds.CUSTOMER)
@Permittable(value = AcceptedTokenType.TENANT, groupId = PermittableGroupIds.IDENTIFICATIONS)
@RequestMapping(
value = "/customers/{identifier}/identifications/{number}",
method = RequestMethod.GET,
Expand All @@ -406,7 +406,7 @@ ResponseEntity<IdentificationCard> findIdentificationCard(@PathVariable("identif
}
}

@Permittable(value = AcceptedTokenType.TENANT, groupId = PermittableGroupIds.CUSTOMER)
@Permittable(value = AcceptedTokenType.TENANT, groupId = PermittableGroupIds.IDENTIFICATIONS)
@RequestMapping(
value = "/customers/{identifier}/identifications",
method = RequestMethod.POST,
Expand All @@ -430,7 +430,7 @@ ResponseEntity<Void> createIdentificationCard(@PathVariable("identifier") final
return ResponseEntity.accepted().build();
}

@Permittable(value = AcceptedTokenType.TENANT, groupId = PermittableGroupIds.CUSTOMER)
@Permittable(value = AcceptedTokenType.TENANT, groupId = PermittableGroupIds.IDENTIFICATIONS)
@RequestMapping(
value = "/customers/{identifier}/identifications/{number}",
method = RequestMethod.PUT,
Expand All @@ -454,7 +454,7 @@ ResponseEntity<Void> updateIdentificationCard(@PathVariable("identifier") final
return ResponseEntity.accepted().build();
}

@Permittable(value = AcceptedTokenType.TENANT, groupId = PermittableGroupIds.CUSTOMER)
@Permittable(value = AcceptedTokenType.TENANT, groupId = PermittableGroupIds.IDENTIFICATIONS)
@RequestMapping(
value = "/customers/{identifier}/identifications/{number}",
method = RequestMethod.DELETE,
Expand All @@ -472,7 +472,7 @@ ResponseEntity<Void> deleteIdentificationCard(@PathVariable("identifier") final
return ResponseEntity.accepted().build();
}

@Permittable(value = AcceptedTokenType.TENANT, groupId = PermittableGroupIds.CUSTOMER)
@Permittable(value = AcceptedTokenType.TENANT, groupId = PermittableGroupIds.PORTRAIT)
@RequestMapping(
value = "/customers/{identifier}/portrait",
method = RequestMethod.GET,
Expand All @@ -490,14 +490,14 @@ public ResponseEntity<byte[]> getPortrait(@PathVariable("identifier") final Stri
.body(portrait.getImage());
}

@Permittable(value = AcceptedTokenType.TENANT, groupId = PermittableGroupIds.CUSTOMER)
@Permittable(value = AcceptedTokenType.TENANT, groupId = PermittableGroupIds.PORTRAIT)
@RequestMapping(
value = "/customers/{identifier}/portrait",
method = RequestMethod.PUT,
method = RequestMethod.POST,
produces = MediaType.APPLICATION_JSON_VALUE,
consumes = MediaType.MULTIPART_FORM_DATA_VALUE
)
public @ResponseBody ResponseEntity<Void> putPortrait(@PathVariable("identifier") final String identifier,
public @ResponseBody ResponseEntity<Void> postPortrait(@PathVariable("identifier") final String identifier,
@RequestBody final MultipartFile portrait) {
if(portrait == null) {
throw ServiceException.badRequest("Portrait not found");
Expand Down Expand Up @@ -527,7 +527,7 @@ public ResponseEntity<byte[]> getPortrait(@PathVariable("identifier") final Stri
return ResponseEntity.accepted().build();
}

@Permittable(value = AcceptedTokenType.TENANT, groupId = PermittableGroupIds.CUSTOMER)
@Permittable(value = AcceptedTokenType.TENANT, groupId = PermittableGroupIds.PORTRAIT)
@RequestMapping(
value = "/customers/{identifier}/portrait",
method = RequestMethod.DELETE,
Expand Down

0 comments on commit 2b8090d

Please sign in to comment.