You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by il...@apache.org on 2015/01/12 18:41:06 UTC

[3/7] syncope git commit: [SYNCOPE-620] server-rest-cxf

http://git-wip-us.apache.org/repos/asf/syncope/blob/8b4e52d7/syncope620/server/rest-cxf/src/main/java/org/apache/syncope/server/rest/cxf/service/WorkflowServiceImpl.java
----------------------------------------------------------------------
diff --git a/syncope620/server/rest-cxf/src/main/java/org/apache/syncope/server/rest/cxf/service/WorkflowServiceImpl.java b/syncope620/server/rest-cxf/src/main/java/org/apache/syncope/server/rest/cxf/service/WorkflowServiceImpl.java
new file mode 100644
index 0000000..2cdc0d1
--- /dev/null
+++ b/syncope620/server/rest-cxf/src/main/java/org/apache/syncope/server/rest/cxf/service/WorkflowServiceImpl.java
@@ -0,0 +1,116 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.syncope.server.rest.cxf.service;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.StreamingOutput;
+import org.apache.syncope.common.lib.types.SubjectType;
+import org.apache.syncope.common.rest.api.RESTHeaders;
+import org.apache.syncope.common.rest.api.service.WorkflowService;
+import org.apache.syncope.server.logic.WorkflowLogic;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+public class WorkflowServiceImpl extends AbstractServiceImpl implements WorkflowService {
+
+    @Autowired
+    private WorkflowLogic logic;
+
+    @Override
+    public Response getOptions(final SubjectType kind) {
+        String key;
+        String value;
+        if (kind == SubjectType.USER) {
+            key = RESTHeaders.ACTIVITI_USER_ENABLED;
+            value = "false"; //Boolean.toString(ActivitiDetector.isActivitiEnabledForUsers());
+        } else {
+            key = RESTHeaders.ACTIVITI_ROLE_ENABLED;
+            value = "false"; //Boolean.toString(ActivitiDetector.isActivitiEnabledForRoles());
+        }
+
+        Response.ResponseBuilder builder = Response.ok().header(HttpHeaders.ALLOW, OPTIONS_ALLOW);
+        if (key != null && value != null) {
+            builder.header(key, value);
+        }
+        return builder.build();
+    }
+
+    @Override
+    public Response exportDefinition(final SubjectType kind) {
+        final MediaType accept =
+                messageContext.getHttpHeaders().getAcceptableMediaTypes().contains(MediaType.APPLICATION_JSON_TYPE)
+                        ? MediaType.APPLICATION_JSON_TYPE
+                        : MediaType.APPLICATION_XML_TYPE;
+
+        StreamingOutput sout = new StreamingOutput() {
+
+            @Override
+            public void write(final OutputStream os) throws IOException {
+                if (kind == SubjectType.USER) {
+                    logic.exportUserDefinition(accept, os);
+                } else {
+                    logic.exportRoleDefinition(accept, os);
+                }
+            }
+        };
+
+        return Response.ok(sout).
+                type(accept).
+                build();
+    }
+
+    @Override
+    public Response exportDiagram(final SubjectType kind) {
+        StreamingOutput sout = new StreamingOutput() {
+
+            @Override
+            public void write(final OutputStream os) throws IOException {
+                if (kind == SubjectType.USER) {
+                    logic.exportUserDiagram(os);
+                } else {
+                    logic.exportRoleDiagram(os);
+                }
+            }
+        };
+
+        return Response.ok(sout).
+                type(RESTHeaders.MEDIATYPE_IMAGE_PNG).
+                build();
+    }
+
+    @Override
+    public void importDefinition(final SubjectType kind, final String definition) {
+        final MediaType contentType =
+                messageContext.getHttpHeaders().getMediaType().equals(MediaType.APPLICATION_JSON_TYPE)
+                        ? MediaType.APPLICATION_JSON_TYPE
+                        : MediaType.APPLICATION_XML_TYPE;
+
+        if (kind == SubjectType.USER) {
+            logic.importUserDefinition(contentType, definition);
+        } else {
+            logic.importRoleDefinition(contentType, definition);
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/syncope/blob/8b4e52d7/syncope620/server/rest-cxf/src/main/resources/restCXFContext.xml
----------------------------------------------------------------------
diff --git a/syncope620/server/rest-cxf/src/main/resources/restCXFContext.xml b/syncope620/server/rest-cxf/src/main/resources/restCXFContext.xml
new file mode 100644
index 0000000..2b6155d
--- /dev/null
+++ b/syncope620/server/rest-cxf/src/main/resources/restCXFContext.xml
@@ -0,0 +1,122 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xmlns:jaxrs="http://cxf.apache.org/jaxrs"
+       xmlns:context="http://www.springframework.org/schema/context"
+       xmlns:aop="http://www.springframework.org/schema/aop"
+       xsi:schemaLocation="http://www.springframework.org/schema/beans
+                           http://www.springframework.org/schema/beans/spring-beans.xsd
+                           http://cxf.apache.org/jaxrs
+                           http://cxf.apache.org/schemas/jaxrs.xsd
+                           http://www.springframework.org/schema/context
+                           http://www.springframework.org/schema/context/spring-context.xsd
+                           http://www.springframework.org/schema/aop 
+                           http://www.springframework.org/schema/aop/spring-aop.xsd">
+
+  <import resource="classpath:META-INF/cxf/cxf.xml"/>
+  <import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>
+
+  <context:component-scan base-package="org.apache.syncope.server.rest.cxf.service"/>  
+
+  <bean id="jaxbProvider" class="org.apache.cxf.jaxrs.provider.JAXBElementProvider">
+    <property name="namespacePrefixes">
+      <map>
+        <entry key="http://syncope.apache.org/2.0">
+          <value>syncope</value>
+        </entry>
+      </map>      
+    </property>
+    <property name="depthProperties">
+      <bean id="depthProperties" class="org.apache.cxf.staxutils.DocumentDepthProperties">
+        <property name="innerElementCountThreshold" value="500"/>
+      </bean>
+    </property>
+    <property name="collectionWrapperMap">
+      <map>
+        <entry>
+          <key>
+            <value>org.apache.syncope.common.lib.to.AbstractPolicyTO</value>
+          </key>
+          <value>policies</value>
+        </entry>
+      </map>
+    </property>
+  </bean>
+
+  <bean id="jacksonObjectMapper" class="org.apache.syncope.server.misc.serialization.UnwrappedObjectMapper"/>
+  <bean id="jsonProvider" class="com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider">
+    <property name="mapper" ref="jacksonObjectMapper"/>
+  </bean>
+
+  <bean id="exceptionMapper" class="org.apache.syncope.server.rest.cxf.service.RestServiceExceptionMapper"/>
+
+  <bean id="validationProvider" class="org.apache.cxf.validation.BeanValidationProvider"/>
+  <bean id="validationInInterceptor" class="org.apache.cxf.jaxrs.validation.JAXRSBeanValidationInInterceptor">
+    <property name="provider" ref="validationProvider"/>
+  </bean>
+  <bean id="validationOutInterceptor" class="org.apache.cxf.jaxrs.validation.JAXRSBeanValidationOutInterceptor">
+    <property name="provider" ref="validationProvider"/>
+  </bean>   
+  
+  <bean id="searchContextProvider" class="org.apache.cxf.jaxrs.ext.search.SearchContextProvider"/>
+  
+  <bean id="wadlGenerator" class="org.apache.cxf.jaxrs.model.wadl.WadlGenerator">
+    <property name="applicationTitle" value="Apache Syncope ${syncope.version}"/>
+    <property name="namespacePrefix" value="syncope"/>
+    <property name="linkJsonToXmlSchema" value="true"/>
+    <property name="useJaxbContextForQnames" value="true"/>
+    <property name="ignoreMessageWriters" value="true"/>
+    <property name="addResourceAndMethodIds" value="true"/>
+    <property name="javaDocPath" value="/WEB-INF/lib/syncope-common-${syncope.version}-javadoc.jar"/>
+  </bean>
+  
+  <bean id="addETagFilter" class="org.apache.syncope.server.rest.cxf.service.AddETagFilter"/>
+
+  <jaxrs:server id="restContainer" address="/" 
+                basePackages="org.apache.syncope.common.rest.api.service, org.apache.syncope.server.rest.cxf.service" 
+                staticSubresourceResolution="true">
+    <jaxrs:resourceComparator>
+      <bean class="org.apache.syncope.server.rest.cxf.QueryResourceInfoComparator"/>
+    </jaxrs:resourceComparator>
+    <jaxrs:properties> 
+      <entry key="search.lax.property.match" value="true"/> 
+    </jaxrs:properties> 
+    <jaxrs:inInterceptors>
+      <ref bean="validationInInterceptor"/>
+    </jaxrs:inInterceptors>         
+    <jaxrs:outInterceptors>
+      <ref bean="validationOutInterceptor"/>
+    </jaxrs:outInterceptors>
+    <jaxrs:providers>
+      <ref bean="jaxbProvider"/>
+      <ref bean="jsonProvider"/>
+      <ref bean="exceptionMapper"/>
+      <ref bean="searchContextProvider"/>
+      <ref bean="wadlGenerator"/>
+      <ref bean="addETagFilter"/>
+    </jaxrs:providers>
+    <jaxrs:extensionMappings>
+      <entry key="json" value="application/json;charset=UTF-8"/>
+      <entry key="xml" value="application/xml;charset=UTF-8"/>
+    </jaxrs:extensionMappings>
+  </jaxrs:server>
+
+</beans>