Skip to content

Commit

Permalink
Merge branch 'master' into feature/ldap-1-4-3-0-snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed Jan 25, 2016
2 parents b92dbaf + 6b83be3 commit 721df6f
Show file tree
Hide file tree
Showing 8 changed files with 198 additions and 72 deletions.
Expand Up @@ -21,6 +21,8 @@
import com.evolveum.midpoint.common.refinery.RefinedResourceSchema;
import com.evolveum.midpoint.prism.*;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.schema.GetOperationOptions;
import com.evolveum.midpoint.schema.SelectorOptions;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.util.ResourceTypeUtil;
import com.evolveum.midpoint.util.DOMUtil;
Expand Down Expand Up @@ -195,26 +197,31 @@ private List<ItemWrapper> createProperties(ContainerWrapper cWrapper, OperationR
} else if (isShadowAssociation(cWrapper)) {
PrismContext prismContext = objectWrapper.getObject().getPrismContext();
Map<QName, PrismContainer<ShadowAssociationType>> assocMap = new HashMap<>();
if (objectWrapper.getAssociations() != null) {
List<PrismContainerValue<ShadowAssociationType>> associations = objectWrapper.getAssociations();
for (PrismContainerValue<ShadowAssociationType> cval : associations) {
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);
}
}
PrismContainer<ShadowAssociationType> associationContainer = cWrapper.getItem();
if (associationContainer != null && associationContainer.getValues() != null) {
// Do NOT load shadows here. This will be huge overhead if there are many associations.
// Load them on-demand (if necessary at all).
List<PrismContainerValue<ShadowAssociationType>> associations = associationContainer.getValues();
if (associations != null) {
for (PrismContainerValue<ShadowAssociationType> cval : associations) {
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);
Expand Down Expand Up @@ -341,7 +348,7 @@ private List<ItemWrapper> createProperties(ContainerWrapper cWrapper, OperationR
return properties;
}

private boolean isShadowAssociation(ContainerWrapper cWrapper) {
private boolean isShadowAssociation(ContainerWrapper cWrapper) {
ObjectWrapper oWrapper = cWrapper.getObject();
PrismContainer container = cWrapper.getItem();

Expand Down
Expand Up @@ -77,7 +77,6 @@ public class ObjectWrapper<O extends ObjectType> implements Serializable, Reviva
private OperationResult result;
private boolean protectedAccount;

private List<PrismContainerValue<ShadowAssociationType>> associations;
private Collection<PrismObject<OrgType>> parentOrgs = new ArrayList<>();

private OperationResult fetchResult;
Expand Down Expand Up @@ -127,14 +126,6 @@ public void revive(PrismContext prismContext) throws SchemaException {
}
}

public List<PrismContainerValue<ShadowAssociationType>> getAssociations() {
return associations;
}

public void setAssociations(List<PrismContainerValue<ShadowAssociationType>> associations) {
this.associations = associations;
}

public Collection<PrismObject<OrgType>> getParentOrgs() {
return parentOrgs;
}
Expand Down
Expand Up @@ -291,45 +291,12 @@ private <P extends ObjectType> List<FocusProjectionDto> loadProjectionWrappers(C
wrapper.setSelectable(true);
wrapper.setMinimalized(true);

if (ShadowType.class.equals(type)) {

PrismContainer<ShadowAssociationType> associationContainer = projection
.findContainer(ShadowType.F_ASSOCIATION);
if (associationContainer != null && associationContainer.getValues() != null) {
List<PrismContainerValue<ShadowAssociationType>> associations = new ArrayList<>(
associationContainer.getValues().size());
for (PrismContainerValue<ShadowAssociationType> associationVal : associationContainer.getValues()) {
ShadowAssociationType associationType = (ShadowAssociationType) associationVal
.asContainerable();
ObjectReferenceType shadowRef = associationType.getShadowRef();
// shadowRef can be null in case of "broken"
// associations we can safely eliminate fetching
// from resource, because we need only the name
if (shadowRef != null) {
PrismObject<ShadowType> associationTargetShadow = getModelService().getObject(ShadowType.class,
shadowRef.getOid(), SelectorOptions.createCollection(GetOperationOptions.createNoFetch()),
task, subResult);
shadowRef.asReferenceValue().setObject(associationTargetShadow);
associations.add(associationVal);
}
}
wrapper.setAssociations(associations);
}

}
wrapper.initializeContainers(this);

list.add(new FocusProjectionDto(wrapper, UserDtoStatus.MODIFY));

subResult.recomputeStatus();
} catch (ObjectNotFoundException ex) {
// this is fix for MID-854, full user/accounts/assignments
// reload if accountRef reference is broken
// because consistency already fixed it.
getObjectModel().reset();
projectionModel.reset();
getParentOrgModel().reset();
assignmentsModel.reset();

} catch (Exception ex) {
subResult.recordFatalError("Couldn't load account." + ex.getMessage(), ex);
LoggingUtils.logException(LOGGER, "Couldn't load account", ex);
Expand Down
Expand Up @@ -70,7 +70,8 @@ public void initSystem(Task initTask, OperationResult initResult) throws Excepti
dummyResourceCtl.setResource(resourceDummy);

repoAddObjectFromFile(USER_JACK_FILE, UserType.class, true, initResult);


importObjectFromFile(ROLE_MAPMAKER_FILE);
}

@Test
Expand Down
Expand Up @@ -17,6 +17,10 @@

import java.io.File;

import javax.xml.namespace.QName;

import com.evolveum.midpoint.schema.constants.MidPointConstants;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.test.util.MidPointTestConstants;

/**
Expand All @@ -42,10 +46,15 @@ public class AdminGuiTestConstants {

public static final File RESOURCE_DUMMY_FILE = new File(COMMON_DIR, "resource-dummy.xml");
public static final String RESOURCE_DUMMY_OID = "10000000-0000-0000-0000-000000000004";
public static final String RESOURCE_DUMMY_NAMESPACE = MidPointConstants.NS_RI;
public static final File RESOURCE_DUMMY_INITIALIZED_FILE = new File(COMMON_DIR, "resource-dummy-initialized.xml");
protected static final QName RESOURCE_DUMMY_ASSOCIATION_GROUP_QNAME = new QName(RESOURCE_DUMMY_NAMESPACE, "group");

public static final File ROLE_SUPERUSER_FILE = new File(COMMON_DIR, "role-superuser.xml");
protected static final String ROLE_SUPERUSER_OID = "00000000-0000-0000-0000-000000000004";

public static final File ROLE_MAPMAKER_FILE = new File(COMMON_DIR, "role-mapmaker.xml");
public static final String ROLE_MAPMAKER_OID = "10000000-0000-0000-0000-000000001605";

public static final File SHADOW_ACCOUNT_JACK_DUMMY_FILE = new File(COMMON_DIR, "shadow-account-jack-dummy.xml");

Expand Down
Expand Up @@ -19,7 +19,10 @@
import static org.testng.AssertJUnit.assertNull;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertFalse;
import static org.testng.AssertJUnit.assertTrue;
import static com.evolveum.midpoint.test.IntegrationTestTools.display;
import static com.evolveum.midpoint.web.AdminGuiTestConstants.*;
import static com.evolveum.midpoint.test.IntegrationTestTools.display;

import java.util.Arrays;
import java.util.List;
Expand All @@ -32,22 +35,37 @@
import org.testng.AssertJUnit;
import org.testng.annotations.Test;

import com.evolveum.icf.dummy.resource.DummyGroup;
import com.evolveum.midpoint.prism.Containerable;
import com.evolveum.midpoint.prism.PrismContainer;
import com.evolveum.midpoint.prism.PrismContainerValue;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.PrismProperty;
import com.evolveum.midpoint.prism.PrismValue;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.util.PrismAsserts;
import com.evolveum.midpoint.prism.util.PrismTestUtil;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.test.DummyResourceContoller;
import com.evolveum.midpoint.test.IntegrationTestTools;
import com.evolveum.midpoint.test.util.TestUtil;
import com.evolveum.midpoint.web.component.prism.AssociationWrapper;
import com.evolveum.midpoint.web.component.prism.ContainerStatus;
import com.evolveum.midpoint.web.component.prism.ContainerWrapper;
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.ValueStatus;
import com.evolveum.midpoint.web.component.prism.ValueWrapper;
import com.evolveum.midpoint.web.util.ModelServiceLocator;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationStatusType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAssociationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowIdentifiersType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;

Expand All @@ -59,9 +77,16 @@
@DirtiesContext(classMode = ClassMode.AFTER_CLASS)
public class TestIntegrationObjectWrapperFactory extends AbstractInitializedGuiIntegrationTest {

private static final String USER_WALLY_NAME = "wally";
private static final String USER_WALLY_FULLNAME = "Wally B. Feed";

public static final String GROUP_DUMMY_MAPMAKERS_NAME = "mapmakers";
private String userWallyOid;
private String accountWallyOid;

@Test
public void testCreateWrapperUser() throws Exception {
final String TEST_NAME = "testCreateWrapperUser";
public void test100CreateWrapperUser() throws Exception {
final String TEST_NAME = "test100CreateWrapperUser";
TestUtil.displayTestTile(TEST_NAME);

PrismObject<UserType> user = getUser(USER_JACK_OID);
Expand Down Expand Up @@ -93,8 +118,8 @@ public void testCreateWrapperUser() throws Exception {
}

@Test
public void testCreateWrapperShadow() throws Exception {
final String TEST_NAME = "testCreateWrapperShadow";
public void test150CreateWrapperShadow() throws Exception {
final String TEST_NAME = "test150CreateWrapperShadow";
TestUtil.displayTestTile(TEST_NAME);

PrismObject<ShadowType> shadow = getShadowModel(accountJackOid);
Expand All @@ -110,7 +135,7 @@ public void testCreateWrapperShadow() throws Exception {
// THEN
TestUtil.displayThen(TEST_NAME);

IntegrationTestTools.display("Wrapper after", objectWrapper);
display("Wrapper after", objectWrapper);

WrapperTestUtil.assertWrapper(objectWrapper, "shadow display name", "shadow description", shadow, ContainerStatus.MODIFYING);
assertEquals("wrong number of containers in "+objectWrapper, 9, objectWrapper.getContainers().size());
Expand All @@ -128,5 +153,83 @@ public void testCreateWrapperShadow() throws Exception {
WrapperTestUtil.assertPropertyWrapper(activationContainerWrapper, ActivationType.F_LOCKOUT_STATUS, null);
}

@Test
public void test220AssignRoleLandluberToWally() throws Exception {
final String TEST_NAME = "test220AssignRoleLandluberToWally";
TestUtil.displayTestTile(this, TEST_NAME);

Task task = taskManager.createTaskInstance(TestIntegrationObjectWrapperFactory.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();

DummyGroup mapmakers = new DummyGroup(GROUP_DUMMY_MAPMAKERS_NAME);
dummyResource.addGroup(mapmakers);

PrismObject<UserType> user = createUser(USER_WALLY_NAME, USER_WALLY_FULLNAME, true);
addObject(user);
userWallyOid = user.getOid();
assignRole(userWallyOid, ROLE_MAPMAKER_OID, task, result);

// preconditions
result.computeStatus();
TestUtil.assertSuccess(result);

PrismObject<UserType> userAfter = getUser(userWallyOid);
display("User after change execution", userAfter);
accountWallyOid = getSingleLinkOid(userAfter);

PrismObject<ShadowType> shadow = getShadowModel(accountWallyOid);
shadow.findReference(ShadowType.F_RESOURCE_REF).getValue().setObject(resourceDummy);
display("Shadow", shadow);

DummyGroup dummyGroup = dummyResource.getGroupByName(GROUP_DUMMY_MAPMAKERS_NAME);
assertNotNull("No group on dummy resource", dummyGroup);
display("Group", dummyGroup);
assertGroupMember(dummyGroup, USER_WALLY_NAME);

// WHEN
TestUtil.displayWhen(TEST_NAME);

ObjectWrapperFactory factory = new ObjectWrapperFactory(getServiceLocator());
ObjectWrapper<ShadowType> objectWrapper = factory.createObjectWrapper("shadow display name", "shadow description", shadow,
ContainerStatus.MODIFYING);

// THEN
TestUtil.displayThen(TEST_NAME);

display("Wrapper after", objectWrapper);

WrapperTestUtil.assertWrapper(objectWrapper, "shadow display name", "shadow description", shadow, ContainerStatus.MODIFYING);
assertEquals("wrong number of containers in "+objectWrapper, 9, objectWrapper.getContainers().size());

ContainerWrapper attributesContainerWrapper = objectWrapper.findContainerWrapper(new ItemPath(ShadowType.F_ATTRIBUTES));
WrapperTestUtil.assertWrapper(attributesContainerWrapper, "attributes", new ItemPath(ShadowType.F_ATTRIBUTES), shadow.findContainer(ShadowType.F_ATTRIBUTES),
true, ContainerStatus.MODIFYING);
WrapperTestUtil.assertPropertyWrapper(attributesContainerWrapper, dummyResourceCtl.getAttributeFullnameQName(), USER_WALLY_FULLNAME);
WrapperTestUtil.assertPropertyWrapper(attributesContainerWrapper, SchemaConstants.ICFS_NAME, USER_WALLY_NAME);
assertEquals("wrong number of items in "+attributesContainerWrapper, 16, attributesContainerWrapper.getItems().size());

ContainerWrapper<ActivationType> activationContainerWrapper = objectWrapper.findContainerWrapper(new ItemPath(UserType.F_ACTIVATION));
WrapperTestUtil.assertWrapper(activationContainerWrapper, "Activation", UserType.F_ACTIVATION, shadow, ContainerStatus.MODIFYING);
WrapperTestUtil.assertPropertyWrapper(activationContainerWrapper, ActivationType.F_ADMINISTRATIVE_STATUS, ActivationStatusType.ENABLED);
WrapperTestUtil.assertPropertyWrapper(activationContainerWrapper, ActivationType.F_LOCKOUT_STATUS, null);

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());
PrismContainer<ShadowIdentifiersType> groupAssociationValueIdentifiers = groupAssociationValuePVal.findContainer(ShadowAssociationType.F_IDENTIFIERS);
PrismProperty<String> groupAssociationUidProp = groupAssociationValueIdentifiers.findProperty(new QName(null,"uid"));
PrismAsserts.assertPropertyValue(groupAssociationUidProp, GROUP_DUMMY_MAPMAKERS_NAME);

}

}

0 comments on commit 721df6f

Please sign in to comment.