private ObjectType convert(Class clazz, PrismObject<? extends ObjectType> o, OperationResultType result) { ObjectType objType = null; try { objType = (ObjectType) prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(clazz).instantiate().asObjectable(); objType.setOid(o.getOid()); objType.setName(o.asObjectable().getName()); return objType; } catch (SchemaException e) { // TODO Auto-generated catch block return objType; } }
private <C extends Containerable, O extends ObjectType> Collection<PrismContainerValue<C>> determineContainerValuesFromCurrentObject( ItemPath path, PrismObject<O> currentObject) { PrismContainer<C> container = currentObject.findContainer(path); if (container == null) { return null; } return container.getValues(); }
public static String debugDump(ObjectType objectType, int indent) { if (objectType == null) { StringBuilder sb = new StringBuilder(); DebugUtil.indentDebugDump(sb, indent); sb.append("null"); return sb.toString(); } return objectType.asPrismObject().debugDump(indent); }
private <T extends ObjectType> void cacheObject(Cache cache, PrismObject<T> object, boolean readOnly) { if (cache != null) { PrismObject<ObjectType> objectToCache; if (readOnly) { object.setImmutable(true); objectToCache = (PrismObject<ObjectType>) object; } else { objectToCache = (PrismObject<ObjectType>) object.clone(); } cache.putObject(object.getOid(), objectToCache); } }
private static String formatObject(PrismObject<? extends ObjectType> object) { if (object == null) { return "null"; } return object.asObjectable().toDebugType()+":"+object.getOid()+"("+object.getElementName()+")"; }
protected <O extends ObjectType> void assertCreateMetadata(PrismObject<O> object, XMLGregorianCalendar start, XMLGregorianCalendar end) { MetadataType metadataType = object.asObjectable().getMetadata(); PrismObject<UserType> defaultActor = getDefaultActor(); assertMetadata(object.toString(), metadataType, true, true, start, end, defaultActor==null?null:defaultActor.getOid(), DEFAULT_CHANNEL); }
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); }
/** * Creates unassign delta by removing each assignment individually by id. */ protected <F extends FocusType> ObjectDelta<F> createUnassignAllDelta(PrismObject<F> focusBefore) throws SchemaException { Collection<ItemDelta<?,?>> modifications = new ArrayList<>(); for (AssignmentType assignmentType: focusBefore.asObjectable().getAssignment()) { modifications.add((createAssignmentModification(assignmentType.getId(), false))); } return prismContext.deltaFactory().object() .createModifyDelta(focusBefore.getOid(), modifications, focusBefore.getCompileTimeClass() ); }
public static <F extends FocusType> void assertNoAssignments(PrismObject<F> user) { F userType = user.asObjectable(); List<AssignmentType> assignments = userType.getAssignment(); assertTrue(user + " does have assignments "+assignments+" while not expecting it", assignments.isEmpty()); }
public static <O extends Objectable> ObjectDeltaImpl<O> createAddDelta(PrismObject<O> objectToAdd) { ObjectDeltaImpl<O> objectDelta = new ObjectDeltaImpl<>(objectToAdd.getCompileTimeClass(), ChangeType.ADD, objectToAdd.getPrismContext()); objectDelta.setOid(objectToAdd.getOid()); objectDelta.setObjectToAdd(objectToAdd); return objectDelta; }
public static <O extends ObjectType> ObjectReferenceType createObjectReference(PrismObject<O> object, Class<? extends ObjectType> implicitReferenceTargetType) { ObjectReferenceType ref = new ObjectReferenceType(); ref.setOid(object.getOid()); if (implicitReferenceTargetType == null || !implicitReferenceTargetType.equals(object.getCompileTimeClass())) { ref.setType(ObjectTypes.getObjectType(object.getCompileTimeClass()).getTypeQName()); } ref.setTargetName(PolyString.toPolyStringType(object.getName())); return ref; }
private void recordError(OperationResult objectResult, PrismObject<? extends ObjectType> object, String errorLabel, Exception e) { String objectLabel = object != null && object.getName() != null ? object.asObjectable().getClass().getSimpleName() + " \"" + object.getName().getOrig() + "\"" : "object"; // We intentionally do NOT record the exception here, because it could override our message with the localizable // one it (potentially) carries. And we really want to show the following message as it contains the name of the object // that couldn't be imported. We hope the exception is recorded in some inner result. objectResult.recordFatalError("Import of " + objectLabel + " failed: " + errorLabel + ": " + e.getMessage()); LOGGER.error("Import of object {} failed: {}: {}", object, errorLabel, e.getMessage(), e); }
@Test public void testReplaceModelOperationContext() throws Exception { PrismObject prismObject = PrismTestUtil.parseObject(new File(TEST_DIR, "task-modelOperationContext-before.xml")); ObjectDelta delta = getPrismContext().deltaFactory().object().createEmptyModifyDelta(TaskType.class, prismObject.getOid() ); delta.addModificationReplaceContainer(TaskType.F_MODEL_OPERATION_CONTEXT); PrismObject changed = prismObject.clone(); ItemDeltaCollectionsUtil.applyTo(delta.getModifications(), changed); Collection<? extends ItemDelta> processedModifications = prismObject.diffModifications(changed, EquivalenceStrategy.LITERAL_IGNORE_METADATA); ItemDeltaCollectionsUtil.applyTo(processedModifications, prismObject); assertNull(prismObject.findContainer(TaskType.F_MODEL_OPERATION_CONTEXT)); }
public void deleteConflictedShadowFromRepo(PrismObject<ShadowType> shadow, OperationResult parentResult){ try{ repositoryService.deleteObject(shadow.getCompileTimeClass(), shadow.getOid(), parentResult); } catch (Exception ex){ throw new SystemException(ex.getMessage(), ex); } }
protected <F extends FocusType> void removeLinks(PrismObject<F> focus) throws ObjectNotFoundException, SchemaException, ObjectAlreadyExistsException { PrismReference linkRef = focus.findReference(FocusType.F_LINK_REF); if (linkRef == null) { return; } OperationResult result = new OperationResult("removeLinks"); ReferenceDelta refDelta = linkRef.createDelta(); refDelta.addValuesToDelete(linkRef.getClonedValues()); repositoryService.modifyObject(focus.getCompileTimeClass(), focus.getOid(), MiscSchemaUtil.createCollection(refDelta), result); assertSuccess(result); }
protected <O extends ObjectType> String addObject(PrismObject<O> object, ModelExecuteOptions options, Task task, OperationResult result) throws ObjectAlreadyExistsException, ObjectNotFoundException, SchemaException, ExpressionEvaluationException, CommunicationException, ConfigurationException, PolicyViolationException, SecurityViolationException { ObjectDelta<O> addDelta = object.createAddDelta(); assertFalse("Immutable object provided?",addDelta.getObjectToAdd().isImmutable()); Collection<ObjectDeltaOperation<? extends ObjectType>> executedDeltas = executeChanges(addDelta, options, task, result); object.setOid(ObjectDeltaOperation.findFocusDeltaOidInCollection(executedDeltas)); return object.getOid(); }
private void assertUserDrake(PrismObject<UserType> user, boolean assertDefinitions, PrismContext prismContext) throws SchemaException, SAXException, IOException { assertEquals("Wrong OID", USER_OID, user.getOid()); assertEquals("Wrong compileTimeClass", UserType.class, user.getCompileTimeClass()); user.checkConsistence(); assertUserDrakeContent(user, assertDefinitions); if (assertDefinitions) { serializeAndValidate(user, prismContext); } }
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 <O extends ObjectType> void serializationRoundTrip(File file) throws Exception { PrismContext prismContext = getPrismContext(); PrismObject<O> parsedObject = prismContext.parseObject(file); System.out.println("\nParsed object:"); System.out.println(parsedObject.debugDump()); serializationRoundTripPrismObject(parsedObject); serializationRoundTripObjectType(parsedObject.asObjectable()); }
protected PrismObject<ShadowType> getShadowAfter(PrismObject<ShadowType> oldObject) { PrismObject<ShadowType> newObject = oldObject.clone(); newObject.asObjectable().setObjectChange(null); return newObject; }