-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP added response classes for results
- Loading branch information
1 parent
1c74b5b
commit 1429299
Showing
9 changed files
with
124 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/main/java/edu/tamu/sage/controller/handler/DiscoveryViewControllerAdvice.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package edu.tamu.sage.controller.handler; | ||
|
||
import static edu.tamu.weaver.response.ApiStatus.ERROR; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.ControllerAdvice; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import edu.tamu.sage.exceptions.DiscoveryContextNotFoundException; | ||
import edu.tamu.weaver.response.ApiResponse; | ||
|
||
@RestController | ||
@ControllerAdvice | ||
public class DiscoveryViewControllerAdvice { | ||
|
||
@ResponseStatus(value = HttpStatus.OK) | ||
@ExceptionHandler(DiscoveryContextNotFoundException.class) | ||
public ApiResponse handleFcrepoOperationFailedException(DiscoveryContextNotFoundException e) { | ||
return new ApiResponse(ERROR, e.getMessage()); | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/edu/tamu/sage/exceptions/DiscoveryContextNotFoundException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package edu.tamu.sage.exceptions; | ||
|
||
public class DiscoveryContextNotFoundException extends Exception { | ||
|
||
/** | ||
* | ||
*/ | ||
private static final long serialVersionUID = -787392244167335114L; | ||
|
||
public DiscoveryContextNotFoundException(String message) { | ||
super(message); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package edu.tamu.sage.model.response; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
import org.apache.solr.common.SolrDocument; | ||
|
||
public class Result { | ||
|
||
private List<ResultField> fields; | ||
|
||
public Result() { | ||
this.fields = new ArrayList<ResultField>(); | ||
} | ||
|
||
public List<ResultField> getFields() { | ||
return fields; | ||
} | ||
|
||
public void setFields(List<ResultField> fields) { | ||
this.fields = fields; | ||
} | ||
|
||
public void addResultField(ResultField resultField) { | ||
this.fields.add(resultField); | ||
} | ||
|
||
public static Result of(SolrDocument doc, Collection<String> fieldNames) { | ||
Result result = new Result(); | ||
for (String s: fieldNames) { | ||
result.addResultField(ResultField.of(s, doc.getFieldValue(s).toString())); | ||
} | ||
return result; | ||
} | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/edu/tamu/sage/model/response/ResultField.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package edu.tamu.sage.model.response; | ||
|
||
public class ResultField { | ||
|
||
String Key; | ||
String Value; | ||
|
||
public ResultField(String key, String value) { | ||
this.Key = key; | ||
this.Value = value; | ||
} | ||
|
||
public String getKey() { | ||
return Key; | ||
} | ||
|
||
public void setKey(String key) { | ||
Key = key; | ||
} | ||
|
||
public String getValue() { | ||
return Value; | ||
} | ||
|
||
public void setValue(String value) { | ||
Value = value; | ||
} | ||
|
||
public static ResultField of(String key, String value) { | ||
return new ResultField(key, value); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
<h1>{{discoveryContext.name}}</h1> | ||
|
||
<div ng-repeat="(i, result) in discoveryContext.results">{{i}}{{result.title_tesim}}</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters