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-6921] Implement Open Access in PSAMA #204

Closed
wants to merge 10 commits into from
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package edu.harvard.dbmi.avillach.data.entity;

import java.io.StringReader;
import java.util.Optional;

import javax.json.Json;
import javax.json.JsonObject;
import javax.json.JsonReader;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.*;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
Expand All @@ -18,6 +18,9 @@ public class Resource extends BaseEntity{
@Column(length = 8192)
private String description;
private String targetURL;


@Convert(converter = ResourcePathConverter.class)
private String resourceRSPath;

@Column(length = 8192)
Expand Down Expand Up @@ -102,4 +105,31 @@ public String toString() {
.add("metadata", metadataObj)
.build().toString();
}

/**
* This resource path converter allows resource paths to contain a reference to a specific stack that is
* imputed at runtime based an an environment parameter. This allows multiple stacks to share the same database.
*
* The ___target_stack___ token in any resource path value will be replaced with the TARGET_STACK environment variable
*/
@Converter
public static class ResourcePathConverter implements AttributeConverter<String, String> {

public ResourcePathConverter() {
}

private static final Optional<String> targetStack = Optional.ofNullable(System.getProperty("TARGET_STACK", null));

@Override
public String convertToDatabaseColumn(String attribute) {
return attribute;
}

@Override
public String convertToEntityAttribute(String dbData) {
return targetStack
.map(stack -> dbData.replace("___target_stack___", stack))
.orElse(dbData);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,25 @@
import edu.harvard.dbmi.avillach.data.entity.Query;

import javax.enterprise.context.ApplicationScoped;
import javax.persistence.PersistenceException;
import javax.transaction.Transactional;
import java.util.UUID;

@Transactional
@ApplicationScoped
public class QueryRepository extends BaseRepository<Query, UUID>{
public class QueryRepository extends BaseRepository<Query, UUID> {

protected QueryRepository() {super(Query.class);}
protected QueryRepository() {
super(Query.class);
}

public Query getQueryUUIDFromCommonAreaUUID(UUID caID) {
String caIDRegex = "%commonAreaUUID\":\"" + caID + "\"%";
String query = "SELECT * FROM query WHERE CONVERT(metadata USING utf8) LIKE ?";
try {
return (Query) em().createNativeQuery(query, Query.class).setParameter(1, caIDRegex).getSingleResult();
} catch (PersistenceException ignored) {
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ protected ResourceRepository() {
super(Resource.class);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.ejb.Singleton;
import javax.enterprise.context.ApplicationScoped;
Expand All @@ -25,7 +26,23 @@ public class PicSureWarInit {
@Resource(mappedName = "java:global/token_introspection_token")
private String token_introspection_token;

//to be able to pre modified
@Resource(mappedName = "java:global/defaultApplicationUUID")
private String default_application_uuid;

@Resource(mappedName = "java:global/openAccessEnabled")
private String open_access_enabled_str;

private boolean open_access_enabled;

@Resource(mappedName = "java:global/openAccessValidateUrl")
private String open_access_validate_url;

@PostConstruct
public void init() {
this.open_access_enabled = Boolean.parseBoolean(open_access_enabled_str);
}

// to be able to pre modified
public static final ObjectMapper objectMapper = new ObjectMapper();

// check the example from Apache HttpClient official website:
Expand All @@ -39,11 +56,7 @@ public class PicSureWarInit {
static {
HTTP_CLIENT_CONNECTION_MANAGER = new PoolingHttpClientConnectionManager();
HTTP_CLIENT_CONNECTION_MANAGER.setMaxTotal(100);
CLOSEABLE_HTTP_CLIENT = HttpClients
.custom()
.setConnectionManager(HTTP_CLIENT_CONNECTION_MANAGER)
.useSystemProperties()
.build();
CLOSEABLE_HTTP_CLIENT = HttpClients.custom().setConnectionManager(HTTP_CLIENT_CONNECTION_MANAGER).useSystemProperties().build();
}


Expand All @@ -54,4 +67,22 @@ public String getToken_introspection_url() {
public String getToken_introspection_token() {
return token_introspection_token;
}

/**
* This method is used to get the default application UUID. This value is either the open or auth hpds resource UUID.
*
* @return the default application UUID
*/
public String getDefaultApplicationUUID() {
return this.default_application_uuid;
}

public boolean isOpenAccessEnabled() {
return open_access_enabled;
}

public String getOpenAccessValidateUrl() {
return this.open_access_validate_url;
}

}
Loading
Loading