Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Evolveum/midpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
KaterynaHonchar committed Jan 25, 2016
2 parents 9165ace + 6b418b4 commit 2f6a722
Show file tree
Hide file tree
Showing 10 changed files with 211 additions and 85 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 @@ -36,7 +36,7 @@
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.model.LookupPropertyModel;
import com.evolveum.midpoint.web.page.admin.users.component.AssociationValueChoosePanel;
import com.evolveum.midpoint.web.page.admin.users.component.AssociationValueChoicePanel;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

import org.apache.commons.lang.ClassUtils;
Expand Down Expand Up @@ -286,7 +286,7 @@ private boolean isRemoveButtonVisible() {
return false;
}
Component inputPanel = this.get(ID_VALUE_CONTAINER).get(ID_INPUT);
if (inputPanel instanceof ValueChoosePanel || inputPanel instanceof AssociationValueChoosePanel){
if (inputPanel instanceof ValueChoosePanel || inputPanel instanceof AssociationValueChoicePanel){
return true;
}

Expand Down Expand Up @@ -658,7 +658,7 @@ public void checkInputValue(AutoCompleteTextField input, AjaxRequestTarget targe
assocTarget.getTypeName(), assocTarget.getKind(), assocTarget.getIntent());

List values = item.getValues();
return new AssociationValueChoosePanel(id, model, values, false, ShadowType.class, query);
return new AssociationValueChoicePanel(id, model, values, false, ShadowType.class, query);
}
}

Expand Down Expand Up @@ -785,7 +785,7 @@ private void removeValue(AjaxRequestTarget target) {
error("Couldn't delete already deleted item: " + wrapper.toString());
target.add(((PageBase) getPage()).getFeedbackPanel());
case NOT_CHANGED:
if (inputPanel instanceof AssociationValueChoosePanel) {
if (inputPanel instanceof AssociationValueChoicePanel) {
((PropertyWrapper)propertyWrapper).setStatus(ValueStatus.DELETED);
}
wrapper.setStatus(ValueStatus.DELETED);
Expand All @@ -799,7 +799,7 @@ private void removeValue(AjaxRequestTarget target) {
if (count == 0 && !hasEmptyPlaceholder(propertyWrapper)) {
if (inputPanel instanceof ValueChoosePanel) {
values.add(new ValueWrapper(propertyWrapper, new PrismReferenceValue(null), ValueStatus.ADDED));
} else if (inputPanel instanceof AssociationValueChoosePanel) {
} else if (inputPanel instanceof AssociationValueChoicePanel) {
Item item = propertyWrapper.getItem();
ItemPath path = item.getPath();
if (path != null){
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 @@ -64,9 +64,9 @@
// (for now ValueChoosePanel works only with PrismReferenceValue);
//in future some super class is to be created to union the common
// functionality of these 2 classes
public class AssociationValueChoosePanel <C extends ObjectType> extends BasePanel<PrismContainerValue<ShadowAssociationType>> {
public class AssociationValueChoicePanel <C extends ObjectType> extends BasePanel<PrismContainerValue<ShadowAssociationType>> {

private static final Trace LOGGER = TraceManager.getTrace(AssociationValueChoosePanel.class);
private static final Trace LOGGER = TraceManager.getTrace(AssociationValueChoicePanel.class);

private static final String ID_LABEL = "label";

Expand All @@ -82,7 +82,7 @@ public class AssociationValueChoosePanel <C extends ObjectType> extends BasePane
private IModel<ValueWrapper<PrismContainerValue<ShadowAssociationType>>> model;
private ObjectQuery query = null;

public AssociationValueChoosePanel(String id, IModel<ValueWrapper<PrismContainerValue<ShadowAssociationType>>> model, List<PrismPropertyValue> values, boolean required, Class<C> type,
public AssociationValueChoicePanel(String id, IModel<ValueWrapper<PrismContainerValue<ShadowAssociationType>>> model, List<PrismPropertyValue> values, boolean required, Class<C> type,
ObjectQuery query){
super(id, (IModel)new PropertyModel<>(model, "value"));
this.model = model;
Expand Down Expand Up @@ -166,8 +166,8 @@ private void initGenericDialog(final Class<C> type, final List<PrismPropertyValu
ObjectSelectionPanel.Context context = new ObjectSelectionPanel.Context(this) {

// See analogous discussion in ChooseTypePanel
public AssociationValueChoosePanel getRealParent() {
return WebMiscUtil.theSameForPage(AssociationValueChoosePanel.this, getCallingPageReference());
public AssociationValueChoicePanel getRealParent() {
return WebMiscUtil.theSameForPage(AssociationValueChoicePanel.this, getCallingPageReference());
}

@Override
Expand Down Expand Up @@ -208,8 +208,8 @@ private void initUserOrgDialog() {
ObjectSelectionPanel.Context context = new ObjectSelectionPanel.Context(this) {

// See analogous discussion in ChooseTypePanel
public AssociationValueChoosePanel getRealParent() {
return WebMiscUtil.theSameForPage(AssociationValueChoosePanel.this, getCallingPageReference());
public AssociationValueChoicePanel getRealParent() {
return WebMiscUtil.theSameForPage(AssociationValueChoicePanel.this, getCallingPageReference());
}

@Override
Expand Down Expand Up @@ -288,9 +288,9 @@ public String getObject() {
}
PrismReferenceValue shadowRef = cval.findReference(ShadowAssociationType.F_SHADOW_REF).getValue();
if (shadowRef.getObject() == null) {
ShadowIdentifiersType identifiers = cval.asContainerable().getIdentifiers();
Element e = (Element) identifiers.getAny().get(0);
return e.getTextContent();
PrismContainer<Containerable> identifiersContainer = cval.findContainer(ShadowAssociationType.F_IDENTIFIERS);
PrismProperty<String> identifierProp = (PrismProperty<String>) identifiersContainer.getValue().getItems().get(0);
return identifierProp.getRealValue();
} else {
return shadowRef.getObject().getName().toString();
}
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

0 comments on commit 2f6a722

Please sign in to comment.