use of com.evolveum.midpoint.prism.ItemDefinition in project midpoint by Evolveum.
the class ConsistencyTest method test124AddAccountDirectAlreadyExists.
//MID-1595, MID-1577
@Test
public void test124AddAccountDirectAlreadyExists() throws Exception {
final String TEST_NAME = "test124AddAccountDirectAlreadyExists";
TestUtil.displayTestTile(TEST_NAME);
OperationResult parentResult = new OperationResult(TEST_NAME);
Task task = taskManager.createTaskInstance();
SchemaHandlingType oldSchemaHandling = resourceTypeOpenDjrepo.getSchemaHandling();
SynchronizationType oldSynchronization = resourceTypeOpenDjrepo.getSynchronization();
try {
// we will reapply this schema handling after this test finish
ItemDefinition syncDef = resourceTypeOpenDjrepo.asPrismObject().getDefinition().findItemDefinition(ResourceType.F_SYNCHRONIZATION);
assertNotNull("null definition for sync delta", syncDef);
ObjectDeltaType omt = unmarshallValueFromFile(REQUEST_RESOURCE_MODIFY_SYNCHRONIZATION, ObjectDeltaType.class);
ObjectDelta objectDelta = DeltaConvertor.createObjectDelta(omt, prismContext);
repositoryService.modifyObject(ResourceType.class, RESOURCE_OPENDJ_OID, objectDelta.getModifications(), parentResult);
requestToExecuteChanges(REQUEST_RESOURCE_MODIFY_RESOURCE_SCHEMA, RESOURCE_OPENDJ_OID, ResourceType.class, task, null, parentResult);
PrismObject<ResourceType> res = repositoryService.getObject(ResourceType.class, RESOURCE_OPENDJ_OID, null, parentResult);
// LOGGER.trace("resource schema handling after modify: {}",
// prismContext.silentMarshalObject(res.asObjectable(), LOGGER));
repoAddObjectFromFile(USER_ABOMBA_FILENAME, parentResult);
requestToExecuteChanges(REQUEST_USER_MODIFY_ADD_ACCOUNT_DIRECTLY, USER_ABOMBA_OID, UserType.class, task, null, parentResult);
String abombaOid = assertUserOneAccountRef(USER_ABOMBA_OID);
ShadowType abombaShadow = repositoryService.getObject(ShadowType.class, abombaOid, null, parentResult).asObjectable();
assertShadowName(abombaShadow, "uid=abomba,OU=people,DC=example,DC=com");
repoAddObjectFromFile(USER_ABOM_FILENAME, parentResult);
requestToExecuteChanges(REQUEST_USER_MODIFY_ADD_ACCOUNT_DIRECTLY, USER_ABOM_OID, UserType.class, task, null, parentResult);
String abomOid = assertUserOneAccountRef(USER_ABOM_OID);
ShadowType abomShadow = repositoryService.getObject(ShadowType.class, abomOid, null, parentResult).asObjectable();
assertShadowName(abomShadow, "uid=abomba1,OU=people,DC=example,DC=com");
ReferenceDelta abombaDeleteAccDelta = ReferenceDelta.createModificationDelete(ShadowType.class, UserType.F_LINK_REF, prismContext, new PrismReferenceValue(abombaOid));
ObjectDelta d = ObjectDelta.createModifyDelta(USER_ABOMBA_OID, abombaDeleteAccDelta, UserType.class, prismContext);
modelService.executeChanges(MiscSchemaUtil.createCollection(d), null, task, parentResult);
assertUserNoAccountRef(USER_ABOMBA_OID, parentResult);
repositoryService.getObject(ShadowType.class, abombaOid, null, parentResult);
ReferenceDelta abomDeleteAccDelta = ReferenceDelta.createModificationDelete(ShadowType.class, UserType.F_LINK_REF, prismContext, abomShadow.asPrismObject());
ObjectDelta d2 = ObjectDelta.createModifyDelta(USER_ABOM_OID, abomDeleteAccDelta, UserType.class, prismContext);
modelService.executeChanges(MiscSchemaUtil.createCollection(d2), null, task, parentResult);
assertUserNoAccountRef(USER_ABOM_OID, parentResult);
try {
repositoryService.getObject(ShadowType.class, abomOid, null, parentResult);
fail("Expected that shadow abom does not exist, but it is");
} catch (ObjectNotFoundException ex) {
// this is expected
} catch (Exception ex) {
fail("Expected object not found exception but got " + ex);
}
LOGGER.info("starting second execution request for user abomba");
OperationResult result = new OperationResult("Add account already exist result.");
requestToExecuteChanges(REQUEST_USER_MODIFY_ADD_ACCOUNT_DIRECTLY, USER_ABOMBA_OID, UserType.class, task, null, result);
String abombaOid2 = assertUserOneAccountRef(USER_ABOMBA_OID);
ShadowType abombaShadow2 = repositoryService.getObject(ShadowType.class, abombaOid2, null, result).asObjectable();
assertShadowName(abombaShadow2, "uid=abomba,OU=people,DC=example,DC=com");
result.computeStatus();
LOGGER.info("Displaying execute changes result");
display(result);
// return the previous changes of resource back
Collection<? extends ItemDelta> schemaHandlingDelta = ContainerDelta.createModificationReplaceContainerCollection(ResourceType.F_SCHEMA_HANDLING, resourceTypeOpenDjrepo.asPrismObject().getDefinition(), oldSchemaHandling.asPrismContainerValue().clone());
PropertyDelta syncDelta = PropertyDelta.createModificationReplaceProperty(ResourceType.F_SYNCHRONIZATION, resourceTypeOpenDjrepo.asPrismObject().getDefinition(), oldSynchronization);
((Collection) schemaHandlingDelta).add(syncDelta);
repositoryService.modifyObject(ResourceType.class, RESOURCE_OPENDJ_OID, schemaHandlingDelta, parentResult);
} catch (Exception ex) {
LOGGER.info("error: " + ex.getMessage(), ex);
throw ex;
}
}
use of com.evolveum.midpoint.prism.ItemDefinition in project midpoint by Evolveum.
the class AssignmentTablePanel method handleModifyAssignmentDelta.
private void handleModifyAssignmentDelta(AssignmentEditorDto assDto, PrismContainerDefinition assignmentDef, PrismContainerValue newValue, ObjectDelta<T> userDelta) throws SchemaException {
LOGGER.debug("Handling modified assignment '{}', computing delta.", new Object[] { assDto.getName() });
PrismValue oldValue = assDto.getOldValue();
Collection<? extends ItemDelta> deltas = oldValue.diff(newValue);
for (ItemDelta delta : deltas) {
ItemPath deltaPath = delta.getPath().rest();
ItemDefinition deltaDef = assignmentDef.findItemDefinition(deltaPath);
delta.setParentPath(WebComponentUtil.joinPath(oldValue.getPath(), delta.getPath().allExceptLast()));
delta.applyDefinition(deltaDef);
userDelta.addModification(delta);
}
}
use of com.evolveum.midpoint.prism.ItemDefinition in project midpoint by Evolveum.
the class RObjectDeltaOperation method toRepo.
public static RObjectDeltaOperation toRepo(RAuditEventRecord record, ObjectDeltaOperation operation, PrismContext prismContext) throws DtoTranslationException {
RObjectDeltaOperation auditDelta = new RObjectDeltaOperation();
auditDelta.setRecord(record);
try {
if (operation.getObjectDelta() != null) {
ObjectDelta delta = operation.getObjectDelta();
String xmlDelta = DeltaConvertor.toObjectDeltaTypeXml(delta, DeltaConversionOptions.createSerializeReferenceNames());
auditDelta.setDelta(xmlDelta);
auditDelta.setDeltaOid(delta.getOid());
auditDelta.setDeltaType(RUtil.getRepoEnumValue(delta.getChangeType(), RChangeType.class));
}
if (operation.getExecutionResult() != null) {
ItemDefinition def = prismContext.getSchemaRegistry().findItemDefinitionByElementName(SchemaConstantsGenerated.C_OPERATION_RESULT);
RUtil.copyResultFromJAXB(def, SchemaConstantsGenerated.C_OPERATION_RESULT, operation.getExecutionResult().createOperationResultType(), auditDelta, prismContext);
}
auditDelta.setObjectName(RPolyString.toRepo(operation.getObjectName()));
auditDelta.setResourceOid(operation.getResourceOid());
auditDelta.setResourceName(RPolyString.toRepo(operation.getResourceName()));
} catch (Exception ex) {
throw new DtoTranslationException(ex.getMessage(), ex);
}
return auditDelta;
}
use of com.evolveum.midpoint.prism.ItemDefinition in project midpoint by Evolveum.
the class QueryInterpreter2 method findAndCreateRestrictionInternal.
private <T extends ObjectFilter> Restriction findAndCreateRestrictionInternal(T filter, InterpretationContext context, Restriction parent, ItemPathResolver resolver, JpaEntityDefinition baseEntityDefinition) throws QueryException {
if (filter instanceof AndFilter) {
return new AndRestriction(context, (AndFilter) filter, baseEntityDefinition, parent);
} else if (filter instanceof OrFilter) {
return new OrRestriction(context, (OrFilter) filter, baseEntityDefinition, parent);
} else if (filter instanceof NotFilter) {
return new NotRestriction(context, (NotFilter) filter, baseEntityDefinition, parent);
} else if (filter instanceof FullTextFilter) {
return new FullTextRestriction(context, (FullTextFilter) filter, baseEntityDefinition, parent);
} else if (filter instanceof InOidFilter) {
return new InOidRestriction(context, (InOidFilter) filter, baseEntityDefinition, parent);
} else if (filter instanceof OrgFilter) {
return new OrgRestriction(context, (OrgFilter) filter, baseEntityDefinition, parent);
} else if (filter instanceof TypeFilter) {
TypeFilter typeFilter = (TypeFilter) filter;
JpaEntityDefinition refinedEntityDefinition = resolver.findRestrictedEntityDefinition(baseEntityDefinition, typeFilter.getType());
return new TypeRestriction(context, typeFilter, refinedEntityDefinition, parent);
} else if (filter instanceof ExistsFilter) {
ExistsFilter existsFilter = (ExistsFilter) filter;
ItemPath path = existsFilter.getFullPath();
ItemDefinition definition = existsFilter.getDefinition();
ProperDataSearchResult<JpaDataNodeDefinition> searchResult = resolver.findProperDataDefinition(baseEntityDefinition, path, definition, JpaDataNodeDefinition.class, context.getPrismContext());
if (searchResult == null) {
throw new QueryException("Path for ExistsFilter (" + path + ") doesn't point to a hibernate entity or property within " + baseEntityDefinition);
}
return new ExistsRestriction(context, existsFilter, searchResult.getEntityDefinition(), parent);
} else if (filter instanceof RefFilter) {
RefFilter refFilter = (RefFilter) filter;
ItemPath path = refFilter.getFullPath();
ItemDefinition definition = refFilter.getDefinition();
ProperDataSearchResult<JpaReferenceDefinition> searchResult = resolver.findProperDataDefinition(baseEntityDefinition, path, definition, JpaReferenceDefinition.class, context.getPrismContext());
if (searchResult == null) {
throw new QueryException("Path for RefFilter (" + path + ") doesn't point to a reference item within " + baseEntityDefinition);
}
return new ReferenceRestriction(context, refFilter, searchResult.getEntityDefinition(), parent, searchResult.getLinkDefinition());
} else if (filter instanceof PropertyValueFilter) {
PropertyValueFilter valFilter = (PropertyValueFilter) filter;
ItemPath path = valFilter.getFullPath();
ItemDefinition definition = valFilter.getDefinition();
ProperDataSearchResult<JpaPropertyDefinition> propDefRes = resolver.findProperDataDefinition(baseEntityDefinition, path, definition, JpaPropertyDefinition.class, context.getPrismContext());
if (propDefRes == null) {
throw new QueryException("Couldn't find a proper data item to query, given base entity " + baseEntityDefinition + " and this filter: " + valFilter.debugDump());
}
// TODO can't be unified?
if (propDefRes.getTargetDefinition() instanceof JpaAnyPropertyDefinition) {
return new AnyPropertyRestriction(context, valFilter, propDefRes.getEntityDefinition(), parent, propDefRes.getLinkDefinition());
} else {
return new PropertyRestriction(context, valFilter, propDefRes.getEntityDefinition(), parent, propDefRes.getLinkDefinition());
}
} else if (filter instanceof NoneFilter || filter instanceof AllFilter || filter instanceof UndefinedFilter) {
// these should be filtered out by the client
throw new IllegalStateException("Trivial filters are not supported by QueryInterpreter: " + filter.debugDump());
} else {
throw new IllegalStateException("Unknown filter: " + filter.debugDump());
}
}
use of com.evolveum.midpoint.prism.ItemDefinition in project midpoint by Evolveum.
the class RUser method copyFromJAXB.
public static void copyFromJAXB(UserType jaxb, RUser repo, RepositoryContext repositoryContext, IdGeneratorResult generatorResult) throws DtoTranslationException {
RFocus.copyFromJAXB(jaxb, repo, repositoryContext, generatorResult);
repo.setName(RPolyString.copyFromJAXB(jaxb.getName()));
repo.setFullName(RPolyString.copyFromJAXB(jaxb.getFullName()));
repo.setGivenName(RPolyString.copyFromJAXB(jaxb.getGivenName()));
repo.setFamilyName(RPolyString.copyFromJAXB(jaxb.getFamilyName()));
repo.setHonorificPrefix(RPolyString.copyFromJAXB(jaxb.getHonorificPrefix()));
repo.setHonorificSuffix(RPolyString.copyFromJAXB(jaxb.getHonorificSuffix()));
repo.setEmployeeNumber(jaxb.getEmployeeNumber());
repo.setLocalityUser(RPolyString.copyFromJAXB(jaxb.getLocality()));
repo.setAdditionalName(RPolyString.copyFromJAXB(jaxb.getAdditionalName()));
repo.setEmailAddress(jaxb.getEmailAddress());
repo.setTelephoneNumber(jaxb.getTelephoneNumber());
repo.setCostCenter(jaxb.getCostCenter());
repo.setLocale(jaxb.getLocale());
repo.setTimezone(jaxb.getTimezone());
repo.setPreferredLanguage(jaxb.getPreferredLanguage());
repo.setTitle(RPolyString.copyFromJAXB(jaxb.getTitle()));
repo.setNickName(RPolyString.copyFromJAXB(jaxb.getNickName()));
ItemDefinition def = jaxb.asPrismObject().getDefinition();
RUtil.copyResultFromJAXB(def, jaxb.F_RESULT, jaxb.getResult(), repo, repositoryContext.prismContext);
//sets
repo.setEmployeeType(RUtil.listToSet(jaxb.getEmployeeType()));
repo.setOrganizationalUnit(RUtil.listPolyToSet(jaxb.getOrganizationalUnit()));
repo.setOrganization(RUtil.listPolyToSet(jaxb.getOrganization()));
}
Aggregations