boolean isResourceAssignment(AssignmentType assignmentType) { return assignmentType.getConstruction() != null; }
ResourceType getAssignmentApprovalTarget(AssignmentType assignmentType, OperationResult result) { if (assignmentType.getConstruction() == null) { return null; } if (assignmentType.getConstruction().getResource() != null) { return assignmentType.getConstruction().getResource(); } ObjectReferenceType resourceRef = assignmentType.getConstruction().getResourceRef(); return primaryChangeAspectHelper.resolveTargetRef(resourceRef, ResourceType.class, result); }
public static ShadowKindType determineConstructionKind(AssignmentType assignmentType) { ConstructionType construction = assignmentType.getConstruction(); if (construction != null){ if (construction.getKind() != null){ return construction.getKind(); } return ShadowKindType.ACCOUNT; } throw new IllegalArgumentException("Construction not defined in the assigment."); }
public static String determineConstructionIntent(AssignmentType assignmentType) { ConstructionType construction = assignmentType.getConstruction(); if (construction != null){ if (construction.getIntent() != null){ return construction.getIntent(); } return SchemaConstants.INTENT_DEFAULT; } throw new IllegalArgumentException("Construction not defined in the assigment."); }
public static String dumpAssignment(AssignmentType assignmentType) { StringBuilder sb = new StringBuilder(); 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("]-> ").append(assignmentType.getTargetRef().getOid()); } return sb.toString(); }
public static <F extends FocusType> void assertAssignedResource(PrismObject<F> user, String resourceOid) { F userType = user.asObjectable(); for (AssignmentType assignmentType: userType.getAssignment()) { if (assignmentType.getConstruction() == null) { continue; } ObjectReferenceType targetRef = assignmentType.getConstruction().getResourceRef(); if (targetRef != null) { if (resourceOid.equals(targetRef.getOid())) { return; } } } AssertJUnit.fail(user + " does NOT have assigned resource "+resourceOid+" while expecting it"); }
public ResourceType resolveResourceRef(AssignmentType a, OperationResult result) { if (a == null) { return null; } if (a.getConstruction() == null) { return null; } if (a.getConstruction().getResourceRef() == null) { return null; } try { return repositoryService.getObject(ResourceType.class, a.getConstruction().getResourceRef().getOid(), null, result).asObjectable(); } catch (ObjectNotFoundException|SchemaException e) { throw new SystemException(e); } }
public static <F extends FocusType> void assertNotAssignedResource(PrismObject<F> user, String resourceOid) { F userType = user.asObjectable(); for (AssignmentType assignmentType: userType.getAssignment()) { if (assignmentType.getConstruction() == null) { continue; } ObjectReferenceType targetRef = assignmentType.getConstruction().getResourceRef(); if (targetRef != null) { if (resourceOid.equals(targetRef.getOid())) { AssertJUnit.fail(user + " does have assigned resource "+resourceOid+" while not expecting it"); } } } }
AssignmentType cloneAndCanonicalizeAssignment(AssignmentType assignmentType) { AssignmentType assignmentClone = assignmentType.clone(); PrismContainerValue.copyDefinition(assignmentClone, assignmentType, prismContext); ConstructionType constructionType = assignmentClone.getConstruction(); if (constructionType != null) { // it should always be non-null constructionType.setResource(null); } return assignmentClone; } }
public static String toShortString(AssignmentType assignment) { if (assignment == null) { return "null"; } StringBuilder sb = new StringBuilder("Assignment("); if (assignment.getConstruction() != null) { sb.append("construction"); // TODO } if (assignment.getTarget() != null) { sb.append(toShortString(assignment.getTarget())); } if (assignment.getTargetRef() != null) { sb.append(toShortString(assignment.getTargetRef())); } sb.append(")"); return sb.toString(); }
protected void assertAssignedNoAccount(PrismObject<UserType> user, String resourceOid) throws ObjectNotFoundException, SchemaException { UserType userType = user.asObjectable(); for (AssignmentType assignmentType: userType.getAssignment()) { ConstructionType construction = assignmentType.getConstruction(); if (construction != null) { if (construction.getKind() != null && construction.getKind() != ShadowKindType.ACCOUNT) { continue; } if (resourceOid.equals(construction.getResourceRef().getOid())) { AssertJUnit.fail(user.toString()+" has account assignment for resource "+resourceOid+" while expecting no such assignment"); } } } }
public static String determineConstructionResource(AssignmentType assignmentType) { ConstructionType construction = assignmentType.getConstruction(); if (construction != null){ if (construction.getResource() != null){ return construction.getResource().getOid(); } else if (construction.getResourceRef() != null){ return construction.getResourceRef().getOid(); } return null; } return null; }
protected AssignmentType assertAssignedAccount(PrismObject<UserType> user, String resourceOid) throws ObjectNotFoundException, SchemaException { UserType userType = user.asObjectable(); for (AssignmentType assignmentType: userType.getAssignment()) { ConstructionType construction = assignmentType.getConstruction(); if (construction != null) { if (construction.getKind() != null && construction.getKind() != ShadowKindType.ACCOUNT) { continue; } if (resourceOid.equals(construction.getResourceRef().getOid())) { return assignmentType; } } } AssertJUnit.fail(user.toString() + " does not have account assignment for resource " + resourceOid); return null; // not reached }
@Test public void addGetRoleWithResourceRefFilter() throws Exception{ PrismObject<RoleType> role = prismContext.parseObject(new File("src/test/resources/basic/role-resource-filter.xml")); System.out.println("role: " + role.debugDump()); System.out.println("role: " + role.asObjectable().getInducement().get(0).getConstruction().getResourceRef().getFilter()); OperationResult result = new OperationResult("sync desc test"); String oid = repositoryService.addObject(role, null, result); role = repositoryService.getObject(RoleType.class, oid, null, result); RoleType roleType = role.asObjectable(); System.out.println("role: " + role.debugDump()); System.out.println("role: " + role.asObjectable().getInducement().get(0).getConstruction().getResourceRef().getFilter()); // desc = roleType.getSynchronizationSituationDescription().get(0); // AssertJUnit.assertEquals("Times don't match", TIME, XMLGregorianCalendarType.asDate(desc.getTimestamp())); }
private void checkNoAssignmentConstruction(UserType jack, String attributeName) { assertEquals("jack's assignments", 1, jack.getAssignment().size()); AssignmentType assignmentType = jack.getAssignment().get(0); ConstructionType constructionType = assignmentType.getConstruction(); assertNotNull("construction is null", constructionType); for (ResourceAttributeDefinitionType attributeDefinitionType : constructionType.getAttribute()) { if (attributeDefinitionType.getRef().equivalent(new ItemPathType(ItemPath.create(new QName(attributeName))))) { fail("Construction attribute " + attributeName + " present, although it shouldn't"); } } }
private void checkAssignmentConstruction(UserType jack, String attributeName, String value) throws SchemaException { assertEquals("jack's assignments", 1, jack.getAssignment().size()); AssignmentType assignmentType = jack.getAssignment().get(0); ConstructionType constructionType = assignmentType.getConstruction(); assertNotNull("construction is null", constructionType); boolean found = false; for (ResourceAttributeDefinitionType attributeDefinitionType : constructionType.getAttribute()) { if (attributeDefinitionType.getRef().equivalent(new ItemPathType(ItemPath.create(new QName(attributeName))))) { ExpressionType expressionType = attributeDefinitionType.getOutbound().getExpression(); assertNotNull("no expression", expressionType); assertEquals("wrong # of expression evaluators", 1, expressionType.getExpressionEvaluator().size()); JAXBElement<?> element = expressionType.getExpressionEvaluator().get(0); PrimitiveXNode valueXNode = (PrimitiveXNode) (((RawType) element.getValue()).serializeToXNode()); assertEquals("wrong outbound value", value, valueXNode.getStringValue()); found = true; } } assertTrue("attribute " + attributeName + " mapping not found", found); }
@Test public void test300UserAssignmentPreview() throws Exception { final String TEST_NAME = "test300UserAssignmentPreview"; Task task = createTask(TEST_NAME); PrismObject<UserType> jack = getUser(USER_JACK_OID); display("jack", jack); AssignmentType ass1 = new AssignmentType(prismContext); ass1.setConstruction(new ConstructionType(prismContext)); ass1.getConstruction().setResourceRef(createObjectRef(RESOURCE_DUMMY_OID, RESOURCE)); ObjectDelta<UserType> delta = deltaFor(UserType.class) .item(UserType.F_ASSIGNMENT).add(ass1) .asObjectDelta(USER_JACK_OID); delta.applyDefinitionIfPresent(jack.getDefinition(), false); /// WHEN displayWhen(TEST_NAME); ModelContext<UserType> modelContext = modelInteractionService.previewChanges(Collections.<ObjectDelta<? extends ObjectType>>singletonList(delta), null, task, task.getResult()); List<ObjectDelta<? extends ObjectType>> primaryDeltas = new ArrayList<>(); List<ObjectDelta<? extends ObjectType>> secondaryDeltas = new ArrayList<>(); fillDeltas(modelContext, primaryDeltas, secondaryDeltas); List<? extends Scene> primaryScenes = modelInteractionService.visualizeDeltas(primaryDeltas, task, task.getResult()); List<? extends Scene> secondaryScenes = modelInteractionService.visualizeDeltas(secondaryDeltas, task, task.getResult()); // THEN displayThen(TEST_NAME); display("primary scenes", primaryScenes); display("secondary scenes", secondaryScenes); // TODO some asserts }
private void collectConstruction(AssignmentPathSegmentImpl segment, PlusMinusZero mode, boolean isValid, EvaluationContext ctx) throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException { assertSourceNotNull(segment.source, ctx.evalAssignment); AssignmentType assignmentType = getAssignmentType(segment, ctx); ConstructionType constructionType = assignmentType.getConstruction(); LOGGER.trace("Preparing construction '{}' in {}", constructionType.getDescription(), segment.source); Construction<AH> construction = new Construction<>(constructionType, segment.source); // We have to clone here as the path is constantly changing during evaluation construction.setAssignmentPath(ctx.assignmentPath.clone()); construction.setFocusOdo(focusOdo); construction.setLensContext(lensContext); construction.setObjectResolver(objectResolver); construction.setPrismContext(prismContext); construction.setMappingFactory(mappingFactory); construction.setMappingEvaluator(mappingEvaluator); construction.setOriginType(OriginType.ASSIGNMENTS); construction.setChannel(channel); construction.setOrderOneObject(segment.getOrderOneObject()); construction.setValid(isValid); construction.setRelativityMode(mode); // Do not evaluate the construction here. We will do it in the second pass. Just prepare everything to be evaluated. if (mode == null) { return; // null mode (i.e. plus + minus) means 'ignore the payload' } ctx.evalAssignment.addConstruction(construction, mode); }
@Test public void test305UserAssignmentAdd() throws Exception { final String TEST_NAME = "test305UserAssignmentAdd"; Task task = createTask(TEST_NAME); display("jack", getUser(USER_JACK_OID)); AssignmentType ass1 = new AssignmentType(); ass1.setConstruction(new ConstructionType()); ass1.getConstruction().setResourceRef(createObjectRef(RESOURCE_DUMMY_OID, RESOURCE)); ObjectDelta<UserType> delta = deltaFor(UserType.class) .item(UserType.F_ASSIGNMENT).add(ass1) .asObjectDelta(USER_JACK_OID); /// WHEN displayWhen(TEST_NAME); final Scene scene = visualizer.visualizeDelta(delta, task, task.getResult()); modelService.executeChanges(Collections.<ObjectDelta<? extends ObjectType>>singletonList(delta), null, task, task.getResult()); // THEN displayThen(TEST_NAME); display("scene", scene); display("jack with assignment", getUser(USER_JACK_OID)); // TODO some asserts }
private void assertJaxb(AccessCertificationCaseType aCase) throws SchemaException { PrismAsserts.assertRefEquivalent("Wrong objectRef", getPrismContext().itemFactory().createReferenceValue("ee53eba7-5c16-4c16-ad15-dd6a2360ab1a", UserType.COMPLEX_TYPE), aCase.getObjectRef().asReferenceValue()); PrismAsserts.assertRefEquivalent("Wrong targetRef", getPrismContext().itemFactory().createReferenceValue("ef2bc95b-76e0-48e2-86d6-3d4f02d3e1a2", ResourceType.COMPLEX_TYPE), aCase.getTargetRef().asReferenceValue()); assertTrue(aCase instanceof AccessCertificationAssignmentCaseType); AccessCertificationAssignmentCaseType assignmentCase = (AccessCertificationAssignmentCaseType) aCase; assertNotNull("no assignment", assignmentCase.getAssignment()); assertEquals((Long) 1L, assignmentCase.getAssignment().getId()); PrismAsserts.assertRefEquivalent("Wrong resourceRef in assignment", getPrismContext().itemFactory().createReferenceValue("ef2bc95b-76e0-48e2-86d6-3d4f02d3e1a2", ResourceType.COMPLEX_TYPE), assignmentCase.getAssignment().getConstruction().getResourceRef().asReferenceValue()); assertEquals("wrong isInducement", Boolean.FALSE, assignmentCase.isIsInducement()); }