Skip to content

Commit

Permalink
Removing schema reference remnants (MID-5000)
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed Aug 20, 2019
1 parent 4b0b66c commit 40c3d5b
Show file tree
Hide file tree
Showing 69 changed files with 473 additions and 647 deletions.
Expand Up @@ -2500,67 +2500,71 @@ public static DisplayType getNewObjectDisplayTypeFromCollectionView(CompiledObje

public static ItemVisibility checkShadowActivationAndPasswordVisibility(ItemWrapper<?, ?, ?,?> itemWrapper,
ShadowType shadowType) {
//
ResourceType resource = shadowType.getResource();

ObjectReferenceType resourceRef = shadowType.getResourceRef();
if (resourceRef == null) {
//TODO: what to return if we don't have resource available?
return ItemVisibility.AUTO;
}
PrismObject<ResourceType> resource = resourceRef.asReferenceValue().getObject();
if (resource == null) {
//TODO: what to return if we don't have resource available?
return ItemVisibility.AUTO;
}
ResourceType resourceType = resource.asObjectable();

CompositeRefinedObjectClassDefinition ocd = null;

try {
RefinedResourceSchema resourceSchema = RefinedResourceSchema.getRefinedSchema(resource.asPrismObject());
RefinedResourceSchema resourceSchema = RefinedResourceSchema.getRefinedSchema(resource);
ocd = resourceSchema.determineCompositeObjectClassDefinition(shadowType.asPrismObject());
} catch (SchemaException e) {
LOGGER.error("Cannot find refined definition for {} in {}", shadowType, resource);
}
ResourceObjectTypeDefinitionType resourceObjectTypeDefinitionType = ResourceTypeUtil.findObjectTypeDefinition(resource.asPrismObject(), shadowType.getKind(), shadowType.getIntent());
ResourceObjectTypeDefinitionType resourceObjectTypeDefinitionType = ResourceTypeUtil.findObjectTypeDefinition(resource, shadowType.getKind(), shadowType.getIntent());


if (SchemaConstants.PATH_ACTIVATION.equivalent(itemWrapper.getPath())) {
if (ResourceTypeUtil.isActivationCapabilityEnabled(resource, resourceObjectTypeDefinitionType)) {
if (ResourceTypeUtil.isActivationCapabilityEnabled(resourceType, resourceObjectTypeDefinitionType)) {
return ItemVisibility.AUTO;
} else {
return ItemVisibility.HIDDEN;
}
}

if (SchemaConstants.PATH_ACTIVATION_ADMINISTRATIVE_STATUS.equivalent(itemWrapper.getPath())) {
if (ResourceTypeUtil.isActivationStatusCapabilityEnabled(resource, resourceObjectTypeDefinitionType)) {
if (ResourceTypeUtil.isActivationStatusCapabilityEnabled(resourceType, resourceObjectTypeDefinitionType)) {
return ItemVisibility.AUTO;
} else {
return ItemVisibility.HIDDEN;
}
}

if (SchemaConstants.PATH_ACTIVATION_LOCKOUT_STATUS.equivalent(itemWrapper.getPath())) {
if (ResourceTypeUtil.isActivationLockoutStatusCapabilityEnabled(resource, resourceObjectTypeDefinitionType)) {
if (ResourceTypeUtil.isActivationLockoutStatusCapabilityEnabled(resourceType, resourceObjectTypeDefinitionType)) {
return ItemVisibility.AUTO;
} else {
return ItemVisibility.HIDDEN;
}
}

if (SchemaConstants.PATH_ACTIVATION_VALID_FROM.equivalent(itemWrapper.getPath())) {
if (ResourceTypeUtil.isActivationValidityFromCapabilityEnabled(resource, resourceObjectTypeDefinitionType)) {
if (ResourceTypeUtil.isActivationValidityFromCapabilityEnabled(resourceType, resourceObjectTypeDefinitionType)) {
return ItemVisibility.AUTO;
} else {
return ItemVisibility.HIDDEN;
}
}

if (SchemaConstants.PATH_ACTIVATION_VALID_TO.equivalent(itemWrapper.getPath())) {
if (ResourceTypeUtil.isActivationValidityToCapabilityEnabled(resource, resourceObjectTypeDefinitionType)) {
if (ResourceTypeUtil.isActivationValidityToCapabilityEnabled(resourceType, resourceObjectTypeDefinitionType)) {
return ItemVisibility.AUTO;
} else {
return ItemVisibility.HIDDEN;
}
}

if (SchemaConstants.PATH_PASSWORD.equivalent(itemWrapper.getPath())) {
if (ResourceTypeUtil.isPasswordCapabilityEnabled(resource, resourceObjectTypeDefinitionType)) {
if (ResourceTypeUtil.isPasswordCapabilityEnabled(resourceType, resourceObjectTypeDefinitionType)) {
return ItemVisibility.AUTO;
} else {
return ItemVisibility.HIDDEN;
Expand All @@ -2580,16 +2584,20 @@ public static ItemVisibility checkShadowActivationAndPasswordVisibility(ItemWrap
}

public static boolean isActivationSupported(ShadowType shadowType) {
ResourceType resource = shadowType.getResource();

ObjectReferenceType resourceRef = shadowType.getResourceRef();
if (resourceRef == null) {
//TODO: what to return if we don't have resource available?
return true;
}
PrismObject<ResourceType> resource = resourceRef.asReferenceValue().getObject();
if (resource == null) {
//TODO: what to return if we don't have resource available?
return true;
}

ResourceObjectTypeDefinitionType resourceObjectTypeDefinitionType = ResourceTypeUtil.findObjectTypeDefinition(resource.asPrismObject(), shadowType.getKind(), shadowType.getIntent());
ResourceObjectTypeDefinitionType resourceObjectTypeDefinitionType = ResourceTypeUtil.findObjectTypeDefinition(resource, shadowType.getKind(), shadowType.getIntent());

if (ResourceTypeUtil.isActivationCapabilityEnabled(resource, resourceObjectTypeDefinitionType)) {
if (ResourceTypeUtil.isActivationCapabilityEnabled(resource.asObjectable(), resourceObjectTypeDefinitionType)) {
return true;
}

Expand All @@ -2598,16 +2606,20 @@ public static boolean isActivationSupported(ShadowType shadowType) {
}

public static boolean isPasswordSupported(ShadowType shadowType) {
ResourceType resource = shadowType.getResource();

ObjectReferenceType resourceRef = shadowType.getResourceRef();
if (resourceRef == null) {
//TODO: what to return if we don't have resource available?
return true;
}
PrismObject<ResourceType> resource = resourceRef.asReferenceValue().getObject();
if (resource == null) {
//TODO: what to return if we don't have resource available?
return true;
}

ResourceObjectTypeDefinitionType resourceObjectTypeDefinitionType = ResourceTypeUtil.findObjectTypeDefinition(resource.asPrismObject(), shadowType.getKind(), shadowType.getIntent());
ResourceObjectTypeDefinitionType resourceObjectTypeDefinitionType = ResourceTypeUtil.findObjectTypeDefinition(resource, shadowType.getKind(), shadowType.getIntent());

if (ResourceTypeUtil.isPasswordCapabilityEnabled(resource, resourceObjectTypeDefinitionType)) {
if (ResourceTypeUtil.isPasswordCapabilityEnabled(resource.asObjectable(), resourceObjectTypeDefinitionType)) {
return true;
}

Expand All @@ -2617,17 +2629,21 @@ public static boolean isPasswordSupported(ShadowType shadowType) {


public static boolean isAssociationSupported(ShadowType shadowType) {
ResourceType resource = shadowType.getResource();

ObjectReferenceType resourceRef = shadowType.getResourceRef();
if (resourceRef == null) {
//TODO: what to return if we don't have resource available?
return true;
}
PrismObject<ResourceType> resource = resourceRef.asReferenceValue().getObject();
if (resource == null) {
//TODO: what to return if we don't have resource available?
return false;
return true;
}

CompositeRefinedObjectClassDefinition ocd = null;

try {
RefinedResourceSchema resourceSchema = RefinedResourceSchema.getRefinedSchema(resource.asPrismObject());
RefinedResourceSchema resourceSchema = RefinedResourceSchema.getRefinedSchema(resource);
ocd = resourceSchema.determineCompositeObjectClassDefinition(shadowType.asPrismObject());
} catch (SchemaException e) {
LOGGER.error("Cannot find refined definition for {} in {}", shadowType, resource);
Expand Down Expand Up @@ -3031,11 +3047,10 @@ public static ExpressionType getAssociationExpression(PrismContainerValueWrapper
}

public static PrismObject<ResourceType> getConstructionResource(ConstructionType construction, String operation, PageBase pageBase){
ResourceType resource = construction.getResource();
if (resource != null){
return resource.asPrismObject();
}
ObjectReferenceType resourceRef = construction.getResourceRef();
if (resourceRef.asReferenceValue().getObject() != null) {
return resourceRef.asReferenceValue().getObject();
}
OperationResult result = new OperationResult(operation);
Task task = pageBase.createSimpleTask(operation);
return WebModelServiceUtils.resolveReferenceNoFetch(resourceRef, pageBase, task, result);
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2018 Evolveum
* Copyright (c) 2010-2019 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -814,7 +814,7 @@ public static boolean isPostAuthenticationEnabled(TaskManager taskManager, Model
public static PrismObject<SystemConfigurationType> loadSystemConfigurationAsPrismObject(PageBase pageBase, Task task, OperationResult result) {

Collection<SelectorOptions<GetOperationOptions>> options = pageBase.getOperationOptionsBuilder()
.items(SystemConfigurationType.F_DEFAULT_USER_TEMPLATE, SystemConfigurationType.F_GLOBAL_PASSWORD_POLICY).resolve()
.items(SystemConfigurationType.F_DEFAULT_USER_TEMPLATE_REF, SystemConfigurationType.F_GLOBAL_PASSWORD_POLICY_REF).resolve()
.build();

PrismObject<SystemConfigurationType> systemConfig = loadObject(
Expand Down
Expand Up @@ -144,7 +144,10 @@ protected IModel<String> getDefaltParentOrgModel() {

@Override
protected void addAdditionalExpressionVariables(ExpressionVariables variables) {
List<OrgType> parentOrgs = getModelObject().getParentOrg();
List<OrgType> parentOrgs = new ArrayList<>();
for (ObjectReferenceType parentOrgRef : getModelObject().getParentOrgRef()) {
parentOrgs.add((OrgType) parentOrgRef.asReferenceValue().getObject().asObjectable());
}
variables.putList(ExpressionConstants.VAR_ORGS, parentOrgs);
}

Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2017 Evolveum
* Copyright (c) 2010-2019 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -165,7 +165,9 @@ protected AssignmentEditorDto addSelectedResourceAssignPerformed(ResourceType re
return null;
}

construction.setResource(resource);
ObjectReferenceType resourceRef = new ObjectReferenceType();
resourceRef.asReferenceValue().setObject(resource.asPrismObject());
construction.setResourceRef(resourceRef);

AssignmentEditorDto dto = new AssignmentEditorDto(UserDtoStatus.ADD, assignment, getPageBase());

Expand Down
@@ -1,5 +1,5 @@
/*
\ * Copyright (c) 2010-2017 Evolveum
\ * Copyright (c) 2010-2019 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -209,9 +209,10 @@ public static AssignmentEditorDto createDtoFromObject(ObjectType object, UserDto
}

private AssignmentEditorDtoType getType(AssignmentType assignment) {
if (assignment.getTarget() != null) {
ObjectReferenceType targetRef = assignment.getTargetRef();
if (targetRef.asReferenceValue().getObject() != null) {
// object assignment
return AssignmentEditorDtoType.getType(assignment.getTarget().getClass());
return AssignmentEditorDtoType.getType(targetRef.asReferenceValue().getObject().getCompileTimeClass());
} else if (assignment.getTargetRef() != null) {
return AssignmentEditorDtoType.getType(assignment.getTargetRef().getType());
}
Expand Down Expand Up @@ -260,8 +261,8 @@ private List<ACAttributeDto> prepareAssignmentAttributes(AssignmentType assignme
OperationResult result = new OperationResult(OPERATION_LOAD_ATTRIBUTES);
ConstructionType construction = assignment.getConstruction();

PrismObject<ResourceType> resource = construction.getResource() != null
? construction.getResource().asPrismObject() : null;
ObjectReferenceType resourceRef = construction.getResourceRef();
PrismObject<ResourceType> resource = resourceRef.asReferenceValue().getObject();
if (resource == null) {
resource = getReference(construction.getResourceRef(), result, pageBase);
}
Expand Down Expand Up @@ -338,22 +339,20 @@ private PrismObject getReference(ObjectReferenceType ref, OperationResult result
}

private boolean isRole(AssignmentType assignment) {
if (assignment.getTarget() != null) {
ObjectReferenceType targetRef = assignment.getTargetRef();
if (targetRef == null) {
return false;
}
if (targetRef.asReferenceValue().getObject() != null) {
// object assignment
return RoleType.class.equals(assignment.getTarget().getClass());
} else if (assignment.getTargetRef() != null) {
return targetRef.asReferenceValue().getObject().canRepresent(RoleType.class);
} else {
// object assignment through reference
if (assignment.getTargetRef().getType() != null) {
return RoleType.COMPLEX_TYPE.equals(assignment.getTargetRef().getType());
}
return false;
} else if (assignment.getConstruction() != null) {
// account assignment through account construction
return false;
}

return false;

}

private ObjectViewDto loadTenantOrgReference(AssignmentType assignment, ObjectReferenceType ref) {
Expand Down Expand Up @@ -404,21 +403,19 @@ private String getNameForTargetObject(AssignmentType assignment) {
if (assignment.getConstruction() != null) {
// account assignment through account construction
ConstructionType construction = assignment.getConstruction();
if (construction.getResource() != null) {
sb.append(WebComponentUtil.getName(construction.getResource()));
} else if (construction.getResourceRef() != null) {
if (construction.getResourceRef() != null) {
sb.append(WebComponentUtil.getName(construction.getResourceRef()));
}
return sb.toString();
}

if (assignment.getTarget() != null) {
sb.append(WebComponentUtil.getEffectiveName(assignment.getTarget(), OrgType.F_DISPLAY_NAME));
appendTenantAndOrgName(sb);
} else if (assignment.getTargetRef() != null) {
Task task = pageBase.createSimpleTask("Load assignment name");
PrismObject<FocusType> target = WebModelServiceUtils.loadObject(FocusType.class,
assignment.getTargetRef().getOid(), pageBase, task, task.getResult());
if (assignment.getTargetRef() != null) {
PrismObject<FocusType> target = assignment.getTargetRef().asReferenceValue().getObject();
if (target == null) {
Task task = pageBase.createSimpleTask("Load assignment name");
target = WebModelServiceUtils.loadObject(FocusType.class,
assignment.getTargetRef().getOid(), pageBase, task, task.getResult());
}
if (target != null) {
sb.append(WebComponentUtil.getEffectiveName(target, OrgType.F_DISPLAY_NAME));
} else {
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2018 Evolveum
* Copyright (c) 2010-2019 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -572,7 +572,7 @@ public boolean isVisible() {

@Override
public boolean isVisible() {
if (!isItemAllowed(ItemPath.create(FocusType.F_ASSIGNMENT, AssignmentType.F_TARGET))){
if (!isItemAllowed(ItemPath.create(FocusType.F_ASSIGNMENT, AssignmentType.F_TARGET_REF))){
return false;
}
AssignmentEditorDto dto = getModel().getObject();
Expand Down Expand Up @@ -811,11 +811,7 @@ private List<ACAttributeDto> loadAttributes() {
return attributes;
}

PrismObject<ResourceType> resource = construction.getResource() != null
? construction.getResource().asPrismObject() : null;
if (resource == null) {
resource = getReference(construction.getResourceRef(), result);
}
PrismObject<ResourceType> resource = getReference(construction.getResourceRef(), result);

PrismContext prismContext = getPageBase().getPrismContext();
RefinedResourceSchema refinedSchema = RefinedResourceSchemaImpl.getRefinedSchema(resource,
Expand Down Expand Up @@ -886,6 +882,9 @@ public int compare(ACAttributeDto a1, ACAttributeDto a2) {
}

private PrismObject getReference(ObjectReferenceType ref, OperationResult result) {
if (ref.asReferenceValue().getObject() != null) {
return ref.asReferenceValue().getObject();
}
OperationResult subResult = result.createSubresult(OPERATION_LOAD_RESOURCE);
subResult.addParam("targetRef", ref.getOid());
PrismObject target = null;
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018 Evolveum
* Copyright (c) 2018-2019 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -846,7 +846,6 @@ protected ItemVisibility getAssignmentBasicTabVisibity(ItemWrapper<?, ?, ?, ?> i
targetType = targetRef.getType();
}
pathsToHide.add(assignmentPath.append(AssignmentType.F_TARGET_REF));
pathsToHide.add(assignmentPath.append(AssignmentType.F_TARGET));

if (OrgType.COMPLEX_TYPE.equals(targetType) || AssignmentsUtil.isPolicyRuleAssignment(assignment)) {
pathsToHide.add(assignmentPath.append(AssignmentType.F_TENANT_REF));
Expand Down

0 comments on commit 40c3d5b

Please sign in to comment.