Skip to content

Commit

Permalink
ALS-7883: Fix issues from checkmarx report
Browse files Browse the repository at this point in the history
  • Loading branch information
ramari16 committed Nov 22, 2024
1 parent 2772073 commit cbc658b
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 261 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@
import javax.persistence.*;

import edu.harvard.dbmi.avillach.util.PicSureStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Entity(name = "query")
public class Query extends BaseEntity {

private static final Logger logger = LoggerFactory.getLogger(Query.class);

//TODO may not need these two things
private Date startTime;
Expand Down Expand Up @@ -89,7 +93,7 @@ public String getQuery() {
outStr += line;
}
} catch (IOException e) {
e.printStackTrace();
throw new UncheckedIOException(e);
}
return outStr;
}
Expand All @@ -106,7 +110,7 @@ public void setQuery(String queryStr) {
gzip.close();
this.query = obj.toByteArray();
} catch (IOException e) {
e.printStackTrace();
throw new UncheckedIOException(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,8 @@ public List<T> getByColumns(CriteriaQuery query, Root root, Predicate... predica
query.select(root);
if (predicates != null && predicates.length > 0)
query.where(predicates);
try{
return em().createQuery(query)
.getResultList();
} catch (PersistenceException e) {
e.printStackTrace();
return null;
}
return em().createQuery(query)
.getResultList();

}

Expand All @@ -168,9 +163,6 @@ public T getUniqueResultByColumns(CriteriaQuery query, Root root, Predicate... p
.getSingleResult();
} catch (NoResultException e){
return null;
} catch (PersistenceException e){
e.printStackTrace();
return null;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public String status() {
lastStatus = ONE_OR_MORE_COMPONENTS_DEGRADED;
}
} catch (Exception e) {
e.printStackTrace();
logger.error("One or more components degraded", e);
lastStatus = ONE_OR_MORE_COMPONENTS_DEGRADED;
}
return lastStatus;
Expand Down
33 changes: 0 additions & 33 deletions pic-sure-initializer/README.md

This file was deleted.

58 changes: 0 additions & 58 deletions pic-sure-initializer/pom.xml

This file was deleted.

This file was deleted.

8 changes: 0 additions & 8 deletions pic-sure-initializer/src/main/resources/log4j.properties

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,31 +1,26 @@
package edu.harvard.hms.dbmi.avillach;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
import org.apache.commons.io.IOUtils;
import com.fasterxml.jackson.databind.ObjectMapper;
import edu.harvard.dbmi.avillach.util.exception.ResourceCommunicationException;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClientBuilder;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;

import edu.harvard.dbmi.avillach.util.exception.ResourceCommunicationException;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class HttpClientUtil {
private final static ObjectMapper json = new ObjectMapper();

private static final Logger logger = LoggerFactory.getLogger(HttpClientUtil.class);

public static HttpResponse retrieveGetResponse(String uri, String token) {
try {
HttpClient client = HttpClientBuilder.create().build();
Expand All @@ -39,32 +34,6 @@ public static HttpResponse retrieveGetResponse(String uri, String token) {
}
}

public static HttpResponse retrievePostResponse(String uri, String token) {
try {
HttpClient client = HttpClientBuilder.create().build();
HttpPost post = new HttpPost(uri);
if (token != null) {
Map<String, String> clientCredentials = new HashMap<String, String>();
clientCredentials.put("BEARER_TOKEN", token);
post.setEntity(new StringEntity(json.writeValueAsString(clientCredentials)));
}
post.setHeader("Content-type","application/json");
return client.execute(post);
} catch (IOException e) {
throw new ResourceCommunicationException(uri, e);
}
}

public static <T> List<T> readListFromResponse(HttpResponse response, Class<T> expectedElementType) {
try {
String responseBody = EntityUtils.toString(response.getEntity(), "UTF-8");
return json.readValue(responseBody, new TypeReference<List<T>>() {});
} catch (IOException e) {
e.printStackTrace();
return new ArrayList<T>();
}
}

public static <T> List<T> readDataObjectsFromResponse(HttpResponse response, Class<T> expectedElementType) {
try {
String responseBody = EntityUtils.toString(response.getEntity(), "UTF-8");
Expand All @@ -79,7 +48,7 @@ public static <T> List<T> readDataObjectsFromResponse(HttpResponse response, Cla
return json.readValue(jn.get("data_objects").toString(), new TypeReference<List<T>>() {});
}
} catch (IOException e) {
e.printStackTrace();
logger.error("Error reading object from response, returning empty list", e);
return new ArrayList<T>();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,6 @@ private String createXAxisLabel(String title) {
return title.substring(title.lastIndexOf(" ") + 1);
} catch (IndexOutOfBoundsException e) {
logger.error("Error getting cross counts: " + e.getMessage());
e.printStackTrace();
return title;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package edu.harvard.dbmi.avillach.util.exception.mapper;

import edu.harvard.dbmi.avillach.util.response.PICSUREResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
Expand All @@ -9,9 +11,11 @@
@Provider
public class IllegalArgumentExceptionMapper implements ExceptionMapper<IllegalArgumentException>{

private static final Logger logger = LoggerFactory.getLogger(IllegalArgumentExceptionMapper.class);

@Override
public Response toResponse(IllegalArgumentException exception) {
exception.printStackTrace();
logger.error("Uncaught exception", exception);
return PICSUREResponse.protocolError(exception.getMessage());
}
}
Loading

0 comments on commit cbc658b

Please sign in to comment.