Return-Path: X-Original-To: apmail-cxf-commits-archive@www.apache.org Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id E48A710887 for ; Wed, 26 Feb 2014 20:32:43 +0000 (UTC) Received: (qmail 84046 invoked by uid 500); 26 Feb 2014 20:32:42 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 83940 invoked by uid 500); 26 Feb 2014 20:32:42 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 83933 invoked by uid 99); 26 Feb 2014 20:32:42 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 26 Feb 2014 20:32:42 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 26 Feb 2014 20:32:39 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 69FCA23888FE; Wed, 26 Feb 2014 20:32:19 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@cxf.apache.org From: owulff@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20140226203219.69FCA23888FE@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 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 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 getEntitlements(int start, int size) { + List list = new ArrayList(); + + 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 @@ + + + + + name + +
+ + + + + + +
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 @@ + + + + + + + + + + + + + + + + + + + + + + + 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 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 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"); + } + + +}