Revision d253efdb
Added by Andreas Kohlbecker over 15 years ago
.gitattributes | ||
---|---|---|
1241 | 1241 |
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/view/DateTimeJSONValueProcessor.java -text |
1242 | 1242 |
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/view/JsonView.java -text |
1243 | 1243 |
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/view/XmlView.java -text |
1244 |
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/view/processor/CalendarJSONValueProcessor.java -text |
|
1245 |
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/view/processor/DateTimeJSONValueProcessor.java -text |
|
1246 |
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/view/processor/InitializedHibernatePropertyFilter.java -text |
|
1247 |
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/view/processor/PartialJSONValueProcessor.java -text |
|
1248 |
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/view/processor/UUIDJSONValueProcessor.java -text |
|
1244 | 1249 |
cdmlib-remote/src/main/resources/log4j.properties -text |
1245 | 1250 |
cdmlib-remote/src/main/resources/spy.properties -text |
1246 | 1251 |
cdmlib-remote/src/main/webapp/WEB-INF/applicationContext.xml -text |
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/service/CdmServiceImpl.java | ||
---|---|---|
24 | 24 |
import org.springframework.stereotype.Service; |
25 | 25 |
import org.springframework.transaction.annotation.Transactional; |
26 | 26 |
|
27 |
import eu.etaxonomy.cdm.api.service.IReferenceService; |
|
27 | 28 |
import eu.etaxonomy.cdm.model.common.AnnotatableEntity; |
28 | 29 |
import eu.etaxonomy.cdm.model.common.Annotation; |
29 | 30 |
import eu.etaxonomy.cdm.model.description.Feature; |
... | ... | |
91 | 92 |
@Qualifier("annotatableDaoImpl") |
92 | 93 |
private AnnotatableDaoImpl<AnnotatableEntity<?>> annotatableDao; |
93 | 94 |
|
95 |
//-------------------------- |
|
96 |
@Autowired |
|
97 |
private IReferenceService referenceService; |
|
98 |
|
|
94 | 99 |
|
95 | 100 |
private final int MAXRESULTS = 500; |
96 | 101 |
|
... | ... | |
254 | 259 |
return result; |
255 | 260 |
} |
256 | 261 |
|
257 |
public ReferenceTO getReference(UUID uuid, Enumeration<Locale> locales) throws CdmObjectNonExisting{ |
|
258 |
ReferenceBase ref = getCdmReferenceBase(uuid); |
|
259 |
ReferenceTO r = refAssembler.getTO(ref, locales); |
|
262 |
public ReferenceBase getReference(UUID uuid, Enumeration<Locale> locales) throws CdmObjectNonExisting{ |
|
263 |
/*ReferenceBase ref = getCdmReferenceBase(uuid); |
|
264 |
ReferenceTO r = refAssembler.getTO(ref, locales); */ |
|
265 |
ReferenceBase r = referenceService.getReferenceByUuid(uuid); |
|
266 |
/* Initialise required collections .. */ |
|
260 | 267 |
return r; |
261 | 268 |
} |
262 | 269 |
public ReferenceSTO getSimpleReference(UUID uuid, Enumeration<Locale> locales) throws CdmObjectNonExisting{ |
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/service/ICdmService.java | ||
---|---|---|
17 | 17 |
import java.util.UUID; |
18 | 18 |
|
19 | 19 |
import eu.etaxonomy.cdm.model.common.Annotation; |
20 |
import eu.etaxonomy.cdm.model.reference.ReferenceBase; |
|
20 | 21 |
import eu.etaxonomy.cdm.persistence.dao.common.ITitledDao; |
21 | 22 |
import eu.etaxonomy.cdm.remote.dto.AnnotationTO; |
22 | 23 |
import eu.etaxonomy.cdm.remote.dto.FeatureTO; |
... | ... | |
111 | 112 |
* @return |
112 | 113 |
* @throws CdmObjectNonExisting |
113 | 114 |
*/ |
114 |
public ReferenceTO getReference(UUID uuid, Enumeration<Locale> locales) throws CdmObjectNonExisting;
|
|
115 |
public ReferenceBase getReference(UUID uuid, Enumeration<Locale> locales) throws CdmObjectNonExisting;
|
|
115 | 116 |
|
116 | 117 |
|
117 | 118 |
public ReferenceSTO getSimpleReference(UUID uuid, Enumeration<Locale> locales) throws CdmObjectNonExisting; |
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/service/RestController.java | ||
---|---|---|
32 | 32 |
import org.springframework.web.servlet.mvc.AbstractController; |
33 | 33 |
|
34 | 34 |
import eu.etaxonomy.cdm.model.common.Annotation; |
35 |
import eu.etaxonomy.cdm.model.reference.ReferenceBase; |
|
35 | 36 |
import eu.etaxonomy.cdm.persistence.dao.common.ITitledDao.MATCH_MODE; |
36 | 37 |
import eu.etaxonomy.cdm.remote.dto.AnnotationTO; |
37 | 38 |
import eu.etaxonomy.cdm.remote.dto.FeatureTO; |
... | ... | |
95 | 96 |
TaxonTO t = service.getTaxon(taxonUuid, featureTreeUuid, locales); |
96 | 97 |
mv.addObject(t); |
97 | 98 |
}else if(dto.equalsIgnoreCase("ref")){ |
98 |
ReferenceTO r = service.getReference(getUuid(uuid), locales);
|
|
99 |
ReferenceBase r = service.getReference(getUuid(uuid), locales);
|
|
99 | 100 |
mv.addObject(r); |
100 | 101 |
}else if(dto.equalsIgnoreCase("whatis")){ |
101 | 102 |
//TODO: somehow the whatis url path is not delegated to this controller ?!#!?? |
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/view/JsonView.java | ||
---|---|---|
13 | 13 |
import java.io.Writer; |
14 | 14 |
import java.util.Collection; |
15 | 15 |
import java.util.Map; |
16 |
import java.util.UUID; |
|
16 | 17 |
|
17 | 18 |
import javax.servlet.http.HttpServletRequest; |
18 | 19 |
import javax.servlet.http.HttpServletResponse; |
... | ... | |
20 | 21 |
import net.sf.json.JSONArray; |
21 | 22 |
import net.sf.json.JSONObject; |
22 | 23 |
import net.sf.json.JsonConfig; |
23 |
import net.sourceforge.jtds.jdbc.DateTime; |
|
24 | 24 |
|
25 | 25 |
import org.apache.commons.logging.Log; |
26 | 26 |
import org.apache.commons.logging.LogFactory; |
27 |
import org.joda.time.Partial; |
|
27 | 28 |
import org.springframework.web.servlet.View; |
28 | 29 |
|
30 |
import eu.etaxonomy.cdm.remote.view.processor.CalendarJSONValueProcessor; |
|
31 |
import eu.etaxonomy.cdm.remote.view.processor.DateTimeJSONValueProcessor; |
|
32 |
import eu.etaxonomy.cdm.remote.view.processor.InitializedHibernatePropertyFilter; |
|
33 |
import eu.etaxonomy.cdm.remote.view.processor.PartialJSONValueProcessor; |
|
34 |
import eu.etaxonomy.cdm.remote.view.processor.UUIDJSONValueProcessor; |
|
29 | 35 |
|
30 | 36 |
public class JsonView extends BaseView implements View{ |
31 | 37 |
Log log = LogFactory.getLog(JsonView.class); |
... | ... | |
38 | 44 |
|
39 | 45 |
public void render(Map model, HttpServletRequest req, HttpServletResponse resp) throws Exception { |
40 | 46 |
// configure the serialisation |
47 |
// TODO implement a more generic approach as done in CATE: http://forge.nesc.ac.uk/cgi-bin/cvsweb.cgi/cate-view/src/main/java/org/cateproject/view/json/JsonConfigFactoryBean.java?rev=1.1&content-type=text/x-cvsweb-markup&cvsroot=cate |
|
41 | 48 |
jsonConfig.registerJsonValueProcessor(org.joda.time.DateTime.class, new DateTimeJSONValueProcessor()); |
49 |
jsonConfig.registerJsonValueProcessor(java.util.Calendar.class, new CalendarJSONValueProcessor()); |
|
50 |
jsonConfig.registerJsonValueProcessor(Partial.class, new PartialJSONValueProcessor()); |
|
51 |
jsonConfig.registerJsonValueProcessor(UUID.class, new UUIDJSONValueProcessor()); |
|
52 |
jsonConfig.setJsonPropertyFilter(new InitializedHibernatePropertyFilter()); |
|
42 | 53 |
|
43 | 54 |
// Retrieve data from model |
44 | 55 |
Object dto = getResponseData(model); |
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/view/XmlView.java | ||
---|---|---|
91 | 91 |
// TODO determine preferred charset from HTTP Accept-Charset header |
92 | 92 |
Writer out = new BufferedWriter(new OutputStreamWriter(response.getOutputStream(), "UTF-8")); |
93 | 93 |
out.append("<?xml version='1.0'?>"); |
94 |
xstream.toXML(dto, out);
|
|
94 |
xstream.toXML(dto, out); |
|
95 | 95 |
} |
96 | 96 |
|
97 | 97 |
} |
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/view/processor/CalendarJSONValueProcessor.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2007 EDIT |
|
3 |
* European Distributed Institute of Taxonomy |
|
4 |
* http://www.e-taxonomy.eu |
|
5 |
* |
|
6 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
7 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
8 |
*/ |
|
9 |
|
|
10 |
package eu.etaxonomy.cdm.remote.view.processor; |
|
11 |
|
|
12 |
import java.text.DateFormat; |
|
13 |
import java.text.SimpleDateFormat; |
|
14 |
import java.util.Calendar; |
|
15 |
|
|
16 |
import net.sf.json.JsonConfig; |
|
17 |
import net.sf.json.processors.JsonValueProcessor; |
|
18 |
|
|
19 |
import org.apache.log4j.Logger; |
|
20 |
|
|
21 |
/** |
|
22 |
* @author a.kohlbecker |
|
23 |
* @created 20.01.2009 |
|
24 |
* @version 1.0 |
|
25 |
*/ |
|
26 |
public class CalendarJSONValueProcessor implements JsonValueProcessor { |
|
27 |
private static Logger logger = Logger.getLogger(DateTimeJSONValueProcessor.class); |
|
28 |
|
|
29 |
private static SimpleDateFormat iso8601Format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssz"); |
|
30 |
|
|
31 |
/* (non-Javadoc) |
|
32 |
* @see net.sf.json.processors.JsonValueProcessor#processArrayValue(java.lang.Object, net.sf.json.JsonConfig) |
|
33 |
*/ |
|
34 |
public Object processArrayValue(Object object, JsonConfig jsonConfig) { |
|
35 |
if(object == null){ |
|
36 |
return ""; |
|
37 |
} |
|
38 |
Calendar calendar = (Calendar) object; |
|
39 |
if (logger.isDebugEnabled()) { |
|
40 |
logger.debug("processArrayValue of java.util.Calendar: " + CalendarJSONValueProcessor.iso8601Format.format(calendar.getTime())); |
|
41 |
} |
|
42 |
return CalendarJSONValueProcessor.iso8601Format.format(calendar.getTime()); |
|
43 |
} |
|
44 |
|
|
45 |
/* (non-Javadoc) |
|
46 |
* @see net.sf.json.processors.JsonValueProcessor#processObjectValue(java.lang.String, java.lang.Object, net.sf.json.JsonConfig) |
|
47 |
*/ |
|
48 |
public Object processObjectValue(String key, Object object, JsonConfig jsonConfig) { |
|
49 |
if(object == null){ |
|
50 |
return ""; |
|
51 |
} |
|
52 |
Calendar dateTime = (Calendar) object; |
|
53 |
if (logger.isDebugEnabled()) { |
|
54 |
logger.debug("processObjectValue of java.util.Calendar: " + CalendarJSONValueProcessor.iso8601Format.format(dateTime.getTime())); |
|
55 |
} |
|
56 |
return CalendarJSONValueProcessor.iso8601Format.format(dateTime.getTime()); |
|
57 |
} |
|
58 |
} |
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/view/processor/DateTimeJSONValueProcessor.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2007 EDIT |
|
3 |
* European Distributed Institute of Taxonomy |
|
4 |
* http://www.e-taxonomy.eu |
|
5 |
* |
|
6 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
7 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
8 |
*/ |
|
9 |
|
|
10 |
package eu.etaxonomy.cdm.remote.view.processor; |
|
11 |
|
|
12 |
import net.sf.json.JsonConfig; |
|
13 |
import net.sf.json.processors.JsonValueProcessor; |
|
14 |
|
|
15 |
import org.apache.log4j.Logger; |
|
16 |
import org.hibernate.Hibernate; |
|
17 |
import org.joda.time.DateTime; |
|
18 |
import org.joda.time.format.DateTimeFormatter; |
|
19 |
import org.joda.time.format.ISODateTimeFormat; |
|
20 |
|
|
21 |
/** |
|
22 |
* @author n.hoffmann |
|
23 |
* @created 24.07.2008 |
|
24 |
* @version 1.0 |
|
25 |
*/ |
|
26 |
public class DateTimeJSONValueProcessor implements JsonValueProcessor { |
|
27 |
private static Logger logger = Logger.getLogger(DateTimeJSONValueProcessor.class); |
|
28 |
|
|
29 |
private static DateTimeFormatter iso8601Format = ISODateTimeFormat.dateTime(); |
|
30 |
|
|
31 |
/* (non-Javadoc) |
|
32 |
* @see net.sf.json.processors.JsonValueProcessor#processArrayValue(java.lang.Object, net.sf.json.JsonConfig) |
|
33 |
*/ |
|
34 |
public Object processArrayValue(Object object, JsonConfig jsonConfig) { |
|
35 |
DateTime dateTime = (DateTime) object; |
|
36 |
if (logger.isDebugEnabled()) { |
|
37 |
logger.debug("processArrayValue of joda.time.DateTime: " + DateTimeJSONValueProcessor.iso8601Format.print(dateTime)); |
|
38 |
} |
|
39 |
return DateTimeJSONValueProcessor.iso8601Format.print(dateTime); |
|
40 |
} |
|
41 |
|
|
42 |
/* (non-Javadoc) |
|
43 |
* @see net.sf.json.processors.JsonValueProcessor#processObjectValue(java.lang.String, java.lang.Object, net.sf.json.JsonConfig) |
|
44 |
*/ |
|
45 |
public Object processObjectValue(String key, Object object, JsonConfig jsonConfig) { |
|
46 |
DateTime dateTime = (DateTime) object; |
|
47 |
if (logger.isDebugEnabled()) { |
|
48 |
logger.debug("processObjectValue of joda.time.DateTime: " + DateTimeJSONValueProcessor.iso8601Format.print(dateTime)); |
|
49 |
} |
|
50 |
return DateTimeJSONValueProcessor.iso8601Format.print(dateTime); |
|
51 |
} |
|
52 |
} |
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/view/processor/InitializedHibernatePropertyFilter.java | ||
---|---|---|
1 |
package eu.etaxonomy.cdm.remote.view.processor; |
|
2 |
|
|
3 |
import net.sf.json.util.PropertyFilter; |
|
4 |
|
|
5 |
import org.apache.log4j.Logger; |
|
6 |
import org.hibernate.Hibernate; |
|
7 |
|
|
8 |
public class InitializedHibernatePropertyFilter implements PropertyFilter { |
|
9 |
|
|
10 |
private static final Logger logger = Logger |
|
11 |
.getLogger(InitializedHibernatePropertyFilter.class); |
|
12 |
|
|
13 |
public boolean apply(Object source, String name, Object value) { |
|
14 |
if (logger.isDebugEnabled()) { |
|
15 |
logger.debug("Property " + name + " : Hibernate.isInitialized? " + Hibernate.isInitialized(value)); |
|
16 |
} |
|
17 |
return (!Hibernate.isInitialized(value) || name.equals("hibernateLazyInitializer")); |
|
18 |
} |
|
19 |
} |
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/view/processor/PartialJSONValueProcessor.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2007 EDIT |
|
3 |
* European Distributed Institute of Taxonomy |
|
4 |
* http://www.e-taxonomy.eu |
|
5 |
* |
|
6 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
7 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
8 |
*/ |
|
9 |
|
|
10 |
package eu.etaxonomy.cdm.remote.view.processor; |
|
11 |
|
|
12 |
import net.sf.json.JsonConfig; |
|
13 |
import net.sf.json.processors.JsonValueProcessor; |
|
14 |
|
|
15 |
import org.apache.log4j.Logger; |
|
16 |
import org.joda.time.Partial; |
|
17 |
|
|
18 |
import eu.etaxonomy.cdm.model.common.PartialUserType; |
|
19 |
|
|
20 |
/** |
|
21 |
* @author a.kohlbecker |
|
22 |
* @created 20.01.2008 |
|
23 |
* @version 1.0 |
|
24 |
*/ |
|
25 |
public class PartialJSONValueProcessor implements JsonValueProcessor { |
|
26 |
private static Logger logger = Logger.getLogger(PartialJSONValueProcessor.class); |
|
27 |
|
|
28 |
|
|
29 |
/* (non-Javadoc) |
|
30 |
* @see net.sf.json.processors.JsonValueProcessor#processArrayValue(java.lang.Object, net.sf.json.JsonConfig) |
|
31 |
*/ |
|
32 |
public Object processArrayValue(Object object, JsonConfig jsonConfig) { |
|
33 |
if(object == null){ |
|
34 |
return ""; |
|
35 |
} |
|
36 |
Partial partial = (Partial) object; |
|
37 |
if (logger.isDebugEnabled()) { |
|
38 |
logger.debug("processArrayValue of joda.time.DateTime: " + PartialUserType.partialToString(partial)); |
|
39 |
} |
|
40 |
return PartialUserType.partialToString(partial); |
|
41 |
} |
|
42 |
|
|
43 |
/* (non-Javadoc) |
|
44 |
* @see net.sf.json.processors.JsonValueProcessor#processObjectValue(java.lang.String, java.lang.Object, net.sf.json.JsonConfig) |
|
45 |
*/ |
|
46 |
public Object processObjectValue(String key, Object object, JsonConfig jsonConfig) { |
|
47 |
if(object == null){ |
|
48 |
return ""; |
|
49 |
} |
|
50 |
Partial partial = (Partial) object; |
|
51 |
if (logger.isDebugEnabled()) { |
|
52 |
logger.debug("processObjectValue of joda.time.DateTime: " + PartialUserType.partialToString(partial)); |
|
53 |
} |
|
54 |
return PartialUserType.partialToString(partial); |
|
55 |
} |
|
56 |
} |
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/view/processor/UUIDJSONValueProcessor.java | ||
---|---|---|
1 |
package eu.etaxonomy.cdm.remote.view.processor; |
|
2 |
|
|
3 |
import java.util.UUID; |
|
4 |
|
|
5 |
import net.sf.json.JsonConfig; |
|
6 |
import net.sf.json.processors.JsonValueProcessor; |
|
7 |
|
|
8 |
import org.apache.log4j.Logger; |
|
9 |
|
|
10 |
public class UUIDJSONValueProcessor implements JsonValueProcessor { |
|
11 |
private static final Logger logger = Logger |
|
12 |
.getLogger(UUIDJSONValueProcessor.class); |
|
13 |
|
|
14 |
public Object processArrayValue(Object obj, JsonConfig jsonConfig) { |
|
15 |
logger.debug("Processing UUID"); |
|
16 |
if(obj == null){ |
|
17 |
return ""; |
|
18 |
} |
|
19 |
UUID uuid = (UUID) obj; |
|
20 |
return uuid.toString(); |
|
21 |
} |
|
22 |
|
|
23 |
public Object processObjectValue(String key, Object obj, |
|
24 |
JsonConfig jsonConfig) { |
|
25 |
logger.debug("Processing UUID"); |
|
26 |
if(obj == null){ |
|
27 |
return ""; |
|
28 |
} |
|
29 |
UUID uuid = (UUID) obj; |
|
30 |
return uuid.toString(); |
|
31 |
}; |
|
32 |
|
|
33 |
} |
Also available in: Unified diff
partial interim implementation of reference REST service, JSON view works, XML view is broken