public <X> PrismProperty<X> createProperty(PrismPropertyDefinition propertyDefinition) throws SchemaException { PrismProperty<X> property = propertyDefinition.instantiate(); add(property); return property; }
public <P extends PrismProperty> P instantiateEmptyProperty() { PrismPropertyDefinition propertyDefinition = getPropertyDefinition(); if (propertyDefinition == null) { throw new IllegalArgumentException("Cannot instantiate property "+ getElementName()+" from delta "+this+": no definition"); } return (P) propertyDefinition.instantiate(getElementName()); }
private <X> PrismProperty<X> resolveStructuredPropertyItem(PrismProperty<Structured> sourceProperty, ItemPath resolvePath, PrismPropertyDefinition outputDefinition) { if (sourceProperty == null) { return null; } PrismProperty<X> outputProperty = outputDefinition.instantiate(); for (Structured sourceRealValue: sourceProperty.getRealValues()) { X outputRealValue = (X) sourceRealValue.resolve(resolvePath); outputProperty.addRealValue(outputRealValue); } return outputProperty; }
protected PrismPropertyValue<T> makePPV(T realValue, PrismPropertyDefinition definition) { PrismProperty<T> property = definition.instantiate(); property.setRealValue(realValue); return property.getAnyValue(); }
itemDefinition.instantiate() : new PrismPropertyImpl<>(itemName, prismContext);
public <X> PrismProperty<X> createProperty(QName propertyName) throws SchemaException { checkMutability(); PrismPropertyDefinition propertyDefinition = determineItemDefinition(propertyName, getComplexTypeDefinition()); if (propertyDefinition == null) { // container has definition, but there is no property definition. This is either runtime schema // or an error if (getParent() != null && getDefinition() != null && !getDefinition().isRuntimeSchema()) { // TODO clean this up throw new IllegalArgumentException("No definition for property "+propertyName+" in "+complexTypeDefinition); } } PrismProperty<X> property; if (propertyDefinition == null) { property = new PrismPropertyImpl<>(propertyName, prismContext); // Definitionless } else { property = propertyDefinition.instantiate(); } add(property, false); return property; }
public static <T,X> PrismProperty<X> convertProperty(PrismProperty<T> srcProp, PrismPropertyDefinition<X> targetDef, PrismContext prismContext) throws SchemaException { if (targetDef.getTypeName().equals(srcProp.getDefinition().getTypeName())) { return (PrismProperty<X>) srcProp; } else { PrismProperty<X> targetProp = targetDef.instantiate(); Class<X> expectedJavaType = XsdTypeMapper.toJavaType(targetDef.getTypeName()); for (PrismPropertyValue<T> srcPVal: srcProp.getValues()) { X convertedRealValue = JavaTypeConverter.convert(expectedJavaType, srcPVal.getValue()); targetProp.add(prismContext.itemFactory().createPropertyValue(convertedRealValue)); } return targetProp; } }
public static Object getIterationTokenVariableValue(LensProjectionContext accCtx) { String iterationTokenOld = null; PrismObject<ShadowType> shadowCurrent = accCtx.getObjectCurrent(); if (shadowCurrent != null) { iterationTokenOld = shadowCurrent.asObjectable().getIterationToken(); } if (iterationTokenOld == null) { return accCtx.getIterationToken(); } PrismPropertyDefinition<String> propDef = accCtx.getPrismContext().definitionFactory().createPropertyDefinition( ExpressionConstants.VAR_ITERATION_TOKEN, DOMUtil.XSD_STRING); PrismProperty<String> propOld = propDef.instantiate(); propOld.setRealValue(iterationTokenOld); PropertyDelta<String> propDelta = propDef.createEmptyDelta(ExpressionConstants.VAR_ITERATION_TOKEN); propDelta.setRealValuesToReplace(accCtx.getIterationToken()); PrismProperty<String> propNew = propDef.instantiate(); propNew.setRealValue(accCtx.getIterationToken()); ItemDeltaItem<PrismPropertyValue<String>,PrismPropertyDefinition<String>> idi = new ItemDeltaItem<>(propOld, propDelta, propNew); return idi; }
public static Object getIterationVariableValue(LensProjectionContext accCtx) { Integer iterationOld = null; PrismObject<ShadowType> shadowCurrent = accCtx.getObjectCurrent(); if (shadowCurrent != null) { iterationOld = shadowCurrent.asObjectable().getIteration(); } if (iterationOld == null) { return accCtx.getIteration(); } PrismPropertyDefinition<Integer> propDef = accCtx.getPrismContext().definitionFactory().createPropertyDefinition(ExpressionConstants.VAR_ITERATION, DOMUtil.XSD_INT); PrismProperty<Integer> propOld = propDef.instantiate(); propOld.setRealValue(iterationOld); PropertyDelta<Integer> propDelta = propDef.createEmptyDelta(ExpressionConstants.VAR_ITERATION); propDelta.setRealValuesToReplace(accCtx.getIteration()); PrismProperty<Integer> propNew = propDef.instantiate(); propNew.setRealValue(accCtx.getIteration()); ItemDeltaItem<PrismPropertyValue<Integer>,PrismPropertyDefinition<Integer>> idi = new ItemDeltaItem<>(propOld, propDelta, propNew); return idi; }
PrismProperty<XMLGregorianCalendar> datePP = datePPD.instantiate(); Date now = new Date(); Date yesterday = new Date(now.getTime()-86400000L);
public static ItemDelta<?, ?> createExtensionDelta(PrismPropertyDefinition definition, Object realValue, PrismContext prismContext) { PrismProperty<Object> property = (PrismProperty<Object>) definition.instantiate(); property.setRealValue(realValue); return prismContext.deltaFactory().property() .createModificationReplaceProperty(ItemPath.create(TaskType.F_EXTENSION, property.getElementName()), definition, realValue); }
PrismProperty<String> outputOidProperty = prismContext.getSchemaRegistry().findPropertyDefinitionByElementName(ReportConstants.REPORT_OUTPUT_OID_PROPERTY_NAME).instantiate(); outputOidProperty.setRealValue(outputOid); task.setExtensionPropertyImmediate(outputOidProperty, subResult);
PrismProperty<String> displayNamePP = displayNamePPD.instantiate(); displayNamePP.setRealValue("Big red ball"); displayNamePP.setImmutable(true);
@Test public void testReindex() throws Exception { final String TEST_NAME = "testReindex"; TestUtil.displayTestTitle(TEST_NAME); OperationResult result = new OperationResult(TEST_NAME); PrismObject<UserType> user = prismContext.createObjectable(UserType.class) .name("unstable") .asPrismObject(); ItemPath UNSTABLE_PATH = ItemPath.create(UserType.F_EXTENSION, "unstable"); PrismPropertyDefinition<String> unstableDef = user.getDefinition().findPropertyDefinition(UNSTABLE_PATH); PrismProperty<String> unstable = unstableDef.instantiate(); unstable.setRealValue("hi"); user.addExtensionItem(unstable); String oid = repositoryService.addObject(user, null, result); // brutal hack -- may stop working in the future! unstableDef.toMutable().setIndexed(true); repositoryService.modifyObject(UserType.class, oid, emptySet(), getModifyOptions(), result); ObjectQuery query = prismContext.queryFor(UserType.class) .item(UNSTABLE_PATH).eq("hi") .build(); int count = repositoryService.countObjects(UserType.class, query, null, result); assertEquals("Wrong # of objects found", 1, count); }
@Test public void test132JackUnAssignRolePirateWithSeaInAssignment() throws Exception { final String TEST_NAME = "test132JackUnAssignRolePirateWithSeaInAssignment"; displayTestTitle(TEST_NAME); Task task = createTask(TEST_NAME); OperationResult result = task.getResult(); PrismContainer<?> extension = getAssignmentExtensionInstance(); PrismSchema piracySchema = getPiracySchema(); PrismPropertyDefinition<String> seaPropDef = piracySchema.findPropertyDefinitionByElementName(PIRACY_SEA_QNAME); PrismProperty<String> seaProp = seaPropDef.instantiate(); seaProp.setRealValue("Caribbean"); extension.add(seaProp); // WHEN unassignRole(USER_JACK_OID, ROLE_PIRATE_OID, extension, task, result); // THEN result.computeStatus(); TestUtil.assertSuccess(result); PrismObject<UserType> userJack = getUser(USER_JACK_OID); display("User after", userJack); assertAssignments(userJack, 0); assertRoleMembershipRef(userJack); assertDelegatedRef(userJack); assertNoDummyAccount(ACCOUNT_JACK_DUMMY_USERNAME); }
@Test public void test139JackUnAssignRoleAdriaticPirateWithSeaInAssignment() throws Exception { final String TEST_NAME = "test139JackUnAssignRoleAdriaticPirateWithSeaInAssignment"; displayTestTitle(TEST_NAME); Task task = createTask(TEST_NAME); OperationResult result = task.getResult(); PrismContainer<?> extension = getAssignmentExtensionInstance(); PrismSchema piracySchema = getPiracySchema(); PrismPropertyDefinition<String> seaPropDef = piracySchema.findPropertyDefinitionByElementName(PIRACY_SEA_QNAME); PrismProperty<String> seaProp = seaPropDef.instantiate(); seaProp.setRealValue("Caribbean"); extension.add(seaProp); // WHEN unassignRole(USER_JACK_OID, ROLE_ADRIATIC_PIRATE_OID, extension, getDefaultOptions(), task, result); // THEN result.computeStatus(); TestUtil.assertSuccess(result); PrismObject<UserType> userJack = getUser(USER_JACK_OID); display("User after", userJack); assertAssignments(userJack, 0); assertRoleMembershipRef(userJack); assertDelegatedRef(userJack); assertNoDummyAccount(ACCOUNT_JACK_DUMMY_USERNAME); }
@Test public void test149JackUnAssignRoleBlackSeaPirateWithSeaInAssignment() throws Exception { final String TEST_NAME = "test149JackUnAssignRoleBlackSeaPirateWithSeaInAssignment"; displayTestTitle(TEST_NAME); Task task = createTask(TEST_NAME); OperationResult result = task.getResult(); PrismContainer<?> extension = getAssignmentExtensionInstance(); PrismSchema piracySchema = getPiracySchema(); PrismPropertyDefinition<String> seaPropDef = piracySchema.findPropertyDefinitionByElementName(PIRACY_SEA_QNAME); PrismProperty<String> seaProp = seaPropDef.instantiate(); seaProp.setRealValue("Caribbean"); extension.add(seaProp); // WHEN unassignRole(USER_JACK_OID, ROLE_BLACK_SEA_PIRATE_OID, extension, getDefaultOptions(), task, result); // THEN result.computeStatus(); TestUtil.assertSuccess(result); PrismObject<UserType> userJack = getUser(USER_JACK_OID); display("User after", userJack); assertAssignments(userJack, 0); assertRoleMembershipRef(userJack); assertDelegatedRef(userJack); assertNoDummyAccount(ACCOUNT_JACK_DUMMY_USERNAME); }
@Test public static void testSerializeTask() throws Exception { ObjectQuery query = getPrismContext().queryFor(ShadowType.class) .item(ShadowType.F_KIND).eq(ShadowKindType.ACCOUNT) .build(); QueryType queryType = getPrismContext().getQueryConverter().createQueryType(query); PrismPropertyDefinition queryDef = getPrismContext().definitionFactory().createPropertyDefinition( SchemaConstants.MODEL_EXTENSION_OBJECT_QUERY, QueryType.COMPLEX_TYPE); PrismProperty<QueryType> queryProp = queryDef.instantiate(); queryProp.setRealValue(queryType); TaskType taskType = getPrismContext().createObject(TaskType.class).asObjectable(); taskType.setExtension(new ExtensionType(getPrismContext())); taskType.getExtension().asPrismContainerValue().add(queryProp); taskType.setName(PolyStringType.fromOrig("Test task")); String xml = getPrismContext().xmlSerializer().serialize(taskType.asPrismObject()); System.out.println("Task serialized:\n" + xml); PrismObject<TaskType> taskParsed = getPrismContext().parserFor(xml).parse(); String xmlSerializedAgain = getPrismContext().xmlSerializer().serialize(taskParsed); System.out.println("Task serialized again:\n" + xmlSerializedAgain); }
PrismSchema piracySchema = getPiracySchema(); PrismPropertyDefinition<String> seaPropDef = piracySchema.findPropertyDefinitionByElementName(PIRACY_SEA_QNAME); PrismProperty<String> seaProp = seaPropDef.instantiate(); seaProp.setRealValue("Caribbean"); extension.add(seaProp);
PrismSchema piracySchema = getPiracySchema(); PrismPropertyDefinition<String> seaPropDef = piracySchema.findPropertyDefinitionByElementName(PIRACY_SEA_QNAME); PrismProperty<String> seaProp = seaPropDef.instantiate(); seaProp.setRealValue("Caribbean"); extension.add(seaProp);