Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ALS-7883: Fix issues from checkmarx report #213

Merged
merged 2 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete


//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
Loading