Return-Path: X-Original-To: apmail-syncope-commits-archive@www.apache.org Delivered-To: apmail-syncope-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 AB924E746 for ; Tue, 4 Dec 2012 08:55:47 +0000 (UTC) Received: (qmail 5971 invoked by uid 500); 4 Dec 2012 08:55:46 -0000 Delivered-To: apmail-syncope-commits-archive@syncope.apache.org Received: (qmail 3419 invoked by uid 500); 4 Dec 2012 08:55:42 -0000 Mailing-List: contact commits-help@syncope.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@syncope.apache.org Delivered-To: mailing list commits@syncope.apache.org Received: (qmail 2582 invoked by uid 99); 4 Dec 2012 08:55:40 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 04 Dec 2012 08:55:40 +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; Tue, 04 Dec 2012 08:55:37 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 2D8F12388AB9; Tue, 4 Dec 2012 08:55:16 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1416823 [2/2] - in /syncope/branches/cxf/common: ./ src/main/java/org/apache/syncope/ src/main/java/org/apache/syncope/annotation/ src/main/java/org/apache/syncope/controller/ src/main/java/org/apache/syncope/exceptions/ src/main/java/org/... Date: Tue, 04 Dec 2012 08:55:11 -0000 To: commits@syncope.apache.org From: jbernhardt@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20121204085516.2D8F12388AB9@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Modified: syncope/branches/cxf/common/src/main/java/org/apache/syncope/util/AttributableOperations.java URL: http://svn.apache.org/viewvc/syncope/branches/cxf/common/src/main/java/org/apache/syncope/util/AttributableOperations.java?rev=1416823&r1=1416822&r2=1416823&view=diff ============================================================================== --- syncope/branches/cxf/common/src/main/java/org/apache/syncope/util/AttributableOperations.java (original) +++ syncope/branches/cxf/common/src/main/java/org/apache/syncope/util/AttributableOperations.java Tue Dec 4 08:55:06 2012 @@ -25,6 +25,7 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; + import org.apache.commons.lang.SerializationUtils; import org.apache.syncope.mod.AbstractAttributableMod; import org.apache.syncope.mod.AttributeMod; @@ -39,7 +40,8 @@ import org.apache.syncope.to.RoleTO; import org.apache.syncope.to.UserTO; /** - * Utility class for manipulating classes extending AbstractAttributableTO and AbstractAttributableMod. + * Utility class for manipulating classes extending AbstractAttributableTO and + * AbstractAttributableMod. * * @see AbstractAttributableTO * @see AbstractAttributableMod @@ -49,6 +51,7 @@ public final class AttributableOperation private AttributableOperations() { } + @SuppressWarnings("unchecked") public static T clone(final T original) { return (T) SerializationUtils.clone(original); } @@ -59,7 +62,8 @@ public final class AttributableOperation } private static void populate(final Map updatedAttrs, - final Map originalAttrs, final AbstractAttributableMod result, final boolean virtuals) { + final Map originalAttrs, final AbstractAttributableMod result, + final boolean virtuals) { for (Map.Entry entry : updatedAttrs.entrySet()) { AttributeMod mod = new AttributeMod(); @@ -99,11 +103,8 @@ public final class AttributableOperation } } - private static void diff( - final AbstractAttributableTO updated, - final AbstractAttributableTO original, - final AbstractAttributableMod result, - final boolean incremental) { + private static void diff(final AbstractAttributableTO updated, final AbstractAttributableTO original, + final AbstractAttributableMod result, final boolean incremental) { // 1. check same id if (updated.getId() != original.getId()) { @@ -181,8 +182,10 @@ public final class AttributableOperation /** * Calculate modifications needed by first in order to be equal to second. * - * @param updated updated UserTO - * @param original original UserTO + * @param updated + * updated UserTO + * @param original + * original UserTO * @return UserMod containing differences */ public static UserMod diff(final UserTO updated, final UserTO original) { @@ -192,9 +195,12 @@ public final class AttributableOperation /** * Calculate modifications needed by first in order to be equal to second. * - * @param updated updated UserTO - * @param original original UserTO - * @param incremental perform incremental diff (without removing existing info) + * @param updated + * updated UserTO + * @param original + * original UserTO + * @param incremental + * perform incremental diff (without removing existing info) * @return UserMod containing differences */ public static UserMod diff(final UserTO updated, final UserTO original, boolean incremental) { @@ -273,8 +279,10 @@ public final class AttributableOperation /** * Calculate modifications needed by first in order to be equal to second. * - * @param updated updated RoleTO - * @param original original RoleTO + * @param updated + * updated RoleTO + * @param original + * original RoleTO * @return RoleMod containing differences */ public static RoleMod diff(final RoleTO updated, final RoleTO original) { @@ -300,13 +308,13 @@ public final class AttributableOperation } // 4. entitlements - Set updatedEnts = new HashSet(updated.getEntitlements()); - Set originalEnts = new HashSet(original.getEntitlements()); - if (updatedEnts.equals(originalEnts)) { - result.setEntitlements(null); - } else { - result.setEntitlements(updated.getEntitlements()); - } + Set updatedEnts = new HashSet(updated.getEntitlementList()); + Set originalEnts = new HashSet(original.getEntitlementList()); + originalEnts.removeAll(updatedEnts); + result.setEntitlementsToBeRemoved(originalEnts); + originalEnts = new HashSet(original.getEntitlementList()); + updatedEnts.removeAll(originalEnts); + result.setEntitlementsToBeAdded(updatedEnts); // 5. owner result.setUserOwner(new ReferenceMod(updated.getUserOwner())); @@ -338,8 +346,8 @@ public final class AttributableOperation return new ArrayList(attrs.values()); } - private static void apply(final T to, - final K mod, final T result) { + private static void apply( + final T to, final K mod, final T result) { // 1. check same id if (to.getId() != mod.getId()) { @@ -347,8 +355,8 @@ public final class AttributableOperation } // 2. attributes - result.setAttributes(getUpdateValues(to.getAttributeMap(), mod.getAttributesToBeRemoved(), mod. - getAttributesToBeUpdated())); + result.setAttributes(getUpdateValues(to.getAttributeMap(), mod.getAttributesToBeRemoved(), + mod.getAttributesToBeUpdated())); // 3. derived attributes Map attrs = to.getDerivedAttributeMap(); @@ -364,8 +372,8 @@ public final class AttributableOperation result.setDerivedAttributes(new ArrayList(attrs.values())); // 4. virtual attributes - result.setVirtualAttributes(getUpdateValues(to.getVirtualAttributeMap(), mod.getVirtualAttributesToBeRemoved(), - mod.getVirtualAttributesToBeUpdated())); + result.setVirtualAttributes(getUpdateValues(to.getVirtualAttributeMap(), + mod.getVirtualAttributesToBeRemoved(), mod.getVirtualAttributesToBeUpdated())); // 5. resources result.getResources().removeAll(mod.getResourcesToBeRemoved()); Added: syncope/branches/cxf/common/src/main/java/org/apache/syncope/validation/InvalidEntityException.java URL: http://svn.apache.org/viewvc/syncope/branches/cxf/common/src/main/java/org/apache/syncope/validation/InvalidEntityException.java?rev=1416823&view=auto ============================================================================== --- syncope/branches/cxf/common/src/main/java/org/apache/syncope/validation/InvalidEntityException.java (added) +++ syncope/branches/cxf/common/src/main/java/org/apache/syncope/validation/InvalidEntityException.java Tue Dec 4 08:55:06 2012 @@ -0,0 +1,92 @@ +/* + * 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.validation; + +import java.util.EnumSet; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import javax.validation.ConstraintViolation; +import javax.validation.ValidationException; +import org.apache.syncope.types.EntityViolationType; + +public class InvalidEntityException extends ValidationException { + + private static final long serialVersionUID = 3249297275444409691L; + + private String entityClassSimpleName; + + private final Map> violations; + + public InvalidEntityException(final String entityClassSimpleName, final Set> violations) { + + super(); + + this.entityClassSimpleName = entityClassSimpleName; + + this.violations = new HashMap>(); + EntityViolationType entityViolationType; + for (ConstraintViolation violation : violations) { + try { + entityViolationType = EntityViolationType.valueOf(violation.getMessageTemplate()); + } catch (IllegalArgumentException e) { + entityViolationType = EntityViolationType.Standard; + entityViolationType.setMessageTemplate(violation.getPropertyPath() + ": " + violation.getMessage()); + } + + if (!this.violations.containsKey(violation.getLeafBean().getClass())) { + + this.violations.put(violation.getLeafBean().getClass(), EnumSet.noneOf(EntityViolationType.class)); + } + + this.violations.get(violation.getLeafBean().getClass()).add(entityViolationType); + } + } + + public final boolean hasViolation(final EntityViolationType type) { + boolean found = false; + for (Class entity : violations.keySet()) { + if (violations.get(entity).contains(type)) { + found = true; + } + } + + return found; + } + + public String getEntityClassSimpleName() { + return entityClassSimpleName; + } + + public final Map> getViolations() { + return violations; + } + + @Override + public String getMessage() { + StringBuilder sb = new StringBuilder(); + + for (Class entity : violations.keySet()) { + sb.append(entity.getSimpleName()).append(" ").append(violations.get(entity).toString()).append(", "); + } + sb.delete(sb.lastIndexOf(", "), sb.length()); + + return sb.toString(); + } +}