Skip to content

Commit

Permalink
Merge pull request #51 from PDXFinder/beta
Browse files Browse the repository at this point in the history
Beta
  • Loading branch information
CsabaHalmagyi committed Jan 17, 2019
2 parents f44e641 + ad5398f commit 4d5ca6a
Show file tree
Hide file tree
Showing 101 changed files with 7,445 additions and 3,791 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Expand Up @@ -14,5 +14,4 @@ hs_err_pid*
*.iml

node_modules

static
/admin/src/main/resources/
@@ -1,34 +1,56 @@
package org.pdxfinder.admin.controllers;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.pdxfinder.admin.pojos.MappingEntity;
import org.pdxfinder.admin.zooma.ZoomaEntity;
import org.pdxfinder.services.MappingService;
import org.pdxfinder.services.UtilityService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.http.*;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.*;
import java.util.concurrent.CompletableFuture;


/*
* Created by csaba on 09/07/2018.
*/
@RestController
@RequestMapping("/api")
public class AjaxController {

private MappingService mappingService;
private final static Logger log = LoggerFactory.getLogger(AjaxController.class);
private ObjectMapper mapper = new ObjectMapper();
private RestTemplate restTemplate;

private final String ZOOMA_URL = "http://scrappy.ebi.ac.uk:8080/annotations";
private String errReport = "";


@Autowired
public AjaxController(MappingService mappingService) {
private UtilityService utilityService;
private MappingService mappingService;

@Autowired
public AjaxController(MappingService mappingService, RestTemplateBuilder restTemplateBuilder) {
this.mappingService = mappingService;
this.restTemplate = restTemplateBuilder.build();
}

@RequestMapping(value = "/api/missingmapping/diagnosis")


/****************************************************************
* INTERACTIONS WITH PDX FINDER KNOWLEDGE BASE *
****************************************************************/


@RequestMapping(value = "/missingmapping/diagnosis")
@ResponseBody
public Map<String, List<MappingEntity>> getMissingMappings(@RequestParam("ds") Optional<String> dataSource){

Expand All @@ -41,7 +63,7 @@ public Map<String, List<MappingEntity>> getMissingMappings(@RequestParam("ds") O
}


@RequestMapping(value = "/api/mapping/diagnosis")
@RequestMapping(value = "/mapping/diagnosis")
@ResponseBody
public Map<String, List<MappingEntity>> getDiagnosisMappings(@RequestParam("ds") Optional<String> dataSource){

Expand All @@ -54,12 +76,102 @@ public Map<String, List<MappingEntity>> getDiagnosisMappings(@RequestParam("ds"
}


@PostMapping("/api/diagnosis")
@PostMapping("/diagnosis")
public ResponseEntity<?> createDiagnosisMappings(@RequestBody List<MappingEntity> newMappings){

log.info(newMappings.toString());
return ResponseEntity.noContent().build();
}






/****************************************************************
* INTERACTIONS WITH ZOOMA *
****************************************************************/


@GetMapping("/zooma/transform")
public List<ZoomaEntity> transformAnnotationForZooma(){

List<ZoomaEntity> zoomaEntities = mappingService.transformMappingsForZooma();
return zoomaEntities; //new ResponseEntity<>(result, HttpStatus.OK);
}



@GetMapping("/zooma")
public ResponseEntity<?> writeAllAnnotationsToZooma(){

Map report = new LinkedHashMap();
List<ZoomaEntity> zoomaEntities = mappingService.transformMappingsForZooma();

int count = 0;
List<ZoomaEntity> failedList = new ArrayList<>();
for (ZoomaEntity zoomaEntity : zoomaEntities){

String entity = zoomaEntity.getBiologicalEntities().getBioEntity()+"__"+count++;
if (writeToZooma(zoomaEntity)){

report.put(entity,"SUCCESS WRITE");
}else{

report.put(entity, "THIS ANNOTATION WAS NOT WRITTEN TO ZOOMA");
failedList.add(zoomaEntity);
}
}

/* LOG FAILED OBJECTS TO FILE */
String failedReport = "";
try{
failedReport = mapper.writeValueAsString(failedList);
}catch (Exception e){}

utilityService.writeToFile(failedReport,(new Date())+"_failed.json");
utilityService.writeToFile(this.errReport,(new Date())+"_error.txt");

return new ResponseEntity<>(report, HttpStatus.OK);
}





public Boolean writeToZooma(ZoomaEntity zoomaEntity){

HttpEntity<String> entity = BuildHttpHeader();
HttpEntity<Object> req = new HttpEntity<>(zoomaEntity, entity.getHeaders());
Map result = new HashMap();

Boolean report = false;
try{
result = restTemplate.postForObject(ZOOMA_URL, req, Map.class);
report = true;
}catch (Exception e){

this.errReport += "\n\n ************************ NEW ERROR LOG "+(new Date())+" *********************** \n"+e;
}

return report;
}






public HttpEntity<String> BuildHttpHeader(){

HttpHeaders headers = new HttpHeaders();
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
headers.add("Content-Type", "application/json");
HttpEntity<String> entity = new HttpEntity<>("parameters", headers);

return entity;
}



}
2 changes: 2 additions & 0 deletions admin/src/main/resources/application.properties
Expand Up @@ -17,3 +17,5 @@ spring.thymeleaf.cache=false
server.port=8081

mappings.diagnosis.file = "";

mappings.mappedTermUrl=http://localhost/data/mappings.json
Expand Up @@ -40,9 +40,15 @@ public class MappingEntity {
* The term that the entity is mapped to. The value of this attribute should be either null (indicating that the
* entity is not mapped to anything yet) or an existing ontology term.
*/
private String mappedTerm;
private String mappedTermLabel;


/**
* The term url that the entity is mapped to. The value of this attribute should be either null (indicating that the
* entity is not mapped to anything yet) or an existing ontology term url.
*/
private String mappedTermUrl;

/**
* Describes whether the mapping rule is direct or inferred
*/
Expand All @@ -64,7 +70,7 @@ public class MappingEntity {


/**
* A list of entities that are similar to the current entity. This list is empty if the entity's mappedTerm is not null.
* A list of entities that are similar to the current entity. This list is empty if the entity's mappedTermLabel is not null.
*/
private List<MappingEntity> suggestedMappings;

Expand All @@ -89,7 +95,7 @@ public MappingEntity(Long entityId, String entityType, List<String> mappingLabel
this.entityType = entityType;
this.mappingLabels = mappingLabels;
this.mappingValues = mappingValues;
this.mappedTerm = null;
this.mappedTermLabel = null;
this.status = "Created";
this.suggestedMappings = new ArrayList<>();
//TODO: get current date, specify date format
Expand All @@ -99,14 +105,14 @@ public MappingEntity(Long entityId, String entityType, List<String> mappingLabel
}

public MappingEntity(Long entityId, String entityType, List<String> mappingLabels, Map<String, String> mappingValues,
String mappedTerm, String status, List<MappingEntity> suggestedMappings, Date dateCreated,
String mappedTermLabel, String status, List<MappingEntity> suggestedMappings, Date dateCreated,
Date dateUpdated) {

this.entityId = entityId;
this.entityType = entityType;
this.mappingLabels = mappingLabels;
this.mappingValues = mappingValues;
this.mappedTerm = mappedTerm;
this.mappedTermLabel = mappedTermLabel;
this.status = status;
this.suggestedMappings = suggestedMappings;
this.dateCreated = dateCreated;
Expand Down Expand Up @@ -146,12 +152,12 @@ public void setMappingValues(Map<String, String> mappingValues) {
this.mappingValues = mappingValues;
}

public String getMappedTerm() {
return mappedTerm;
public String getMappedTermLabel() {
return mappedTermLabel;
}

public void setMappedTerm(String mappedTerm) {
this.mappedTerm = mappedTerm;
public void setMappedTermLabel(String mappedTermLabel) {
this.mappedTermLabel = mappedTermLabel;
}

public String getMapType() {
Expand Down Expand Up @@ -202,4 +208,11 @@ public void setDateUpdated(Date dateUpdated) {
this.dateUpdated = dateUpdated;
}

public String getMappedTermUrl() {
return mappedTermUrl;
}

public void setMappedTermUrl(String mappedTermUrl) {
this.mappedTermUrl = mappedTermUrl;
}
}
@@ -0,0 +1,58 @@
package org.pdxfinder.admin.zooma;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;

@JsonPropertyOrder({
"bioEntity",
"studies",
"bioEntityUri"
})
public class BiologicalEntities {

private String bioEntity;
private Studies studies;
private Object bioEntityUri;


public BiologicalEntities() {
}

public BiologicalEntities(String bioEntity, Studies studies, Object bioEntityUri) {
this.bioEntity = bioEntity;
this.studies = studies;
this.bioEntityUri = bioEntityUri;
}

@JsonProperty("bioEntity")
public String getBioEntity() {
return bioEntity;
}

@JsonProperty("bioEntity")
public void setBioEntity(String bioEntity) {
this.bioEntity = bioEntity;
}

@JsonProperty("studies")
public Studies getStudies() {
return studies;
}

@JsonProperty("studies")
public void setStudies(Studies studies) {
this.studies = studies;
}

@JsonProperty("bioEntityUri")
public Object getBioEntityUri() {
return bioEntityUri;
}

@JsonProperty("bioEntityUri")
public void setBioEntityUri(Object bioEntityUri) {
this.bioEntityUri = bioEntityUri;
}

}
49 changes: 49 additions & 0 deletions data-model/src/main/java/org/pdxfinder/admin/zooma/Property.java
@@ -0,0 +1,49 @@
package org.pdxfinder.admin.zooma;

import java.util.HashMap;
import java.util.Map;
import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;

@JsonPropertyOrder({
"propertyType",
"propertyValue"
})
public class Property {

private String propertyType;
private String propertyValue;

public Property() {
}

public Property(String propertyType, String propertyValue) {
this.propertyType = propertyType;
this.propertyValue = propertyValue;
}

@JsonProperty("propertyType")
public String getPropertyType() {
return propertyType;
}

@JsonProperty("propertyType")
public void setPropertyType(String propertyType) {
this.propertyType = propertyType;
}

@JsonProperty("propertyValue")
public String getPropertyValue() {
return propertyValue;
}

@JsonProperty("propertyValue")
public void setPropertyValue(String propertyValue) {
this.propertyValue = propertyValue;
}

}

0 comments on commit 4d5ca6a

Please sign in to comment.