use of com.evolveum.prism.xml.ns._public.types_3.PolyStringType in project midpoint by Evolveum.
the class FocusProcessor method applyObjectPolicyConstraints.
private <F extends FocusType> void applyObjectPolicyConstraints(LensFocusContext<F> focusContext, ObjectPolicyConfigurationType objectPolicyConfigurationType) throws SchemaException {
if (objectPolicyConfigurationType == null) {
return;
}
final PrismObject<F> focusNew = focusContext.getObjectNew();
if (focusNew == null) {
// This is delete. Nothing to do.
return;
}
for (PropertyConstraintType propertyConstraintType : objectPolicyConfigurationType.getPropertyConstraint()) {
ItemPath itemPath = propertyConstraintType.getPath().getItemPath();
if (BooleanUtils.isTrue(propertyConstraintType.isOidBound())) {
PrismProperty<Object> prop = focusNew.findProperty(itemPath);
if (prop == null || prop.isEmpty()) {
String newValue = focusNew.getOid();
if (newValue == null) {
newValue = OidUtil.generateOid();
}
LOGGER.trace("Generating new OID-bound value for {}: {}", itemPath, newValue);
PrismObjectDefinition<F> focusDefinition = focusContext.getObjectDefinition();
PrismPropertyDefinition<Object> propDef = focusDefinition.findPropertyDefinition(itemPath);
if (propDef == null) {
throw new SchemaException("No definition for property " + itemPath + " in " + focusDefinition + " as specified in object policy");
}
PropertyDelta<Object> propDelta = propDef.createEmptyDelta(itemPath);
if (String.class.isAssignableFrom(propDef.getTypeClass())) {
propDelta.setValueToReplace(new PrismPropertyValue<Object>(newValue, OriginType.USER_POLICY, null));
} else if (PolyString.class.isAssignableFrom(propDef.getTypeClass())) {
propDelta.setValueToReplace(new PrismPropertyValue<Object>(new PolyString(newValue), OriginType.USER_POLICY, null));
} else {
throw new SchemaException("Unsupported type " + propDef.getTypeName() + " for property " + itemPath + " in " + focusDefinition + " as specified in object policy, only string and polystring properties are supported for OID-bound mode");
}
focusContext.swallowToSecondaryDelta(propDelta);
focusContext.recompute();
}
}
}
// Deprecated
if (BooleanUtils.isTrue(objectPolicyConfigurationType.isOidNameBoundMode())) {
// Generate the name now - unless it is already present
PolyStringType focusNewName = focusNew.asObjectable().getName();
if (focusNewName == null) {
String newValue = focusNew.getOid();
if (newValue == null) {
newValue = OidUtil.generateOid();
}
LOGGER.trace("Generating new name (bound to OID): {}", newValue);
PrismObjectDefinition<F> focusDefinition = focusContext.getObjectDefinition();
PrismPropertyDefinition<PolyString> focusNameDef = focusDefinition.findPropertyDefinition(FocusType.F_NAME);
PropertyDelta<PolyString> nameDelta = focusNameDef.createEmptyDelta(new ItemPath(FocusType.F_NAME));
nameDelta.setValueToReplace(new PrismPropertyValue<PolyString>(new PolyString(newValue), OriginType.USER_POLICY, null));
focusContext.swallowToSecondaryDelta(nameDelta);
focusContext.recompute();
}
}
}
use of com.evolveum.prism.xml.ns._public.types_3.PolyStringType in project midpoint by Evolveum.
the class AbstractModelIntegrationTest method dumpFocus.
protected <F extends FocusType> void dumpFocus(String message, PrismObject<F> focus) throws ObjectNotFoundException, SchemaException {
OperationResult result = new OperationResult(AbstractIntegrationTest.class.getName() + ".dumpFocus");
StringBuilder sb = new StringBuilder();
sb.append(focus.debugDump(0));
sb.append("\nOrgs:");
for (ObjectReferenceType parentOrgRef : focus.asObjectable().getParentOrgRef()) {
sb.append("\n");
DebugUtil.indentDebugDump(sb, 1);
PrismObject<OrgType> org = repositoryService.getObject(OrgType.class, parentOrgRef.getOid(), null, result);
sb.append(org);
PolyStringType displayName = org.asObjectable().getDisplayName();
if (displayName != null) {
sb.append(": ").append(displayName);
}
}
sb.append("\nProjections:");
for (ObjectReferenceType linkRef : focus.asObjectable().getLinkRef()) {
PrismObject<ShadowType> shadow = repositoryService.getObject(ShadowType.class, linkRef.getOid(), null, result);
ObjectReferenceType resourceRef = shadow.asObjectable().getResourceRef();
PrismObject<ResourceType> resource = repositoryService.getObject(ResourceType.class, resourceRef.getOid(), null, result);
sb.append("\n");
DebugUtil.indentDebugDump(sb, 1);
sb.append(resource);
sb.append("/");
sb.append(shadow.asObjectable().getKind());
sb.append("/");
sb.append(shadow.asObjectable().getIntent());
sb.append(": ");
sb.append(shadow.asObjectable().getName());
}
sb.append("\nAssignments:");
for (AssignmentType assignmentType : focus.asObjectable().getAssignment()) {
sb.append("\n");
DebugUtil.indentDebugDump(sb, 1);
if (assignmentType.getConstruction() != null) {
sb.append("Constr(").append(assignmentType.getConstruction().getDescription()).append(") ");
}
if (assignmentType.getTargetRef() != null) {
sb.append("-[");
if (assignmentType.getTargetRef().getRelation() != null) {
sb.append(assignmentType.getTargetRef().getRelation().getLocalPart());
}
sb.append("]-> ");
Class<? extends ObjectType> targetClass = ObjectTypes.getObjectTypeFromTypeQName(assignmentType.getTargetRef().getType()).getClassDefinition();
;
PrismObject<? extends ObjectType> target = repositoryService.getObject(targetClass, assignmentType.getTargetRef().getOid(), null, result);
sb.append(target);
}
}
display(message, sb.toString());
}
use of com.evolveum.prism.xml.ns._public.types_3.PolyStringType in project midpoint by Evolveum.
the class CommunicationExceptionHandler method handleError.
@Override
public <T extends ShadowType> T handleError(T shadow, FailedOperation op, Exception ex, boolean doDiscovery, boolean compensate, Task task, OperationResult parentResult) throws SchemaException, GenericFrameworkException, CommunicationException, ObjectNotFoundException, ObjectAlreadyExistsException, ConfigurationException {
if (!doDiscovery) {
parentResult.recordFatalError(ex);
if (ex instanceof CommunicationException) {
throw (CommunicationException) ex;
} else {
throw new CommunicationException(ex.getMessage(), ex);
}
}
Validate.notNull(shadow, "Shadow must not be null.");
OperationResult operationResult = parentResult.createSubresult("com.evolveum.midpoint.provisioning.consistency.impl.CommunicationExceptionHandler.handleError." + op.name());
operationResult.addParam("shadow", shadow);
operationResult.addParam("currentOperation", op);
operationResult.addParam("exception", ex.getMessage());
// first modify last availability status in the resource, so by others
// operations, we can know that it is down
resourceManager.modifyResourceAvailabilityStatus(shadow.getResource().asPrismObject(), AvailabilityStatusType.DOWN, operationResult);
if ((!isPostpone(shadow.getResource()) || !compensate) && !FailedOperation.GET.equals(op)) {
LOGGER.trace("Postponing operation turned off.");
operationResult.recordFatalError(ex.getMessage(), ex);
throw new CommunicationException(ex.getMessage(), ex);
}
// Task task = null;
ObjectDelta delta = null;
ResourceOperationDescription operationDescription = null;
switch(op) {
case ADD:
// if it is first time, just store the whole account to the repo
LOGGER.trace("Postponing ADD operation for {}", ObjectTypeUtil.toShortString(shadow));
ResourceType resource = shadow.getResource();
if (shadow.getFailedOperationType() == null) {
// ResourceType resource = shadow.getResource();
if (shadow.getName() == null) {
shadow.setName(new PolyStringType(ShadowUtil.determineShadowName(shadow.asPrismObject())));
}
if (shadow.getResourceRef() == null || shadow.getResourceRef().getOid() == null) {
if (resource != null) {
shadow.getResourceRef().setOid(shadow.getResource().getOid());
}
}
if (shadow.getResourceRef() != null && resource != null) {
shadow.setResource(null);
}
shadow.setAttemptNumber(getAttemptNumber(shadow));
shadow.setFailedOperationType(FailedOperationTypeType.ADD);
ConstraintsChecker.onShadowAddOperation(shadow);
// Unlike addObject calls during normal provisioning, here we preserve all activation information, including e.g. administrativeStatus.
// It is needed for shadow creation during error recovery.
String oid = cacheRepositoryService.addObject(shadow.asPrismObject(), null, operationResult);
shadow.setOid(oid);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Stored new shadow for unfinished operation:\n{}", shadow.asPrismObject().debugDump(1));
}
// if it is seccond time ,just increade the attempt number
} else {
if (FailedOperationTypeType.ADD == shadow.getFailedOperationType()) {
Collection<? extends ItemDelta> attemptdelta = createAttemptModification(shadow, null);
ConstraintsChecker.onShadowModifyOperation(attemptdelta);
cacheRepositoryService.modifyObject(ShadowType.class, shadow.getOid(), attemptdelta, operationResult);
}
}
// error
for (OperationResult subRes : parentResult.getSubresults()) {
subRes.muteError();
}
operationResult.computeStatus();
parentResult.recordHandledError("Could not create object=" + shadow.getName().getOrig() + " on the resource, because " + ObjectTypeUtil.toShortString(resource) + // there will be something like ": Add object failed" appended, so the final dot was a bit ugly here
" is unreachable at the moment. Shadow is stored in the repository and the resource object will be created when the resource goes online");
// task = taskManager.createTaskInstance();
delta = ObjectDelta.createAddDelta(shadow.asPrismObject());
operationDescription = createOperationDescription(shadow, ex, resource, delta, task, operationResult);
changeNotificationDispatcher.notifyInProgress(operationDescription, task, parentResult);
return shadow;
case MODIFY:
if (shadow.getFailedOperationType() == null || shadow.getFailedOperationType() == FailedOperationTypeType.MODIFY) {
shadow.setFailedOperationType(FailedOperationTypeType.MODIFY);
Collection<ItemDelta> modifications = createShadowModification(shadow);
ConstraintsChecker.onShadowModifyOperation(modifications);
getCacheRepositoryService().modifyObject(ShadowType.class, shadow.getOid(), modifications, operationResult);
delta = ObjectDelta.createModifyDelta(shadow.getOid(), modifications, shadow.asPrismObject().getCompileTimeClass(), prismContext);
// operationResult.recordSuccess();
// return shadow;
} else {
if (FailedOperationTypeType.ADD == shadow.getFailedOperationType()) {
if (shadow.getObjectChange() != null && shadow.getOid() != null) {
Collection<? extends ItemDelta> deltas = DeltaConvertor.toModifications(shadow.getObjectChange().getItemDelta(), shadow.asPrismObject().getDefinition());
ConstraintsChecker.onShadowModifyOperation(deltas);
cacheRepositoryService.modifyObject(ShadowType.class, shadow.getOid(), deltas, operationResult);
delta = ObjectDelta.createModifyDelta(shadow.getOid(), deltas, shadow.asPrismObject().getCompileTimeClass(), prismContext);
// return shadow;
// operationResult.recordSuccess();
}
}
}
for (OperationResult subRes : parentResult.getSubresults()) {
subRes.muteError();
}
operationResult.computeStatus();
parentResult.recordHandledError("Could not apply modifications to " + ObjectTypeUtil.toShortString(shadow) + " on the " + ObjectTypeUtil.toShortString(shadow.getResource()) + ", because resource is unreachable. Modifications will be applied when the resource goes online");
// task = taskManager.createTaskInstance();
//
operationDescription = createOperationDescription(shadow, ex, shadow.getResource(), delta, task, operationResult);
changeNotificationDispatcher.notifyInProgress(operationDescription, task, parentResult);
return shadow;
case DELETE:
shadow.setFailedOperationType(FailedOperationTypeType.DELETE);
Collection<ItemDelta> modifications = createShadowModification(shadow);
ConstraintsChecker.onShadowModifyOperation(modifications);
getCacheRepositoryService().modifyObject(ShadowType.class, shadow.getOid(), modifications, operationResult);
for (OperationResult subRes : parentResult.getSubresults()) {
subRes.muteError();
}
parentResult.recordHandledError("Could not delete " + ObjectTypeUtil.getShortTypeName(shadow) + " from the resource " + ObjectTypeUtil.toShortString(shadow.getResource()) + ", because resource is unreachable. Resource object will be delete when the resource goes online");
// operationResult.recordSuccess();
operationResult.computeStatus();
// task = taskManager.createTaskInstance();
// task.setChannel(QNameUtil.qNameToUri(SchemaConstants.CHANGE_CHANNEL_DISCOVERY));
delta = ObjectDelta.createDeleteDelta(shadow.asPrismObject().getCompileTimeClass(), shadow.getOid(), prismContext);
operationDescription = createOperationDescription(shadow, ex, shadow.getResource(), delta, task, operationResult);
changeNotificationDispatcher.notifyInProgress(operationDescription, task, parentResult);
return shadow;
case GET:
// result..
for (OperationResult subRes : parentResult.getSubresults()) {
subRes.muteError();
}
operationResult.recordPartialError("Could not get " + ObjectTypeUtil.toShortString(shadow) + " from the resource " + ObjectTypeUtil.toShortString(shadow.getResource()) + ", because resource is unreachable. Returning shadow from the repository");
shadow.setFetchResult(operationResult.createOperationResultType());
// operationResult.computeStatus();
return shadow;
default:
throw new CommunicationException(ex);
}
}
use of com.evolveum.prism.xml.ns._public.types_3.PolyStringType in project midpoint by Evolveum.
the class PrismPropertyValue method checkConsistenceInternal.
@Override
public void checkConsistenceInternal(Itemable rootItem, boolean requireDefinitions, boolean prohibitRaw, ConsistencyCheckScope scope) {
if (!scope.isThorough()) {
return;
}
ItemPath myPath = getPath();
if (prohibitRaw && rawElement != null) {
throw new IllegalStateException("Raw element in property value " + this + " (" + myPath + " in " + rootItem + ")");
}
if (value == null && rawElement == null && expression == null) {
throw new IllegalStateException("Neither value, expression nor raw element specified in property value " + this + " (" + myPath + " in " + rootItem + ")");
}
if (value != null && rawElement != null) {
throw new IllegalStateException("Both value and raw element specified in property value " + this + " (" + myPath + " in " + rootItem + ")");
}
if (value != null) {
if (value instanceof Recomputable) {
try {
((Recomputable) value).checkConsistence();
} catch (IllegalStateException e) {
throw new IllegalStateException(e.getMessage() + " in property value " + this + " (" + myPath + " in " + rootItem + ")", e);
}
}
if (value instanceof PolyStringType) {
throw new IllegalStateException("PolyStringType found in property value " + this + " (" + myPath + " in " + rootItem + ")");
}
if (value instanceof ProtectedStringType) {
if (((ProtectedStringType) value).isEmpty()) {
throw new IllegalStateException("Empty ProtectedStringType found in property value " + this + " (" + myPath + " in " + rootItem + ")");
}
}
PrismContext prismContext = getPrismContext();
if (value instanceof PolyString && prismContext != null) {
PolyString poly = (PolyString) value;
String orig = poly.getOrig();
String norm = poly.getNorm();
PolyStringNormalizer polyStringNormalizer = prismContext.getDefaultPolyStringNormalizer();
String expectedNorm = polyStringNormalizer.normalize(orig);
if (!norm.equals(expectedNorm)) {
throw new IllegalStateException("PolyString has inconsistent orig (" + orig + ") and norm (" + norm + ") in property value " + this + " (" + myPath + " in " + rootItem + ")");
}
}
}
}
use of com.evolveum.prism.xml.ns._public.types_3.PolyStringType in project midpoint by Evolveum.
the class DeltaConvertor method toObjectDeltaOperationType.
public static void toObjectDeltaOperationType(ObjectDeltaOperation delta, ObjectDeltaOperationType odo, DeltaConversionOptions options) throws SchemaException {
odo.setObjectDelta(DeltaConvertor.toObjectDeltaType(delta.getObjectDelta(), options));
if (delta.getExecutionResult() != null) {
odo.setExecutionResult(delta.getExecutionResult().createOperationResultType());
}
if (delta.getObjectName() != null) {
odo.setObjectName(new PolyStringType(delta.getObjectName()));
}
odo.setResourceOid(delta.getResourceOid());
if (delta.getResourceName() != null) {
odo.setResourceName(new PolyStringType(delta.getResourceName()));
}
}
Aggregations