
org.connid.bundles.cmd.methods.CmdExecuteQuery Maven / Gradle / Ivy
The newest version!
/**
* Copyright (C) 2011 ConnId ([email protected])
*
* 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 org.connid.bundles.cmd.methods;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ConnectException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import org.connid.bundles.cmd.CmdConfiguration;
import org.connid.bundles.cmd.search.Operand;
import org.identityconnectors.common.Pair;
import org.identityconnectors.common.StringUtil;
import org.identityconnectors.common.logging.Log;
import org.identityconnectors.common.security.GuardedString;
import org.identityconnectors.framework.common.exceptions.ConnectorException;
import org.identityconnectors.framework.common.objects.AttributeBuilder;
import org.identityconnectors.framework.common.objects.ConnectorObjectBuilder;
import org.identityconnectors.framework.common.objects.Name;
import org.identityconnectors.framework.common.objects.ObjectClass;
import org.identityconnectors.framework.common.objects.OperationalAttributes;
import org.identityconnectors.framework.common.objects.ResultsHandler;
import org.identityconnectors.framework.common.objects.Uid;
public class CmdExecuteQuery extends CmdExec {
private static final Log LOG = Log.getLog(CmdExecuteQuery.class);
private static final String ITEM_SEPARATOR = "--- NEW SEARCH RESULT ITEM ---";
private final String scriptPath;
private final Operand filter;
private final ResultsHandler resultsHandler;
public CmdExecuteQuery(final ObjectClass oc, final String scriptPath, final Operand filter, final ResultsHandler rh) {
super(oc);
this.scriptPath = scriptPath;
this.filter = filter;
this.resultsHandler = rh;
}
public void execQuery() throws ConnectException {
final Process proc;
if (filter == null) {
LOG.ok("Full search (no filter) ...");
proc = exec(scriptPath, null);
readOutput(proc);
} else {
LOG.ok("Search with filter {0} ...", filter);
proc = exec(scriptPath, createEnv());
switch (filter.getOperator()) {
case EQ:
readOutput(proc);
break;
case SW:
break;
case EW:
break;
case C:
break;
case OR:
break;
case AND:
break;
default:
throw new ConnectorException("Wrong Operator");
}
}
waitFor(proc);
}
private List> createEnv() {
List> attributes = new ArrayList>();
LOG.ok("Creating environment for search with:");
LOG.ok(CmdConfiguration.OBJECT_CLASS + ": {0}", oc.getObjectClassValue());
LOG.ok("Query filter {0}= {1}", filter.getAttributeName(), filter.getAttributeValue());
attributes.add(new Pair(filter.getAttributeName(), filter.getAttributeValue()));
attributes.add(new Pair(CmdConfiguration.OBJECT_CLASS, oc.getObjectClassValue()));
return attributes;
}
private void fillUserHandler(final String searchScriptOutput) throws ConnectException {
if (searchScriptOutput == null || searchScriptOutput.isEmpty()) {
throw new ConnectException("No results found");
}
final Properties attrs = StringUtil.toProperties(searchScriptOutput);
final ConnectorObjectBuilder bld = new ConnectorObjectBuilder();
for (Map.Entry
© 2015 - 2025 Weber Informatics LLC | Privacy Policy