use of com.evolveum.midpoint.prism.PrismProperty in project midpoint by Evolveum.
the class ShadowIntegrityCheckResultHandler method checkOrFixActivationItem.
private void checkOrFixActivationItem(ShadowCheckResult checkResult, PrismObject<ShadowType> shadow, PrismContainerValue<ActivationType> activation, QName itemName) {
PrismProperty property = activation.findProperty(new ItemPath(itemName));
if (property == null || property.isEmpty()) {
return;
}
checkResult.recordWarning(Statistics.EXTRA_ACTIVATION_DATA, "Unexpected activation item: " + property);
if (fixExtraData) {
PropertyDelta delta = PropertyDelta.createReplaceEmptyDelta(shadow.getDefinition(), new ItemPath(ShadowType.F_ACTIVATION, itemName));
checkResult.addFixDelta(delta, Statistics.EXTRA_ACTIVATION_DATA);
}
}
use of com.evolveum.midpoint.prism.PrismProperty in project midpoint by Evolveum.
the class ShadowManager method updateShadow.
/**
* Updates repository shadow based on shadow from resource. Handles rename cases,
* change of auxiliary object classes, etc.
* @returns repository shadow as it should look like after the update
*/
@SuppressWarnings("unchecked")
public PrismObject<ShadowType> updateShadow(ProvisioningContext ctx, PrismObject<ShadowType> currentResourceShadow, PrismObject<ShadowType> oldRepoShadow, OperationResult parentResult) throws SchemaException, ObjectNotFoundException, ObjectAlreadyExistsException, ConfigurationException, CommunicationException, ExpressionEvaluationException {
RefinedObjectClassDefinition ocDef = ctx.computeCompositeObjectClassDefinition(currentResourceShadow);
ObjectDelta<ShadowType> shadowDelta = oldRepoShadow.createModifyDelta();
PrismContainer<Containerable> currentResourceAttributesContainer = currentResourceShadow.findContainer(ShadowType.F_ATTRIBUTES);
PrismContainer<Containerable> oldRepoAttributesContainer = oldRepoShadow.findContainer(ShadowType.F_ATTRIBUTES);
ShadowType oldRepoShadowType = oldRepoShadow.asObjectable();
ShadowType currentResourceShadowType = currentResourceShadow.asObjectable();
if (oldRepoShadowType.isExists() != currentResourceShadowType.isExists()) {
// Resource object obviously exists when we have got here
shadowDelta.addModificationReplaceProperty(ShadowType.F_EXISTS, currentResourceShadowType.isExists());
}
CachingStategyType cachingStrategy = ProvisioningUtil.getCachingStrategy(ctx);
for (Item<?, ?> currentResourceItem : currentResourceAttributesContainer.getValue().getItems()) {
if (currentResourceItem instanceof PrismProperty<?>) {
PrismProperty<?> currentResourceAttrProperty = (PrismProperty<?>) currentResourceItem;
RefinedAttributeDefinition<Object> attrDef = ocDef.findAttributeDefinition(currentResourceAttrProperty.getElementName());
if (ProvisioningUtil.shouldStoreAtributeInShadow(ocDef, attrDef.getName(), cachingStrategy)) {
MatchingRule matchingRule = matchingRuleRegistry.getMatchingRule(attrDef.getMatchingRuleQName(), attrDef.getTypeName());
PrismProperty<Object> oldRepoAttributeProperty = oldRepoAttributesContainer.findProperty(currentResourceAttrProperty.getElementName());
if (oldRepoAttributeProperty == null) {
PropertyDelta<?> attrAddDelta = currentResourceAttrProperty.createDelta();
for (PrismPropertyValue pval : currentResourceAttrProperty.getValues()) {
Object normalizedRealValue;
if (matchingRule == null) {
normalizedRealValue = pval.getValue();
} else {
normalizedRealValue = matchingRule.normalize(pval.getValue());
}
attrAddDelta.addValueToAdd(new PrismPropertyValue(normalizedRealValue));
LOGGER.trace("CURRENT ATTR:\n{}\nATTR DELTA:\n{}", currentResourceAttrProperty.debugDump(1), attrAddDelta.debugDump(1));
}
shadowDelta.addModification(attrAddDelta);
} else {
if (attrDef.isSingleValue()) {
Object currentResourceRealValue = currentResourceAttrProperty.getRealValue();
Object currentResourceNormalizedRealValue;
if (matchingRule == null) {
currentResourceNormalizedRealValue = currentResourceRealValue;
} else {
currentResourceNormalizedRealValue = matchingRule.normalize(currentResourceRealValue);
}
if (!currentResourceNormalizedRealValue.equals(oldRepoAttributeProperty.getRealValue())) {
LOGGER.trace("CURRENT ATTR:\n{}\ncurrentResourceNormalizedRealValue: {}", currentResourceAttrProperty.debugDump(1), currentResourceNormalizedRealValue);
shadowDelta.addModificationReplaceProperty(currentResourceAttrProperty.getPath(), currentResourceNormalizedRealValue);
}
} else {
PrismProperty<Object> normalizedCurrentResourceAttrProperty = (PrismProperty<Object>) currentResourceAttrProperty.clone();
if (matchingRule != null) {
for (PrismPropertyValue pval : normalizedCurrentResourceAttrProperty.getValues()) {
Object normalizedRealValue = matchingRule.normalize(pval.getValue());
pval.setValue(normalizedRealValue);
}
}
PropertyDelta<Object> attrDiff = oldRepoAttributeProperty.diff(normalizedCurrentResourceAttrProperty);
LOGGER.trace("DIFF:\n{}\n-\n{}\n=:\n{}", oldRepoAttributeProperty == null ? null : oldRepoAttributeProperty.debugDump(1), normalizedCurrentResourceAttrProperty == null ? null : normalizedCurrentResourceAttrProperty.debugDump(1), attrDiff == null ? null : attrDiff.debugDump(1));
if (attrDiff != null && !attrDiff.isEmpty()) {
attrDiff.setParentPath(new ItemPath(ShadowType.F_ATTRIBUTES));
shadowDelta.addModification(attrDiff);
}
}
}
}
}
}
for (Item<?, ?> oldRepoItem : oldRepoAttributesContainer.getValue().getItems()) {
if (oldRepoItem instanceof PrismProperty<?>) {
PrismProperty<?> oldRepoAttrProperty = (PrismProperty<?>) oldRepoItem;
RefinedAttributeDefinition<Object> attrDef = ocDef.findAttributeDefinition(oldRepoAttrProperty.getElementName());
PrismProperty<Object> currentAttribute = currentResourceAttributesContainer.findProperty(oldRepoAttrProperty.getElementName());
if (attrDef == null || !ProvisioningUtil.shouldStoreAtributeInShadow(ocDef, attrDef.getName(), cachingStrategy) || currentAttribute == null) {
// No definition for this property it should not be there or no current value: remove it from the shadow
PropertyDelta<?> oldRepoAttrPropDelta = oldRepoAttrProperty.createDelta();
oldRepoAttrPropDelta.addValuesToDelete((Collection) PrismPropertyValue.cloneCollection(oldRepoAttrProperty.getValues()));
shadowDelta.addModification(oldRepoAttrPropDelta);
}
}
}
PolyString currentShadowName = ShadowUtil.determineShadowName(currentResourceShadow);
PolyString oldRepoShadowName = oldRepoShadow.getName();
if (!currentShadowName.equalsOriginalValue(oldRepoShadowName)) {
PropertyDelta<?> shadowNameDelta = PropertyDelta.createModificationReplaceProperty(ShadowType.F_NAME, oldRepoShadow.getDefinition(), currentShadowName);
shadowDelta.addModification(shadowNameDelta);
}
PropertyDelta<QName> auxOcDelta = (PropertyDelta) PrismProperty.diff(oldRepoShadow.findProperty(ShadowType.F_AUXILIARY_OBJECT_CLASS), currentResourceShadow.findProperty(ShadowType.F_AUXILIARY_OBJECT_CLASS));
if (auxOcDelta != null) {
shadowDelta.addModification(auxOcDelta);
}
if (cachingStrategy == CachingStategyType.NONE) {
if (oldRepoShadowType.getCachingMetadata() != null) {
shadowDelta.addModificationReplaceProperty(ShadowType.F_CACHING_METADATA);
}
} else if (cachingStrategy == CachingStategyType.PASSIVE) {
compareUpdateProperty(shadowDelta, SchemaConstants.PATH_ACTIVATION_ADMINISTRATIVE_STATUS, currentResourceShadow, oldRepoShadow);
compareUpdateProperty(shadowDelta, SchemaConstants.PATH_ACTIVATION_VALID_FROM, currentResourceShadow, oldRepoShadow);
compareUpdateProperty(shadowDelta, SchemaConstants.PATH_ACTIVATION_VALID_TO, currentResourceShadow, oldRepoShadow);
compareUpdateProperty(shadowDelta, SchemaConstants.PATH_ACTIVATION_LOCKOUT_STATUS, currentResourceShadow, oldRepoShadow);
CachingMetadataType cachingMetadata = new CachingMetadataType();
cachingMetadata.setRetrievalTimestamp(clock.currentTimeXMLGregorianCalendar());
shadowDelta.addModificationReplaceProperty(ShadowType.F_CACHING_METADATA, cachingMetadata);
} else {
throw new ConfigurationException("Unknown caching strategy " + cachingStrategy);
}
if (!shadowDelta.isEmpty()) {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Updating repo shadow {} with delta:\n{}", oldRepoShadow, shadowDelta.debugDump(1));
}
ConstraintsChecker.onShadowModifyOperation(shadowDelta.getModifications());
try {
repositoryService.modifyObject(ShadowType.class, oldRepoShadow.getOid(), shadowDelta.getModifications(), parentResult);
} catch (ObjectAlreadyExistsException e) {
// This should not happen for shadows
throw new SystemException(e.getMessage(), e);
}
PrismObject<ShadowType> newRepoShadow = oldRepoShadow.clone();
shadowDelta.applyTo(newRepoShadow);
return newRepoShadow;
} else {
LOGGER.trace("No need to update repo shadow {} (empty delta)", oldRepoShadow);
return oldRepoShadow;
}
}
use of com.evolveum.midpoint.prism.PrismProperty in project midpoint by Evolveum.
the class ShadowManager method fixShadow.
/**
* Re-reads the shadow, re-evaluates the identifiers and stored values, updates them if necessary. Returns
* fixed shadow.
*/
public PrismObject<ShadowType> fixShadow(ProvisioningContext ctx, PrismObject<ShadowType> origRepoShadow, OperationResult parentResult) throws ObjectNotFoundException, SchemaException, ConfigurationException, CommunicationException, ExpressionEvaluationException {
PrismObject<ShadowType> currentRepoShadow = repositoryService.getObject(ShadowType.class, origRepoShadow.getOid(), null, parentResult);
ProvisioningContext shadowCtx = ctx.spawn(currentRepoShadow);
RefinedObjectClassDefinition ocDef = shadowCtx.getObjectClassDefinition();
PrismContainer<Containerable> attributesContainer = currentRepoShadow.findContainer(ShadowType.F_ATTRIBUTES);
if (attributesContainer != null && attributesContainer.getValue() != null) {
ObjectDelta<ShadowType> shadowDelta = currentRepoShadow.createModifyDelta();
for (Item<?, ?> item : attributesContainer.getValue().getItems()) {
if (item instanceof PrismProperty<?>) {
PrismProperty<?> attrProperty = (PrismProperty<?>) item;
RefinedAttributeDefinition<Object> attrDef = ocDef.findAttributeDefinition(attrProperty.getElementName());
if (attrDef == null) {
// No definition for this property, it should not be in the shadow
PropertyDelta<?> oldRepoAttrPropDelta = attrProperty.createDelta();
oldRepoAttrPropDelta.addValuesToDelete((Collection) PrismPropertyValue.cloneCollection(attrProperty.getValues()));
shadowDelta.addModification(oldRepoAttrPropDelta);
} else {
MatchingRule matchingRule = matchingRuleRegistry.getMatchingRule(attrDef.getMatchingRuleQName(), attrDef.getTypeName());
List<PrismPropertyValue> valuesToAdd = null;
List<PrismPropertyValue> valuesToDelete = null;
for (PrismPropertyValue attrVal : attrProperty.getValues()) {
Object currentRealValue = attrVal.getValue();
Object normalizedRealValue = matchingRule.normalize(currentRealValue);
if (!normalizedRealValue.equals(currentRealValue)) {
if (attrDef.isSingleValue()) {
shadowDelta.addModificationReplaceProperty(attrProperty.getPath(), normalizedRealValue);
break;
} else {
if (valuesToAdd == null) {
valuesToAdd = new ArrayList<>();
}
valuesToAdd.add(new PrismPropertyValue(normalizedRealValue));
if (valuesToDelete == null) {
valuesToDelete = new ArrayList<>();
}
valuesToDelete.add(new PrismPropertyValue(currentRealValue));
}
}
}
PropertyDelta attrDelta = attrProperty.createDelta(attrProperty.getPath());
if (valuesToAdd != null) {
attrDelta.addValuesToAdd(valuesToAdd);
}
if (valuesToDelete != null) {
attrDelta.addValuesToDelete(valuesToDelete);
}
shadowDelta.addModification(attrDelta);
}
}
}
if (!shadowDelta.isEmpty()) {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Fixing shadow {} with delta:\n{}", origRepoShadow, shadowDelta.debugDump());
}
try {
repositoryService.modifyObject(ShadowType.class, origRepoShadow.getOid(), shadowDelta.getModifications(), parentResult);
} catch (ObjectAlreadyExistsException e) {
// This should not happen for shadows
throw new SystemException(e.getMessage(), e);
}
shadowDelta.applyTo(currentRepoShadow);
} else {
LOGGER.trace("No need to fixing shadow {} (empty delta)", origRepoShadow);
}
} else {
LOGGER.trace("No need to fixing shadow {} (no atttributes)", origRepoShadow);
}
return currentRepoShadow;
}
use of com.evolveum.midpoint.prism.PrismProperty in project midpoint by Evolveum.
the class ModelWebService method parseScripts.
private List<JAXBElement<?>> parseScripts(ExecuteScriptsType parameters) throws JAXBException, SchemaException {
List<JAXBElement<?>> scriptsToExecute = new ArrayList<>();
if (parameters.getXmlScripts() != null) {
for (Object scriptAsObject : parameters.getXmlScripts().getAny()) {
if (scriptAsObject instanceof JAXBElement) {
scriptsToExecute.add((JAXBElement) scriptAsObject);
} else {
throw new IllegalArgumentException("Invalid script type: " + scriptAsObject.getClass());
}
}
} else {
// here comes MSL script decoding (however with a quick hack to allow passing XML as text here)
String scriptsAsString = parameters.getMslScripts();
if (scriptsAsString.startsWith("<?xml")) {
PrismProperty expressionType = (PrismProperty) prismContext.parserFor(scriptsAsString).xml().parseItem();
if (expressionType.size() != 1) {
throw new IllegalArgumentException("Unexpected number of scripting expressions at input: " + expressionType.size() + " (expected 1)");
}
scriptsToExecute.add(expressionType.getAnyValue().toJaxbElement());
}
}
return scriptsToExecute;
}
use of com.evolveum.midpoint.prism.PrismProperty in project midpoint by Evolveum.
the class MidPointDataSource method getFieldValue.
@Override
public Object getFieldValue(JRField jrField) throws JRException {
String fieldName = jrField.getName();
if (fieldName.equals("oid")) {
if (currentObject.getParent() instanceof PrismObject) {
return ((PrismObject) currentObject.getParent()).getOid();
} else {
throw new IllegalStateException("oid property is not supported for " + currentObject.getClass());
}
} else if (PARENT_NAME.equals(fieldName)) {
PrismContainerable parent1 = currentObject.getParent();
if (!(parent1 instanceof PrismContainer)) {
return null;
}
return ((PrismContainer) parent1).getParent();
} else if (THIS_NAME.equals(fieldName)) {
return currentObject;
}
ItemPathType itemPathType = new ItemPathType(fieldName);
ItemPath path = itemPathType.getItemPath();
Item i = currentObject.findItem(path);
if (i == null) {
return null;
}
if (i instanceof PrismProperty) {
if (i.isSingleValue()) {
return normalize(((PrismProperty) i).getRealValue(), jrField.getValueClass());
}
List normalized = new ArrayList<>();
for (Object real : ((PrismProperty) i).getRealValues()) {
normalized.add(normalize(real, jrField.getValueClass()));
}
return ((PrismProperty) i).getRealValues();
} else if (i instanceof PrismReference) {
if (i.isSingleValue()) {
return ObjectTypeUtil.createObjectRef(((PrismReference) i).getValue());
}
List<Referencable> refs = new ArrayList<Referencable>();
for (PrismReferenceValue refVal : ((PrismReference) i).getValues()) {
refs.add(ObjectTypeUtil.createObjectRef(refVal));
}
return refs;
} else if (i instanceof PrismContainer) {
if (i.isSingleValue()) {
return ((PrismContainer) i).getValue().asContainerable();
}
List<Containerable> containers = new ArrayList<Containerable>();
for (Object pcv : i.getValues()) {
if (pcv instanceof PrismContainerValue) {
containers.add(((PrismContainerValue) pcv).asContainerable());
}
}
return containers;
} else
throw new JRException("Could not get value of the fileld: " + fieldName);
// return
// throw new UnsupportedOperationException("dataSource.getFiledValue() not supported");
}
Aggregations