Skip to content

Commit

Permalink
Merge branch 'main' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
micnori committed Sep 16, 2024
2 parents f2346a0 + 1e889ac commit 928ea2b
Show file tree
Hide file tree
Showing 6 changed files with 292 additions and 255 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public class CompanyLocation {

@NotNull
private String id;
@NotNull
private String name;
@NotNull
private String address, streetNumber, zip, city;
Expand Down Expand Up @@ -204,7 +203,7 @@ public boolean equals(Object obj) {
if (id == null) {
if (other.id != null)
return false;
} else if (!id.equals(other.id))
} else if (!id.equalsIgnoreCase(other.id))
return false;
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ public CompanyLocation updateLocation(String companyId, CompanyLocation location
public void deleteLocation(String companyId, String locationId) {
companyRepo.findById(companyId).ifPresent(company -> {
if (company.getLocations() != null) {
company.getLocations().removeIf(l -> l.getId() == null && locationId == null || l.getId().equals(locationId));
company.getLocations().removeIf(l -> l.getId() == null && locationId == null || l.getId().equalsIgnoreCase(locationId));
companyRepo.save(company);
}
});
Expand Down Expand Up @@ -372,17 +372,26 @@ public Employee getEmployeeByCode(String companyId, String code) {
* @param employee
* @return
*/
public Employee updateEmployee(String companyId, Employee employee) {
employeeRepo.findById(employee.getId()).ifPresent(e -> {
if (e.getCompanyId().equals(companyId)) {
public Employee updateEmployee(String companyId, Employee employee) throws InconsistentDataException {
Employee e = employeeRepo.findById(employee.getId()).orElse(null);
if(e != null) {
if(e.getCompanyId().equals(companyId)) {
Company c = companyRepo.findById(companyId).orElse(null);
if(c == null) {
throw new InconsistentDataException("Company not found", "COMPANY_NOT_FOUND");
}
CompanyLocation loc = getCompanyLocation(c, employee.getLocation());
if(loc == null) {
throw new InconsistentDataException("Location not found", "LOCATION_NOT_FOUND");
}
e.setCompanyEmail(employee.getCompanyEmail());
e.setCode(employee.getCode());
e.setLocation(employee.getLocation());
e.setName(employee.getName());
e.setSurname(employee.getSurname());
employeeRepo.save(e);
}
});
}
}
return employeeRepo.findById(employee.getId()).orElse(null);
}

Expand Down Expand Up @@ -423,6 +432,11 @@ public Optional<Company> findByCode(String code) {
* @throws IOException
*/
public void importEmployees(String companyId, InputStream inputStream) throws Exception {
Company c = companyRepo.findById(companyId).orElse(null);
if(c == null) {
throw new InconsistentDataException("Company not found", "COMPANY_NOT_FOUND");
}

List<String[]> lines = null;

ByteArrayOutputStream baos = new ByteArrayOutputStream();
Expand All @@ -436,14 +450,18 @@ public void importEmployees(String companyId, InputStream inputStream) throws Ex
Set<String> codes = new HashSet<>();
int i = 0;
for (String[] l: lines) {
String code = stringValue(l[2], i + 1, 3, true);
String code = stringValue(l[2], i + 2, 3, true);
if (codes.contains(code)) {
throw new InconsistentDataException("Duplicate employees", "INVALID_CSV_DUPLICATE_EMPLOYEES");
}
Employee existing = employeeRepo.findByCompanyIdAndCodeIgnoreCase(companyId, code).stream().findAny().orElse(null);
String location = stringValue(l[3], i + 1, 4, true);
String name = stringValue(l[0], i + 1, 1, true);
String surname = stringValue(l[1], i + 1, 2, true);
String location = stringValue(l[3], i + 2, 4, true);
String name = stringValue(l[0], i + 2, 1, true);
String surname = stringValue(l[1], i + 2, 2, true);
CompanyLocation loc = getCompanyLocation(c, location);
if(loc == null) {
throw new ImportDataException(i + 2, 4);
}
if (existing != null) {
existing.setLocation(location);
existing.setName(name);
Expand Down Expand Up @@ -483,6 +501,11 @@ private List<String[]> readCSV(InputStream is, char separator, int columns) thro
}

public void importLocations(String companyId, InputStream inputStream) throws Exception {
Company c = companyRepo.findById(companyId).orElse(null);
if(c == null) {
throw new InconsistentDataException("Company not found", "COMPANY_NOT_FOUND");
}

List<String[]> lines = null;

ByteArrayOutputStream baos = new ByteArrayOutputStream();
Expand All @@ -495,46 +518,44 @@ public void importLocations(String companyId, InputStream inputStream) throws Ex
}
int i = 0;
List<CompanyLocation> locations = new LinkedList<>();
Set<String> locationIds = new HashSet<>();
for (String[] l : lines) {
CompanyLocation loc = new CompanyLocation();
String id = stringValue(l[0], i+1, 0, true);
if (locationIds.contains(id)) {
throw new InconsistentDataException("Duplicate locations", "INVALID_CSV_DUPLICATE_LOCATIONS");
String id = stringValue(l[0], i+2, 0, true);
CompanyLocation loc = getCompanyLocation(c, id);
if (loc == null) {
loc = new CompanyLocation();
}
locationIds.add(id);

loc.setId(id);
loc.setName(stringValue(l[1], i+1, 1, true));
loc.setAddress(stringValue(l[2], i+1, 2, true));
loc.setStreetNumber(stringValue(l[3], i+1, 3, false));
loc.setZip(stringValue(l[4], i+1, 4, true));
loc.setCity(stringValue(l[5], i+1, 5, true));
loc.setProvince(stringValue(l[6], i+1, 6, false));
loc.setRegion(stringValue(l[7], i+1, 7, false));
loc.setCountry(stringValue(l[8], i+1, 8, false));
loc.setName(stringValue(l[1], i+2, 1, false));
loc.setAddress(stringValue(l[2], i+2, 2, true));
loc.setStreetNumber(stringValue(l[3], i+2, 3, false));
loc.setZip(stringValue(l[4], i+2, 4, true));
loc.setCity(stringValue(l[5], i+2, 5, true));
loc.setProvince(stringValue(l[6], i+2, 6, false));
loc.setRegion(stringValue(l[7], i+2, 7, false));
loc.setCountry(stringValue(l[8], i+2, 8, false));

//Double radius = doubeValue(l[9], i+1, 8, false);
//if (radius == null) radius = 200d;
loc.setRadius(200d);
loc.setLatitude(doubeValue(l[9], i+1, 9, true));
loc.setLongitude(doubeValue(l[10], i+1, 10, true));
loc.setLatitude(doubeValue(l[9], i+2, 9, true));
loc.setLongitude(doubeValue(l[10], i+2, 10, true));

// check non-working days
String nwDoW = stringValue(l[11], i + 1, 11, false);
String nwDoW = stringValue(l[11], i + 2, 11, false);
if (nwDoW.length() > 0) {
loc.setNonWorking(new LinkedList<>());
String[] days = nwDoW.toLowerCase().split(",");
for (String d: days) {
if (DW.containsKey(d.trim())) {
loc.getNonWorking().add(DW.get(d.trim()));
} else {
throw new ImportDataException(i + 1, 11);
throw new ImportDataException(i + 2, 11);
}
}
}
// check exception days
String nwDays = stringValue(l[12], i + 1, 12, false);
String nwDays = stringValue(l[12], i + 2, 12, false);
if (nwDays.length() > 0) {
loc.setNonWorkingDays(new HashSet<>());
String[] days = nwDays.toLowerCase().split(",");
Expand All @@ -546,7 +567,7 @@ public void importLocations(String companyId, InputStream inputStream) throws Ex
try {
date = LocalDate.parse(d.trim(), dateFormatter );
} catch (Exception e1) {
throw new ImportDataException(i + 1, 11);
throw new ImportDataException(i + 2, 11);
}
}
loc.getNonWorkingDays().add(date.toString());
Expand All @@ -556,18 +577,24 @@ public void importLocations(String companyId, InputStream inputStream) throws Ex
i++;
}
if (locations.size() > 0) {
Company c = companyRepo.findById(companyId).orElse(null);
if (c != null) {
Map<String, CompanyLocation> map = locations.stream().collect(Collectors.toMap(l -> l.getId(), l -> l));
if (c.getLocations() != null) {
for (CompanyLocation l : c.getLocations()) {
if (!map.containsKey(l.getId())) locations.add(l);
}
Map<String, CompanyLocation> map = locations.stream().collect(Collectors.toMap(l -> l.getId(), l -> l));
if (c.getLocations() != null) {
for (CompanyLocation l : c.getLocations()) {
if (!map.containsKey(l.getId())) locations.add(l);
}
c.setLocations(locations);
companyRepo.save(c);
}
c.setLocations(locations);
companyRepo.save(c);
}
}

private CompanyLocation getCompanyLocation(Company c, String locationId) {
for(CompanyLocation l : c.getLocations()) {
if(l.getId().equalsIgnoreCase(locationId)) {
return l;
}
}
return null;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ public ResponseEntity<Employee> createEmployee(@PathVariable String companyId, @
*/
@PutMapping("/companies/{companyId}/employees/{employeeId:.*}")
//@PreAuthorize("hasAnyAuthority(\"" + Constants.ROLE_ADMIN + "\", \""+Constants.ROLE_COMPANY_ADMIN + "\", \""+Constants.ROLE_MOBILITY_MANAGER+"\")")
public ResponseEntity<Employee> updateEmployee(@PathVariable String companyId, @PathVariable String employeeId, @Valid @RequestBody Employee employee) {
public ResponseEntity<Employee> updateEmployee(@PathVariable String companyId, @PathVariable String employeeId,
@Valid @RequestBody Employee employee) throws InconsistentDataException {
log.debug("Updating a employee {} / {}", companyId, employeeId);
if (!userService.isInCompanyRole(companyId, Constants.ROLE_TERRITORY_MANAGER, Constants.ROLE_MOBILITY_MANAGER)) throw new SecurityException("Insufficient rights");
return ResponseEntity.ok(companyService.updateEmployee(companyId, employee));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,20 +150,20 @@ export default {
this.$emit('returnGeosearch', results);
}, 500)
},
getStringAddress(structuredValue) {
var returnAddress = "";
if (structuredValue.amenity) returnAddress += "<br />" + structuredValue.amenity;
if (structuredValue.office) returnAddress += "<br />" + structuredValue.office;
if (structuredValue.road) returnAddress += "<br />" + structuredValue.road;
if (structuredValue.house_number)
returnAddress += ", " + structuredValue.house_number;
if (structuredValue.city) returnAddress += "<br />" + structuredValue.city;
if (structuredValue.country) returnAddress += "<br />" + structuredValue.country;
if (structuredValue.postcode) returnAddress += "<br />" + structuredValue.postcode;
if (structuredValue.state) returnAddress += "<br />" + structuredValue.state;
if (structuredValue.county) returnAddress += "<br />" + structuredValue.county;
return returnAddress;
},
// getStringAddress(structuredValue) {
// var returnAddress = "";
// if (structuredValue.amenity) returnAddress += "<br />" + structuredValue.amenity;
// if (structuredValue.office) returnAddress += "<br />" + structuredValue.office;
// if (structuredValue.road) returnAddress += "<br />" + structuredValue.road;
// if (structuredValue.house_number)
// returnAddress += ", " + structuredValue.house_number;
// if (structuredValue.city) returnAddress += "<br />" + structuredValue.city;
// if (structuredValue.country) returnAddress += "<br />" + structuredValue.country;
// if (structuredValue.postcode) returnAddress += "<br />" + structuredValue.postcode;
// if (structuredValue.state) returnAddress += "<br />" + structuredValue.state;
// if (structuredValue.county) returnAddress += "<br />" + structuredValue.county;
// return returnAddress;
// },
async getAddress() {
this.loading = true;
let address = {
Expand Down Expand Up @@ -225,17 +225,17 @@ export default {
addresIsValid() {
return this.initialAddresIsValid;
},
tooltipContent() {
if (this.dragging) return "...";
if (this.loading) return "Loading...";
return `<strong>${
this.address && this.address.structuredValue
? this.getStringAddress(this.address.structuredValue)
: ""
}</strong> <hr/><strong>lat:</strong> ${
this.position?.lat
}<br/> <strong>lng:</strong> ${this.position?.lng}`;
},
// tooltipContent() {
// if (this.dragging) return "...";
// if (this.loading) return "Loading...";
// return `<strong>${
// this.address && this.address.structuredValue
// ? this.getStringAddress(this.address.structuredValue)
// : ""
// }</strong> <hr/><strong>lat:</strong> ${
// this.position?.lat
// }<br/> <strong>lng:</strong> ${this.position?.lng}`;
// },
},
watch: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
<v-row >
<v-col cols="12">
<div v-if="typeCall == 'location'">
<p>Il file deve seguire il formato dell'esempio e tutti i campi devono essere valorizzati.</p>
<p>I valori nella colonna <b>Identificativo sede</b> devono essere univoci.</p>
<p>Il file deve seguire il formato dell'esempio. Tutti i campi, a parte 'Nome' devono essere valorizzati.</p>
<p>I valori nella colonna <b>Codice sede</b> devono essere univoci.</p>
<p>Il processo di import aggiungerà al database tutte le sedi indicate nel file oppure, se nel database dovessero già esistere delle sedi con l'identificativo valorizzato nel file, ne aggiornerà tutti i dati con i valori del file.</p>
</div>
<div v-if="typeCall == 'employee'">
<p>Il file deve seguire il formato dell'esempio e tutte le colonne devono essere valorizzate.</p>
<p>Il valore indicato nella colonna <b>Codice dipendente</b> è utilizzato per identificare il dipendente, dunque deve essere univoco e non possono esistere duplicati.</p>
<p>La procedura di import aggiungerà al database tutti i dipendenti inseriti nel file a meno che il loro codice non corrisponda a quello di un dipendente già inserito nel database; in questo caso tutti i dati del dipendente già inserito verranno aggiornati con i valori indicati nel file importato.</p>
<p>Il valore indicato nella colonna <b>Codice sede</b> è utilizzato per associare il dipendente ad una specifica sede, dunque deve corrispondere esattamente ad all'identificativo di una delle sedi inserite nel database (si veda 'Gestione Sedi').</p>
<p>Il valore indicato nella colonna <b>Codice sede</b> è utilizzato per associare il dipendente ad una specifica sede, dunque deve corrispondere esattamente all'identificativo di una delle sedi inserite nel database (si veda 'Gestione Sedi').</p>
</div>
</v-col>
</v-row>
Expand Down
Loading

0 comments on commit 928ea2b

Please sign in to comment.