source: VirtualCollectionRegistry/trunk/VirtualCollectionRegistry/src/main/java/de/uni_leipzig/asv/clarin/webservices/pidservices2/PidObject.java @ 5482

Last change on this file since 5482 was 5482, checked in by Twan Goosen, 10 years ago

Updated the PID services according to a the new version (2.0.6-SNAPSHOT) provided by Thomas Eckart

  • Property svn:eol-style set to native
File size: 1.7 KB
Line 
1package de.uni_leipzig.asv.clarin.webservices.pidservices2;
2
3import java.util.HashMap;
4import java.util.Iterator;
5import java.util.Map;
6
7import net.sf.json.JSONArray;
8
9import com.jayway.jsonpath.JsonPath;
10import com.jayway.jsonpath.PathNotFoundException;
11
12/**
13 * Stores most(!) relevant information of a PID JSON object retrieved from the GWDG
14 *
15 * @author Thomas Eckart
16 */
17public class PidObject {
18        private final String handleIdentifier;
19        private final Map<HandleField, String> fieldMap;
20
21        public PidObject(String pid, JSONArray pidJsonArray) {
22                this.handleIdentifier = pid;
23
24                fieldMap = new HashMap<HandleField, String>();
25                String jsonPath;
26                for (HandleField fieldName : HandleField.values()) {
27                        try {
28                                jsonPath = "$..[?(@.type=='" + fieldName + "')].parsed_data[0]";
29                                fieldMap.put(fieldName, JsonPath.read(pidJsonArray, jsonPath).toString());
30                        } catch (PathNotFoundException pnfe) {
31                                fieldMap.put(fieldName, null);
32                        }
33                }
34        }
35
36        /**
37         * Returns handle identifier
38         *
39         * @return handle identifier
40         */
41        public String getHandleIdentifier() {
42                return handleIdentifier;
43        }
44
45        /**
46         * Returns stored value in EPIC handle for a specific field
47         *
48         * @param field
49         *            name of the stored field
50         * @return value of the stored field ('parsed_data'), may be null
51         */
52        public String getValue(HandleField fieldName) {
53                return fieldMap.get(fieldName);
54        }
55
56        @Override
57        public String toString() {
58                StringBuilder sb = new StringBuilder(handleIdentifier);
59                sb.append(" (Values: ");
60                Iterator<HandleField> fieldIterator = fieldMap.keySet().iterator();
61                while (fieldIterator.hasNext()) {
62                        HandleField field = fieldIterator.next();
63                        sb.append(" " + field + "=\"" + fieldMap.get(field) + "\"");
64                }
65                sb.append(")");
66                return sb.toString();
67        }
68}
Note: See TracBrowser for help on using the repository browser.