Skip to content

Commit

Permalink
Removed additional details from customer table, ensured save, view an…
Browse files Browse the repository at this point in the history
…d edit works. Disabled hsql popup. Added a sample transaction to the data sql
  • Loading branch information
surajcm committed Jun 16, 2020
1 parent 98e0729 commit 3444b06
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 114 deletions.
55 changes: 0 additions & 55 deletions src/main/java/com/poseidon/customer/dao/entities/Customer.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,6 @@ public class Customer {
@Column(name = "email")
private String email;

@Column(name = "contactPerson1")
private String contactPerson1;

@Column(name = "contactPhone1")
private String contactPhone1;

@Column(name = "contactPerson2")
private String contactPerson2;

@Column(name = "contactPhone2")
private String contactPhone2;

@Column(name = "note")
private String note;

@Column(name = "createdOn")
private OffsetDateTime createdOn;

Expand Down Expand Up @@ -121,46 +106,6 @@ public void setEmail(final String email) {
this.email = email;
}

public String getContactPerson1() {
return contactPerson1;
}

public void setContactPerson1(final String contactPerson1) {
this.contactPerson1 = contactPerson1;
}

public String getContactPhone1() {
return contactPhone1;
}

public void setContactPhone1(final String contactPhone1) {
this.contactPhone1 = contactPhone1;
}

public String getContactPerson2() {
return contactPerson2;
}

public void setContactPerson2(final String contactPerson2) {
this.contactPerson2 = contactPerson2;
}

public String getContactPhone2() {
return contactPhone2;
}

public void setContactPhone2(final String contactPhone2) {
this.contactPhone2 = contactPhone2;
}

public String getNote() {
return note;
}

public void setNote(final String note) {
this.note = note;
}

public OffsetDateTime getCreatedOn() {
return createdOn;
}
Expand Down
36 changes: 15 additions & 21 deletions src/main/java/com/poseidon/customer/dao/impl/CustomerDAOImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
@Service
@SuppressWarnings("unused")
public class CustomerDAOImpl implements CustomerDAO {

private static final Logger LOG = LoggerFactory.getLogger(CustomerDAOImpl.class);
private static final String MOBILE = "mobile";

Expand Down Expand Up @@ -97,6 +96,11 @@ public CustomerVO getCustomerFromId(final Long id) throws CustomerException {
Optional<Customer> customer = customerRepository.findById(id);
if (customer.isPresent()) {
customerVO = convertToSingleCustomerVO(customer.get());
Optional<CustomerAdditionalDetails> additionalDetails =
customerAdditionalDetailsRepository.findByCustomerId(customer.get().getCustomerId());
if (additionalDetails.isPresent()) {
updateCustomerWithAdditionalDetails(customerVO, additionalDetails.get());
}
}
} catch (DataAccessException ex) {
LOG.error(ex.getLocalizedMessage());
Expand Down Expand Up @@ -169,6 +173,16 @@ private void updateAdditionalDetails(final CustomerVO currentCustomerVo,
customerAdditionalDetails.setNote(currentCustomerVo.getNotes());
}

private void updateCustomerWithAdditionalDetails(final CustomerVO customerVO,
final CustomerAdditionalDetails customerAdditionalDetails) {
customerVO.setContactPerson1(customerAdditionalDetails.getContactPerson1());
customerVO.setContactPerson2(customerAdditionalDetails.getContactPerson2());
customerVO.setContactMobile1(customerAdditionalDetails.getContactPhone1());
customerVO.setContactMobile2(customerAdditionalDetails.getContactPhone2());
customerVO.setNotes(customerAdditionalDetails.getNote());

}

private boolean isAdditionalDetailsPresent(final CustomerVO currentCustomerVo) {
return currentCustomerVo.getContactPerson1() != null || currentCustomerVo.getContactPerson2() != null
|| currentCustomerVo.getContactMobile1() != null || currentCustomerVo.getContactMobile2() != null
Expand All @@ -183,11 +197,6 @@ private void updateCustomerWithCustomerVo(final CustomerVO currentCustomerVo, fi
customer.setPhone(currentCustomerVo.getPhoneNo());
customer.setMobile(currentCustomerVo.getMobile());
customer.setEmail(currentCustomerVo.getEmail());
customer.setContactPerson1(currentCustomerVo.getContactPerson1());
customer.setContactPhone1(currentCustomerVo.getContactMobile1());
customer.setContactPerson2(currentCustomerVo.getContactPerson2());
customer.setContactPhone2(currentCustomerVo.getContactMobile2());
customer.setNote(currentCustomerVo.getNotes());
customer.setModifiedBy(currentCustomerVo.getModifiedBy());
}

Expand Down Expand Up @@ -219,11 +228,6 @@ private CustomerVO convertToSingleCustomerVO(final Customer customer) {
customerVO.setPhoneNo(customer.getPhone());
customerVO.setMobile(customer.getMobile());
customerVO.setEmail(customer.getEmail());
customerVO.setContactPerson1(customer.getContactPerson1());
customerVO.setContactMobile1(customer.getContactPhone1());
customerVO.setContactPerson2(customer.getContactPerson2());
customerVO.setContactMobile2(customer.getContactPhone2());
customerVO.setNotes(customer.getNote());
customerVO.setCreatedBy(customer.getCreatedBy());
customerVO.setModifiedBy(customer.getModifiedBy());
return customerVO;
Expand All @@ -237,11 +241,6 @@ private Customer convertToSingleCustomer(final CustomerVO currentCustomerVO) {
customer.setPhone(currentCustomerVO.getPhoneNo());
customer.setMobile(currentCustomerVO.getMobile());
customer.setEmail(currentCustomerVO.getEmail());
customer.setContactPerson1(currentCustomerVO.getContactPerson1());
customer.setContactPhone1(currentCustomerVO.getContactMobile1());
customer.setContactPerson2(currentCustomerVO.getContactPerson2());
customer.setContactPhone2(currentCustomerVO.getContactMobile2());
customer.setNote(currentCustomerVO.getNotes());
customer.setCreatedBy(currentCustomerVO.getCreatedBy());
customer.setModifiedBy(currentCustomerVO.getModifiedBy());
return customer;
Expand All @@ -258,11 +257,6 @@ private List<CustomerVO> convertToCustomerVO(final List<Customer> customers) {
customerVO.setPhoneNo(customer.getPhone());
customerVO.setMobile(customer.getMobile());
customerVO.setEmail(customer.getEmail());
customerVO.setContactPerson1(customer.getContactPerson1());
customerVO.setContactMobile1(customer.getContactPhone1());
customerVO.setContactPerson2(customer.getContactPerson2());
customerVO.setContactMobile2(customer.getContactPhone2());
customerVO.setNotes(customer.getNote());
customerVO.setCreatedBy(customer.getCreatedBy());
customerVO.setModifiedBy(customer.getModifiedBy());
customerVOS.add(customerVO);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,6 @@ public ModelAndView saveCustomer(final CustomerForm customerForm) {
LOG.info(CUSTOMER_FORM_IS, customerForm);
try {
CustomerVO customerVO = customerForm.getCurrentCustomerVO();
customerVO.setCreatedOn(OffsetDateTime.now(ZoneId.systemDefault()));
customerVO.setModifiedOn(OffsetDateTime.now(ZoneId.systemDefault()));
customerVO.setCreatedBy(customerForm.getLoggedInUser());
customerVO.setModifiedBy(customerForm.getLoggedInUser());
//populate customer additional details
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/com/poseidon/init/Initializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ public class Initializer {
*/
@PostConstruct
public void init() {
System.setProperty("java.awt.headless", "false");
DatabaseManagerSwing.main(
new String[]{"--url", "jdbc:hsqldb:mem:testdb", "--user", "sa", "--password", ""});
if (false) {
System.setProperty("java.awt.headless", "false");
DatabaseManagerSwing.main(
new String[]{"--url", "jdbc:hsqldb:mem:testdb", "--user", "sa", "--password", ""});
}
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.poseidon.transaction.dao.impl;

import com.poseidon.customer.dao.entities.Customer;
import com.poseidon.customer.dao.entities.CustomerAdditionalDetails;
import com.poseidon.customer.dao.impl.CustomerAdditionalDetailsRepository;
import com.poseidon.customer.dao.impl.CustomerRepository;
import com.poseidon.make.dao.entities.Make;
import com.poseidon.make.dao.entities.Model;
Expand Down Expand Up @@ -46,6 +48,8 @@ public class TransactionDAOImpl implements TransactionDAO {
private MakeRepository makeRepository;
@Autowired
private ModelRepository modelRepository;
@Autowired
private CustomerAdditionalDetailsRepository customerAdditionalDetailsRepository;
@PersistenceContext
private EntityManager em;

Expand Down Expand Up @@ -411,10 +415,14 @@ private TransactionReportVO convertToTransactionReportVO(final Transaction trans
txs.setPhone(customer.getPhone());
txs.setMobile(customer.getMobile());
txs.setEmail(customer.getEmail());
txs.setContactPerson1(customer.getContactPerson1());
txs.setContactPh1(customer.getContactPhone1());
txs.setContactPerson2(customer.getContactPerson2());
txs.setContactPh2(customer.getContactPhone2());
Optional<CustomerAdditionalDetails> additionalDetails =
customerAdditionalDetailsRepository.findByCustomerId(customer.getCustomerId());
if (additionalDetails.isPresent()) {
txs.setContactPerson1(additionalDetails.get().getContactPerson1());
txs.setContactPh1(additionalDetails.get().getContactPhone1());
txs.setContactPerson2(additionalDetails.get().getContactPerson2());
txs.setContactPh2(additionalDetails.get().getContactPhone2());
}
}
txs.setProductCategory(transaction.getProductCategory());
Make make = makeRepository.getOne(transaction.getMakeId());
Expand Down
28 changes: 16 additions & 12 deletions src/main/resources/data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -43,32 +43,36 @@ insert into model (id, modelName, makeId, createdOn, modifiedOn, createdBy, modi
insert into model (id, modelName, makeId, createdOn, modifiedOn, createdBy, modifiedBy) values
(3, 'ThinkPad', 3 ,'2019-08-01 00:00:00','2019-08-01 09:25:00','admin','admin');

insert into customer (id, name, address1, address2, phone, mobile, email, note, contactPerson1,
contactPerson2, contactPhone1, contactPhone2,createdBy, createdOn, modifiedBy, modifiedOn) values
(1, 'John Wick', '5630 N Sheridan', 'Chicago', '0404 232323', '555888999', 'test@testmail.com', 'Fix in 10 days',
'John', 'Hartigan', '888999777', '333555666', 'admin', '2020-06-08 00:00:00', 'admin', '2020-06-08 00:00:00')
insert into customer (id, name, address1, address2, phone, mobile, email,createdBy, createdOn, modifiedBy, modifiedOn)
values (1, 'John Wick', '5630 N Sheridan', 'Chicago', '0404 232323', '555888999', 'test@testmail.com',
'admin', '2020-06-08 00:00:00', 'admin', '2020-06-08 00:00:00')

insert into customer_additional_details (id, customerId, contactPerson1, contactPerson2, contactPhone1, contactPhone2,
note, createdBy, createdOn, modifiedBy, modifiedOn) values
(1, 1, 'John', 'Hartigan', '888999777', '333555666', 'Fix in 10 days',
'admin', '2020-06-08 00:00:00', 'admin', '2020-06-08 00:00:00')

insert into customer (id, name, address1, address2, phone, mobile, email, note,
contactPerson1, contactPerson2, contactPhone1, contactPhone2,createdBy, createdOn, modifiedBy, modifiedOn) values
(2, 'Nick Fury', '500 W Madison', 'Chicago', '0404 343242', '87878789', 'director@shield.com', 'Send over for parts',
'Philip', 'Coulson', '3322552233', '123131331', 'admin', '2020-06-13 00:00:00', 'admin', '2020-06-13 00:00:00')
insert into customer (id, name, address1, address2, phone, mobile, email, createdBy, createdOn, modifiedBy, modifiedOn)
values (2, 'Nick Fury', '500 W Madison', 'Chicago', '0404 343242', '87878789', 'director@shield.com',
'admin', '2020-06-13 00:00:00', 'admin', '2020-06-13 00:00:00')

insert into customer_additional_details (id, customerId, contactPerson1, contactPerson2, contactPhone1, contactPhone2,
note, createdBy, createdOn, modifiedBy, modifiedOn) values
(2, 2, 'Philip', 'Coulson', '3322552233', '123131331', 'Send over for parts',
'admin', '2020-06-13 00:00:00', 'admin', '2020-06-13 00:00:00')

insert into customer (id, name, address1, address2, phone, mobile, email, note,
contactPerson1, contactPerson2, contactPhone1, contactPhone2, createdBy, createdOn, modifiedBy, modifiedOn) values
(3, 'Steve Rogers', '5650 N Clark', 'California', '0424 1978', '5557771978', 'steve@mcu.com', 'Dig legacy pc parts',
'Tony', 'Stark', '8989898', '2223131', 'admin', '2020-06-15 00:00:00', 'admin', '2020-06-15 00:00:00')
insert into customer (id, name, address1, address2, phone, mobile, email, createdBy, createdOn, modifiedBy, modifiedOn)
values (3, 'Steve Rogers', '5650 N Clark', 'California', '0424 1978', '5557771978', 'steve@mcu.com',
'admin', '2020-06-15 00:00:00', 'admin', '2020-06-15 00:00:00')

insert into customer_additional_details (id, customerId, contactPerson1, contactPerson2, contactPhone1, contactPhone2,
note, createdBy, createdOn, modifiedBy, modifiedOn) values
(3, 3, 'Tony', 'Stark', '8989898', '2223131', 'Dig legacy pc parts',
'admin', '2020-06-15 00:00:00', 'admin', '2020-06-15 00:00:00')

insert into transaction (id, tagNo, dateReported, customerId, productCategory, makeId, modelId,
serialNo, accessories, complaintReported, complaintDiagnosed, engineerRemarks, repairAction, note, status,
createdBy, createdOn, modifiedBy, modifiedOn) values (1, 'WON2N1', '2020-06-15 00:00:00', 1 , 'LAPTOP', 1, 1,
'AEPEP88990', 'Charger', 'Startup failure', 'Battery connectivity', 'Power circuit broken',
'Replace Board', 'Purchase new board', 'ACCEPTED',
'admin', '2020-06-15 00:00:00', 'admin', '2020-06-15 00:00:00')
15 changes: 5 additions & 10 deletions src/main/resources/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,11 @@ alter table model add foreign key (id) REFERENCES make(id);
create table customer (
id bigint generated by default as identity (start with 1) primary key,
name varchar(150) not null,
address1 varchar(200) not null,
address2 varchar(200) not null,
phone varchar(20) not null,
mobile varchar(20) not null,
email varchar(20) not null,
contactPerson1 varchar(150) not null,
contactPhone1 varchar(20) not null,
contactPerson2 varchar(150) not null,
contactPhone2 varchar(20) not null,
note varchar(500) not null,
address1 varchar(200),
address2 varchar(200),
phone varchar(20),
mobile varchar(20),
email varchar(20),
createdOn datetime not null,
modifiedOn datetime,
createdBy varchar(45) not null,
Expand Down
3 changes: 1 addition & 2 deletions src/main/resources/static/js/customer-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,14 @@ function viewCustomer() {
}

function viewRow() {
//alert(" going to view customer !!!!");
var userRow;
var customerId;
var checks = document.getElementsByName('checkField');
if (checks.checked) {
userRow = document.getElementById("myTable").rows[0];
customerId = userRow.cells[0].childNodes[0].value;
} else {
for(var i = 0; i < checks.length ; i++) {
for (var i = 0; i < checks.length ; i++) {
if (checks[i].checked) {
userRow = document.getElementById("myTable").rows[i+1];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ private Customer mockCustomer() {
customer.setAddress1("ABC");
customer.setAddress2("ABC");
setCustomerContacts(customer);
customer.setNote("ABC");
customer.setCreatedBy("ABC");
customer.setModifiedBy("ABC");
return customer;
Expand All @@ -172,9 +171,5 @@ private void setCustomerContacts(final Customer customer) {
customer.setPhone("ABC");
customer.setMobile("ABC");
customer.setEmail("ABC");
customer.setContactPerson1("ABC");
customer.setContactPhone1("ABC");
customer.setContactPerson2("ABC");
customer.setContactPhone2("ABC");
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.poseidon.transaction.dao.impl;

import com.poseidon.customer.dao.entities.Customer;
import com.poseidon.customer.dao.entities.CustomerAdditionalDetails;
import com.poseidon.customer.dao.impl.CustomerAdditionalDetailsRepository;
import com.poseidon.customer.dao.impl.CustomerRepository;
import com.poseidon.make.dao.entities.Make;
import com.poseidon.make.dao.entities.Model;
Expand Down Expand Up @@ -37,13 +39,17 @@ public class TransactionDAOImplTest {
private final CustomerRepository customerRepository = Mockito.mock(CustomerRepository.class);
private final MakeRepository makeRepository = Mockito.mock(MakeRepository.class);
private final ModelRepository modelRepository = Mockito.mock(ModelRepository.class);
private final CustomerAdditionalDetailsRepository customerAdditionalDetailsRepository =
Mockito.mock(CustomerAdditionalDetailsRepository.class);

@BeforeEach
public void setup() {
Whitebox.setInternalState(transactionDAO, "transactionRepository", transactionRepository);
Whitebox.setInternalState(transactionDAO, "customerRepository", customerRepository);
Whitebox.setInternalState(transactionDAO, "makeRepository", makeRepository);
Whitebox.setInternalState(transactionDAO, "modelRepository", modelRepository);
Whitebox.setInternalState(transactionDAO, "customerAdditionalDetailsRepository",
customerAdditionalDetailsRepository);
}

@Test
Expand Down Expand Up @@ -131,6 +137,8 @@ public void deleteTransactionFailure() {
@Test
public void fetchTransactionFromTagSuccess() throws TransactionException {
when(customerRepository.findById(anyLong())).thenReturn(Optional.of(mockCustomer()));
when(customerAdditionalDetailsRepository.findByCustomerId(anyLong()))
.thenReturn(Optional.of(mockCustomerAdditionalDetails()));
when(makeRepository.getOne(anyLong())).thenReturn(mockMake());
when(modelRepository.getOne(anyLong())).thenReturn(mockModel());
when(transactionRepository.findBytagno(anyString())).thenReturn(mockTransaction());
Expand Down Expand Up @@ -214,6 +222,16 @@ private Customer mockCustomer() {
return customer;
}

private CustomerAdditionalDetails mockCustomerAdditionalDetails() {
CustomerAdditionalDetails additionalDetails = new CustomerAdditionalDetails();
additionalDetails.setNote("ABC");
additionalDetails.setContactPerson1("ABC");
additionalDetails.setContactPhone1("12321323");
additionalDetails.setContactPerson2("ABC");
additionalDetails.setContactPhone2("12321323");
return additionalDetails;
}

private Make mockMake() {
Make make = new Make();
make.setMakeId(1234L);
Expand Down

0 comments on commit 3444b06

Please sign in to comment.