Skip to content

Commit

Permalink
working on location/org services
Browse files Browse the repository at this point in the history
  • Loading branch information
cliffcaseyyet committed Jan 22, 2025
1 parent bd0cd7a commit bde8bb6
Show file tree
Hide file tree
Showing 15 changed files with 405 additions and 55 deletions.
15 changes: 12 additions & 3 deletions dev-resources/sql/proposed-schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ EXCEPTION
WHEN duplicate_object THEN null;
END $$;


-- needs expansion
DO $$ BEGIN
CREATE TYPE person_org_relation AS ENUM (
'UNION', 'PROFESSIONAL ORGANIZATION');
EXCEPTION
WHEN duplicate_object THEN null;
END $$;

DO $$ BEGIN
CREATE TYPE learning_status AS ENUM (
'ATTEMPTED', 'COMPLETED', 'PASSED', 'FAILED');
Expand Down Expand Up @@ -108,18 +117,18 @@ CREATE TABLE IF NOT EXISTS person (
current_security_clearance VARCHAR(255), --check on this
highest_security_clearance VARCHAR(255), --check on this
union_membership BOOLEAN,
union_id UUID REFERENCES organization (id),
professional_membership_id UUID REFERENCES organization (id),
updated_by VARCHAR(20),
inserted_date TIMESTAMP WITH TIME ZONE,
last_modified TIMESTAMP WITH TIME ZONE
);



CREATE TABLE IF NOT EXISTS person_organization (
id UUID PRIMARY KEY,
person_id UUID NOT NULL REFERENCES person (id),
organization_id UUID NOT NULL REFERENCES organization (id),
relationship_type VARCHAR(255), --controlled vocabulary
relationship_type person_org_relation NOT NULL,
updated_by VARCHAR(20),
inserted_date TIMESTAMP WITH TIME ZONE,
last_modified TIMESTAMP WITH TIME ZONE
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/deloitte/elrr/InputSanitizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public class InputSanitizer {
private static final String CHAR_WHITE_LIST_REGEX = "^[\\x09\\x0A\\x0D\\x20-\\x7E | \\xC2-\\xDF | \\xE0\\xA0-\\xBF | [\\xE1-\\xEC\\xEE\\xEF]{2} | \\xED\\x80-\\x9F | [\\xF0\\\\x90-\\xBF]{2} | [\\xF1-\\xF3]{3} | [\\xF4\\x80-\\x8F]{2}]*$";

public static boolean isValidInput(String input) {
return GenericValidator.matchRegexp(input, CHAR_WHITE_LIST_REGEX);
Boolean response = GenericValidator.matchRegexp(input, CHAR_WHITE_LIST_REGEX);
return response;
}
}
23 changes: 10 additions & 13 deletions src/main/java/com/deloitte/elrr/SanitizingFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void doFilter(ServletRequest request, ServletResponse response,
});

try {
if (hasHomoGlyphs(httpRequest)) {
if (hasHomoGlyphs(new JSONObject(httpRequest.getBody()))) {
httpResponse.sendError(HttpServletResponse.SC_BAD_REQUEST,
"Request body contains homoglyphs.");
return;
Expand All @@ -79,23 +79,20 @@ public void doFilter(ServletRequest request, ServletResponse response,
chain.doFilter(httpRequest, response);
}

private static boolean hasHomoGlyphs(WrappedHttp httpRequest) {

if (httpRequest.getBody().isEmpty())
return false;
private static boolean hasHomoGlyphs(JSONObject jo){
Confusables confusables = Confusables.fromInternal();
JSONObject jsonObject = new JSONObject(httpRequest.getBody());
Iterator<String> keys = jsonObject.keys();

Iterator<String> keys = jo.keys();
while (keys.hasNext()) {
String key = keys.next();
String value = (String) jsonObject.get(key);
boolean dangerousKey = confusables.isDangerous(key);
boolean dangerousValue = confusables.isDangerous(value);
if (dangerousKey || dangerousValue) {
return true;
Object val = jo.get(key);
if (val instanceof JSONObject) {
if (hasHomoGlyphs((JSONObject) val)) return true;
} else if (confusables.isDangerous(key)
|| confusables.isDangerous((String) val)) {
return true;
}
}
return false;
}

}
168 changes: 168 additions & 0 deletions src/main/java/com/deloitte/elrr/controller/LocationController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
/**
*
*/
package com.deloitte.elrr.controller;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import jakarta.validation.Valid;

import org.modelmapper.ModelMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.AbstractAggregateRoot;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.deloitte.elrr.dto.LocationDto;
import com.deloitte.elrr.entity.Location;
import com.deloitte.elrr.exception.ResourceNotFoundException;
import com.deloitte.elrr.jpa.svc.LocationSvc;
import com.deloitte.elrr.jpa.svc.LocationSvc;

import lombok.extern.slf4j.Slf4j;

@CrossOrigin(origins = {
"http://ec2-18-116-20-188.us-east-2.compute.amazonaws.com:3001",
"http://ec2-18-116-20-188.us-east-2.compute.amazonaws.com:5000" })
@RestController
@RequestMapping("api")
@Slf4j
public class LocationController {
/**
*
*/
@Autowired
private LocationSvc locationSvc;
/**
*
*/
@Autowired
private ModelMapper mapper;

/**
*
* @param locationId
* @return ResponseEntity<List<LocationDto>>
* @throws ResourceNotFoundException
*/
@GetMapping("/location")
public ResponseEntity<List<LocationDto>> getAllLocations(
@RequestParam(value = "id", required = false) final UUID locationId) throws ResourceNotFoundException {
try {
log.debug("Get Location id:........." + locationId);
List<LocationDto> locationList = new ArrayList<>();
if (locationId == null) {
locationSvc.findAll().forEach(loc -> locationList.add(
mapper.map(loc, LocationDto.class)));
} else {
Location location = locationSvc.get(locationId)
.orElseThrow(() -> new ResourceNotFoundException(
"Location not found for this id :: "
+ locationId));
LocationDto locationDto = mapper.map(location, LocationDto.class);
locationList.add(locationDto);
}

if (locationList.isEmpty()) {
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
} else {
return ResponseEntity.ok(locationList);
}
} catch (Exception e) {
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
}

/**
*
* @param locationId
* @return ResponseEntity<LocationDto>
* @throws ResourceNotFoundException
*/
@GetMapping("/location/{id}")
public ResponseEntity<LocationDto> getLocationById(
@PathVariable(value = "id") final UUID locationId)
throws ResourceNotFoundException {
log.debug("Get Location id:........." + locationId);
Location location = locationSvc.get(locationId)
.orElseThrow(() -> new ResourceNotFoundException(
"Location not found for this id :: "
+ locationId));
LocationDto locationDto = mapper.map(location,
LocationDto.class);
return ResponseEntity.ok().body(locationDto);
}

/**
*
* @param locationDto
* @return ResponseEntity<LocationDto>
*/
@PostMapping("/location")
public ResponseEntity<LocationDto> createLocation(
@Valid @RequestBody final LocationDto locationDto) {
Location org = mapper.map(locationDto, Location.class);
LocationDto response = mapper.map(locationSvc.save(org), LocationDto.class);
return new ResponseEntity<>(response, HttpStatus.CREATED);
}

/**
*
* @param locationId
* @param locationDto
* @return ResponseEntity<LocationDto>
* @throws ResourceNotFoundException
*/
@PutMapping("/location/{id}")
public ResponseEntity<LocationDto> updateLocation(
@PathVariable(value = "id") final UUID locationId,
@Valid @RequestBody final LocationDto locationDto)
throws ResourceNotFoundException {
log.info("Updating Location:.........");
log.info("Updating Location id:........." + locationId);
Location location = locationSvc.get(locationId)
.orElseThrow(() -> new ResourceNotFoundException(
"Location not found for this id to update :: "
+ locationId));
log.info("Update Location:........." + locationDto);
// Assigning values from request
mapper.map(locationDto, location);
// Reset Id / Primary key from query parameter
location.setId(locationId);
log.info("Update Location:........." + location);
return ResponseEntity.ok(mapper.map(locationSvc.save(location),
LocationDto.class));

}

/**
*
* @param locationId
* @return ResponseEntity<HttpStatus>
*/
@DeleteMapping("/location/{id}")
public ResponseEntity<HttpStatus> deleteLocation(
@PathVariable(value = "id") final UUID locationId) {
try {
log.info("Deleting Location:.........");
log.info("Deleting Location id:........." + locationId);
locationSvc.delete(locationId);
return ResponseEntity.ok(HttpStatus.NO_CONTENT);
} catch (Exception e) {
return ResponseEntity.ok(HttpStatus.INTERNAL_SERVER_ERROR);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ public ResponseEntity<PersonDto> getPersonById(
public ResponseEntity<PersonDto> createPerson(
@Valid @RequestBody final PersonDto personDto) {
Person person = mapper.map(personDto, Person.class);
log.info(person.getMailingAddress().getApartmentRoomSuiteNumber());
PersonDto response = mapper.map(personSvc.save(person), PersonDto.class);
return new ResponseEntity<>(response, HttpStatus.CREATED);
}
Expand Down
46 changes: 46 additions & 0 deletions src/main/java/com/deloitte/elrr/dto/LocationDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.deloitte.elrr.dto;

import java.io.Serializable;
import java.util.UUID;
import jakarta.validation.constraints.Size;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
@AllArgsConstructor
@Data
public class LocationDto implements Serializable {

private static final long serialVersionUID = -8031955138252824918L;

private UUID id;

@Size(max = 255)
private String streetNumberAndName;

@Size(max = 255)
private String apartmentRoomSuiteNumber;

@Size(max = 255)
private String city;

@Size(max = 255)
private String stateAbbreviation;

@Size(max = 255)
private String postalCode;

@Size(max = 255)
private String county;

@Size(max = 255)
private String countryCode;

@Size(max = 255)
private String latitude;

@Size(max = 255)
private String longitude;

}
4 changes: 0 additions & 4 deletions src/main/java/com/deloitte/elrr/dto/OrganizationDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
import jakarta.validation.constraints.Size;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;

/**
* @author mnelakurti
Expand All @@ -21,8 +19,6 @@
@RequiredArgsConstructor
@AllArgsConstructor
@Data
@Getter
@Setter
public class OrganizationDto implements Serializable {

/**
Expand Down
14 changes: 5 additions & 9 deletions src/main/java/com/deloitte/elrr/dto/PersonDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,15 @@
import java.util.Date;
import java.util.UUID;

import jakarta.validation.Valid;
import jakarta.validation.constraints.Size;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;

/**
* @author mnelakurti
*
*/
@RequiredArgsConstructor
@AllArgsConstructor
@Data
@Getter
@Setter
public class PersonDto implements Serializable {

private static final long serialVersionUID = -8031955138252824918L;
Expand Down Expand Up @@ -64,7 +57,7 @@ public class PersonDto implements Serializable {
@Size(max = 255)
private String heightUnit;

private String weight;
private BigDecimal weight;

@Size(max = 255)
private String weightUnit;
Expand All @@ -84,4 +77,7 @@ public class PersonDto implements Serializable {
private String highestSecurityClearance;

private Boolean unionMembership;

@Valid
private LocationDto mailingAddress;
}
Loading

0 comments on commit bde8bb6

Please sign in to comment.