use of org.apache.commons.lang3.builder.ToStringStyleTest.Person in project API by ca-cwds.
the class PersonService method create.
/**
* {@inheritDoc}
*
* @see gov.ca.cwds.rest.services.CrudsService#create(gov.ca.cwds.rest.api.Request)
*/
@Override
@UnitOfWork(value = "ns")
public PostedPerson create(Request request) {
assert request instanceof Person;
Person person = (Person) request;
gov.ca.cwds.data.persistence.ns.Person managedPerson = new gov.ca.cwds.data.persistence.ns.Person(person, null, null);
managedPerson = personDao.create(managedPerson);
populatePersonDetails(person, managedPerson);
managedPerson = personDao.find(managedPerson.getId());
PostedPerson postedPerson = new PostedPerson(managedPerson);
try {
final gov.ca.cwds.rest.api.domain.es.Person esPerson = new gov.ca.cwds.rest.api.domain.es.Person(managedPerson.getId().toString(), managedPerson.getFirstName(), managedPerson.getLastName(), managedPerson.getGender(), DomainChef.cookDate(managedPerson.getDateOfBirth()), managedPerson.getSsn(), managedPerson.getClass().getName(), MAPPER.writeValueAsString(managedPerson));
final String document = MAPPER.writeValueAsString(esPerson);
// If the people index is missing, create it.
elasticsearchDao.createIndexIfNeeded(elasticsearchDao.getDefaultAlias());
// The ES Dao manages its own connections. No need to manually start or stop.
// elasticsearchDao.index(elasticsearchDao.getDefaultAlias(),
// elasticsearchDao.getDefaultDocType(), document, esPerson.getId());
} catch (Exception e) {
LOGGER.error("Unable to Index Person in ElasticSearch", e);
throw new ApiException("Unable to Index Person in ElasticSearch", e);
}
return postedPerson;
}
use of org.apache.commons.lang3.builder.ToStringStyleTest.Person in project API by ca-cwds.
the class ScreeningToReferralService method processAllegations.
/*
* CMS Allegation - one for each allegation
*/
private Set<Allegation> processAllegations(ScreeningToReferral scr, String referralId, HashMap<Long, String> perpatratorClient, HashMap<Long, String> victimClient, Set<ErrorMessage> messages) throws ServiceException {
Set<Allegation> processedAllegations = new HashSet<>();
Set<Allegation> allegations;
String victimClientId = "";
String perpatratorClientId = "";
allegations = scr.getAllegations();
if (allegations == null || allegations.isEmpty()) {
String message = " Referral must have at least one Allegation ";
ServiceException exception = new ServiceException(message);
logError(message, exception, messages);
return processedAllegations;
}
for (Allegation allegation : allegations) {
try {
if (!ParticipantValidator.isVictimParticipant(scr, allegation.getVictimPersonId())) {
String message = " Allegation/Victim Person Id does not contain a Participant with a role of Victim ";
ServiceException exception = new ServiceException(message);
logError(message, exception, messages);
}
} catch (Exception e) {
logError(e.getMessage(), e, messages);
// next allegation
continue;
}
if (victimClient.containsKey(allegation.getVictimPersonId())) {
// this is the legacy Id (CLIENT) of the victime
victimClientId = victimClient.get(allegation.getVictimPersonId());
}
if (allegation.getPerpetratorPersonId() != 0) {
try {
if (!ParticipantValidator.isPerpetratorParticipant(scr, allegation.getPerpetratorPersonId())) {
String message = " Allegation/Perpetrator Person Id does not contain a Participant with a role of Perpetrator ";
ServiceException exception = new ServiceException(message);
logError(message, exception, messages);
}
} catch (Exception e) {
logError(e.getMessage(), e, messages);
// next allegation
continue;
}
}
if (perpatratorClient.containsKey(allegation.getPerpetratorPersonId())) {
// this is the legacy Id (CLIENT) of the perpetrator
perpatratorClientId = perpatratorClient.get(allegation.getPerpetratorPersonId());
}
if (victimClientId.isEmpty()) {
String message = " Victim could not be determined for an allegation ";
ServiceException exception = new ServiceException(message);
logError(message, exception, messages);
// next allegation
continue;
}
if (allegation.getLegacyId() == null || allegation.getLegacyId().isEmpty()) {
// create an allegation in CMS legacy database
gov.ca.cwds.rest.api.domain.cms.Allegation cmsAllegation = new gov.ca.cwds.rest.api.domain.cms.Allegation("", DEFAULT_CODE, "", scr.getLocationType(), "", DEFAULT_CODE, allegationTypeCode, scr.getReportNarrative(), "", false, DEFAULT_NON_PROTECTING_PARENT_CODE, false, victimClientId, perpatratorClientId, referralId, DEFAULT_COUNTY_SPECIFIC_CODE, false, DEFAULT_CODE);
buildErrors(messages, validator.validate(cmsAllegation));
PostedAllegation postedAllegation = this.allegationService.create(cmsAllegation);
allegation.setLegacyId(postedAllegation.getId());
allegation.setLegacySourceTable(ALLEGATION_TABLE_NAME);
processedAllegations.add(allegation);
} else {
gov.ca.cwds.rest.api.domain.cms.Allegation foundAllegation = this.allegationService.find(allegation.getLegacyId());
if (foundAllegation == null) {
String message = " Legacy Id on Allegation does not correspond to an existing CMS/CWS Allegation ";
ServiceException se = new ServiceException(message);
logError(message, se, messages);
// next allegation
continue;
}
}
}
return processedAllegations;
}
use of org.apache.commons.lang3.builder.ToStringStyleTest.Person in project alf.io by alfio-event.
the class ReservationFlowIntegrationTest method reservationFlowTest.
/**
* Test a complete offline payment flow.
* Will not check in detail...
*/
@Test
public void reservationFlowTest() throws Exception {
String eventName = event.getShortName();
assertTrue(checkInManager.findAllFullTicketInfo(event.getId()).isEmpty());
List<EventStatistic> eventStatistic = eventStatisticsManager.getAllEventsWithStatistics(user);
assertEquals(1, eventStatistic.size());
assertTrue(eventStatisticsManager.getTicketSoldStatistics(event.getId(), new Date(0), DateUtils.addDays(new Date(), 1)).isEmpty());
EventWithAdditionalInfo eventWithAdditionalInfo = eventStatisticsManager.getEventWithAdditionalInfo(event.getShortName(), user);
assertEquals(0, eventWithAdditionalInfo.getNotSoldTickets());
assertEquals(0, eventWithAdditionalInfo.getSoldTickets());
assertEquals(20, eventWithAdditionalInfo.getAvailableSeats());
eventManager.toggleActiveFlag(event.getId(), user, true);
// list events
String eventList = eventController.listEvents(new BindingAwareModelMap(), Locale.ENGLISH);
if (eventManager.getPublishedEvents().size() == 1) {
Assert.assertTrue(eventList.startsWith("redirect:/"));
} else {
assertEquals("/event/event-list", eventList);
}
//
// show event
String showEvent = eventController.showEvent(eventName, new BindingAwareModelMap(), new MockHttpServletRequest(), Locale.ENGLISH);
assertEquals("/event/show-event", showEvent);
//
// check calendar
checkCalendar(eventName);
//
String redirectResult = reserveTicket(eventName);
String redirectStart = "redirect:/event/" + eventName + "/reservation/";
// check reservation success
Assert.assertTrue(redirectResult.startsWith(redirectStart));
Assert.assertTrue(redirectResult.endsWith("/book"));
//
String reservationIdentifier = redirectResult.substring(redirectStart.length()).replace("/book", "");
// check that the payment page is shown
String reservationPage = reservationController.showPaymentPage(eventName, reservationIdentifier, null, null, null, null, null, null, null, null, null, null, null, null, new BindingAwareModelMap(), Locale.ENGLISH);
assertEquals("/event/reservation-page", reservationPage);
//
// pay offline
String successPage = payOffline(eventName, reservationIdentifier);
assertEquals("redirect:/event/" + eventName + "/reservation/" + reservationIdentifier + "/success", successPage);
//
// go to success page, payment is still pending
String confirmationPage = reservationController.showConfirmationPage(eventName, reservationIdentifier, false, false, new BindingAwareModelMap(), Locale.ENGLISH, new MockHttpServletRequest());
Assert.assertTrue(confirmationPage.endsWith("/waitingPayment"));
assertEquals("/event/reservation-waiting-for-payment", reservationController.showWaitingPaymentPage(eventName, reservationIdentifier, new BindingAwareModelMap(), Locale.ENGLISH));
//
validatePayment(eventName, reservationIdentifier);
//
Assert.assertTrue(reservationController.showWaitingPaymentPage(eventName, reservationIdentifier, new BindingAwareModelMap(), Locale.ENGLISH).endsWith("/success"));
//
TicketDecorator ticketDecorator = checkReservationComplete(eventName, reservationIdentifier);
//
String ticketIdentifier = ticketDecorator.getUuid();
// ticket is still not assigned, will redirect
Assert.assertTrue(ticketController.showTicket(eventName, ticketIdentifier, false, Locale.ENGLISH, new BindingAwareModelMap()).startsWith("redirect:/event/"));
Assert.assertTrue(ticketController.showTicketForUpdate(eventName, ticketIdentifier, new BindingAwareModelMap(), Locale.ENGLISH).startsWith("redirect:/event/"));
//
String fname1 = "Test";
String lname1 = "McTest";
// assign ticket to person
assignTicket(eventName, reservationIdentifier, ticketIdentifier, fname1, lname1);
assertEquals(1, checkInManager.findAllFullTicketInfo(event.getId()).size());
assertEquals("/event/update-ticket", ticketController.showTicketForUpdate(eventName, ticketIdentifier, new BindingAwareModelMap(), Locale.ENGLISH));
//
assertEquals("/event/show-ticket", ticketController.showTicket(eventName, ticketIdentifier, false, Locale.ENGLISH, new BindingAwareModelMap()));
//
checkCSV(eventName, ticketIdentifier, fname1 + " " + lname1);
// use api to update
UpdateTicketOwnerForm updateTicketOwnerForm = new UpdateTicketOwnerForm();
updateTicketOwnerForm.setFirstName("Test");
updateTicketOwnerForm.setLastName("Testson");
updateTicketOwnerForm.setEmail("testmctest@test.com");
updateTicketOwnerForm.setUserLanguage("en");
reservationApiController.assignTicketToPerson(eventName, ticketIdentifier, true, updateTicketOwnerForm, new BeanPropertyBindingResult(updateTicketOwnerForm, "updateTicketForm"), new MockHttpServletRequest(), new BindingAwareModelMap(), null);
checkCSV(eventName, ticketIdentifier, "Test Testson");
//
// update
String fname2 = "Test";
String lname2 = "OTest";
assignTicket(eventName, reservationIdentifier, ticketIdentifier, fname2, lname2);
checkCSV(eventName, ticketIdentifier, fname2 + " " + lname2);
// lock ticket
Principal principal = Mockito.mock(Principal.class);
Mockito.when(principal.getName()).thenReturn(user);
eventApiController.toggleTicketLocking(eventName, ticketDecorator.getCategoryId(), ticketDecorator.getId(), principal);
assignTicket(eventName, reservationIdentifier, ticketIdentifier, fname1, fname2);
checkCSV(eventName, ticketIdentifier, fname2 + " " + lname2);
// ticket has changed, update
ticketDecorator = checkReservationComplete(eventName, reservationIdentifier);
// check stats after selling one ticket
assertFalse(eventStatisticsManager.getTicketSoldStatistics(event.getId(), new Date(0), DateUtils.addDays(new Date(), 2)).isEmpty());
EventWithAdditionalInfo eventWithAdditionalInfo2 = eventStatisticsManager.getEventWithAdditionalInfo(event.getShortName(), user);
assertEquals(0, eventWithAdditionalInfo2.getNotSoldTickets());
assertEquals(1, eventWithAdditionalInfo2.getSoldTickets());
assertEquals(20, eventWithAdditionalInfo2.getAvailableSeats());
assertEquals(0, eventWithAdditionalInfo2.getCheckedInTickets());
// --- check in sequence
String ticketCode = ticketDecorator.ticketCode(event.getPrivateKey());
TicketAndCheckInResult ticketAndCheckInResult = checkInApiController.findTicketWithUUID(event.getId(), ticketIdentifier, ticketCode);
assertEquals(CheckInStatus.OK_READY_TO_BE_CHECKED_IN, ticketAndCheckInResult.getResult().getStatus());
CheckInApiController.TicketCode tc = new CheckInApiController.TicketCode();
tc.setCode(ticketCode);
assertEquals(CheckInStatus.SUCCESS, checkInApiController.checkIn(event.getId(), ticketIdentifier, tc, new TestingAuthenticationToken("ciccio", "ciccio")).getResult().getStatus());
List<ScanAudit> audits = scanAuditRepository.findAllForEvent(event.getId());
assertFalse(audits.isEmpty());
assertTrue(audits.stream().anyMatch(sa -> sa.getTicketUuid().equals(ticketIdentifier)));
TicketAndCheckInResult ticketAndCheckInResultOk = checkInApiController.findTicketWithUUID(event.getId(), ticketIdentifier, ticketCode);
assertEquals(CheckInStatus.ALREADY_CHECK_IN, ticketAndCheckInResultOk.getResult().getStatus());
// check stats after check in one ticket
assertFalse(eventStatisticsManager.getTicketSoldStatistics(event.getId(), new Date(0), DateUtils.addDays(new Date(), 1)).isEmpty());
EventWithAdditionalInfo eventWithAdditionalInfo3 = eventStatisticsManager.getEventWithAdditionalInfo(event.getShortName(), user);
assertEquals(0, eventWithAdditionalInfo3.getNotSoldTickets());
assertEquals(0, eventWithAdditionalInfo3.getSoldTickets());
assertEquals(20, eventWithAdditionalInfo3.getAvailableSeats());
assertEquals(1, eventWithAdditionalInfo3.getCheckedInTickets());
// test revert check in
assertTrue(checkInApiController.revertCheckIn(event.getId(), ticketIdentifier, principal));
assertFalse(checkInApiController.revertCheckIn(event.getId(), ticketIdentifier, principal));
TicketAndCheckInResult ticketAndCheckInResult2 = checkInApiController.findTicketWithUUID(event.getId(), ticketIdentifier, ticketCode);
assertEquals(CheckInStatus.OK_READY_TO_BE_CHECKED_IN, ticketAndCheckInResult2.getResult().getStatus());
UsersApiController.UserWithPasswordAndQRCode sponsorUser = usersApiController.insertUser(new UserModification(null, event.getOrganizationId(), "SPONSOR", "sponsor", "first", "last", "email@email.com"), "http://localhost:8080", principal);
Principal sponsorPrincipal = Mockito.mock(Principal.class);
Mockito.when(sponsorPrincipal.getName()).thenReturn(sponsorUser.getUsername());
// check failures
assertEquals(CheckInStatus.EVENT_NOT_FOUND, attendeeApiController.scanBadge(new AttendeeApiController.SponsorScanRequest("not-existing-event", "not-existing-ticket"), sponsorPrincipal).getBody().getResult().getStatus());
assertEquals(CheckInStatus.TICKET_NOT_FOUND, attendeeApiController.scanBadge(new AttendeeApiController.SponsorScanRequest(eventName, "not-existing-ticket"), sponsorPrincipal).getBody().getResult().getStatus());
assertEquals(CheckInStatus.INVALID_TICKET_STATE, attendeeApiController.scanBadge(new AttendeeApiController.SponsorScanRequest(eventName, ticketIdentifier), sponsorPrincipal).getBody().getResult().getStatus());
//
// check stats after revert check in one ticket
assertFalse(eventStatisticsManager.getTicketSoldStatistics(event.getId(), new Date(0), DateUtils.addDays(new Date(), 1)).isEmpty());
EventWithAdditionalInfo eventWithAdditionalInfo4 = eventStatisticsManager.getEventWithAdditionalInfo(event.getShortName(), user);
assertEquals(0, eventWithAdditionalInfo4.getNotSoldTickets());
assertEquals(1, eventWithAdditionalInfo4.getSoldTickets());
assertEquals(20, eventWithAdditionalInfo4.getAvailableSeats());
assertEquals(0, eventWithAdditionalInfo4.getCheckedInTickets());
CheckInApiController.TicketCode tc2 = new CheckInApiController.TicketCode();
tc2.setCode(ticketCode);
TicketAndCheckInResult ticketAndcheckInResult = checkInApiController.checkIn(event.getId(), ticketIdentifier, tc2, new TestingAuthenticationToken("ciccio", "ciccio"));
assertEquals(CheckInStatus.SUCCESS, ticketAndcheckInResult.getResult().getStatus());
//
//
List<Integer> offlineIdentifiers = checkInApiController.getOfflineIdentifiers(event.getShortName(), 0L, new MockHttpServletResponse(), principal);
assertTrue(offlineIdentifiers.isEmpty());
configurationRepository.insertEventLevel(event.getOrganizationId(), event.getId(), ConfigurationKeys.OFFLINE_CHECKIN_ENABLED.name(), "true", null);
configurationRepository.insert(ConfigurationKeys.ALFIO_PI_INTEGRATION_ENABLED.name(), "true", null);
offlineIdentifiers = checkInApiController.getOfflineIdentifiers(event.getShortName(), 0L, new MockHttpServletResponse(), principal);
assertFalse(offlineIdentifiers.isEmpty());
Map<String, String> payload = checkInApiController.getOfflineEncryptedInfo(event.getShortName(), Collections.emptyList(), offlineIdentifiers, principal);
assertEquals(1, payload.size());
Ticket ticket = ticketAndcheckInResult.getTicket();
String ticketKey = ticket.hmacTicketInfo(event.getPrivateKey());
String hashedTicketKey = DigestUtils.sha256Hex(ticketKey);
String encJson = payload.get(hashedTicketKey);
assertNotNull(encJson);
String ticketPayload = CheckInManager.decrypt(ticket.getUuid() + "/" + ticketKey, encJson);
Map<String, String> jsonPayload = Json.fromJson(ticketPayload, new TypeReference<Map<String, String>>() {
});
assertNotNull(jsonPayload);
assertEquals(8, jsonPayload.size());
assertEquals("Test", jsonPayload.get("firstName"));
assertEquals("OTest", jsonPayload.get("lastName"));
assertEquals("Test OTest", jsonPayload.get("fullName"));
assertEquals(ticket.getUuid(), jsonPayload.get("uuid"));
assertEquals("testmctest@test.com", jsonPayload.get("email"));
assertEquals("CHECKED_IN", jsonPayload.get("status"));
String categoryName = ticketCategoryRepository.findByEventId(event.getId()).stream().findFirst().orElseThrow(IllegalStateException::new).getName();
assertEquals(categoryName, jsonPayload.get("category"));
//
// check register sponsor scan success flow
assertTrue(attendeeApiController.getScannedBadges(event.getShortName(), EventUtil.JSON_DATETIME_FORMATTER.format(LocalDateTime.of(1970, 1, 1, 0, 0)), sponsorPrincipal).getBody().isEmpty());
assertEquals(CheckInStatus.SUCCESS, attendeeApiController.scanBadge(new AttendeeApiController.SponsorScanRequest(eventName, ticket.getUuid()), sponsorPrincipal).getBody().getResult().getStatus());
assertEquals(1, attendeeApiController.getScannedBadges(event.getShortName(), EventUtil.JSON_DATETIME_FORMATTER.format(LocalDateTime.of(1970, 1, 1, 0, 0)), sponsorPrincipal).getBody().size());
//
eventManager.deleteEvent(event.getId(), principal.getName());
}
use of org.apache.commons.lang3.builder.ToStringStyleTest.Person in project sqlg by pietermartin.
the class TestCaptureSchemaTableEdges method testCaptureSchemaTableLabelsRollback.
@Test
public void testCaptureSchemaTableLabelsRollback() {
Assume.assumeTrue(this.sqlgGraph.getSqlDialect().supportsTransactionalSchema());
Vertex person1 = this.sqlgGraph.addVertex(T.label, "Person", "name", "pieter");
Vertex car1 = this.sqlgGraph.addVertex(T.label, "Car", "name", "bmw");
person1.addEdge("drives", car1);
Vertex car2 = this.sqlgGraph.addVertex(T.label, "Car", "name", "toyota");
person1.addEdge("drives", car2);
Vertex bmw = this.sqlgGraph.addVertex(T.label, "Model", "name", "bmw");
car1.addEdge("model", bmw);
Vertex toyota = this.sqlgGraph.addVertex(T.label, "Model", "name", "toyota");
car2.addEdge("model", toyota);
this.sqlgGraph.tx().rollback();
Map<SchemaTable, Pair<Set<SchemaTable>, Set<SchemaTable>>> localTables = this.sqlgGraph.getTopology().getTableLabels();
assertTrue(localTables.containsKey(SchemaTable.of(SQLG_SCHEMA, "V_vertex")));
assertFalse(localTables.containsKey(SchemaTable.of(this.sqlgGraph.getSqlDialect().getPublicSchema(), "V_Person")));
assertFalse(localTables.containsKey(SchemaTable.of(this.sqlgGraph.getSqlDialect().getPublicSchema(), "V_Car")));
assertFalse(localTables.containsKey(SchemaTable.of(this.sqlgGraph.getSqlDialect().getPublicSchema(), "V_Model")));
assertFalse(localTables.containsKey(SchemaTable.of(this.sqlgGraph.getSqlDialect().getPublicSchema(), "E_drives")));
assertFalse(localTables.containsKey(SchemaTable.of(this.sqlgGraph.getSqlDialect().getPublicSchema(), "E_model")));
}
use of org.apache.commons.lang3.builder.ToStringStyleTest.Person in project sqlg by pietermartin.
the class TestRepeatStepGraphOut method testGremlinLeftJoin.
@Test
public void testGremlinLeftJoin() {
Vertex marko = this.sqlgGraph.addVertex(T.label, "Person", "name", "marko");
Vertex josh = this.sqlgGraph.addVertex(T.label, "Person", "name", "josh");
Vertex lop = this.sqlgGraph.addVertex(T.label, "Software", "name", "lop");
marko.addEdge("knows", josh);
marko.addEdge("created", lop);
josh.addEdge("created", lop);
this.sqlgGraph.tx().commit();
DefaultGraphTraversal<Vertex, Path> traversal = (DefaultGraphTraversal<Vertex, Path>) this.sqlgGraph.traversal().V().repeat(__.out()).times(2).emit().path();
Assert.assertEquals(3, traversal.getSteps().size());
List<Path> paths = traversal.toList();
Assert.assertEquals(2, traversal.getSteps().size());
Assert.assertEquals(4, paths.size());
Assert.assertTrue(paths.stream().anyMatch(p -> p.size() == 2 && p.get(0).equals(marko) && p.get(1).equals(lop)));
paths.remove(paths.stream().filter(p -> p.size() == 2 && p.get(0).equals(marko) && p.get(1).equals(lop)).findAny().get());
Assert.assertTrue(paths.stream().anyMatch(p -> p.size() == 2 && p.get(0).equals(josh) && p.get(1).equals(lop)));
paths.remove(paths.stream().filter(p -> p.size() == 2 && p.get(0).equals(josh) && p.get(1).equals(lop)).findAny().get());
Assert.assertTrue(paths.stream().anyMatch(p -> p.size() == 2 && p.get(0).equals(marko) && p.get(1).equals(josh)));
paths.remove(paths.stream().filter(p -> p.size() == 2 && p.get(0).equals(marko) && p.get(1).equals(josh)).findAny().get());
Assert.assertTrue(paths.stream().anyMatch(p -> p.size() == 3 && p.get(0).equals(marko) && p.get(1).equals(josh) && p.get(2).equals(lop)));
paths.remove(paths.stream().filter(p -> p.size() == 3 && p.get(0).equals(marko) && p.get(1).equals(josh) && p.get(2).equals(lop)).findAny().get());
Assert.assertTrue(paths.isEmpty());
DefaultGraphTraversal<Vertex, Vertex> traversal1 = (DefaultGraphTraversal<Vertex, Vertex>) this.sqlgGraph.traversal().V().repeat(__.out()).times(2).emit();
Assert.assertEquals(2, traversal1.getSteps().size());
List<Vertex> vertices = traversal1.toList();
Assert.assertEquals(1, traversal1.getSteps().size());
Assert.assertEquals(4, vertices.size());
Assert.assertTrue(vertices.remove(josh));
Assert.assertTrue(vertices.remove(lop));
Assert.assertTrue(vertices.remove(lop));
Assert.assertTrue(vertices.remove(lop));
Assert.assertTrue(vertices.isEmpty());
}
Aggregations