Project

General

Profile

« Previous | Next » 

Revision f1a25720

Added by Katja Luther over 6 years ago

  • ID f1a25720755daa96e8838a617a660dfced7b9f31
  • Parent 23e50194

first implementation for change from joda time to java8 time

View differences:

cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/view/RdfView.java
10 10

  
11 11

  
12 12

  
13
import java.time.ZonedDateTime;
13 14
import java.util.Collection;
14 15
import java.util.HashMap;
15 16
import java.util.Iterator;
16 17
import java.util.Map;
17 18

  
18

  
19

  
20 19
import javax.servlet.http.HttpServletRequest;
21 20
import javax.servlet.http.HttpServletResponse;
22 21
import javax.xml.transform.stream.StreamResult;
23 22

  
24 23
import org.dozer.Mapper;
25
import org.joda.time.DateTime;
26 24
import org.springframework.beans.factory.annotation.Autowired;
27 25
import org.springframework.beans.factory.annotation.Qualifier;
28 26
import org.springframework.oxm.Marshaller;
......
35 33
import eu.etaxonomy.remote.dto.rdf.Rdf;
36 34

  
37 35
/**
38
 * This class handles rdf views by mapping data objects to corresponding rdf objects, which are later 
39
 * run through a marshaller to produce xml or json 
40
 * 
36
 * This class handles rdf views by mapping data objects to corresponding rdf objects, which are later
37
 * run through a marshaller to produce xml or json
38
 *
41 39
 * @author b.clarke,c.mathew
42 40
 * @version 1.0.0
43 41
 * @created 25-Nov-2012
44 42
 */
45 43

  
46 44
public class RdfView extends AbstractView {
47
	
45

  
48 46
	//FIXME : the standard marshaller as defined in remote.xml is not used in web service views so it
49 47
	//is commented aout for the moment.
50
	
48

  
51 49
//	private Marshaller marshaller;
52
	
50

  
53 51
	private Marshaller rdfMarshaller;
54
	
52

  
55 53
	private Mapper mapper;
56
	
54

  
57 55
//	private Map<Class<? extends CdmBase>,Class<? extends BaseThing>> classMap = new HashMap<Class<? extends CdmBase>,Class<? extends BaseThing>>();
58 56
	private Map<Class<? extends RemoteResponse>,Class<? extends BaseThing>> remoteClassMap = new HashMap<Class<? extends RemoteResponse>,Class<? extends BaseThing>>();
59
	
57

  
60 58
	private Integer expiresPlus;
61
	
59

  
62 60
    public enum Type{
63 61
        RDFXML("application/rdf+xml"),
64 62
        RDFJSON("application/rdf+json");
......
84 82
    public void setType(Type type) {
85 83
        this.type = type;
86 84
    }
87
    
85

  
88 86
    /*
89 87
     * (non-Javadoc)
90 88
     * @see org.springframework.web.servlet.View#getContentType()
......
93 91
    public String getContentType() {
94 92
        return type.getContentType();
95 93
    }
96
    
94

  
97 95
	public RdfView() {
98 96
//		classMap.put(Taxon.class, TaxonConcept.class);
99 97
//		classMap.put(Synonym.class, TaxonConcept.class);
100 98
//		classMap.put(TaxonDescription.class, SpeciesProfileModel.class);
101
		
102
		remoteClassMap.put(eu.etaxonomy.cdm.remote.dto.namecatalogue.NameInformation.class, 
99

  
100
		remoteClassMap.put(eu.etaxonomy.cdm.remote.dto.namecatalogue.NameInformation.class,
103 101
				eu.etaxonomy.cdm.remote.dto.cdm.NameInformationRdf.class);
104 102
	}
105
	
103

  
106 104
//	@Autowired
107 105
//	public void setMarshaller(Marshaller marshaller) {
108 106
//		this.marshaller = marshaller;
109 107
//	}
110
	
108

  
111 109
	@Autowired
112 110
	@Qualifier("rdfMarshaller")
113 111
	public void setRdfMarshaller(Marshaller rdfMarshaller) {
114 112
		this.rdfMarshaller = rdfMarshaller;
115 113
	}
116
	
114

  
117 115
	@Autowired
118 116
	public void setMapper(Mapper mapper) {
119 117
		this.mapper = mapper;
120 118
	}
121
	
119

  
122 120
	public void setExpiresPlus(Integer expiresPlus) {
123 121
		this.expiresPlus = expiresPlus;
124 122
	}
......
127 125
	protected void renderMergedOutputModel(Map model,HttpServletRequest request, HttpServletResponse response)
128 126
			throws Exception {
129 127
		if(expiresPlus != null) {
130
		    DateTime expires = new DateTime();
131
	        response.setHeader(HTTPConstants.EXPIRES_HEADER, HTTPConstants.HTTP_DATE_FORMAT.format(expires.plusDays(expiresPlus).toDate()));
128
		    ZonedDateTime expires = ZonedDateTime.now();
129
	        response.setHeader(HTTPConstants.EXPIRES_HEADER, HTTPConstants.HTTP_DATE_FORMAT.format(expires.plusDays(expiresPlus).toLocalDate()));
132 130
	    }
133
			
131

  
134 132
		rdfMarshaller.marshal(buildRdf(model), new StreamResult(response.getOutputStream()));
135 133
	}
136
	
137
	
134

  
135

  
138 136
	public Rdf buildRdf(Map model) {
139 137
		Rdf rdf = new Rdf();
140 138
		for(Object object : model.values()) {
......
144 142
//		        if(clazz != null) {
145 143
//		          rdf.addThing((BaseThing)mapper.map(identifiableEntity, clazz));
146 144
//		        }
147
//		    } else 
145
//		    } else
148 146
		    if(object instanceof Collection) {
149 147
		    	Collection c = (Collection)object;
150 148
		    	Iterator itr = c.iterator();
151
		    	while(itr.hasNext()) {		    		
149
		    	while(itr.hasNext()) {
152 150
		    		Object obj = itr.next();
153 151
		    		Class clazz = remoteClassMap.get(obj.getClass());
154 152
		    		if(clazz != null) {
......
157 155
		    		}
158 156
		    	}
159 157
		    }
160
		} 	
158
		}
161 159
		return rdf;
162 160
	}
163 161

  

Also available in: Unified diff