Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Evolveum/midpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed Nov 29, 2017
2 parents 3a6bfad + 9ee4a6f commit 404f992
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 20 deletions.
Expand Up @@ -222,7 +222,7 @@ public static <T extends ObjectType> PrismObject<T> loadObject(Class<T> type, St
PageBase page, Task task, OperationResult result) {
return loadObject(type, oid, options, true, page, task, result);
}

@Nullable
public static <T extends ObjectType> PrismObject<T> loadObject(Class<T> type, String oid,
Collection<SelectorOptions<GetOperationOptions>> options, boolean allowNotFound,
Expand Down Expand Up @@ -281,6 +281,67 @@ public static <T extends ObjectType> PrismObject<T> loadObject(Class<T> type, St

return object;
}

//TODO consider using modelServiceLocator instead of PageBase in other methods.. Do we even need it? What about showResult? Should it be
// here or directly in the page? Consider usability and readabiltiy
@Nullable
public static <T extends ObjectType> PrismObject<T> loadObject(ObjectReferenceType objectReference,
ModelServiceLocator page, Task task, OperationResult result) {
Class<T> type = page.getPrismContext().getSchemaRegistry().determineClassForType(objectReference.getType());
String oid = objectReference.getOid();
Collection<SelectorOptions<GetOperationOptions>> options = null;
LOGGER.debug("Loading {} with oid {}, options {}", type.getSimpleName(), oid, options);

OperationResult subResult;
if (result != null) {
subResult = result.createMinorSubresult(OPERATION_LOAD_OBJECT);
} else {
subResult = new OperationResult(OPERATION_LOAD_OBJECT);
}
PrismObject<T> object = null;
try {
if (options == null) {
options = SelectorOptions.createCollection(GetOperationOptions.createResolveNames());
} else {
GetOperationOptions getOpts = SelectorOptions.findRootOptions(options);
if (getOpts == null) {
options.add(new SelectorOptions<>(GetOperationOptions.createResolveNames()));
} else {
getOpts.setResolveNames(Boolean.TRUE);
}
}
object = page.getModelService().getObject(type, oid, options, task, subResult);
} catch (AuthorizationException e) {
// Not authorized to access the object. This is probably caused by a reference that
// point to an object that the current user cannot read. This is no big deal.
// Just do not display that object.
subResult.recordHandledError(e);
LOGGER.debug("User {} is not authorized to read {} {}",
task.getOwner() != null ? task.getOwner().getName() : null, type.getSimpleName(), oid);
return null;
} catch (ObjectNotFoundException e) {
// Object does not exist. It was deleted in the meanwhile, or not created yet. This could happen quite often.
subResult.recordHandledError(e);
LOGGER.debug("{} {} does not exist", type.getSimpleName(), oid, e);
return null;

} catch (Exception ex) {
subResult.recordFatalError("WebModelUtils.couldntLoadObject", ex);
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load object", ex);
} finally {
subResult.computeStatus();
}
// TODO reconsider this part: until recently, the condition was always 'false'
if (WebComponentUtil.showResultInPage(subResult)) {
if (page instanceof PageBase) {
((PageBase)page).showResult(subResult);
}
}

LOGGER.debug("Loaded {} with result {}", object, subResult);

return object;
}

public static boolean isNoFetch(Collection<SelectorOptions<GetOperationOptions>> options) {
if (options == null) {
Expand Down
Expand Up @@ -271,7 +271,7 @@ private <O extends ObjectType, C extends Containerable> ContainerWrapper<C> crea
}
Task task = modelServiceLocator.createSimpleTask("Load resource ref");
//TODO: is it safe to case modelServiceLocator to pageBase?
PrismObject<ResourceType> resource = WebModelServiceUtils.loadObject(shadow.getResourceRef(), (PageBase) modelServiceLocator, task, result);
PrismObject<ResourceType> resource = WebModelServiceUtils.loadObject(shadow.getResourceRef(), modelServiceLocator, task, result);

result.computeStatusIfUnknown();
if (!result.isAcceptable()) {
Expand Down
Expand Up @@ -120,7 +120,7 @@ private boolean canAddDefault() {
}

private boolean canReadOrModifyAndNonEmpty() {
return getItemDefinition().canRead() && !getItem().isEmpty(); //(getItemDefinition().canModify() || getItemDefinition().canRead()) && !getItem().isEmpty();
return getItemDefinition().canRead() && (!getItem().isEmpty() || getItemDefinition().isEmphasized()); //(getItemDefinition().canModify() || getItemDefinition().canRead()) && !getItem().isEmpty();
}

private boolean canReadOrModifyAndShowEmpty() {
Expand Down
Expand Up @@ -45,6 +45,7 @@
import com.evolveum.midpoint.prism.PrismContainerValue;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.PrismProperty;
import com.evolveum.midpoint.prism.PrismReferenceValue;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.util.PrismAsserts;
import com.evolveum.midpoint.prism.util.PrismTestUtil;
Expand All @@ -68,6 +69,7 @@
import com.evolveum.midpoint.web.component.prism.ItemWrapper;
import com.evolveum.midpoint.web.component.prism.ObjectWrapper;
import com.evolveum.midpoint.web.component.prism.ObjectWrapperFactory;
import com.evolveum.midpoint.web.component.prism.ReferenceWrapper;
import com.evolveum.midpoint.web.component.prism.ValueStatus;
import com.evolveum.midpoint.web.component.prism.ValueWrapper;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationStatusType;
Expand Down Expand Up @@ -257,7 +259,7 @@ public void test150CreateWrapperShadow() throws Exception {
WrapperTestUtil.assertPropertyWrapper(attributesContainerValueWrapper, SchemaConstants.ICFS_NAME, USER_JACK_USERNAME);
assertEquals("wrong number of items in "+attributesContainerWrapper, 17, attributesContainerValueWrapper.getItems().size());

ContainerWrapper<ActivationType> activationContainerWrapper = objectWrapper.findContainerWrapper(new ItemPath(UserType.F_ACTIVATION));
ContainerWrapper<ActivationType> activationContainerWrapper = objectWrapper.findContainerWrapper(new ItemPath(ShadowType.F_ACTIVATION));
assertEquals("wrong number of values in "+activationContainerWrapper, 1, activationContainerWrapper.getValues().size());
ContainerValueWrapper<ActivationType> activationContainerValueWrapper = activationContainerWrapper.getValues().iterator().next();
WrapperTestUtil.assertWrapper(activationContainerWrapper, "ShadowType.activation", UserType.F_ACTIVATION, shadow, ContainerStatus.MODIFYING);
Expand Down Expand Up @@ -338,30 +340,31 @@ public void test220AssignRoleLandluberToWally() throws Exception {
WrapperTestUtil.assertPropertyWrapper(attributesContainerValueWrapper, SchemaConstants.ICFS_NAME, USER_WALLY_NAME);
assertEquals("wrong number of items in "+attributesContainerWrapper, 17, attributesContainerValueWrapper.getItems().size());

ContainerWrapper<ActivationType> activationContainerWrapper = objectWrapper.findContainerWrapper(new ItemPath(UserType.F_ACTIVATION));
ContainerWrapper<ActivationType> activationContainerWrapper = objectWrapper.findContainerWrapper(new ItemPath(ShadowType.F_ACTIVATION));
WrapperTestUtil.assertWrapper(activationContainerWrapper, "ShadowType.activation", UserType.F_ACTIVATION, shadow, ContainerStatus.MODIFYING);
assertEquals("wrong number of containers in "+activationContainerWrapper, 1, activationContainerWrapper.getValues().size());
ContainerValueWrapper<ActivationType> activationContainerValueWrapper = activationContainerWrapper.getValues().iterator().next();
WrapperTestUtil.assertPropertyWrapper(activationContainerValueWrapper, ActivationType.F_ADMINISTRATIVE_STATUS, ActivationStatusType.ENABLED);
WrapperTestUtil.assertPropertyWrapper(activationContainerValueWrapper, ActivationType.F_LOCKOUT_STATUS, null);

//TODO: fix
// ContainerWrapper<ShadowAssociationType> associationContainerWrapper = objectWrapper.findContainerWrapper(new ItemPath(ShadowType.F_ASSOCIATION));
// assertNotNull("No association container wrapper", associationContainerWrapper);
// assertEquals("wrong number of items in "+associationContainerWrapper, 2, associationContainerWrapper.getItems().size());
// ItemWrapper groupAssociationWrapper = associationContainerWrapper.findPropertyWrapper(RESOURCE_DUMMY_ASSOCIATION_GROUP_QNAME);
// assertNotNull("No group association property wrapper", groupAssociationWrapper);
// assertTrue("Wrong type of group association property wrapper: "+groupAssociationWrapper.getClass(), groupAssociationWrapper instanceof AssociationWrapper);
// List<ValueWrapper> groupAssociationValues = groupAssociationWrapper.getValues();
// assertEquals("wrong number of values in "+groupAssociationWrapper, 1, groupAssociationValues.size());
// ValueWrapper groupAssociationValue = groupAssociationValues.get(0);
// PrismContainerValue<ShadowAssociationType> groupAssociationValuePVal = (PrismContainerValue<ShadowAssociationType>) groupAssociationValue.getValue();
// display("groupAssociationValuePVal", groupAssociationValuePVal);
// assertEquals("wrong number of values in "+groupAssociationValue, ValueStatus.NOT_CHANGED, groupAssociationValue.getStatus());
// assertEquals("Wrong group association name", RESOURCE_DUMMY_ASSOCIATION_GROUP_QNAME, groupAssociationValuePVal.findProperty(ShadowAssociationType.F_NAME).getRealValue());
ContainerWrapper<ShadowAssociationType> associationContainerWrapper = objectWrapper.findContainerWrapper(new ItemPath(ShadowType.F_ASSOCIATION));
assertNotNull("No association container wrapper", associationContainerWrapper);
assertTrue("Wrong type of group association property wrapper: "+associationContainerWrapper.getClass(), associationContainerWrapper instanceof AssociationWrapper);
assertEquals("wrong number of items in "+associationContainerWrapper, 1, associationContainerWrapper.getValues().size());
ReferenceWrapper groupAssociationWrapper = (ReferenceWrapper) associationContainerWrapper.findPropertyWrapper(RESOURCE_DUMMY_ASSOCIATION_GROUP_QNAME);
assertNotNull("No group association property wrapper", groupAssociationWrapper);
List<ValueWrapper> groupAssociationValues = groupAssociationWrapper.getValues();
assertEquals("wrong number of values in "+groupAssociationWrapper, 1, groupAssociationValues.size());
ValueWrapper groupAssociationValue = groupAssociationValues.get(0);
PrismReferenceValue groupAssociationValuePVal = (PrismReferenceValue) groupAssociationValue.getValue();
display("groupAssociationValuePVal", groupAssociationValuePVal);
assertEquals("wrong number of values in "+groupAssociationValue, ValueStatus.NOT_CHANGED, groupAssociationValue.getStatus());
assertEquals("Wrong group association name", RESOURCE_DUMMY_ASSOCIATION_GROUP_QNAME, groupAssociationWrapper.getItemDefinition().getName());
assertEquals("Wrong group association value", GROUP_DUMMY_MAPMAKERS_NAME, groupAssociationValuePVal.asReferencable().getTargetName().getOrig());
// PrismContainer<ShadowIdentifiersType> groupAssociationValueIdentifiers = groupAssociationValuePVal.findContainer(ShadowAssociationType.F_IDENTIFIERS);
// PrismProperty<String> groupAssociationUidProp = groupAssociationValueIdentifiers.findProperty(new QName(null,"uid"));
// PrismAsserts.assertPropertyValue(groupAssociationUidProp, GROUP_DUMMY_MAPMAKERS_NAME);
// PrismAsserts.assertPropertyValue(groupAssociationValuePVal.asReferencable().getTargetName(), GROUP_DUMMY_MAPMAKERS_NAME);
}

/**
Expand Down Expand Up @@ -439,7 +442,7 @@ public void test800EditSchemaJackPropReadAllModifySomeUser() throws Exception {

// THEN
additionalNameWrapper = mainContainerWrapper.findPropertyWrapper(UserType.F_ADDITIONAL_NAME);
assertEquals("Wrong additionalName visible", Boolean.FALSE, (Boolean)additionalNameWrapper.isVisible()); // not visible, because it is not allowed
assertEquals("Wrong additionalName visible", Boolean.TRUE, (Boolean)additionalNameWrapper.isVisible()); // visible, because show empty

}

Expand Down

0 comments on commit 404f992

Please sign in to comment.