private <O extends ObjectType> PrismPropertyDefinition<?> getItemDefinition(PrismObject<O> object, ItemPath path) { ItemDefinition<?> itemDef = object.getDefinition().findItemDefinition(path); if (itemDef == null) { return null; } else if (!(itemDef instanceof PrismPropertyDefinition)) { return null; } return (PrismPropertyDefinition<?>) itemDef; }
private static PropertyDelta<XMLGregorianCalendar> createSynchronizationTimestampDelta(PrismObject<ShadowType> object, QName propName, XMLGregorianCalendar timestamp, PrismContext prismContext) { PropertyDelta<XMLGregorianCalendar> syncSituationDelta = prismContext.deltaFactory().property() .createReplaceDelta(object.getDefinition(), propName, timestamp); return syncSituationDelta; }
@Override public PrismReferenceValue createReferenceValue(PrismObject<?> target) { PrismReferenceValue rv = new PrismReferenceValueImpl(target.getOid()); rv.setPrismContext(prismContext); rv.setObject(target); if (target.getDefinition() != null) { rv.setTargetType(target.getDefinition().getTypeName()); } return rv; }
private <T extends ObjectType> List<ReferenceDelta> createAddParentRefDelta(PrismObject<T> object) { PrismReference parentOrgRef = object.findReference(ObjectType.F_PARENT_ORG_REF); if (parentOrgRef == null || parentOrgRef.isEmpty()) { return new ArrayList<>(); } PrismObjectDefinition def = object.getDefinition(); ReferenceDelta delta = prismContext.deltaFactory().reference().createModificationAdd(ObjectType.F_PARENT_ORG_REF, def, parentOrgRef.getClonedValues()); return Collections.singletonList(delta); }
private QName determineElementQName(Objectable objectable) { PrismObject<?> prismObject = objectable.asPrismObject(); if (prismObject.getElementName() != null) { return prismObject.getElementName(); } PrismObjectDefinition<?> definition = prismObject.getDefinition(); if (definition != null) { if (definition.getName() != null) { return definition.getName(); } } throw new IllegalStateException("Cannot determine element name of "+objectable); }
private <F extends FocusType> List<PropertyDelta<?>> createShadowIntentAndSynchronizationTimestampDelta(SynchronizationContext<F> syncCtx, boolean saveIntent) throws SchemaException { Validate.notNull(syncCtx.getApplicableShadow(), "No current nor old shadow present: "); List<PropertyDelta<?>> modifications = SynchronizationUtils.createSynchronizationTimestampsDelta(syncCtx.getApplicableShadow(), prismContext); if (saveIntent && StringUtils.isNotBlank(syncCtx.getIntent())) { PropertyDelta<String> intentDelta = prismContext.deltaFactory().property().createModificationReplaceProperty(ShadowType.F_INTENT, syncCtx.getApplicableShadow().getDefinition(), syncCtx.getIntent()); modifications.add(intentDelta); } return modifications; }
private static PropertyDelta<SynchronizationSituationType> createSynchronizationSituationDelta( PrismObject<ShadowType> shadow, SynchronizationSituationType situation, PrismContext prismContext) { if (situation == null) { SynchronizationSituationType oldValue = shadow.asObjectable().getSynchronizationSituation(); return prismContext.deltaFactory().property().createModificationDeleteProperty(ShadowType.F_SYNCHRONIZATION_SITUATION, shadow.getDefinition(), oldValue); } return prismContext.deltaFactory().property().createModificationReplaceProperty(ShadowType.F_SYNCHRONIZATION_SITUATION, shadow.getDefinition(), situation); }
private void applyDeltas(TaskType worker, List<ItemDeltaType> deltas) throws SchemaException { Collection<? extends ItemDelta> itemDeltas = DeltaConvertor.toModifications(deltas, worker.asPrismObject().getDefinition()); ItemDeltaCollectionsUtil.applyTo(itemDeltas, worker.asPrismContainerValue()); }
@Override public PrismObjectDefinition<O> getDefinition() { PrismObject<O> anyObject = getAnyObject(); if (anyObject != null) { return anyObject.getDefinition(); } if (delta != null) { return delta.getPrismContext().getSchemaRegistry().findObjectDefinitionByCompileTimeClass(delta.getObjectTypeClass()); } return null; }
private <T> PropertyDelta<T> createShadowPropertyReplaceDelta(PrismObject<ShadowType> repoShadow, QName propName, T value) { PrismPropertyDefinition<T> def = repoShadow.getDefinition().findPropertyDefinition(ItemName.fromQName(propName)); PropertyDelta<T> delta = def.createEmptyDelta(ItemPath.create(propName)); if (value == null) { delta.setValueToReplace(); } else { delta.setRealValuesToReplace(value); } return delta; }
@Test public void testUserConstruction() throws Exception { System.out.println("\n\n ===[ testUserConstruction ]===\n"); // GIVEN PrismContext prismContext = PrismTestUtil.getPrismContext(); // WHEN PrismObject<UserType> user = prismContext.createObject(UserType.class); // THEN assertNotNull(user); SchemaTestUtil.assertUserDefinition(user.getDefinition()); }
private void checkOrFixActivationItem(ShadowCheckResult checkResult, PrismObject<ShadowType> shadow, PrismContainerValue<ActivationType> activation, ItemName itemName) { PrismProperty property = activation.findProperty(itemName); if (property == null || property.isEmpty()) { return; } checkResult.recordWarning(ShadowStatistics.EXTRA_ACTIVATION_DATA, "Unexpected activation item: " + property); if (fixExtraData) { PropertyDelta delta = prismContext.deltaFactory().property().createReplaceEmptyDelta(shadow.getDefinition(), ItemPath.create(ShadowType.F_ACTIVATION, itemName)); checkResult.addFixDelta(delta, ShadowStatistics.EXTRA_ACTIVATION_DATA); } }
private SceneImpl visualize(PrismObject<? extends ObjectType> object, SceneImpl owner, VisualizationContext context, Task task, OperationResult result) { SceneImpl scene = new SceneImpl(owner); scene.setChangeType(null); scene.setName(createSceneName(object)); scene.setSourceRelPath(EMPTY_PATH); scene.setSourceAbsPath(EMPTY_PATH); scene.setSourceDefinition(object.getDefinition()); scene.setSourceValue(object.getValue()); scene.setSourceDelta(null); visualizeItems(scene, object.getValue().getItems(), false, context, task, result); return scene; }
@Test public void test100AddCampaignNonOverwrite() throws Exception { PrismObject<AccessCertificationCampaignType> campaign = prismContext.parseObject(CAMPAIGN_1_FILE); campaignDef = campaign.getDefinition(); OperationResult result = new OperationResult("test100AddCampaignNonOverwrite"); campaign1Oid = repositoryService.addObject(campaign, null, result); result.recomputeStatus(); AssertJUnit.assertTrue(result.isSuccess()); checkCampaign(campaign1Oid, result, prismContext.parseObject(CAMPAIGN_1_FILE), null, null); checksCountsStandard(result); }
@SuppressWarnings("unchecked") private ObjectDelta<? extends FocusType> assignmentToDelta(ModelContext<?> modelContext, AssignmentType assignmentType, String objectOid) { PrismObject<FocusType> focus = (PrismObject<FocusType>) modelContext.getFocusContext().getObjectNew(); PrismContainerDefinition<AssignmentType> prismContainerDefinition = focus.getDefinition().findContainerDefinition(FocusType.F_ASSIGNMENT); ItemDelta<PrismContainerValue<AssignmentType>,PrismContainerDefinition<AssignmentType>> addRoleDelta = prismContext.deltaFactory().container().create( ItemPath.EMPTY_PATH, FocusType.F_ASSIGNMENT, prismContainerDefinition); PrismContainerValue<AssignmentType> assignmentValue = assignmentType.asPrismContainerValue().clone(); addRoleDelta.addValueToAdd(assignmentValue); Class focusClass = primaryChangeAspectHelper.getFocusClass(modelContext); return modelContext.getPrismContext().deltaFactory().object().createModifyDelta(objectOid, addRoleDelta, focusClass ); }
private <F extends FocusType> void unlink(LensContext<F> context, FocusType persona, OperationResult result) throws ObjectNotFoundException, SchemaException, ObjectAlreadyExistsException { ObjectDelta<F> delta = context.getFocusContext().getObjectNew().createModifyDelta(); PrismReferenceValue refValue = prismContext.itemFactory().createReferenceValue(); refValue.setOid(persona.getOid()); refValue.setTargetType(persona.asPrismObject().getDefinition().getTypeName()); delta.addModificationDeleteReference(FocusType.F_PERSONA_REF, refValue); repositoryService.modifyObject(delta.getObjectTypeClass(), delta.getOid(), delta.getModifications(), result); }
private <F extends FocusType> void link(LensContext<F> context, FocusType persona, OperationResult result) throws ObjectNotFoundException, SchemaException, ObjectAlreadyExistsException { ObjectDelta<F> delta = context.getFocusContext().getObjectNew().createModifyDelta(); PrismReferenceValue refValue = prismContext.itemFactory().createReferenceValue(); refValue.setOid(persona.getOid()); refValue.setTargetType(persona.asPrismObject().getDefinition().getTypeName()); delta.addModificationAddReference(FocusType.F_PERSONA_REF, refValue); repositoryService.modifyObject(delta.getObjectTypeClass(), delta.getOid(), delta.getModifications(), result); }
protected AssignmentType getAssignmentType(File assignmentFile) throws java.io.IOException, JAXBException, SchemaException { AssignmentType assignmentType = unmarshallValueFromFile(assignmentFile, AssignmentType.class); // We need to make sure that the assignment has a parent PrismContainerDefinition<AssignmentType> assignmentContainerDefinition = userTypeJack.asPrismObject().getDefinition().findContainerDefinition(UserType.F_ASSIGNMENT); PrismContainer<AssignmentType> assignmentContainer = assignmentContainerDefinition.instantiate(); assignmentContainer.add(assignmentType.asPrismContainerValue().clone()); return assignmentType; }
private void addObjectViaModelWS(ObjectType objectType, ModelExecuteOptionsType options, Holder<String> oidHolder, Holder<OperationResultType> resultHolder) throws FaultMessage { ObjectDeltaListType deltaList = new ObjectDeltaListType(); ObjectDeltaType objectDelta = new ObjectDeltaType(); objectDelta.setObjectToAdd(objectType); QName type = objectType.asPrismObject().getDefinition().getTypeName(); objectDelta.setObjectType(type); objectDelta.setChangeType(ChangeTypeType.ADD); deltaList.getDelta().add(objectDelta); ObjectDeltaOperationListType objectDeltaOperationListType = modelWeb.executeChanges(deltaList, options); ObjectDeltaOperationType objectDeltaOperationType = getOdoFromDeltaOperationList(objectDeltaOperationListType, objectDelta); resultHolder.value = objectDeltaOperationType.getExecutionResult(); oidHolder.value = ((ObjectType) objectDeltaOperationType.getObjectDelta().getObjectToAdd()).getOid(); }
private void assertObjectTemplatePrism(PrismObject<ObjectTemplateType> object, QName elementName) { assertEquals("Wrong oid", "10000000-0000-0000-0000-000000000002", object.getOid()); PrismObjectDefinition<ObjectTemplateType> objectDefinition = object.getDefinition(); assertNotNull("No object definition", objectDefinition); PrismAsserts.assertObjectDefinition(objectDefinition, elementName, ObjectTemplateType.COMPLEX_TYPE, ObjectTemplateType.class); assertEquals("Wrong class", ObjectTemplateType.class, object.getCompileTimeClass()); assertEquals("Wrong object item name", elementName, object.getElementName()); ObjectTemplateType objectType = object.asObjectable(); assertNotNull("asObjectable resulted in null", objectType); assertPropertyValue(object, "name", PrismTestUtil.createPolyString("Default User Template")); assertPropertyDefinition(object, "name", PolyStringType.COMPLEX_TYPE, 0, 1); }