Skip to content

Commit

Permalink
fixing param processing when no value was set
Browse files Browse the repository at this point in the history
improving remote query executer.
  • Loading branch information
katkav committed Apr 17, 2015
1 parent 6a1db70 commit 57ac2d6
Show file tree
Hide file tree
Showing 8 changed files with 223 additions and 94 deletions.
Expand Up @@ -190,6 +190,9 @@ private void runConfirmPerformed(AjaxRequestTarget target, IModel<ReportDto> mod
reportParamValue.revive(getPrismContext());
paramContainer.add(reportParamValue);
for (JasperReportParameterDto paramDto : params){
if (paramDto.getValue() == null){
continue;
}
QName typeName = null;
if (XmlTypeConverter.canConvert(paramDto.getType())){
typeName = XsdTypeMapper.toXsdType(paramDto.getType());
Expand Down
@@ -0,0 +1,86 @@
package com.evolveum.midpoint.report.ds.impl;

import java.util.HashMap;
import java.util.Map;

import javax.xml.ws.BindingProvider;

import org.apache.cxf.frontend.ClientProxy;
import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.interceptor.LoggingOutInterceptor;
import org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor;
import org.apache.wss4j.dom.WSConstants;
import org.apache.wss4j.dom.handler.WSHandlerConstants;

import com.evolveum.midpoint.xml.ns._public.report.report_3.ReportPortType;
import com.evolveum.midpoint.xml.ns._public.report.report_3.ReportService;

public class MidPointClientConfiguration {

private String username;
private String password;
private String endpoint;

public MidPointClientConfiguration() {
System.out.println("client configuration init");
}


public ReportPortType createReportPort() {
System.out.println("creating endpoint with credentials " + username + ": " + password);
System.out.println("Endpoint URL: "+ endpoint);
ClientPasswordHandler.setPassword(password);

// uncomment this if you want to use Fiddler or any other proxy
//ProxySelector.setDefault(new MyProxySelector("127.0.0.1", 8888));

ReportService reportService = new ReportService();
ReportPortType reportPort = reportService.getReportPort();
BindingProvider bp = (BindingProvider)reportPort;
Map<String, Object> requestContext = bp.getRequestContext();
requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpoint);

org.apache.cxf.endpoint.Client client = ClientProxy.getClient(reportPort);
org.apache.cxf.endpoint.Endpoint cxfEndpoint = client.getEndpoint();

Map<String,Object> outProps = new HashMap<String,Object>();

outProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN);
outProps.put(WSHandlerConstants.USER, username);
outProps.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_DIGEST);
outProps.put(WSHandlerConstants.PW_CALLBACK_CLASS, ClientPasswordHandler.class.getName());

WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(outProps);
cxfEndpoint.getOutInterceptors().add(wssOut);
// enable the following to get client-side logging of outgoing requests and incoming responses
cxfEndpoint.getOutInterceptors().add(new LoggingOutInterceptor());
cxfEndpoint.getInInterceptors().add(new LoggingInInterceptor());

return reportPort;
}

public String getUsername() {
return username;
}

public void setUsername(String username) {
this.username = username;
}

public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}

public String getEndpoint() {
return endpoint;
}

public void setEndpoint(String endpoint) {
this.endpoint = endpoint;
}

}
@@ -1,11 +1,9 @@
package com.evolveum.midpoint.report.ds.impl;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

import javax.xml.bind.JAXBElement;
import javax.xml.ws.BindingProvider;

import net.sf.jasperreports.engine.JRDataSource;
import net.sf.jasperreports.engine.JRDataset;
Expand All @@ -16,12 +14,8 @@
import net.sf.jasperreports.engine.base.JRBaseParameter;
import net.sf.jasperreports.engine.query.JRAbstractQueryExecuter;

import org.apache.cxf.frontend.ClientProxy;
import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.interceptor.LoggingOutInterceptor;
import org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor;
import org.apache.wss4j.dom.WSConstants;
import org.apache.wss4j.dom.handler.WSHandlerConstants;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.evolveum.midpoint.prism.query.InOidFilter;
import com.evolveum.midpoint.prism.query.ObjectFilter;
Expand All @@ -36,14 +30,13 @@
import com.evolveum.midpoint.xml.ns._public.common.common_3.EntryType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ParamsType;
import com.evolveum.midpoint.xml.ns._public.report.report_3.ReportPortType;
import com.evolveum.midpoint.xml.ns._public.report.report_3.ReportService;

public class MidPointRemoteQueryExecutor extends JRAbstractQueryExecuter{

// Configuration
public static final String ADM_USERNAME = "administrator";
public static final String ADM_PASSWORD = "5ecr3t";
private static final String DEFAULT_ENDPOINT_URL = "http://localhost:8080/midpoint/ws/report-3";
// public static final String ADM_USERNAME = "administrator";
// public static final String ADM_PASSWORD = "5ecr3t";
// private static final String DEFAULT_ENDPOINT_URL = "http://localhost:8080/midpoint/ws/report-3";

private String query;
private ReportPortType reportPort;
Expand All @@ -59,15 +52,6 @@ public String getQuery() {
@Override
protected void parseQuery() {
query = getStringQuery();

// ParamsType params = getParameters();
// LOGGER.trace("Report query: " + queryString);
// ObjectQuery q;
// if (StringUtils.isEmpty(queryString)) {
// q = null;
// } else {
// query = reportPort.parseQuery(queryString, params);
// }
}


Expand All @@ -85,7 +69,25 @@ private boolean containsExpression(ObjectFilter subFilter){
protected MidPointRemoteQueryExecutor(JasperReportsContext jasperReportsContext, JRDataset dataset,
Map<String, ? extends JRValueParameter> parametersMap) {
super(jasperReportsContext, dataset, parametersMap);
reportPort = createReportPort(null);
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("ctx-report-ds-context.xml");
MidPointClientConfiguration clientConfig = (MidPointClientConfiguration) applicationContext.getBean("clientConfig");
// Properties prop = new Properties();
// String propFileName = "client.properties";
//
// InputStream inputStream = getClass().getClassLoader().getResourceAsStream(propFileName);
//
// try {
// prop.load(inputStream);
// } catch (Exception e) {
// throw new RuntimeException(e);
// }
//
// MidPointClientConfiguration clientConfig = new MidPointClientConfiguration();
// clientConfig.setEndpoint((String) prop.get("service.endpoint"));
// clientConfig.setUsername((String) prop.get("auth.username"));
// clientConfig.setPassword((String) prop.get("auht.password"));
reportPort = clientConfig.createReportPort();
// reportPort = createReportPort();
parseQuery();
}

Expand Down Expand Up @@ -136,42 +138,42 @@ protected String getParameterReplacement(String parameterName) {
throw new UnsupportedOperationException("QueryExecutor.getParameterReplacement() not supported");
}

private static ReportPortType createReportPort(String[] args) {
String endpointUrl = DEFAULT_ENDPOINT_URL;

if (args != null && args.length > 0) {
endpointUrl = args[0];
}

System.out.println("Endpoint URL: "+endpointUrl);

// uncomment this if you want to use Fiddler or any other proxy
//ProxySelector.setDefault(new MyProxySelector("127.0.0.1", 8888));

ReportService reportService = new ReportService();
ReportPortType reportPort = reportService.getReportPort();
BindingProvider bp = (BindingProvider)reportPort;
Map<String, Object> requestContext = bp.getRequestContext();
requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointUrl);

org.apache.cxf.endpoint.Client client = ClientProxy.getClient(reportPort);
org.apache.cxf.endpoint.Endpoint cxfEndpoint = client.getEndpoint();

Map<String,Object> outProps = new HashMap<String,Object>();

outProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN);
outProps.put(WSHandlerConstants.USER, ADM_USERNAME);
outProps.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_DIGEST);
outProps.put(WSHandlerConstants.PW_CALLBACK_CLASS, ClientPasswordHandler.class.getName());

WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(outProps);
cxfEndpoint.getOutInterceptors().add(wssOut);
// enable the following to get client-side logging of outgoing requests and incoming responses
cxfEndpoint.getOutInterceptors().add(new LoggingOutInterceptor());
cxfEndpoint.getInInterceptors().add(new LoggingInInterceptor());

return reportPort;
}
// private static ReportPortType createReportPort(String[] args) {
// String endpointUrl = DEFAULT_ENDPOINT_URL;
//
// if (args != null && args.length > 0) {
// endpointUrl = args[0];
// }
//
// System.out.println("Endpoint URL: "+endpointUrl);
//
// // uncomment this if you want to use Fiddler or any other proxy
// //ProxySelector.setDefault(new MyProxySelector("127.0.0.1", 8888));
//
// ReportService reportService = new ReportService();
// ReportPortType reportPort = reportService.getReportPort();
// BindingProvider bp = (BindingProvider)reportPort;
// Map<String, Object> requestContext = bp.getRequestContext();
// requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointUrl);
//
// org.apache.cxf.endpoint.Client client = ClientProxy.getClient(reportPort);
// org.apache.cxf.endpoint.Endpoint cxfEndpoint = client.getEndpoint();
//
// Map<String,Object> outProps = new HashMap<String,Object>();
//
// outProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN);
// outProps.put(WSHandlerConstants.USER, ADM_USERNAME);
// outProps.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_DIGEST);
// outProps.put(WSHandlerConstants.PW_CALLBACK_CLASS, ClientPasswordHandler.class.getName());
//
// WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(outProps);
// cxfEndpoint.getOutInterceptors().add(wssOut);
// // enable the following to get client-side logging of outgoing requests and incoming responses
// cxfEndpoint.getOutInterceptors().add(new LoggingOutInterceptor());
// cxfEndpoint.getInInterceptors().add(new LoggingInInterceptor());
//
// return reportPort;
// }

private String getStringQuery(){
if (dataset.getQuery() == null){
Expand Down
5 changes: 5 additions & 0 deletions model/report-ds-impl/src/main/resources/client.properties
@@ -0,0 +1,5 @@
#client configuration for jasper remote query executer
service.endpoint=http://localhost:8080/midpoint/ws/report-3

auth.username=administrator
auht.password=5ecr3t
48 changes: 48 additions & 0 deletions model/report-ds-impl/src/main/resources/ctx-report-ds-context.xml
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2010-2013 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.
-->

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"
default-lazy-init="false" default-autowire="byName">

<import resource="classpath:META-INF/cxf/cxf.xml"/>
<!-- <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml"> -->
<import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>

<!-- <context:component-scan base-package="com.evolveum.midpoint.report.ds.impl" /> -->
<!-- <context:spring-configured/> -->

<util:properties id="clientProperties" location="classpath:client.properties" />

<context:property-placeholder properties-ref="clientProperties" />

<bean id="clientConfig" class="com.evolveum.midpoint.report.ds.impl.MidPointClientConfiguration"
p:username="${auth.username}"
p:password="${auht.password}"
p:endpoint="${service.endpoint}"/>


</beans>
Expand Up @@ -160,34 +160,18 @@ public TaskRunResult run(Task task) {
Map<String, Object> parameters = completeReport(parentReport, result);

PrismContainer<ReportParameterType> reportParams = (PrismContainer) task.getExtensionItem(ReportConstants.REPORT_PARAMS_PROPERTY_NAME);
if (reportParams != null){
PrismContainerValue<ReportParameterType> reportParamsValues = reportParams.getValue();
List<Item<?,?>> items = reportParamsValues.getItems();
for (Item item : items){
PrismProperty pp = (PrismProperty) item;
Object value = pp.getRealValue();
String paramName = ItemPath.getName(pp.getPath().lastNamed()).getLocalPart();
parameters.put(paramName, value);
}



//
// for (PrismPropertyValue<ReportParameterType> paramValue : getV){
// ReportParameterType val = paramValue.getValue();
// Class clazz = Class.forName(val.getType());
// Object value = null;
// if (XmlTypeConverter.canConvert(clazz)){
// value = XmlTypeConverter.toJavaValue(val.getValue(), clazz);
// } else {
// XNode xnode = prismContext.getParserDom().parse(val.getValue());
// value = prismContext.getBeanConverter().unmarshall(xnode, clazz);
//
// }

// }
}

if (reportParams != null) {
PrismContainerValue<ReportParameterType> reportParamsValues = reportParams.getValue();
List<Item<?, ?>> items = reportParamsValues.getItems();
if (items != null) {
for (Item item : items) {
PrismProperty pp = (PrismProperty) item;
Object value = pp.getRealValue();
String paramName = ItemPath.getName(pp.getPath().lastNamed()).getLocalPart();
parameters.put(paramName, value);
}
}
}

JasperReport jasperReport = ReportTypeUtil.loadJasperReport(parentReport);
LOGGER.trace("compile jasper design, create jasper report : {}", jasperReport);
Expand Down
Expand Up @@ -163,14 +163,7 @@ public void runReport(PrismObject<ReportType> object, PrismContainer<ReportParam
task.setObjectRef(object.getOid(), ReportType.COMPLEX_TYPE);
try {
if (paramContainer != null && !paramContainer.isEmpty()){
// PrismContainerDefinition<ReportParameterType> propertyDef = prismContext.getSchemaRegistry().findContainerDefinitionByElementName(ReportConstants.REPORT_PARAMS_PROPERTY_NAME);
// PrismContainer<ReportParameterType> container = propertyDef.instantiate();
// for (ReportParameterType reportParam : params){
// container.add(reportParam.asPrismContainerValue());
// }

task.setExtensionContainer(paramContainer);

}
} catch (SchemaException e) {
throw new SystemException(e);
Expand Down

0 comments on commit 57ac2d6

Please sign in to comment.