protected boolean assignmentMatches(AssignmentType assignmentType, String targetOid, QName relation) { ObjectReferenceType targetRef = assignmentType.getTargetRef(); if (targetRef == null) { return false; } return referenceMatches(targetRef, targetOid, relation); }
public static String prettyPrint(AssignmentType assignmentType) { if (assignmentType == null) { return "null"; } StringBuilder sb = new StringBuilder("AssignmentType("); if (assignmentType.getTarget() != null) { sb.append("target:"); sb.append(prettyPrint(assignmentType.getTarget())); } if (assignmentType.getTargetRef() != null) { sb.append("target:"); sb.append(prettyPrint(assignmentType.getTargetRef())); } if (assignmentType.getConstruction() != null) { sb.append(prettyPrint(assignmentType.getConstruction())); } sb.append(", "); if (assignmentType.getActivation() != null) { sb.append(prettyPrint(assignmentType.getActivation())); } sb.append(")"); return sb.toString(); }
@Override public boolean equals(Object object) { if (!(object instanceof AssignmentType)) { return false; } AssignmentType other = ((AssignmentType) object); return asPrismContainerValue().equivalent(other.asPrismContainerValue()); }
public AssignmentType clone() { AssignmentType object = new AssignmentType(); PrismContainerValue value = asPrismContainerValue().clone(); object.setupContainerValue(value); return object; }
protected AssignmentType createAssignmentIdOnly(long id) { AssignmentType assignment = new AssignmentType(); assignment.asPrismContainerValue().setId(id); return assignment; }
repo.setTransient(generatorResult.isTransient(jaxb.asPrismContainerValue())); repo.setId(RUtil.toInteger(jaxb.getId())); repo.setOrder(jaxb.getOrder()); repo.setLifecycleState(jaxb.getLifecycleState()); repo.setPolicySituation(RUtil.listToSet(jaxb.getPolicySituation())); if (jaxb.getExtension() != null) { RAssignmentExtension extension = new RAssignmentExtension(); extension.setOwner(repo); RAssignmentExtension.fromJaxb(jaxb.getExtension(), extension, RAssignmentExtensionType.EXTENSION, repositoryContext); if (jaxb.getActivation() != null) { RActivation activation = new RActivation(); RActivation.fromJaxb(jaxb.getActivation(), activation, repositoryContext); repo.setActivation(activation); if (jaxb.getTarget() != null) { LOGGER.warn("Target from assignment type won't be saved. It should be translated to target reference."); repo.setTargetRef(RUtil.jaxbRefToEmbeddedRepoRef(jaxb.getTargetRef(), repositoryContext.relationRegistry)); repo.setTenantRef(RUtil.jaxbRefToEmbeddedRepoRef(jaxb.getTenantRef(), repositoryContext.relationRegistry)); repo.setOrgRef(RUtil.jaxbRefToEmbeddedRepoRef(jaxb.getOrgRef(), repositoryContext.relationRegistry)); if (jaxb.getConstruction() != null) {
@Test public void testAssignmentHashcode3() throws SchemaException { LOGGER.info("\n\n===[ testAssignmentHashcode3 ]===\n"); System.out.println("\n\n===[ testAssignmentHashcode3 ]===\n"); PrismContext prismContext = PrismTestUtil.getPrismContext(); AssignmentType a1a = new AssignmentType(prismContext) .beginActivation() .validTo("2018-01-01T00:00:00.000+01:00") .end(); AssignmentType a1b = a1a.clone(); // use unqualified item name for validTo a1b.getActivation().asPrismContainerValue() .findItem(ActivationType.F_VALID_TO) .setElementName(new QName("validTo")); System.out.println("a1a = " + a1a.asPrismContainerValue().debugDump()); System.out.println("a1b = " + a1b.asPrismContainerValue().debugDump()); // WHEN assertEquals("Wrong hashCode", a1a.hashCode(), a1b.hashCode()); }
private AssignmentType toDelete(AssignmentType assignment, boolean byId) { if (assignment == null) { return null; } if (!byId) { return assignment.clone(); } else { AssignmentType rv = new AssignmentType(prismContext); rv.setId(assignment.getId()); return rv; } }
@Test public void test220UserContainerReplace() throws Exception { final String TEST_NAME = "test220UserContainerReplace"; Task task = createTask(TEST_NAME); AssignmentType ass1 = new AssignmentType(prismContext); ass1.setActivation(new ActivationType(prismContext)); ass1.getActivation().setAdministrativeStatus(ActivationStatusType.DISABLED); ass1.getActivation().setValidFrom(XmlTypeConverter.createXMLGregorianCalendar(2010, 1, 1, 0, 0, 0)); ass1.setTargetRef(createObjectRef(ROLE_SUPERUSER_OID, ROLE)); ActivationType act1 = new ActivationType(prismContext); act1.setAdministrativeStatus(ActivationStatusType.DISABLED); ObjectDelta<?> delta = deltaFor(UserType.class) .item(UserType.F_NAME).replace("admin") .item(UserType.F_ACTIVATION).replace(act1) .item(UserType.F_ASSIGNMENT).replace(ass1) .asObjectDelta(USER_ADMINISTRATOR_OID); /// WHEN displayWhen(TEST_NAME); final Scene scene = visualizer.visualizeDelta((ObjectDelta<? extends ObjectType>) delta, task, task.getResult()); // THEN displayThen(TEST_NAME); display("scene", scene); // TODO some asserts }
private void processAssignment(AssignmentType assignment, ObjectType object, List<AccessCertificationCaseType> caseList) { AccessCertificationAssignmentCaseType assignmentCase = new AccessCertificationAssignmentCaseType(prismContext); assignmentCase.setAssignment(assignment.clone()); assignmentCase.setObjectRef(ObjectTypeUtil.createObjectRef(object, prismContext)); assignmentCase.setTenantRef(assignment.getTenantRef()); assignmentCase.setOrgRef(assignment.getOrgRef()); assignmentCase.setActivation(assignment.getActivation()); if (assignment.getTargetRef() != null) { assignmentCase.setTargetRef(assignment.getTargetRef()); } else { // very strange: assignment with no target, but participating in the exclusion? // maybe a dynamic target, though } caseList.add(assignmentCase); }
public static AssignmentType createTargetAssignment(String targetOid, QName type) { AssignmentType assignmentType = new AssignmentType(); ObjectReferenceType targetRef = new ObjectReferenceType(); targetRef.setOid(targetOid); targetRef.setType(type); assignmentType.setTargetRef(targetRef); return assignmentType; }
boolean isResourceAssignment(AssignmentType assignmentType) { return assignmentType.getConstruction() != null; }
protected PrismContainerValue<AssignmentType> createPrismValue(String oid, QName targetTypeQName, List<ItemDelta<PrismContainerValue<AssignmentType>, PrismContainerDefinition<AssignmentType>>> additionalAttributeDeltas, ExpressionEvaluationContext params) { AssignmentType assignmentType = new AssignmentType(getPrismContext()); PrismContainerValue<AssignmentType> assignmentCVal = assignmentType.asPrismContainerValue(); ObjectReferenceType targetRef = new ObjectReferenceType(); targetRef.setOid(oid); targetRef.setType(targetTypeQName); targetRef.setRelation(getRelation()); assignmentType.setTargetRef(targetRef); assignmentType.getSubtype().addAll(getSubtypes()); try { if (additionalAttributeDeltas != null) { ItemDeltaCollectionsUtil.applyTo(additionalAttributeDeltas, assignmentCVal); } getPrismContext().adopt(assignmentCVal, FocusType.COMPLEX_TYPE, FocusType.F_ASSIGNMENT); if (InternalsConfig.consistencyChecks) { assignmentCVal.assertDefinitions("assignmentCVal in assignment expression in "+params.getContextDescription()); } } catch (SchemaException e) { // Should not happen throw new SystemException(e); } return assignmentCVal; }
@NotNull public static <T extends ObjectType> AssignmentType createAssignmentTo(@NotNull ObjectReferenceType ref, @Nullable PrismContext prismContext) { AssignmentType assignment = new AssignmentType(prismContext); if (QNameUtil.match(ref.getType(), ResourceType.COMPLEX_TYPE)) { ConstructionType construction = new ConstructionType(); construction.setResourceRef(ref); assignment.setConstruction(construction); } else { assignment.setTargetRef(ref); } return assignment; }
@NotNull public static AssignmentType createAssignmentWithConstruction(@NotNull PrismObject<ResourceType> object, ShadowKindType kind, String intent, PrismContext prismContext) { AssignmentType assignment = new AssignmentType(prismContext); ConstructionType construction = new ConstructionType(prismContext); construction.setResourceRef(createObjectRef(object, prismContext)); construction.setKind(kind); construction.setIntent(intent); assignment.setConstruction(construction); return assignment; }
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(); }
private <F extends AssignmentHolderType> void createAssignmentDelta(LensContext<F> context, LensProjectionContext accountContext) throws SchemaException{ Class<F> focusClass = context.getFocusClass(); ContainerDelta<AssignmentType> assignmentDelta = prismContext.deltaFactory().container() .createDelta(AssignmentHolderType.F_ASSIGNMENT, focusClass); AssignmentType assignment = new AssignmentType(); ConstructionType constructionType = new ConstructionType(); constructionType.setResourceRef(ObjectTypeUtil.createObjectRef(accountContext.getResource(), prismContext)); assignment.setConstruction(constructionType); assignmentDelta.addValueToAdd(assignment.asPrismContainerValue()); PrismContainerDefinition<AssignmentType> containerDefinition = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(focusClass).findContainerDefinition(AssignmentHolderType.F_ASSIGNMENT); assignmentDelta.applyDefinition(containerDefinition); context.getFocusContext().swallowToProjectionWaveSecondaryDelta(assignmentDelta); }
@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 <F extends FocusType> void applyAssignmentValueMetadataAdd(LensContext<F> context, PrismContainerValue<AssignmentType> assignmentContainerValue, String desc, XMLGregorianCalendar now, Task task, OperationResult result) throws SchemaException { AssignmentType assignmentType = assignmentContainerValue.asContainerable(); MetadataType metadataType = assignmentType.getMetadata(); if (metadataType == null) { metadataType = new MetadataType(); assignmentType.setMetadata(metadataType); } transplantRequestMetadata(context, metadataType); // This applies the effective status only to assignments that are completely new (whole container is added/replaced) // The effectiveStatus of existing assignments is processed in FocusProcessor.processAssignmentActivation() // We cannot process that here. Because this code is not even triggered when there is no delta. So recompute will not work. ActivationType activationType = assignmentType.getActivation(); ActivationStatusType effectiveStatus = activationComputer.getEffectiveStatus(assignmentType.getLifecycleState(), activationType, null); if (activationType == null) { activationType = new ActivationType(); assignmentType.setActivation(activationType); } activationType.setEffectiveStatus(effectiveStatus); applyCreateMetadata(context, metadataType, now, task); if (LOGGER.isTraceEnabled()) { LOGGER.trace("Adding operational data {} to assignment cval ({}):\nMETADATA:\n{}\nACTIVATION:\n{}", metadataType, desc, assignmentContainerValue.debugDump(1), activationType.asPrismContainerValue().debugDump(1)); } }