Skip to content
Permalink
Browse files
added external references to office
  • Loading branch information
mgeiss committed Sep 12, 2017
1 parent 8f38890 commit 70ad20231f76ca22a4e59f5c767747fda7cafacd
Showing 16 changed files with 438 additions and 25 deletions.
@@ -28,6 +28,7 @@ public interface EventConstants {
String OPERATION_DELETE_OFFICE = "delete-office";
String OPERATION_PUT_ADDRESS = "put-address";
String OPERATION_DELETE_ADDRESS = "delete-address";
String OPERATION_PUT_REFERENCE = "put-reference";

String OPERATION_POST_EMPLOYEE = "post-employee";
String OPERATION_PUT_EMPLOYEE = "put-employee";
@@ -42,6 +43,7 @@ public interface EventConstants {
String SELECTOR_DELETE_OFFICE = OPERATION_HEADER + " = '" + OPERATION_DELETE_OFFICE + "'";
String SELECTOR_PUT_ADDRESS = OPERATION_HEADER + " = '" + OPERATION_PUT_ADDRESS + "'";
String SELECTOR_DELETE_ADDRESS = OPERATION_HEADER + " = '" + OPERATION_DELETE_ADDRESS + "'";
String SELECTOR_PUT_REFERENCE = OPERATION_HEADER + " = '" + OPERATION_PUT_REFERENCE + "'";

String SELECTOR_POST_EMPLOYEE = OPERATION_HEADER + " = '" + OPERATION_POST_EMPLOYEE + "'";
String SELECTOR_PUT_EMPLOYEE = OPERATION_HEADER + " = '" + OPERATION_PUT_EMPLOYEE + "'";
@@ -22,6 +22,7 @@
import io.mifos.office.api.v1.domain.ContactDetail;
import io.mifos.office.api.v1.domain.Employee;
import io.mifos.office.api.v1.domain.EmployeePage;
import io.mifos.office.api.v1.domain.ExternalReference;
import io.mifos.office.api.v1.domain.Office;
import io.mifos.office.api.v1.domain.OfficePage;
import org.springframework.cloud.netflix.feign.FeignClient;
@@ -33,6 +34,7 @@
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import javax.validation.Valid;
import java.util.List;

@SuppressWarnings("unused")
@@ -223,4 +225,14 @@ void setContactDetails(@PathVariable("useridentifier") final String identifier,
)
@ThrowsException(status = HttpStatus.NOT_FOUND, exception = NotFoundException.class)
void deleteContactDetails(@PathVariable("useridentifier") final String identifier);

@RequestMapping(
value = "/offices/{identifier}/references",
method = RequestMethod.PUT,
consumes = MediaType.APPLICATION_JSON_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE
)
@ThrowsException(status = HttpStatus.NOT_FOUND, exception = NotFoundException.class)
void addExternalReference(@PathVariable("identifier") final String officeIdentifier,
@RequestBody @Valid final ExternalReference externalReference);
}
@@ -0,0 +1,53 @@
/*
* Copyright 2017 The Mifos Initiative
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.mifos.office.api.v1.domain;

import io.mifos.core.lang.validation.constraints.ValidIdentifier;

import javax.validation.constraints.NotNull;

public class ExternalReference {

public enum State {
ACTIVE,
INACTIVE
}

@ValidIdentifier
private String type;
@NotNull
private State state;

public ExternalReference() {
super();
}

public String getType() {
return this.type;
}

public void setType(final String type) {
this.type = type;
}

public String getState() {
return this.state.name();
}

public void setState(final String state) {
this.state = State.valueOf(state);
}
}
@@ -26,6 +26,7 @@ public class Office {
private String name;
private String description;
private Address address;
private Boolean externalReferences;

public Office() {
super();
@@ -70,4 +71,12 @@ public Address getAddress() {
public void setAddress(Address address) {
this.address = address;
}

public Boolean getExternalReferences() {
return this.externalReferences;
}

public void setExternalReferences(final Boolean externalReferences) {
this.externalReferences = externalReferences;
}
}
@@ -26,8 +26,8 @@
import io.mifos.office.api.v1.EventConstants;
import io.mifos.office.api.v1.client.AlreadyExistsException;
import io.mifos.office.api.v1.client.BadRequestException;
import io.mifos.office.api.v1.client.OrganizationManager;
import io.mifos.office.api.v1.client.NotFoundException;
import io.mifos.office.api.v1.client.OrganizationManager;
import io.mifos.office.api.v1.domain.ContactDetail;
import io.mifos.office.api.v1.domain.Employee;
import io.mifos.office.api.v1.domain.EmployeePage;
@@ -36,7 +36,12 @@
import io.mifos.office.util.EmployeeFactory;
import io.mifos.office.util.OfficeFactory;
import org.apache.commons.lang3.RandomStringUtils;
import org.junit.*;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.RuleChain;
import org.junit.rules.TestRule;
import org.junit.runner.RunWith;
@@ -24,17 +24,27 @@
import io.mifos.core.test.listener.EnableEventRecording;
import io.mifos.core.test.listener.EventRecorder;
import io.mifos.office.api.v1.EventConstants;
import io.mifos.office.api.v1.client.*;
import io.mifos.office.api.v1.client.AlreadyExistsException;
import io.mifos.office.api.v1.client.BadRequestException;
import io.mifos.office.api.v1.client.ChildrenExistException;
import io.mifos.office.api.v1.client.NotFoundException;
import io.mifos.office.api.v1.client.OrganizationManager;
import io.mifos.office.api.v1.domain.Address;
import io.mifos.office.api.v1.domain.Employee;
import io.mifos.office.api.v1.domain.ExternalReference;
import io.mifos.office.api.v1.domain.Office;
import io.mifos.office.api.v1.domain.OfficePage;
import io.mifos.office.rest.config.OfficeRestConfiguration;
import io.mifos.office.util.AddressFactory;
import io.mifos.office.util.EmployeeFactory;
import io.mifos.office.util.OfficeFactory;
import org.apache.commons.lang3.RandomStringUtils;
import org.junit.*;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.RuleChain;
import org.junit.rules.TestRule;
import org.junit.runner.RunWith;
@@ -310,7 +320,7 @@ public void shouldDeleteOffice() throws Exception{
}

@Test(expected = ChildrenExistException.class)
public void shouldNotDeleteOfficeWithBranches() throws Exception{
public void shouldNotDeleteOfficeWithBranches() throws Exception {
final Office parent = OfficeFactory.createRandomOffice();
this.organizationManager.createOffice(parent);
this.eventRecorder.wait(EventConstants.OPERATION_POST_OFFICE, parent.getIdentifier());
@@ -323,7 +333,7 @@ public void shouldNotDeleteOfficeWithBranches() throws Exception{
}

@Test(expected = ChildrenExistException.class)
public void shouldNotDeleteOfficeWithEmployees() throws Exception{
public void shouldNotDeleteOfficeWithEmployees() throws Exception {
final Office office = OfficeFactory.createRandomOffice();
this.organizationManager.createOffice(office);
this.eventRecorder.wait(EventConstants.OPERATION_POST_OFFICE, office.getIdentifier());
@@ -336,6 +346,59 @@ public void shouldNotDeleteOfficeWithEmployees() throws Exception{
this.organizationManager.deleteOffice(office.getIdentifier());
}

@Test(expected = ChildrenExistException.class)
public void shouldNotDeleteOfficeWithActiveExternalReference() throws Exception {
final Office randomOffice = OfficeFactory.createRandomOffice();
this.organizationManager.createOffice(randomOffice);
Assert.assertTrue(this.eventRecorder.wait(EventConstants.OPERATION_POST_OFFICE, randomOffice.getIdentifier()));

final ExternalReference externalReference = new ExternalReference();
externalReference.setType("anytype");
externalReference.setState(ExternalReference.State.ACTIVE.name());

this.organizationManager.addExternalReference(randomOffice.getIdentifier(), externalReference);
Assert.assertTrue(this.eventRecorder.wait(EventConstants.OPERATION_PUT_REFERENCE, randomOffice.getIdentifier()));

this.organizationManager.deleteOffice(randomOffice.getIdentifier());
}

@Test
public void shouldDeleteOfficeWithInactiveExternalReference() throws Exception {
final Office randomOffice = OfficeFactory.createRandomOffice();
this.organizationManager.createOffice(randomOffice);
Assert.assertTrue(this.eventRecorder.wait(EventConstants.OPERATION_POST_OFFICE, randomOffice.getIdentifier()));

final ExternalReference externalReference = new ExternalReference();
externalReference.setType("anytype");
externalReference.setState(ExternalReference.State.INACTIVE.name());

this.organizationManager.addExternalReference(randomOffice.getIdentifier(), externalReference);
Assert.assertTrue(this.eventRecorder.wait(EventConstants.OPERATION_PUT_REFERENCE, randomOffice.getIdentifier()));

final Office office = this.organizationManager.findOfficeByIdentifier(randomOffice.getIdentifier());
Assert.assertFalse(office.getExternalReferences());

this.organizationManager.deleteOffice(randomOffice.getIdentifier());
Assert.assertTrue(this.eventRecorder.wait(EventConstants.OPERATION_DELETE_OFFICE, randomOffice.getIdentifier()));
}

@Test
public void shouldIndicateOfficeHasExternalReferences() throws Exception {
final Office randomOffice = OfficeFactory.createRandomOffice();
this.organizationManager.createOffice(randomOffice);
Assert.assertTrue(this.eventRecorder.wait(EventConstants.OPERATION_POST_OFFICE, randomOffice.getIdentifier()));

final ExternalReference externalReference = new ExternalReference();
externalReference.setType("anytype");
externalReference.setState(ExternalReference.State.ACTIVE.name());

this.organizationManager.addExternalReference(randomOffice.getIdentifier(), externalReference);
Assert.assertTrue(this.eventRecorder.wait(EventConstants.OPERATION_PUT_REFERENCE, randomOffice.getIdentifier()));

final Office office = this.organizationManager.findOfficeByIdentifier(randomOffice.getIdentifier());
Assert.assertTrue(office.getExternalReferences());
}

@Configuration
@ComponentScan(
basePackages = "io.mifos.office.listener"
@@ -94,4 +94,15 @@ public void onDeleteAddress(@Header(TenantHeaderFilter.TENANT_HEADER) final Stri
throws Exception {
this.eventRecorder.event(tenant, EventConstants.OPERATION_DELETE_ADDRESS, payload, String.class);
}

@JmsListener(
subscription = EventConstants.DESTINATION,
destination = EventConstants.DESTINATION,
selector = EventConstants.SELECTOR_PUT_REFERENCE
)
public void onPutAReference(@Header(TenantHeaderFilter.TENANT_HEADER) final String tenant,
final String payload)
throws Exception {
this.eventRecorder.event(tenant, EventConstants.OPERATION_PUT_REFERENCE, payload, String.class);
}
}
@@ -0,0 +1,37 @@
/*
* Copyright 2017 The Mifos Initiative
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.mifos.office.internal.command;

import io.mifos.office.api.v1.domain.ExternalReference;

public class AddExternalReferenceCommand {
private final String officeIdentifier;
private final ExternalReference externalReference;

public AddExternalReferenceCommand(final String officeIdentifier, final ExternalReference externalReference) {
super();
this.officeIdentifier = officeIdentifier;
this.externalReference = externalReference;
}

public String officeIdentifier() {
return this.officeIdentifier;
}

public ExternalReference externalReference() {
return this.externalReference;
}
}
@@ -24,12 +24,12 @@
import io.mifos.office.api.v1.domain.ContactDetail;
import io.mifos.office.api.v1.domain.Employee;
import io.mifos.office.internal.command.CreateEmployeeCommand;
import io.mifos.office.internal.command.DeleteContactDetailCommand;
import io.mifos.office.internal.command.DeleteEmployeeCommand;
import io.mifos.office.internal.command.SetContactDetailsCommand;
import io.mifos.office.internal.command.UpdateEmployeeCommand;
import io.mifos.office.internal.mapper.ContactDetailMapper;
import io.mifos.office.internal.mapper.EmployeeMapper;
import io.mifos.office.internal.command.DeleteContactDetailCommand;
import io.mifos.office.internal.repository.ContactDetailEntity;
import io.mifos.office.internal.repository.ContactDetailRepository;
import io.mifos.office.internal.repository.EmployeeEntity;

0 comments on commit 70ad202

Please sign in to comment.