Skip to content

Commit

Permalink
ALS-5387: More robust implementation of feature
Browse files Browse the repository at this point in the history
  • Loading branch information
ramari16 committed Dec 8, 2023
1 parent 2ab8d49 commit cd76183
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
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,23 @@ public String toString() {
.add("metadata", metadataObj)
.build().toString();
}

@Converter
protected class ResourcePathConverter implements AttributeConverter {


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

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

@Override
public Object convertToEntityAttribute(Object dbData) {
return targetStack.map(stack -> {
return ((String) dbData).replace("___target_stack___", stack);
}).orElse((String) dbData);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,4 @@ public class ResourceRepository extends BaseRepository<Resource, UUID> {
protected ResourceRepository() {
super(Resource.class);
}

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

public Resource getById(UUID id) {
Resource resource = super.getById(id);
targetStack.ifPresent(stack -> {
resource.setResourceRSPath(resource.getResourceRSPath().replace("___target_stack___", stack));
});
return resource;
}
}

0 comments on commit cd76183

Please sign in to comment.