
org.xlcloud.console.entitlements.CompositeEntitlementDictionary Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2012 AMG.lab, a Bull Group Company
*
* Licensed 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.xlcloud.console.entitlements;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.Predicate;
import org.xlcloud.console.context.EntitlementEngine;
import org.xlcloud.console.context.IdentityContext;
import org.xlcloud.console.entitlements.scope.predicates.EntitlementDictionaryPredicate;
import org.xlcloud.service.AccessToken;
import org.xlcloud.service.Group;
import org.xlcloud.service.User;
/**
* Representation of the composite entitlement dictionary.
* Composite dictionary contains a list of other child dictionaries.
*
* @author Konrad Król, AMG.net
*/
public class CompositeEntitlementDictionary extends AbstractEntitlementDictionary {
private List includedEntitlementDictionaries = new ArrayList();
public CompositeEntitlementDictionary(Long id, String description, CompositeEntitlementDictionary parent) {
super(id, description, parent);
}
public CompositeEntitlementDictionary(Long id, String description) {
super(id, description);
}
/**
* Adds a new dictionary to the list of children dictionaries.
* @param entitlementDictionary entitlement dictionary
*/
public void addIncludedEntitlementDictionary(EntitlementDictionary entitlementDictionary) {
includedEntitlementDictionaries.add(entitlementDictionary);
}
/**
* @return included dictionaries that are children of this dictionary
*/
public List getIncludedEntitlementDictionaries() {
return includedEntitlementDictionaries;
}
/** {@inheritDoc} */
@Override
public boolean availableFor(final EntitlementEngine entitlementEngine, final IdentityContext identityContext, final EntitlementDictionaryPredicate predicate) {
return anyOfIncludedEntitlementDictionaries(new Predicate() {
@Override
public boolean evaluate(Object object) {
return ((EntitlementDictionary) object).availableFor(entitlementEngine, identityContext, predicate);
}
});
}
/** {@inheritDoc} */
@Override
public boolean isOwnedBy(final User user, final EntitlementEngine entitlementEngine) {
return anyOfIncludedEntitlementDictionaries(new Predicate() {
@Override
public boolean evaluate(Object object) {
return ((EntitlementDictionary) object).isOwnedBy(user, entitlementEngine);
}
});
}
/** {@inheritDoc} */
@Override
public boolean isOwnedBy(final Group group, final EntitlementEngine entitlementEngine) {
return anyOfIncludedEntitlementDictionaries(new Predicate() {
@Override
public boolean evaluate(Object object) {
return ((EntitlementDictionary) object).isOwnedBy(group, entitlementEngine);
}
});
}
/** {@inheritDoc} */
@Override
public boolean isOwnedBy(final AccessToken accessToken, final User accessTokenUser, final EntitlementEngine entitlementEngine) {
return anyOfIncludedEntitlementDictionaries(new Predicate() {
@Override
public boolean evaluate(Object object) {
return ((EntitlementDictionary) object).isOwnedBy(accessToken, accessTokenUser, entitlementEngine);
}
});
}
private boolean anyOfIncludedEntitlementDictionaries(Predicate predicate) {
return CollectionUtils.exists(includedEntitlementDictionaries, predicate);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy