Merge "Inherit from oparent"
[vfc/nfvo/wfengine.git] / winery / org.eclipse.winery.repository / src / main / java / org / eclipse / winery / repository / resources / entitytypes / nodetypes / VisualAppearanceResource.java
1 /*******************************************************************************
2  * Copyright (c) 2012-2013 University of Stuttgart.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * and the Apache License 2.0 which both accompany this distribution,
6  * and are available at http://www.eclipse.org/legal/epl-v10.html
7  * and http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Contributors:
10  *     Oliver Kopp - initial API and implementation
11  *******************************************************************************/
12 package org.eclipse.winery.repository.resources.entitytypes.nodetypes;
13
14 import java.io.InputStream;
15 import java.util.Map;
16
17 import javax.ws.rs.Consumes;
18 import javax.ws.rs.FormParam;
19 import javax.ws.rs.GET;
20 import javax.ws.rs.HeaderParam;
21 import javax.ws.rs.PUT;
22 import javax.ws.rs.Path;
23 import javax.ws.rs.Produces;
24 import javax.ws.rs.core.MediaType;
25 import javax.ws.rs.core.Response;
26 import javax.xml.namespace.QName;
27
28 import org.eclipse.winery.common.constants.QNames;
29 import org.eclipse.winery.common.ids.definitions.NodeTypeId;
30 import org.eclipse.winery.repository.backend.BackendUtils;
31 import org.eclipse.winery.repository.backend.constants.Filename;
32 import org.eclipse.winery.repository.datatypes.ids.elements.VisualAppearanceId;
33 import org.eclipse.winery.repository.resources.GenericVisualAppearanceResource;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
36
37 import com.sun.jersey.api.view.Viewable;
38 import com.sun.jersey.multipart.FormDataBodyPart;
39 import com.sun.jersey.multipart.FormDataParam;
40
41 public class VisualAppearanceResource extends GenericVisualAppearanceResource {
42         
43         private static final Logger logger = LoggerFactory.getLogger(VisualAppearanceResource.class);
44         
45         
46         public VisualAppearanceResource(NodeTypeResource res, Map<QName, String> map, NodeTypeId parentId) {
47                 super(res, map, new VisualAppearanceId(parentId));
48         }
49         
50         @GET
51         @Produces(MediaType.TEXT_HTML)
52         public Response getHTML() {
53                 Viewable viewable = new Viewable("/jsp/entitytypes/nodetypes/visualappearance.jsp", this);
54                 return Response.ok().entity(viewable).build();
55         }
56         
57         @GET
58         @Path("50x50")
59         public Response get50x50Image(@HeaderParam("If-Modified-Since") String modified) {
60                 return this.getImage(Filename.FILENAME_BIG_ICON, modified);
61         }
62         
63         @PUT
64         @Path("50x50")
65         @Consumes(MediaType.MULTIPART_FORM_DATA)
66         public Response post50x50Image(@FormDataParam("file") InputStream uploadedInputStream, @FormDataParam("file") FormDataBodyPart body) {
67                 return this.putImage(Filename.FILENAME_BIG_ICON, uploadedInputStream, body.getMediaType());
68         }
69         
70         @GET
71         @Path("bordercolor")
72         public String getBorderColor() {
73                 return BackendUtils.getColorAndSetDefaultIfNotExisting(this.getId().getParent().getXmlId().getDecoded(), QNames.QNAME_BORDER_COLOR, this.otherAttributes, this.res);
74         }
75         
76         @PUT
77         @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
78         @Path("bordercolor")
79         public Response putBorderColor(@FormParam("color") String color) {
80                 this.otherAttributes.put(QNames.QNAME_BORDER_COLOR, color);
81                 return BackendUtils.persist(this.res);
82         }
83         
84 }