use of com.evolveum.midpoint.xml.ns._public.common.common_3.AttributeFetchStrategyType in project midpoint by Evolveum.
the class ProvisioningUtil method createAttributesToReturn.
public static AttributesToReturn createAttributesToReturn(ProvisioningContext ctx) throws SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException, ExpressionEvaluationException {
RefinedObjectClassDefinition objectClassDefinition = ctx.getObjectClassDefinition();
ResourceType resource = ctx.getResource();
boolean apply = false;
AttributesToReturn attributesToReturn = new AttributesToReturn();
// Attributes
boolean hasMinimal = false;
for (RefinedAttributeDefinition attributeDefinition : objectClassDefinition.getAttributeDefinitions()) {
if (attributeDefinition.getFetchStrategy() == AttributeFetchStrategyType.MINIMAL) {
hasMinimal = true;
break;
}
}
attributesToReturn.setReturnDefaultAttributes(!hasMinimal);
Collection<ResourceAttributeDefinition> explicit = new ArrayList<ResourceAttributeDefinition>();
for (RefinedAttributeDefinition attributeDefinition : objectClassDefinition.getAttributeDefinitions()) {
AttributeFetchStrategyType fetchStrategy = attributeDefinition.getFetchStrategy();
if (fetchStrategy != null && fetchStrategy == AttributeFetchStrategyType.EXPLICIT) {
explicit.add(attributeDefinition);
} else if (hasMinimal && fetchStrategy != AttributeFetchStrategyType.MINIMAL) {
explicit.add(attributeDefinition);
}
}
if (!explicit.isEmpty()) {
attributesToReturn.setAttributesToReturn(explicit);
apply = true;
}
// Password
CredentialsCapabilityType credentialsCapabilityType = ResourceTypeUtil.getEffectiveCapability(resource, CredentialsCapabilityType.class);
if (credentialsCapabilityType != null) {
if (SelectorOptions.hasToLoadPath(SchemaConstants.PATH_PASSWORD_VALUE, ctx.getGetOperationOptions())) {
attributesToReturn.setReturnPasswordExplicit(true);
apply = true;
} else {
if (!CapabilityUtil.isPasswordReturnedByDefault(credentialsCapabilityType)) {
// There resource is capable of returning password but it does not
// do it by default
AttributeFetchStrategyType passwordFetchStrategy = objectClassDefinition.getPasswordFetchStrategy();
if (passwordFetchStrategy == AttributeFetchStrategyType.EXPLICIT) {
attributesToReturn.setReturnPasswordExplicit(true);
apply = true;
}
}
}
}
// Activation
ActivationCapabilityType activationCapabilityType = ResourceTypeUtil.getEffectiveCapability(resource, ActivationCapabilityType.class);
if (activationCapabilityType != null) {
if (CapabilityUtil.isCapabilityEnabled(activationCapabilityType.getStatus())) {
if (!CapabilityUtil.isActivationStatusReturnedByDefault(activationCapabilityType)) {
// not do it by default
if (SelectorOptions.hasToLoadPath(SchemaConstants.PATH_ACTIVATION_ADMINISTRATIVE_STATUS, ctx.getGetOperationOptions())) {
attributesToReturn.setReturnAdministrativeStatusExplicit(true);
apply = true;
} else {
AttributeFetchStrategyType administrativeStatusFetchStrategy = objectClassDefinition.getActivationFetchStrategy(ActivationType.F_ADMINISTRATIVE_STATUS);
if (administrativeStatusFetchStrategy == AttributeFetchStrategyType.EXPLICIT) {
attributesToReturn.setReturnAdministrativeStatusExplicit(true);
apply = true;
}
}
}
}
if (CapabilityUtil.isCapabilityEnabled(activationCapabilityType.getValidFrom())) {
if (!CapabilityUtil.isActivationValidFromReturnedByDefault(activationCapabilityType)) {
if (SelectorOptions.hasToLoadPath(SchemaConstants.PATH_ACTIVATION_VALID_FROM, ctx.getGetOperationOptions())) {
attributesToReturn.setReturnValidFromExplicit(true);
apply = true;
} else {
AttributeFetchStrategyType administrativeStatusFetchStrategy = objectClassDefinition.getActivationFetchStrategy(ActivationType.F_VALID_FROM);
if (administrativeStatusFetchStrategy == AttributeFetchStrategyType.EXPLICIT) {
attributesToReturn.setReturnValidFromExplicit(true);
apply = true;
}
}
}
}
if (CapabilityUtil.isCapabilityEnabled(activationCapabilityType.getValidTo())) {
if (!CapabilityUtil.isActivationValidToReturnedByDefault(activationCapabilityType)) {
if (SelectorOptions.hasToLoadPath(SchemaConstants.PATH_ACTIVATION_VALID_TO, ctx.getGetOperationOptions())) {
attributesToReturn.setReturnValidToExplicit(true);
apply = true;
} else {
AttributeFetchStrategyType administrativeStatusFetchStrategy = objectClassDefinition.getActivationFetchStrategy(ActivationType.F_VALID_TO);
if (administrativeStatusFetchStrategy == AttributeFetchStrategyType.EXPLICIT) {
attributesToReturn.setReturnValidToExplicit(true);
apply = true;
}
}
}
}
if (CapabilityUtil.isCapabilityEnabled(activationCapabilityType.getLockoutStatus())) {
if (!CapabilityUtil.isActivationLockoutStatusReturnedByDefault(activationCapabilityType)) {
// not do it by default
if (SelectorOptions.hasToLoadPath(SchemaConstants.PATH_ACTIVATION_LOCKOUT_STATUS, ctx.getGetOperationOptions())) {
attributesToReturn.setReturnAdministrativeStatusExplicit(true);
apply = true;
} else {
AttributeFetchStrategyType statusFetchStrategy = objectClassDefinition.getActivationFetchStrategy(ActivationType.F_LOCKOUT_STATUS);
if (statusFetchStrategy == AttributeFetchStrategyType.EXPLICIT) {
attributesToReturn.setReturnLockoutStatusExplicit(true);
apply = true;
}
}
}
}
}
if (apply) {
return attributesToReturn;
} else {
return null;
}
}
Aggregations