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
katkav committed May 27, 2014
2 parents 1eedc11 + 98e1f30 commit 4c00c3f
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 32 deletions.
Expand Up @@ -21,6 +21,7 @@
import com.evolveum.midpoint.prism.delta.ChangeType;
import com.evolveum.midpoint.prism.delta.ObjectDelta;
import com.evolveum.midpoint.prism.delta.ReferenceDelta;
import com.evolveum.midpoint.prism.match.PolyStringOrigMatchingRule;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.query.*;
import com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition;
Expand Down Expand Up @@ -527,29 +528,30 @@ private ObjectQuery createQuery() {
try {
ObjectQuery query = null;

List<ObjectFilter> conditions = new ArrayList<ObjectFilter>();
List<ObjectFilter> conditions = new ArrayList<>();
ObjectClassComplexTypeDefinition def = getAccountDefinition();
if (dto.isIdentifiers()) {

List<ResourceAttributeDefinition> identifiers = new ArrayList<ResourceAttributeDefinition>();
List<ResourceAttributeDefinition> identifiers = new ArrayList<>();
if (def.getIdentifiers() != null) {
identifiers.addAll(def.getIdentifiers());
}

//TODO set matching rule instead fo null
for (ResourceAttributeDefinition attrDef : identifiers) {
conditions.add(EqualFilter.createEqual(new ItemPath(ShadowType.F_ATTRIBUTES), attrDef, dto.getSearchText()));
conditions.add(EqualFilter.createEqual(new ItemPath(ShadowType.F_ATTRIBUTES, attrDef.getName()),
attrDef, dto.getSearchText()));
}
}

if (dto.isName()) {
List<ResourceAttributeDefinition> secondaryIdentifiers = new ArrayList<ResourceAttributeDefinition>();
List<ResourceAttributeDefinition> secondaryIdentifiers = new ArrayList<>();
if (def.getSecondaryIdentifiers() != null) {
secondaryIdentifiers.addAll(def.getSecondaryIdentifiers());
}
for (ResourceAttributeDefinition attrDef : secondaryIdentifiers) {
conditions.add(SubstringFilter.createSubstring(new ItemPath(ShadowType.F_ATTRIBUTES),
attrDef, dto.getSearchText()));
conditions.add(SubstringFilter.createSubstring(
new ItemPath(ShadowType.F_ATTRIBUTES, attrDef.getName()), attrDef, dto.getSearchText()));
}
}

Expand Down Expand Up @@ -711,7 +713,8 @@ private void clearSearchPerformed(AjaxRequestTarget target){

ResourceContentStorage storage = getSessionStorage().getResourceContent();
storage.setAccountContentSearch(searchModel.getObject());
panel.setCurrentPage(storage.getAccountContentPaging());
storage.setAccountContentPaging(null);
panel.setCurrentPage(null);

target.add(get(ID_SEARCH_FORM));
target.add(panel);
Expand Down
Expand Up @@ -96,18 +96,19 @@ public Iterator<AccountContentDto> internalIterator(long first, long count) {
} else {
query = baseQuery;
}

query.setPaging(paging);
List<PrismObject<ShadowType>> list = getModel().searchObjects(ShadowType.class,
query, null, task, result);

if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Query filter:\n{}", query);
}

List<PrismObject<ShadowType>> list = getModel().searchObjects(ShadowType.class, query, null, task, result);

AccountContentDto dto;
for (PrismObject<ShadowType> object : list) {
dto = createAccountContentDto(object, result);
getAvailableData().add(dto);
}

result.recordSuccess();
} catch (Exception ex) {
result.recordFatalError("Couldn't list objects.", ex);
LoggingUtils.logException(LOGGER, "Couldn't list objects", ex);
Expand Down Expand Up @@ -160,11 +161,12 @@ private AccountContentDto createAccountContentDto(PrismObject<ShadowType> object
protected void addInlineMenuToDto(AccountContentDto dto) {
}

private PrismObject<UserType> loadOwner(String accountOid, OperationResult result) throws SecurityViolationException, SchemaException {
OperationResult ownerResult = result.createSubresult(OPERATION_LOAD_OWNER);
private PrismObject<UserType> loadOwner(String accountOid, OperationResult result)
throws SecurityViolationException, SchemaException {

Task task = getPage().createSimpleTask(OPERATION_LOAD_OWNER);
try {
return getModel().findShadowOwner(accountOid, task, ownerResult);
return getModel().findShadowOwner(accountOid, task, result);
} catch (ObjectNotFoundException ex) {
//owner was not found, it's possible and it's ok on unlinked accounts
}
Expand Down
Expand Up @@ -3,6 +3,7 @@

import java.awt.Color;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.sql.Timestamp;
Expand Down Expand Up @@ -825,7 +826,10 @@ public static String getDateTime()
}

public static String getReportOutputFilePath(ReportType reportType){

File exportFolder = new File(EXPORT_DIR);
if (!exportFolder.exists() || !exportFolder.isDirectory()) {
exportFolder.mkdir();
}

String output = EXPORT_DIR + reportType.getName().getOrig() + " " + getDateTime();
switch (reportType.getExport())
Expand Down
Expand Up @@ -1851,7 +1851,7 @@ public boolean handle(ConnectorObject connectorObject) {
LOGGER.trace("Start to convert filter: {}", query.getFilter().debugDump());
filter = interpreter.interpret(query.getFilter(), icfNameMapper);

LOGGER.trace("ICF filter: {}", filter.toString());
LOGGER.trace("ICF filter: {}", filter);
}

icfConnectorFacade.search(icfObjectClass, filter, icfHandler, options);
Expand Down
Expand Up @@ -22,6 +22,7 @@

import javax.xml.namespace.QName;

import com.evolveum.midpoint.prism.PrismPropertyValue;
import org.identityconnectors.framework.common.objects.Attribute;
import org.identityconnectors.framework.common.objects.AttributeBuilder;
import org.identityconnectors.framework.common.objects.filter.Filter;
Expand Down Expand Up @@ -63,12 +64,7 @@ public <T> Filter interpret(ObjectFilter objectFilter, IcfNameMapper icfNameMapp
if (objectFilter instanceof EqualFilter) {
EqualFilter<T> eq = (EqualFilter<T>) objectFilter;

Collection<Object> convertedValues = new ArrayList<Object>();
for (PrismValue value : eq.getValues()) {
Object converted = UcfUtil.convertValueToIcf(value, null, propName);
convertedValues.add(converted);
}

Collection<Object> convertedValues = convertValues(propName, eq.getValues());
if (convertedValues.isEmpty()) {
// See MID-1460
throw new UnsupportedOperationException("Equals filter with a null value is NOT supported by ICF");
Expand All @@ -84,12 +80,7 @@ public <T> Filter interpret(ObjectFilter objectFilter, IcfNameMapper icfNameMapp
} else if (objectFilter instanceof InFilter) {
InFilter<T> in = (InFilter<T>) objectFilter;

Collection<Object> convertedValues = new ArrayList<Object>();
for (PrismValue value : in.getValues()) {
Object converted = UcfUtil.convertValueToIcf(value, null, propName);
convertedValues.add(converted);
}

Collection convertedValues = convertValues(propName, (List) in.getValues());
if (convertedValues.isEmpty()) {
throw new IllegalArgumentException("In filter with a null value makes no sense");
} else {
Expand All @@ -99,8 +90,16 @@ public <T> Filter interpret(ObjectFilter objectFilter, IcfNameMapper icfNameMapp

} else if (objectFilter instanceof SubstringFilter) {
SubstringFilter substring = (SubstringFilter) objectFilter;
Object converted = UcfUtil.convertValueToIcf(substring.getValues(), null, propName);
return FilterBuilder.contains(AttributeBuilder.build(icfName, converted));
Collection<Object> convertedValues = convertValues(propName, substring.getValues());
if (convertedValues.isEmpty()) {
throw new IllegalArgumentException("Substring filter with null value makes no sense");
} else {
if (convertedValues.size() != 1) {
throw new IllegalArgumentException("Substring filter with multiple values makes no sense");
//maybe it does, through OR clauses
}
return FilterBuilder.contains(AttributeBuilder.build(icfName, convertedValues.iterator().next()));
}
} else {
throw new UnsupportedOperationException("Unsupported filter type: " + objectFilter.debugDump());
}
Expand All @@ -111,7 +110,15 @@ public <T> Filter interpret(ObjectFilter objectFilter, IcfNameMapper icfNameMapp
} else {
throw new UnsupportedOperationException("Unsupported parent path "+valueFilter.getParentPath()+" in filter: " + objectFilter.debugDump());
}

}

private <T> Collection<Object> convertValues(QName propName, List<PrismPropertyValue<T>> values) throws SchemaException {
Collection<Object> convertedValues = new ArrayList<>();
for (PrismValue value : values) {
Object converted = UcfUtil.convertValueToIcf(value, null, propName);
convertedValues.add(converted);
}

return convertedValues;
}
}

0 comments on commit 4c00c3f

Please sign in to comment.