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
katkav committed Jun 9, 2017
2 parents d374e9f + e5193d6 commit 9903ac1
Show file tree
Hide file tree
Showing 7 changed files with 556 additions and 66 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2016 Evolveum
* Copyright (c) 2010-2017 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 @@ -36,6 +36,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;

import org.identityconnectors.common.logging.Log;
import org.identityconnectors.common.security.GuardedString;
Expand Down Expand Up @@ -1185,50 +1186,28 @@ public void executeQuery(ObjectClass objectClass, Filter query, ResultsHandler h
try {
if (ObjectClass.ACCOUNT.is(objectClass.getObjectClassValue())) {

Collection<DummyAccount> accounts = resource.listAccounts();
for (DummyAccount account : accounts) {
ConnectorObject co = convertToConnectorObject(account, attributesToGet);
if (matches(query, co)) {
co = filterOutAttributesToGet(co, account, attributesToGet, options.getReturnDefaultAttributes());
handler.handle(co);
}
}
search(objectClass, query, handler, options,
resource::listAccounts, resource::getAccountByUsername, resource::getAccountById, this::convertToConnectorObject, null);

} else if (ObjectClass.GROUP.is(objectClass.getObjectClassValue())) {

Collection<DummyGroup> groups = resource.listGroups();
for (DummyGroup group : groups) {
ConnectorObject co = convertToConnectorObject(group, attributesToGet);
if (matches(query, co)) {
if (attributesToGetHasAttribute(attributesToGet, DummyGroup.ATTR_MEMBERS_NAME)) {
resource.recordGroupMembersReadCount();
}
co = filterOutAttributesToGet(co, group, attributesToGet, options.getReturnDefaultAttributes());
handler.handle(co);
}
}

search(objectClass, query, handler, options,
resource::listGroups, resource::getGroupByName, resource::getGroupById, this::convertToConnectorObject,
object -> {
if (attributesToGetHasAttribute(attributesToGet, DummyGroup.ATTR_MEMBERS_NAME)) {
resource.recordGroupMembersReadCount();
}
});

} else if (objectClass.is(OBJECTCLASS_PRIVILEGE_NAME)) {

Collection<DummyPrivilege> privs = resource.listPrivileges();
for (DummyPrivilege priv : privs) {
ConnectorObject co = convertToConnectorObject(priv, attributesToGet);
if (matches(query, co)) {
co = filterOutAttributesToGet(co, priv, attributesToGet, options.getReturnDefaultAttributes());
handler.handle(co);
}
}

search(objectClass, query, handler, options,
resource::listPrivileges, resource::getPrivilegeByName, resource::getPrivilegeById, this::convertToConnectorObject, null);

} else if (objectClass.is(OBJECTCLASS_ORG_NAME)) {

Collection<DummyOrg> orgs = resource.listOrgs();
for (DummyOrg org : orgs) {
ConnectorObject co = convertToConnectorObject(org, attributesToGet);
if (matches(query, co)) {
co = filterOutAttributesToGet(co, org, attributesToGet, options.getReturnDefaultAttributes());
handler.handle(co);
}
}
search(objectClass, query, handler, options,
resource::listOrgs, resource::getOrgByName, resource::getOrgById, this::convertToConnectorObject, null);

} else {
throw new ConnectorException("Unknown object class "+objectClass);
Expand All @@ -1250,6 +1229,80 @@ public void executeQuery(ObjectClass objectClass, Filter query, ResultsHandler h

log.info("executeQuery::end");
}

private <T extends DummyObject> void search(ObjectClass objectClass, Filter query, ResultsHandler handler, OperationOptions options,
Lister<T> lister, Getter<T> nameGetter, Getter<T> idGetter, Converter<T> converter, Consumer<T> recorder) throws ConnectException, FileNotFoundException, SchemaViolationException, ConflictException {
Collection<String> attributesToGet = getAttrsToGet(options);
log.ok("attributesToGet={0}", attributesToGet);

if (isEqualsFilter(query, Name.NAME)) {
Attribute nameAttribute = ((EqualsFilter)query).getAttribute();
String name = (String)nameAttribute.getValue().get(0);
T object = nameGetter.get(name);
if (object != null) {
handleObject(object, handler, options, attributesToGet, converter, recorder);
}
return;
}

if (isEqualsFilter(query, Uid.NAME)) {
Attribute uidAttribute = ((EqualsFilter)query).getAttribute();
String uid = (String)uidAttribute.getValue().get(0);
T object;
if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_NAME)) {
object = nameGetter.get(uid);
} else if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_UUID)) {
object = idGetter.get(uid);
} else {
throw new IllegalStateException("Unknown UID mode "+configuration.getUidMode());
}
if (object != null) {
handleObject(object, handler, options, attributesToGet, converter, recorder);
}
return;
}

// Brute force: list all, filter out
Collection<T> allObjects = lister.list();
for (T object : allObjects) {
ConnectorObject co = converter.convert(object, attributesToGet);
if (matches(query, co)) {
handleConnectorObject(object, co, handler, options, attributesToGet, recorder);
}
}
}

private <T extends DummyObject> void handleObject(T object, ResultsHandler handler, OperationOptions options, Collection<String> attributesToGet, Converter<T> converter, Consumer<T> recorder) throws SchemaViolationException {
ConnectorObject co = converter.convert(object, attributesToGet);
handleConnectorObject(object, co, handler, options, attributesToGet, recorder);
}

private <T extends DummyObject> void handleConnectorObject(T object, ConnectorObject co, ResultsHandler handler, OperationOptions options, Collection<String> attributesToGet, Consumer<T> recorder) {
if (recorder != null) {
recorder.accept(object);
}
co = filterOutAttributesToGet(co, object, attributesToGet, options.getReturnDefaultAttributes());
handler.handle(co);
}

private boolean isEqualsFilter(Filter icfFilter, String icfAttrname) {
return icfFilter != null && (icfFilter instanceof EqualsFilter) && icfAttrname.equals(((EqualsFilter)icfFilter).getName());
}

@FunctionalInterface
interface Lister<T> {
Collection<T> list() throws ConnectException, FileNotFoundException, SchemaViolationException, ConflictException;
}

@FunctionalInterface
interface Getter<T> {
T get(String id) throws ConnectException, FileNotFoundException, SchemaViolationException, ConflictException;
}

@FunctionalInterface
interface Converter<T extends DummyObject> {
ConnectorObject convert(T object, Collection<String> attributesToGet) throws SchemaViolationException;
}

private boolean shouldRequireBaseContext(ObjectClass objectClass, Filter query,
OperationOptions options) {
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2014 Evolveum
* Copyright (c) 2010-2017 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 @@ -136,22 +136,24 @@ public static <O extends Containerable> ObjectQuery createObjectQueryInternal(Pr

}

public static QueryType createQueryType(ObjectQuery query, PrismContext prismContext) throws SchemaException{

public static QueryType createQueryType(ObjectQuery query, PrismContext prismContext) throws SchemaException {
ObjectFilter filter = query.getFilter();
QueryType queryType = new QueryType();
if (filter != null){
SearchFilterType filterType = new SearchFilterType();
MapXNode filterXNode = QueryConvertor.serializeFilter(filter, prismContext);
filterType.setFilterClauseXNode(filterXNode);
queryType.setFilter(filterType);
if (filter != null) {
queryType.setFilter(createSearchFilterType(filter, prismContext));
}

queryType.setPaging(PagingConvertor.createPagingType(query.getPaging()));
return queryType;

}


public static SearchFilterType createSearchFilterType(ObjectFilter filter, PrismContext prismContext) throws SchemaException {
if (filter == null) {
return null;
}
SearchFilterType filterType = new SearchFilterType();
MapXNode filterXNode = QueryConvertor.serializeFilter(filter, prismContext);
filterType.setFilterClauseXNode(filterXNode);
return filterType;
}

}
@@ -0,0 +1,31 @@
/**
* Copyright (c) 2016-2017 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.evolveum.midpoint.util;

import java.io.Serializable;

/**
* Almost the same as java.util.function.Supplier, but this one is Serializable.
* That is very useful especially in use in Wicket models.
*
* @author Radovan Semancik
*/
@FunctionalInterface
public interface FailableProducer<T> extends Serializable {

T run() throws Exception;

}
Expand Up @@ -263,11 +263,12 @@ public PrismObject<ShadowType> getShadow(String oid, PrismObject<ShadowType> rep
// This may be OK, e.g. for connectors that have running async add operation.
if (canReturnCachedAfterNotFoundOnResource(options, repositoryShadow, resource)) {
LOGGER.trace("Object not found on reading of {}, but we can return cached shadow", repositoryShadow);
parentResult.muteLastSubresultError();
parentResult.deleteLastSubresultIfError(); // we don't want to see 'warning-like' orange boxes in GUI (TODO reconsider this)
parentResult.recordSuccess();
repositoryShadow.asObjectable().setExists(false);
PrismObject<ShadowType> resultShadow = futurizeShadow(repositoryShadow, options, resource);
applyAttributesDefinition(ctx, resultShadow);
LOGGER.trace("Returning futurized shadow:\n{}", DebugUtil.debugDumpLazily(resultShadow));
return resultShadow;
} else {
throw e;
Expand Down

0 comments on commit 9903ac1

Please sign in to comment.