Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 6 additions & 15 deletions src/main/java/com/systelab/seed/BaseException.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.systelab.seed;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
* SeedException wraps all checked standard Java exception and enriches them with a custom error code.
* You can use this code to retrieve localized error messages and to link to our online documentation.
Expand All @@ -9,18 +12,16 @@ public class BaseException extends Exception {
private static final long serialVersionUID = 3714428835173293220L;
private final ErrorCode errorCode;

@AllArgsConstructor
@Getter
public enum ErrorCode {
ALLERGY_ALREADY_EXIST(5),
ALLERGY_NOT_FOUND(4),
PATIENT_NOT_FOUND(3),
USER_NOT_FOUND(2),
DEFAULT_ERROR(1);

private final int errorCode;

ErrorCode(int errorCode) {
this.errorCode = errorCode;
}
private final int code;
}

public BaseException(ErrorCode code) {
Expand All @@ -33,16 +34,6 @@ public BaseException(String message, Throwable cause, ErrorCode code) {
this.errorCode = code;
}

public BaseException(String message, ErrorCode code) {
super(message);
this.errorCode = code;
}

public BaseException(Throwable cause, ErrorCode code) {
super(cause);
this.errorCode = code;
}

public ErrorCode getCode() {
return this.errorCode;
}
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/com/systelab/seed/allergy/entity/Allergy.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import lombok.NoArgsConstructor;

import javax.persistence.Entity;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
Expand All @@ -20,8 +19,8 @@
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "allergy")
@NamedQueries({@NamedQuery(name = com.systelab.seed.allergy.entity.Allergy.FIND_ALL, query = "SELECT a FROM Allergy a ORDER BY a.name"),
@NamedQuery(name = com.systelab.seed.allergy.entity.Allergy.ALL_COUNT, query = "SELECT COUNT(a.id) FROM Allergy a")})
@NamedQuery(name = com.systelab.seed.allergy.entity.Allergy.FIND_ALL, query = "SELECT a FROM Allergy a ORDER BY a.name")
@NamedQuery(name = com.systelab.seed.allergy.entity.Allergy.ALL_COUNT, query = "SELECT COUNT(a.id) FROM Allergy a")
public class Allergy extends BaseEntity {
public static final String FIND_ALL = "Allergy.findAll";
public static final String ALL_COUNT = "Allergy.allCount";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ public class TokenAuthenticationFilter implements ContainerRequestFilter {
public void filter(ContainerRequestContext requestContext) {

try {
logger.info(requestContext.getUriInfo().getRequestUri().toString());
if (logger.isInfoEnabled()){
logger.info(requestContext.getUriInfo().getRequestUri().toString());
}
String userRole = tokenGenerator.getRoleFromToken(getTokenFromHeader(requestContext));
if (!methodIsAllowed(resourceInfo.getResourceMethod(), userRole)) {
requestContext.abortWith(Response.status(Response.Status.UNAUTHORIZED).build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private AtomicRateLimiter getLimiter(String key) {

private void logLimitExceeded(UriInfo uriInfo, String byAddress) {
String path = uriInfo.getAbsolutePath().getPath();
logger.warn("Overloaded {0} request {1}; discarding it", new Object[]{byAddress, path});
logger.warn("Overloaded {} request {}; discarding it", byAddress, path);
}

private String getRateExceededMessage(AtomicRateLimiter rateLimiter) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,22 @@
import com.systelab.seed.BaseException;
import com.systelab.seed.infrastructure.security.PasswordDigest;

import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Base64;
import javax.inject.Inject;
import org.slf4j.Logger;


public class SHA256PasswordDigest implements PasswordDigest {
@Inject
private Logger logger;

@Override
public String digest(String plainTextPassword) throws BaseException {
try {
MessageDigest md = MessageDigest.getInstance("SHA-256");
md.update(plainTextPassword.getBytes("UTF-8"));
md.update(plainTextPassword.getBytes(StandardCharsets.UTF_8));
byte[] passwordDigest = md.digest();
return new String(Base64.getEncoder().encode(passwordDigest));
} catch (NoSuchAlgorithmException | UnsupportedEncodingException e) {
logger.error(e.getMessage(), e);
} catch (NoSuchAlgorithmException e) {
throw new BaseException("Incorrect algorithm implementation", e, BaseException.ErrorCode.DEFAULT_ERROR);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class DeleteOldPatientsTimerBean {
private Logger logger;

@Inject
PatientMaintenanceServiceHealthCheck healthCheck;
private PatientMaintenanceServiceHealthCheck healthCheck;

@EJB
private PatientService patientService;
Expand Down Expand Up @@ -54,7 +54,7 @@ private void createTimer() {
}

private void cancelAnyRunningTimer() {
timerService.getTimers().stream().forEach((timer) -> {
timerService.getTimers().stream().forEach(timer -> {
logger.info("Found running timer with info: {}, cancelling it", timer.getInfo());
timer.cancel();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ public HealthCheckResponse call() {
return working ? builder.up().build() : builder.down().build();
}

public void setWorking(boolean working) {
this.working = working;
public synchronized void setWorking(boolean working) {
PatientMaintenanceServiceHealthCheck.working = working;
}

public void setLastExecution(LocalDateTime lastExecution) {
this.lastExecution = lastExecution;
public synchronized void setLastExecution(LocalDateTime lastExecution) {
PatientMaintenanceServiceHealthCheck.lastExecution = lastExecution;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

public class BodyMassIndexCalculator {

private BodyMassIndexCalculator()
{
}

private static boolean isValidWeight(Double value) {
return value != null && Double.isFinite(value) && value > 1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
interface IdentityClient {

@RequestLine("GET /identity/v1/medical-record-number")
public String getMedicalRecordNumber();
String getMedicalRecordNumber();
}

public class MedicalRecordNumberService {

private static final String UNDEFINED = "UNDEFINED";

@Inject
private Logger logger;

Expand All @@ -26,14 +28,15 @@ public class MedicalRecordNumberService {

public String getMedicalRecordNumber() {

logger.info(String.format("medicalRecordNumberServiceUrl: %s", medicalRecordNumberServiceUrl));

if (logger.isInfoEnabled()){
logger.info(String.format("medicalRecordNumberServiceUrl: %s", medicalRecordNumberServiceUrl));
}
IdentityClient client = HystrixFeign.builder().target(IdentityClient.class, medicalRecordNumberServiceUrl, MedicalRecordNumberService::defaultMedicalRecordNumber);
return client.getMedicalRecordNumber();
}

private static String defaultMedicalRecordNumber() {
return "UNDEFINED";
return UNDEFINED;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ private void addPatientToWorkBook(Sheet sheet, int rowIndex, Patient patient) {
Row row = sheet.createRow(rowIndex);
createCell(row, colNum++, patient.getName());
createCell(row, colNum++, patient.getSurname());
createCell(row, colNum++, patient.getEmail());
createCell(row, colNum, patient.getEmail());
}

private void createCell(Row row, int colIndex, String value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void onPatientCreated(@Observes @PatientCreated Patient patient) {
try (JsonGenerator generator = Json.createGenerator(writer)) {
generator.writeStartObject().write("patientid", patient.getId().toString()).write("patientname", patient.getName()).writeEnd();
}
sessions.forEach((session) -> sendMessageToSession(session, writer.toString()));
sessions.forEach(session -> sendMessageToSession(session, writer.toString()));
}

private void sendMessageToSession(Session session, String json) {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/systelab/seed/patient/entity/Patient.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "patient")
@NamedQueries({@NamedQuery(name = Patient.FIND_ALL, query = "SELECT p FROM Patient p ORDER BY p.surname"),
@NamedQuery(name = Patient.ALL_COUNT, query = "SELECT COUNT(p.id) FROM Patient p"),
@NamedQuery(name = Patient.DEACTIVATE, query = "UPDATE Patient p SET p.active = FALSE WHERE p.modificationTime < :modificationTime")})
@NamedQuery(name = Patient.FIND_ALL, query = "SELECT p FROM Patient p ORDER BY p.surname")
@NamedQuery(name = Patient.ALL_COUNT, query = "SELECT COUNT(p.id) FROM Patient p")
@NamedQuery(name = Patient.DEACTIVATE, query = "UPDATE Patient p SET p.active = FALSE WHERE p.modificationTime < :modificationTime")
public class Patient extends BaseEntity {
public static final String FIND_ALL = "Patient.findAll";
public static final String ALL_COUNT = "Patient.allCount";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,7 @@ public Response addAllergyToPatient(@PathParam("uid") String uid, @RequestBody(d
} catch (PatientNotFoundException ex) {
logger.error(PatientAllergyResource.INVALID_PATIENT_ERROR_MESSAGE, ex);
return Response.status(Status.NOT_FOUND).build();
} catch (AllergyNotFoundException ex) {
logger.error(PatientAllergyResource.INVALID_ALLERGY_ERROR_MESSAGE, ex);
return Response.status(Status.NOT_FOUND).build();
} catch (AllergyAlreadyExistException ex) {
} catch (AllergyNotFoundException | AllergyAlreadyExistException ex) {
logger.error(PatientAllergyResource.INVALID_ALLERGY_ERROR_MESSAGE, ex);
return Response.status(Status.NOT_FOUND).build();
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/systelab/seed/user/entity/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
@EqualsAndHashCode(callSuper = true)
@AllArgsConstructor
@Table(name = "SeedUser")
@NamedQueries({@NamedQuery(name = User.FIND_ALL, query = "SELECT u FROM User u ORDER BY u.surname DESC"), @NamedQuery(name = User.FIND_BY_LOGIN_PASSWORD, query = "SELECT u FROM User u WHERE u.login = :login AND u.password = :password"),
@NamedQuery(name = User.ALL_COUNT, query = "SELECT COUNT(u.id) FROM User u")})

@NamedQuery(name = User.FIND_ALL, query = "SELECT u FROM User u ORDER BY u.surname DESC")
@NamedQuery(name = User.FIND_BY_LOGIN_PASSWORD, query = "SELECT u FROM User u WHERE u.login = :login AND u.password = :password")
@NamedQuery(name = User.ALL_COUNT, query = "SELECT COUNT(u.id) FROM User u")
@XmlRootElement
public class User extends BaseEntity {
public static final String FIND_ALL = "User.findAll";
Expand Down
3 changes: 3 additions & 0 deletions src/main/webapp/swagger/oauth2-redirect.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<!doctype html>
<html lang="en-US">
<head>
<title>OAUTH redirect</title>
</head>
<body onload="run()">
</body>
</html>
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/systelab/seed/RESTResourceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import static io.restassured.RestAssured.given;

public class RESTResourceTest {
public abstract class RESTResourceTest {

protected static final String AUTHORIZATION_HEADER = "Authorization";

Expand Down
24 changes: 12 additions & 12 deletions src/test/java/com/systelab/seed/allergy/AllergyResourceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

@TmsLink("TC0002_AllergyManagement_IntegrationTest")
@Feature("Allergy Test Suite.\n\nGoal:\nThe goal of this TC is to verify that the Allergies management actions (CRUD) behave as expected according the specifications and the input values.\n\nEnvironment:\n...\nPreconditions:\nN/A.")
public class AllergyResourceTest extends RESTResourceTest {
class AllergyResourceTest extends RESTResourceTest {

private Response doCreateAllergy(Allergy allergy){
return given().body(allergy).when().post("/allergies/allergy");
Expand Down Expand Up @@ -61,7 +61,7 @@ private void checkAllergyData(Allergy expected, Allergy actual){

@Description("Create a new allergy with name, sign and symptoms")
@Test
public void testCreateAllergy() {
void testCreateAllergy() {
String expectedName = "Tree pollen";
String expectedSigns = "Watering eyes";

Expand All @@ -75,7 +75,7 @@ public void testCreateAllergy() {

@Description("Create a new allergy with all information")
@Test
public void testCreateAllergyAllInfo() {
void testCreateAllergyAllInfo() {
String expectedName = "Tree pollen";
String expectedSigns = "Watering eyes";
String expectedSymptoms = "Sneezing";
Expand All @@ -98,15 +98,15 @@ private void testCreateInvalidAllergy(Allergy allergy) {

@Description("Create a Allergy with invalid data: mandatory fields empty (name, signs)")
@Test
public void testCreateInvalidAllergyMandatoryFieldsEmpty() {
void testCreateInvalidAllergyMandatoryFieldsEmpty() {
testCreateInvalidAllergy(getAllergyData("", "", "Sneezing"));
testCreateInvalidAllergy(getAllergyData("", "Sneezing", "Sneezing"));
testCreateInvalidAllergy(getAllergyData("Pollen", "", "Sneezing"));
}

@Description("Create a Allergy with invalid data: name, signs or symptoms field too long")
@Test
public void testCreateInvalidAllergyTooLongText() {
void testCreateInvalidAllergyTooLongText() {
String tooLongString = "thisStringIsIntendedToCauseAnExceptionBecauseOfItsExcessiveLengthTheMostLongStringAllowedMustHaveLessThanTeoHundredAndFiftyFiveCharactersThisShouldBeVerifiedInEveryTextFieldToEnsureTheLimitationIsWorkingProperlyThisStringOnlyHasEnglishLettersButMoreScenarios";
testCreateInvalidAllergy(getAllergyData(tooLongString, "Watering eyes", "Sneezing"));
testCreateInvalidAllergy(getAllergyData("Tree pollen", tooLongString, "Sneezing"));
Expand Down Expand Up @@ -134,7 +134,7 @@ private void createSomeAllergies(int numberOfAllergies) {

@Description("Get a list of allergies")
@Test
public void testGetAllergyList() {
void testGetAllergyList() {
int numberOfAllergies = 5;

Response responseBefore = doGetAllergyList();
Expand All @@ -156,7 +156,7 @@ public void testGetAllergyList() {

@Description("Get a Allergy by id")
@Test
public void testGetAllergy() {
void testGetAllergy() {
Allergy allergy = getAllergyData("Tree pollen", "Watering eyes", "Dry, red and cracked skin");
Response responseCre = doCreateAllergy(allergy);
Allergy allergyCreated = responseCre.then().assertThat().statusCode(200)
Expand All @@ -174,7 +174,7 @@ public void testGetAllergy() {

@Description("Get a allergy with an non-existing id")
@Test
public void testGetUnexistingAllergy() {
void testGetUnexistingAllergy() {
int statusCode = given()
.when().get("/allergies/38400000-8cf0-11bd-b23e-10b96e4ef00d")
.then()
Expand All @@ -184,7 +184,7 @@ public void testGetUnexistingAllergy() {

@Description("Delete a allergy by id")
@Test
public void testDeleteAllergy() {
void testDeleteAllergy() {
Allergy allergy = getAllergyData("Tree pollen", "Watering eyes", "Dry, red and cracked skin");
Response responseCre = doCreateAllergy(allergy);
Allergy allergyCreated = responseCre.then().assertThat().statusCode(200)
Expand All @@ -205,7 +205,7 @@ public void testDeleteAllergy() {

@Description("Delete non-existing Allergy")
@Test
public void testDeleteUnexistingAllergy() {
void testDeleteUnexistingAllergy() {
int statusCode = given()
.when().delete("/allergies/38400000-8cf0-11bd-b23e-10b96e4ef00d")
.then()
Expand All @@ -215,7 +215,7 @@ public void testDeleteUnexistingAllergy() {

@Description("Update a allergy by id")
@Test
public void testUpdateAllergy() {
void testUpdateAllergy() {
Allergy allergy = getAllergyData("Tree pollen", "Watering eyes", "Dry, red and cracked skin");
Response responseCre = doCreateAllergy(allergy);
Allergy allergyCreated = responseCre.then().assertThat().statusCode(200)
Expand All @@ -234,7 +234,7 @@ public void testUpdateAllergy() {

@Description("Update non-existent allergy, that is Create new Allergy")
@Test
public void testUpdateUnexistingAllergy() {
void testUpdateUnexistingAllergy() {
Allergy allergy = getAllergyData("Tree pollen", "Watering eyes", "Dry, red and cracked skin");
Allergy allergyCreated = given().body(allergy)
.when().put("/allergies/38400000-8cf0-11bd-b23e-10b96e4ef00d")
Expand Down
Loading