cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From owu...@apache.org
Subject svn commit: r1572238 - in /cxf/fediz/trunk/services/idp/src: main/java/org/apache/cxf/fediz/service/idp/domain/ main/java/org/apache/cxf/fediz/service/idp/service/ main/java/org/apache/cxf/fediz/service/idp/service/jpa/ main/resources/ main/resources/M...
Date Wed, 26 Feb 2014 20:32:19 GMT
Author: owulff
Date: Wed Feb 26 20:32:18 2014
New Revision: 1572238

URL: http://svn.apache.org/r1572238
Log:
Entitlements entity added

Added:
    cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/domain/Entitlement.java
    cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/EntitlementDAO.java
    cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/EntitlementDAOJPAImpl.java
    cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/EntitlementEntity.java
    cxf/fediz/trunk/services/idp/src/test/java/org/apache/cxf/fediz/service/idp/service/jpa/EntitlementDAOJPATest.java
Modified:
    cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/DBLoaderSpring.java
    cxf/fediz/trunk/services/idp/src/main/resources/META-INF/orm.xml
    cxf/fediz/trunk/services/idp/src/main/resources/entities-realma.xml

Added: cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/domain/Entitlement.java
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/domain/Entitlement.java?rev=1572238&view=auto
==============================================================================
--- cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/domain/Entitlement.java
(added)
+++ cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/domain/Entitlement.java
Wed Feb 26 20:32:18 2014
@@ -0,0 +1,68 @@
+/**
+ * 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.cxf.fediz.service.idp.domain;
+
+import java.io.Serializable;
+
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement(name = "entitlement", namespace = "http://org.apache.cxf.fediz/")
+public class Entitlement implements Serializable {
+    
+    private static final long serialVersionUID = 2635896159019665467L;
+    
+    protected String name;
+    protected String description;
+    protected int id;
+    protected boolean internal;
+    
+    @XmlAttribute
+    public int getId() {
+        return id;
+    }
+
+    public void setId(int id) {
+        this.id = id;
+    }
+    
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getDescription() {
+        return description;
+    }
+
+    public void setDescription(String description) {
+        this.description = description;
+    }
+
+    public boolean isInternal() {
+        return internal;
+    }
+
+    public void setInternal(boolean internal) {
+        this.internal = internal;
+    }
+}

Added: cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/EntitlementDAO.java
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/EntitlementDAO.java?rev=1572238&view=auto
==============================================================================
--- cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/EntitlementDAO.java
(added)
+++ cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/EntitlementDAO.java
Wed Feb 26 20:32:18 2014
@@ -0,0 +1,38 @@
+/**
+ * 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.cxf.fediz.service.idp.service;
+
+import java.util.List;
+
+import org.apache.cxf.fediz.service.idp.domain.Entitlement;
+
+public interface EntitlementDAO {
+
+    List<Entitlement> getEntitlements(int start, int size);
+    
+    Entitlement getEntitlement(String name);
+    
+    Entitlement addEntitlement(Entitlement entitlement);
+    
+    void updateEntitlement(String name, Entitlement entitlement);
+    
+    void deleteEntitlement(String name);
+
+}

Modified: cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/DBLoaderSpring.java
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/DBLoaderSpring.java?rev=1572238&r1=1572237&r2=1572238&view=diff
==============================================================================
--- cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/DBLoaderSpring.java
(original)
+++ cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/DBLoaderSpring.java
Wed Feb 26 20:32:18 2014
@@ -71,6 +71,12 @@ public class DBLoaderSpring implements D
             ctx.refresh();
             ctx.start();
             
+            Collection<EntitlementEntity> entitlements = ctx.
+                getBeansOfType(EntitlementEntity.class, true, true).values();
+            for (EntitlementEntity e : entitlements) {
+                em.persist(e);
+            }
+            LOG.info(entitlements.size() + " EntitlementEntity added");
             
             LOG.info("" + ctx.getBeanDefinitionCount());
             LOG.info(ctx.getBeanDefinitionNames().toString());

Added: cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/EntitlementDAOJPAImpl.java
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/EntitlementDAOJPAImpl.java?rev=1572238&view=auto
==============================================================================
--- cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/EntitlementDAOJPAImpl.java
(added)
+++ cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/EntitlementDAOJPAImpl.java
Wed Feb 26 20:32:18 2014
@@ -0,0 +1,148 @@
+/**
+ * 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.cxf.fediz.service.idp.service.jpa;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import javax.persistence.Query;
+
+import org.apache.cxf.fediz.service.idp.domain.Entitlement;
+import org.apache.cxf.fediz.service.idp.service.EntitlementDAO;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Repository;
+import org.springframework.transaction.annotation.Transactional;
+
+
+@Repository
+@Transactional
+public class EntitlementDAOJPAImpl implements EntitlementDAO {
+    
+    private static final Logger LOG = LoggerFactory.getLogger(EntitlementDAOJPAImpl.class);
+
+    private EntityManager em;
+    
+    @PersistenceContext
+    public void setEntityManager(EntityManager entityManager) {
+        this.em = entityManager;
+    }
+    
+    @Override
+    public List<Entitlement> getEntitlements(int start, int size) {
+        List<Entitlement> list = new ArrayList<Entitlement>();
+        
+        Query query = null;
+        query = em.createQuery("select e from Entitlement e");
+        
+        //@SuppressWarnings("rawtypes")
+        List entitlementEntities = query
+            .setFirstResult(start)
+            .setMaxResults(size)
+            .getResultList();
+
+        for (Object obj : entitlementEntities) {
+            EntitlementEntity entity = (EntitlementEntity) obj;
+            list.add(entity2domain(entity));
+        }
+        
+        return list;
+    }
+    
+    @Override
+    public Entitlement addEntitlement(Entitlement entitlement) {
+        EntitlementEntity entity = new EntitlementEntity();
+        domain2entity(entitlement, entity);
+        em.persist(entity);
+        
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Entitlement '" + entitlement.getName() + "' added");
+        }
+        return entity2domain(entity);
+    }
+
+    @Override
+    public Entitlement getEntitlement(String name) {
+        return entity2domain(getEntitlementEntity(name, em));
+    }
+
+    @Override
+    public void updateEntitlement(String name, Entitlement entitlement) {
+        Query query = null;
+        query = em.createQuery("select e from Entitlement e where e.name=:name");
+        query.setParameter("name", name);
+        
+        //@SuppressWarnings("rawtypes")
+        EntitlementEntity entitlementEntity = (EntitlementEntity)query.getSingleResult();
+        
+        domain2entity(entitlement, entitlementEntity);
+        
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Entitlement '" + entitlement.getName() + "' added");
+        }
+        em.persist(entitlementEntity);
+    }
+
+    @Override
+    public void deleteEntitlement(String name) {
+        Query query = null;
+        query = em.createQuery("select e from Entitlement e where e.name=:name");
+        query.setParameter("name", name);
+        
+        //@SuppressWarnings("rawtypes")
+        Object entitlementObj = query.getSingleResult();
+        em.remove(entitlementObj);
+        
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Entitlement '" + name + "' deleted");
+        }
+    }
+    
+    static EntitlementEntity getEntitlementEntity(String name, EntityManager em) {
+        Query query = null;
+        query = em.createQuery("select e from Entitlement e where e.name=:name");
+        query.setParameter("name", name);
+        
+        //@SuppressWarnings("rawtypes")
+        return (EntitlementEntity)query.getSingleResult();
+    }
+    
+    public static void domain2entity(Entitlement entitlement, EntitlementEntity entity) {
+        //The ID must not be updated if the entity has got an id already (update case)
+        if (entitlement.getId() > 0) {
+            entity.setId(entitlement.getId());
+        }
+        //property 'internal' can't be changed, default is false
+        entity.setName(entitlement.getName());
+        entity.setDescription(entitlement.getDescription());
+    }
+    
+    public static Entitlement entity2domain(EntitlementEntity entity) {
+        Entitlement entitlement = new Entitlement();
+        entitlement.setId(entity.getId());
+        entitlement.setName(entity.getName());
+        entitlement.setDescription(entity.getDescription());
+        entitlement.setInternal(entity.isInternal());
+        return entitlement;
+    }
+
+}

Added: cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/EntitlementEntity.java
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/EntitlementEntity.java?rev=1572238&view=auto
==============================================================================
--- cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/EntitlementEntity.java
(added)
+++ cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/service/jpa/EntitlementEntity.java
Wed Feb 26 20:32:18 2014
@@ -0,0 +1,72 @@
+/**
+ * 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.cxf.fediz.service.idp.service.jpa;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+
+import org.apache.openjpa.persistence.jdbc.Index;
+
+@Entity(name = "Entitlement")
+public class EntitlementEntity {
+    
+    @Id
+    private int id;
+    
+    @Index
+    private String name;
+    
+    private String description;
+    
+    //Internal entities can't be updated, changed and deleted
+    //Default: false
+    private boolean internal;
+        
+    public int getId() {
+        return id;
+    }
+
+    public void setId(int id) {
+        this.id = id;
+    }
+    
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getDescription() {
+        return description;
+    }
+
+    public void setDescription(String description) {
+        this.description = description;
+    }
+
+    public boolean isInternal() {
+        return internal;
+    }
+
+    public void setInternal(boolean internal) {
+        this.internal = internal;
+    }
+}

Modified: cxf/fediz/trunk/services/idp/src/main/resources/META-INF/orm.xml
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/services/idp/src/main/resources/META-INF/orm.xml?rev=1572238&r1=1572237&r2=1572238&view=diff
==============================================================================
--- cxf/fediz/trunk/services/idp/src/main/resources/META-INF/orm.xml (original)
+++ cxf/fediz/trunk/services/idp/src/main/resources/META-INF/orm.xml Wed Feb 26 20:32:18 2014
@@ -137,4 +137,20 @@
             </id>
         </attributes>
     </entity>
+    
+    <entity class="org.apache.cxf.fediz.service.idp.service.jpa.EntitlementEntity">
+        <table>
+            <unique-constraint>
+                <column-name>name</column-name>
+            </unique-constraint>
+        </table>
+        <attributes>
+            <id name="id">
+                <generated-value generator="SEQ_Entitlement"
+                    strategy="TABLE" />
+                <table-generator name="SEQ_Entitlement"
+                    pk-column-value="SEQ_Entitlement" initial-value="100" />
+            </id>
+        </attributes>
+    </entity>
 </entity-mappings>

Modified: cxf/fediz/trunk/services/idp/src/main/resources/entities-realma.xml
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/services/idp/src/main/resources/entities-realma.xml?rev=1572238&r1=1572237&r2=1572238&view=diff
==============================================================================
--- cxf/fediz/trunk/services/idp/src/main/resources/entities-realma.xml (original)
+++ cxf/fediz/trunk/services/idp/src/main/resources/entities-realma.xml Wed Feb 26 20:32:18
2014
@@ -156,6 +156,44 @@
         <property name="description"
             value="Description for email" />
     </bean>
+    
+    
+    <bean id="entitlement_claim_list"
+        class="org.apache.cxf.fediz.service.idp.service.jpa.EntitlementEntity">
+        <property name="name"
+            value="CLAIM_LIST" />
+        <property name="description"
+            value="Description for CLAIM_LIST" />
+    </bean>
+    <bean id="entitlement_claim_create"
+        class="org.apache.cxf.fediz.service.idp.service.jpa.EntitlementEntity">
+        <property name="name"
+            value="CLAIM_CREATE" />
+        <property name="description"
+            value="Description for CLAIM_CREATE" />
+    </bean>
+    <bean id="entitlement_claim_read"
+        class="org.apache.cxf.fediz.service.idp.service.jpa.EntitlementEntity">
+        <property name="name"
+            value="CLAIM_READ" />
+        <property name="description"
+            value="Description for CLAIM_READ" />
+    </bean>
+    <bean id="entitlement_claim_update"
+        class="org.apache.cxf.fediz.service.idp.service.jpa.EntitlementEntity">
+        <property name="name"
+            value="CLAIM_UPDATE" />
+        <property name="description"
+            value="Description for CLAIM_UPDATE" />
+    </bean>
+    <bean id="entitlement_claim_delete"
+        class="org.apache.cxf.fediz.service.idp.service.jpa.EntitlementEntity">
+        <property name="name"
+            value="CLAIM_DELETE" />
+        <property name="description"
+            value="Description for CLAIM_DELETE" />
+    </bean>
+
 
 </beans>
 

Added: cxf/fediz/trunk/services/idp/src/test/java/org/apache/cxf/fediz/service/idp/service/jpa/EntitlementDAOJPATest.java
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/services/idp/src/test/java/org/apache/cxf/fediz/service/idp/service/jpa/EntitlementDAOJPATest.java?rev=1572238&view=auto
==============================================================================
--- cxf/fediz/trunk/services/idp/src/test/java/org/apache/cxf/fediz/service/idp/service/jpa/EntitlementDAOJPATest.java
(added)
+++ cxf/fediz/trunk/services/idp/src/test/java/org/apache/cxf/fediz/service/idp/service/jpa/EntitlementDAOJPATest.java
Wed Feb 26 20:32:18 2014
@@ -0,0 +1,115 @@
+/**
+ * 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.cxf.fediz.service.idp.service.jpa;
+
+import java.util.List;
+
+import org.apache.cxf.fediz.service.idp.domain.Entitlement;
+import org.apache.cxf.fediz.service.idp.service.EntitlementDAO;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.dao.DataIntegrityViolationException;
+import org.springframework.dao.EmptyResultDataAccessException;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.util.Assert;
+
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations = { "classpath:testContext.xml" })
+public class EntitlementDAOJPATest {
+
+    @Autowired
+    private EntitlementDAO entitlementDAO;
+    
+    
+    @BeforeClass
+    public static void init() {
+        System.setProperty("spring.profiles.active", "jpa");
+    }
+    
+    
+    @Test
+    public void testReadAllEntitlements() {
+        List<Entitlement> entitlements = entitlementDAO.getEntitlements(0, 999);
+        Assert.isTrue(5 == entitlements.size(), "Size doesn't match");
+    }
+    
+    @Test
+    public void testReadExistingEntitlement() {
+        Entitlement entitlement = entitlementDAO.getEntitlement("CLAIM_LIST");
+        Assert.isTrue("CLAIM_LIST".equals(entitlement.getName()),
+                      "Entitlement name doesn't match");
+        Assert.isTrue("Description for CLAIM_LIST".equals(entitlement.getDescription()),
+                      "Entitlement Description doesn't match");
+    }
+    
+    
+    @Test(expected = EmptyResultDataAccessException.class)
+    public void testTryReadNonexistingEntitlement() {
+        entitlementDAO.getEntitlement("CLAIM_NOT_EXIST");
+    }
+    
+    
+    @Test
+    public void testAddNewEntitlement() {
+        Entitlement entitlement5 = new Entitlement();
+        entitlement5.setName("GUGUS_CREATE");
+        entitlement5.setDescription("Any entitlement");
+        entitlementDAO.addEntitlement(entitlement5);
+        
+        List<Entitlement> entitlements = entitlementDAO.getEntitlements(0, 999);
+        Assert.isTrue(6 == entitlements.size(), "Size doesn't match. Entitlement not added");
+    }
+    
+    
+    @Test(expected = DataIntegrityViolationException.class)
+    public void testTryAddExistingEntitlement() {
+        Entitlement entitlement5 = new Entitlement();
+        entitlement5.setName("CLAIM_DELETE");
+        entitlement5.setDescription("Description for CLAIM_DELETE");
+        entitlementDAO.addEntitlement(entitlement5);
+    }
+    
+    
+    @Test(expected = EmptyResultDataAccessException.class)
+    public void testTryRemoveUnknownEntitlement() {
+        entitlementDAO.deleteEntitlement("GUGUS_NOT_EXIST");
+    }
+    
+    
+    @Test(expected = EmptyResultDataAccessException.class)
+    public void testRemoveExistingEntitlement() {
+        
+        Entitlement entitlement5 = new Entitlement();
+        entitlement5.setName("CLAIM_TO_DELETE");
+        entitlement5.setDescription("Description for CLAIM_TO_DELETE");
+        entitlementDAO.addEntitlement(entitlement5);
+        
+        entitlementDAO.deleteEntitlement("CLAIM_TO_DELETE");
+        
+        entitlementDAO.getEntitlement("CLAIM_TO_DELETE");
+    }
+    
+
+}



Mime
View raw message