private List<PrismContainer> getChildrenContainers(PrismObject parent) { List<PrismContainer> containers = new ArrayList<>(); if (ObjectType.class.isAssignableFrom(parent.getCompileTimeClass())) { containers.add(parent.findContainer(ObjectType.F_TRIGGER)); } if (LookupTableType.class.isAssignableFrom(parent.getCompileTimeClass())) { containers.add(parent.findContainer(LookupTableType.F_ROW)); } if (FocusType.class.isAssignableFrom(parent.getCompileTimeClass())) { containers.add(parent.findContainer(FocusType.F_ASSIGNMENT)); } if (AbstractRoleType.class.isAssignableFrom(parent.getCompileTimeClass())) { containers.add(parent.findContainer(AbstractRoleType.F_INDUCEMENT)); containers.add(parent.findContainer(AbstractRoleType.F_EXCLUSION)); containers.add(parent.findContainer(AbstractRoleType.F_AUTHORIZATION)); PrismContainer policyConstraints = parent.findContainer(AbstractRoleType.F_POLICY_CONSTRAINTS); if (policyConstraints != null) { containers.add(policyConstraints.findContainer(PolicyConstraintsType.F_MAX_ASSIGNEES)); containers.add(policyConstraints.findContainer(PolicyConstraintsType.F_MIN_ASSIGNEES)); } } return containers; }
private AssignmentItemDto createAssignmentItem( PrismObject<UserType> user, PrismContainerValue assignment, Task task, OperationResult result) { PrismReference targetRef = assignment.findReference(AssignmentType.F_TARGET_REF); if (targetRef == null || targetRef.isEmpty()) { // account construction PrismContainer construction = assignment.findContainer(AssignmentType.F_CONSTRUCTION); String name = null; String description = null; if (construction.getValue().asContainerable() != null && !construction.isEmpty()) { ConstructionType constr = (ConstructionType) construction.getValue().asContainerable(); description = (String) construction.getPropertyRealValue(ConstructionType.F_DESCRIPTION, String.class); if (constr.getResourceRef() != null) { ObjectReferenceType resourceRef = constr.getResourceRef(); PrismObject resource = WebModelUtils.loadObject( ResourceType.class, resourceRef.getOid(), this, task, result); name = WebMiscUtil.getName(resource); } } return new AssignmentItemDto( AssignmentEditorDtoType.ACCOUNT_CONSTRUCTION, name, description, null); } PrismReferenceValue refValue = targetRef.getValue(); PrismObject value = refValue.getObject(); if (value == null) { // resolve reference value = WebModelUtils.loadObject(ObjectType.class, refValue.getOid(), this, task, result); } if (value == null) { // we couldn't resolve assignment details return new AssignmentItemDto(null, null, null, null); } String name = WebMiscUtil.getName(value); AssignmentEditorDtoType type = AssignmentEditorDtoType.getType(value.getCompileTimeClass()); String relation = refValue.getRelation() != null ? refValue.getRelation().getLocalPart() : null; String description = null; if (RoleType.class.isAssignableFrom(value.getCompileTimeClass())) { description = (String) value.getPropertyRealValue(RoleType.F_DESCRIPTION, String.class); } return new AssignmentItemDto(type, name, description, relation); }
public boolean isProtectedAccount() { if (object == null || !(ShadowType.class.isAssignableFrom(object.getCompileTimeClass()))) { return false; } PrismProperty<Boolean> protectedObject = object.findProperty(ShadowType.F_PROTECTED_OBJECT); if (protectedObject == null) { return false; } return protectedObject.getRealValue() != null ? protectedObject.getRealValue() : false; }
@Override public <T extends ObjectType> String addObject( PrismObject<T> object, RepoAddOptions options, OperationResult parentResult) throws ObjectAlreadyExistsException, SchemaException { String oid = repository.addObject(object, options, parentResult); Cache cache = getCache(); // DON't cache the object here. The object may not have proper "JAXB" form, e.g. some pieces may // be // DOM element instead of JAXB elements. Not to cache it is safer and the performance loss // is acceptable. if (cache != null) { // Invalidate the cache entry if it happens to be there cache.removeObject(oid); cache.clearQueryResults(object.getCompileTimeClass()); } return oid; }
private void assertTask(PrismObject<TaskType> task) { task.checkConsistence(); assertEquals("Wrong oid", "44444444-4444-4444-4444-000000001111", task.getOid()); PrismObjectDefinition<TaskType> usedDefinition = task.getDefinition(); assertNotNull("No task definition", usedDefinition); PrismAsserts.assertObjectDefinition( usedDefinition, new QName(SchemaConstantsGenerated.NS_COMMON, "task"), TaskType.COMPLEX_TYPE, TaskType.class); assertEquals("Wrong class in task", TaskType.class, task.getCompileTimeClass()); TaskType taskType = task.asObjectable(); assertNotNull("asObjectable resulted in null", taskType); assertPropertyValue(task, "name", PrismTestUtil.createPolyString("Task2")); assertPropertyDefinition(task, "name", PolyStringType.COMPLEX_TYPE, 0, 1); assertPropertyValue(task, "taskIdentifier", "44444444-4444-4444-4444-000000001111"); assertPropertyDefinition(task, "taskIdentifier", DOMUtil.XSD_STRING, 0, 1); assertPropertyDefinition( task, "executionStatus", JAXBUtil.getTypeQName(TaskExecutionStatusType.class), 1, 1); PrismProperty<TaskExecutionStatusType> executionStatusProperty = task.findProperty(TaskType.F_EXECUTION_STATUS); PrismPropertyValue<TaskExecutionStatusType> executionStatusValue = executionStatusProperty.getValue(); TaskExecutionStatusType executionStatus = executionStatusValue.getValue(); assertEquals("Wrong execution status", TaskExecutionStatusType.RUNNABLE, executionStatus); PrismContainer extension = task.getExtension(); PrismContainerValue extensionValue = extension.getValue(); assertTrue("Extension parent", extensionValue.getParent() == extension); assertNull("Extension ID", extensionValue.getId()); }
private List<ItemWrapper> createProperties(PageBase pageBase) { result = new OperationResult(CREATE_PROPERTIES); List<ItemWrapper> properties = new ArrayList<ItemWrapper>(); PrismContainerDefinition definition = null; PrismObject parent = getObject().getObject(); Class clazz = parent.getCompileTimeClass(); if (ShadowType.class.isAssignableFrom(clazz)) { QName name = containerDefinition.getName(); if (ShadowType.F_ATTRIBUTES.equals(name)) { try { definition = objectWrapper.getRefinedAttributeDefinition(); if (definition == null) { PrismReference resourceRef = parent.findReference(ShadowType.F_RESOURCE_REF); PrismObject<ResourceType> resource = resourceRef.getValue().getObject(); definition = pageBase .getModelInteractionService() .getEditObjectClassDefinition( (PrismObject<ShadowType>) objectWrapper.getObject(), resource, AuthorizationPhaseType.REQUEST) .toResourceAttributeContainerDefinition(); if (LOGGER.isTraceEnabled()) { LOGGER.trace("Refined account def:\n{}", definition.debugDump()); } } } catch (Exception ex) { LoggingUtils.logException( LOGGER, "Couldn't load definitions from refined schema for shadow", ex); result.recordFatalError( "Couldn't load definitions from refined schema for shadow, reason: " + ex.getMessage(), ex); return properties; } } else { definition = containerDefinition; } } else if (ResourceType.class.isAssignableFrom(clazz)) { if (containerDefinition != null) { definition = containerDefinition; } else { definition = container.getDefinition(); } } else { definition = containerDefinition; } if (definition == null) { LOGGER.error( "Couldn't get property list from null definition {}", new Object[] {container.getElementName()}); return properties; } // assignments are treated in a special way -- we display names of // org.units and roles // (but only if ObjectWrapper.isShowAssignments() is true; otherwise // they are filtered out by ObjectWrapper) if (container.getCompileTimeClass() != null && AssignmentType.class.isAssignableFrom(container.getCompileTimeClass())) { for (Object o : container.getValues()) { PrismContainerValue<AssignmentType> pcv = (PrismContainerValue<AssignmentType>) o; AssignmentType assignmentType = pcv.asContainerable(); if (assignmentType.getTargetRef() == null) { continue; } // hack... we want to create a definition for Name // PrismPropertyDefinition def = ((PrismContainerValue) // pcv.getContainer().getParent()).getContainer().findProperty(ObjectType.F_NAME).getDefinition(); PrismPropertyDefinition def = new PrismPropertyDefinition( ObjectType.F_NAME, DOMUtil.XSD_STRING, pcv.getPrismContext()); if (OrgType.COMPLEX_TYPE.equals(assignmentType.getTargetRef().getType())) { def.setDisplayName("Org.Unit"); def.setDisplayOrder(100); } else if (RoleType.COMPLEX_TYPE.equals(assignmentType.getTargetRef().getType())) { def.setDisplayName("Role"); def.setDisplayOrder(200); } else { continue; } PrismProperty<Object> temp = def.instantiate(); String value = formatAssignmentBrief(assignmentType); temp.setValue(new PrismPropertyValue<Object>(value)); // TODO: do this.isReadOnly() - is that OK? (originally it was the default behavior for all // cases) properties.add(new PropertyWrapper(this, temp, this.isReadonly(), ValueStatus.NOT_CHANGED)); } } else if (isShadowAssociation()) { PrismContext prismContext = objectWrapper.getObject().getPrismContext(); Map<QName, PrismContainer<ShadowAssociationType>> assocMap = new HashMap<>(); if (objectWrapper.getAssociations() != null) { for (PrismContainerValue<ShadowAssociationType> cval : objectWrapper.getAssociations()) { ShadowAssociationType associationType = cval.asContainerable(); QName assocName = associationType.getName(); PrismContainer<ShadowAssociationType> fractionalContainer = assocMap.get(assocName); if (fractionalContainer == null) { fractionalContainer = new PrismContainer<>( ShadowType.F_ASSOCIATION, ShadowAssociationType.class, cval.getPrismContext()); fractionalContainer.setDefinition(cval.getParent().getDefinition()); // HACK: set the name of the association as the element name so wrapper.getName() will // return correct data. fractionalContainer.setElementName(assocName); assocMap.put(assocName, fractionalContainer); } try { fractionalContainer.add(cval.clone()); } catch (SchemaException e) { // Should not happen throw new SystemException("Unexpected error: " + e.getMessage(), e); } } } PrismReference resourceRef = parent.findReference(ShadowType.F_RESOURCE_REF); PrismObject<ResourceType> resource = resourceRef.getValue().getObject(); // HACK. The revive should not be here. Revive is no good. The next use of the resource will // cause parsing of resource schema. We need some centralized place to maintain live cached // copies // of resources. try { resource.revive(prismContext); } catch (SchemaException e) { throw new SystemException(e.getMessage(), e); } RefinedResourceSchema refinedSchema; CompositeRefinedObjectClassDefinition rOcDef; try { refinedSchema = RefinedResourceSchema.getRefinedSchema(resource); rOcDef = refinedSchema.determineCompositeObjectClassDefinition(parent); } catch (SchemaException e) { throw new SystemException(e.getMessage(), e); } // Make sure even empty associations have their wrappers so they can be displayed and edited for (RefinedAssociationDefinition assocDef : rOcDef.getAssociations()) { QName name = assocDef.getName(); if (!assocMap.containsKey(name)) { PrismContainer<ShadowAssociationType> fractionalContainer = new PrismContainer<>( ShadowType.F_ASSOCIATION, ShadowAssociationType.class, prismContext); fractionalContainer.setDefinition(getItemDefinition()); // HACK: set the name of the association as the element name so wrapper.getName() will // return correct data. fractionalContainer.setElementName(name); assocMap.put(name, fractionalContainer); } } for (Entry<QName, PrismContainer<ShadowAssociationType>> assocEntry : assocMap.entrySet()) { // HACK HACK HACK, the container wrapper should not parse itself. This code should not be // here. AssociationWrapper assocWrapper = new AssociationWrapper( this, assocEntry.getValue(), this.isReadonly(), ValueStatus.NOT_CHANGED); properties.add(assocWrapper); } } else { // if not an assignment if ((container.getValues().size() == 1 || container.getValues().isEmpty()) && (containerDefinition == null || containerDefinition.isSingleValue())) { // there's no point in showing properties for non-single-valued // parent containers, // so we continue only if the parent is single-valued Collection<ItemDefinition> propertyDefinitions = definition.getDefinitions(); for (ItemDefinition itemDef : propertyDefinitions) { if (itemDef instanceof PrismPropertyDefinition) { PrismPropertyDefinition def = (PrismPropertyDefinition) itemDef; if (def.isIgnored() || skipProperty(def)) { continue; } if (!showInheritedObjectAttributes && INHERITED_OBJECT_ATTRIBUTES.contains(def.getName())) { continue; } // capability handling for activation properties if (isShadowActivation() && !hasCapability(def)) { continue; } if (isShadowAssociation()) { continue; } PrismProperty property = container.findProperty(def.getName()); boolean propertyIsReadOnly; // decision is based on parent object status, not this // container's one (because container can be added also // to an existing object) if (objectWrapper.getStatus() == ContainerStatus.MODIFYING) { propertyIsReadOnly = !def.canModify(); } else { propertyIsReadOnly = !def.canAdd(); } if (property == null) { properties.add( new PropertyWrapper( this, def.instantiate(), propertyIsReadOnly, ValueStatus.ADDED)); } else { properties.add( new PropertyWrapper(this, property, propertyIsReadOnly, ValueStatus.NOT_CHANGED)); } } else if (itemDef instanceof PrismReferenceDefinition) { PrismReferenceDefinition def = (PrismReferenceDefinition) itemDef; if (INHERITED_OBJECT_ATTRIBUTES.contains(def.getName())) { continue; } PrismReference reference = container.findReference(def.getName()); boolean propertyIsReadOnly; // decision is based on parent object status, not this // container's one (because container can be added also // to an existing object) if (objectWrapper.getStatus() == ContainerStatus.MODIFYING) { propertyIsReadOnly = !def.canModify(); } else { propertyIsReadOnly = !def.canAdd(); } if (reference == null) { properties.add( new ReferenceWrapper( this, def.instantiate(), propertyIsReadOnly, ValueStatus.ADDED)); } else { properties.add( new ReferenceWrapper( this, reference, propertyIsReadOnly, ValueStatus.NOT_CHANGED)); } } } } } Collections.sort(properties, new ItemWrapperComparator()); result.recomputeStatus(); return properties; }
private boolean isUser() { ObjectWrapper wrapper = getContainer().getObject(); PrismObject object = wrapper.getObject(); return UserType.class.isAssignableFrom(object.getCompileTimeClass()); }
public ObjectDelta getObjectDelta() throws SchemaException { if (ContainerStatus.ADDING.equals(getStatus())) { return createAddingObjectDelta(); } ObjectDelta delta = new ObjectDelta(object.getCompileTimeClass(), ChangeType.MODIFY, object.getPrismContext()); delta.setOid(object.getOid()); List<ContainerWrapper> containers = getContainers(); // sort containers by path size Collections.sort(containers, new PathSizeComparator()); for (ContainerWrapper containerWrapper : getContainers()) { // create ContainerDelta for association container // HACK HACK HACK create correct procession for association container data // according to its structure if (containerWrapper.getItemDefinition().getName().equals(ShadowType.F_ASSOCIATION)) { ContainerDelta<ShadowAssociationType> associationDelta = ContainerDelta.createDelta( ShadowType.F_ASSOCIATION, containerWrapper.getItemDefinition()); List<AssociationWrapper> associationItemWrappers = (List<AssociationWrapper>) containerWrapper.getItems(); for (AssociationWrapper associationItemWrapper : associationItemWrappers) { List<ValueWrapper> assocValueWrappers = associationItemWrapper.getValues(); for (ValueWrapper assocValueWrapper : assocValueWrappers) { PrismContainerValue<ShadowAssociationType> assocValue = (PrismContainerValue<ShadowAssociationType>) assocValueWrapper.getValue(); if (assocValueWrapper.getStatus() == ValueStatus.DELETED) { associationDelta.addValueToDelete(assocValue.clone()); } else if (assocValueWrapper.getStatus().equals(ValueStatus.ADDED)) { associationDelta.addValueToAdd(assocValue.clone()); } } } delta.addModification(associationDelta); } else { if (!containerWrapper.hasChanged()) { continue; } for (ItemWrapper itemWrapper : (List<ItemWrapper>) containerWrapper.getItems()) { if (!itemWrapper.hasChanged()) { continue; } ItemPath containerPath = containerWrapper.getPath() != null ? containerWrapper.getPath() : new ItemPath(); if (itemWrapper instanceof PropertyWrapper) { ItemDelta pDelta = computePropertyDeltas((PropertyWrapper) itemWrapper, containerPath); if (!pDelta.isEmpty()) { delta.addModification(pDelta); } } if (itemWrapper instanceof ReferenceWrapper) { ReferenceDelta pDelta = computeReferenceDeltas((ReferenceWrapper) itemWrapper, containerPath); if (!pDelta.isEmpty()) { delta.addModification(pDelta); } } } } } // returning container to previous order Collections.sort(containers, new ItemWrapperComparator()); // Make sure we have all the definitions if (object.getPrismContext() != null) { object.getPrismContext().adopt(delta); } return delta; }
private List<ContainerWrapper> createContainers(PageBase pageBase) { result = new OperationResult(CREATE_CONTAINERS); List<ContainerWrapper> containers = new ArrayList<ContainerWrapper>(); try { Class clazz = object.getCompileTimeClass(); if (ShadowType.class.isAssignableFrom(clazz)) { PrismContainer attributes = object.findContainer(ShadowType.F_ATTRIBUTES); ContainerStatus status = attributes != null ? getStatus() : ContainerStatus.ADDING; if (attributes == null) { PrismContainerDefinition definition = object.getDefinition().findContainerDefinition(ShadowType.F_ATTRIBUTES); attributes = definition.instantiate(); } ContainerWrapper container = new ContainerWrapper( this, attributes, status, new ItemPath(ShadowType.F_ATTRIBUTES), pageBase); addSubresult(container.getResult()); container.setMain(true); containers.add(container); if (hasResourceCapability( ((ShadowType) object.asObjectable()).getResource(), ActivationCapabilityType.class)) { containers.addAll( createCustomContainerWrapper(object, ShadowType.F_ACTIVATION, pageBase)); } if (hasResourceCapability( ((ShadowType) object.asObjectable()).getResource(), CredentialsCapabilityType.class)) { containers.addAll( createCustomContainerWrapper(object, ShadowType.F_CREDENTIALS, pageBase)); } PrismContainer<ShadowAssociationType> associationContainer = object.findOrCreateContainer(ShadowType.F_ASSOCIATION); container = new ContainerWrapper( this, associationContainer, ContainerStatus.MODIFYING, new ItemPath(ShadowType.F_ASSOCIATION), pageBase); addSubresult(container.getResult()); containers.add(container); } else if (ResourceType.class.isAssignableFrom(clazz)) { containers = createResourceContainers(pageBase); } else if (ReportType.class.isAssignableFrom(clazz)) { containers = createReportContainers(pageBase); } else { ContainerWrapper container = new ContainerWrapper(this, object, getStatus(), null, pageBase); addSubresult(container.getResult()); containers.add(container); containers.addAll(createContainerWrapper(object, null, pageBase)); } } catch (Exception ex) { // TODO: shouldn't be this exception thrown???? LoggingUtils.logUnexpectedException(LOGGER, "Error occurred during container wrapping", ex); result.recordFatalError( "Error occurred during container wrapping, reason: " + ex.getMessage(), ex); } Collections.sort(containers, new ItemWrapperComparator()); result.recomputeStatus(); result.recordSuccessIfUnknown(); return containers; }