diff --git a/build-system/pom.xml b/build-system/pom.xml index bcbd837f68a..78bef7e07a7 100644 --- a/build-system/pom.xml +++ b/build-system/pom.xml @@ -551,6 +551,14 @@ velocity 1.7 + + + + org.apache.poi + poi + 3.10.1 + + diff --git a/gui/admin-gui/pom.xml b/gui/admin-gui/pom.xml index 4bedce0a079..d83f05c8666 100644 --- a/gui/admin-gui/pom.xml +++ b/gui/admin-gui/pom.xml @@ -534,6 +534,12 @@ + + + org.apache.poi + poi + 3.10.1 + commons-javaflow commons-javaflow diff --git a/infra/schema/pom.xml b/infra/schema/pom.xml index 7588f7735da..c79a531d156 100644 --- a/infra/schema/pom.xml +++ b/infra/schema/pom.xml @@ -234,6 +234,67 @@ http://www.w3.org/2000/09/xmldsig + + src/main/resources/xml/ns/private/report/reportWrapper.wsdl + classpath:xml/ns/private/report/reportWrapper.wsdl + ${basedir}/src/main/resources/META-INF/jax-ws-catalog-compile-time.xml + + -impl + -verbose + -validate + -xjc-Xts + -xjc-XhashCode + -xjc-Xequals + + -xjc-Xequals-equalsStrategyClass=com.evolveum.midpoint.util.xml.DomAwareEqualsStrategy + + -nexclude + http://prism.evolveum.com/xml/ns/public/types-3 + -nexclude + http://prism.evolveum.com/xml/ns/public/annotation-3 + -nexclude + http://prism.evolveum.com/xml/ns/public/query-3 + + + -xjc-Xmidpoint + + + + + src/main/resources/xml/ns/private/fake/fakeWrapper-report.wsdl + ${basedir}/src/main/resources/META-INF/jax-ws-catalog-compile-time.xml + + -impl + -verbose + -validate + -xjc-Xts + -xjc-XhashCode + -xjc-Xequals + + -xjc-Xequals-equalsStrategyClass=com.evolveum.midpoint.util.xml.DomAwareEqualsStrategy + + -xjc-Xmidpoint + -nexclude + http://prism.evolveum.com/xml/ns/public/types-3 + -nexclude + http://prism.evolveum.com/xml/ns/public/annotation-3 + -nexclude + http://prism.evolveum.com/xml/ns/public/query-3 + -nexclude + http://midpoint.evolveum.com/xml/ns/public/common/common-3 + -nexclude + http://www.w3.org/2001/04/xmlenc + -nexclude + http://www.w3.org/2001/XMLSchema + -nexclude + http://www.w3.org/XML/1998/namespace + -nexclude + http://www.w3.org/2000/09/xmldsig + + src/main/resources/xml/ns/private/model/modelWrapper.wsdl classpath:xml/ns/private/model/modelWrapper.wsdl diff --git a/infra/schema/src/main/java/com/evolveum/midpoint/schema/DeltaConvertor.java b/infra/schema/src/main/java/com/evolveum/midpoint/schema/DeltaConvertor.java index 7193a360cac..815d3a694f7 100644 --- a/infra/schema/src/main/java/com/evolveum/midpoint/schema/DeltaConvertor.java +++ b/infra/schema/src/main/java/com/evolveum/midpoint/schema/DeltaConvertor.java @@ -85,11 +85,10 @@ public static ObjectDelta createObjectDelta(ObjectModi return objectDelta; } - - public static ObjectDelta createObjectDelta(ObjectDeltaType objectDeltaType, - PrismContext prismContext) throws SchemaException { - Validate.notNull(prismContext, "No prismContext in DeltaConvertor.createObjectDelta call"); + public static ObjectDelta createObjectDelta(ObjectDeltaType objectDeltaType, + PrismContext prismContext, boolean allowRawValues) throws SchemaException { + Validate.notNull(prismContext, "No prismContext in DeltaConvertor.createObjectDelta call"); QName objectType = objectDeltaType.getObjectType(); if (objectType == null) { throw new SchemaException("No objectType specified"); @@ -109,8 +108,10 @@ public static ObjectDelta createObjectDelta(ObjectDelt ObjectDelta objectDelta = new ObjectDelta(type, ChangeType.MODIFY, prismContext); objectDelta.setOid(objectDeltaType.getOid()); for (ItemDeltaType propMod : objectDeltaType.getItemDelta()) { - ItemDelta itemDelta = createItemDelta(propMod, objDef); - objectDelta.addModification(itemDelta); + ItemDelta itemDelta = createItemDelta(propMod, objDef, allowRawValues); + if (itemDelta != null){ + objectDelta.addModification(itemDelta); + } } return objectDelta; } else if (objectDeltaType.getChangeType() == ChangeTypeType.DELETE) { @@ -123,6 +124,13 @@ public static ObjectDelta createObjectDelta(ObjectDelt } + + public static ObjectDelta createObjectDelta(ObjectDeltaType objectDeltaType, + PrismContext prismContext) throws SchemaException { + return createObjectDelta(objectDeltaType, prismContext, false); + + } + public static ObjectDeltaOperation createObjectDeltaOperation(ObjectDeltaOperationType objectDeltaOperationType, PrismContext prismContext) throws SchemaException { ObjectDeltaOperation retval = new ObjectDeltaOperation(createObjectDelta(objectDeltaOperationType.getObjectDelta(), prismContext)); @@ -271,8 +279,8 @@ public static ItemDelta createItemDelta(ItemDeltaType return createItemDelta(propMod, objectDefinition); } - public static ItemDelta createItemDelta(ItemDeltaType propMod, PrismContainerDefinition pcDef) throws - SchemaException { + public static ItemDelta createItemDelta(ItemDeltaType propMod, PrismContainerDefinition pcDef, boolean allowRawValues) throws + SchemaException { ItemPathType parentPathType = propMod.getPath(); ItemPath parentPath = null; if (parentPathType != null){ @@ -289,6 +297,9 @@ public static ItemDelta createItemDelta(ItemDeltaType if (containingPcd == null) { containerDef = pcDef.findContainerDefinition(parentPath.allUpToLastNamed()); if (containerDef == null){ + if (allowRawValues){ + return null; + } throw new SchemaException("No definition for " + parentPath.allUpToLastNamed().lastNamed().getName() + " (while creating delta for " + pcDef + ")"); } } @@ -304,6 +315,12 @@ public static ItemDelta createItemDelta(ItemDeltaType } return itemDelta; + + } + + public static ItemDelta createItemDelta(ItemDeltaType propMod, PrismContainerDefinition pcDef) throws + SchemaException { + return createItemDelta(propMod, pcDef, false); } /** diff --git a/infra/schema/src/main/java/com/evolveum/midpoint/schema/MidPointPrismContextFactory.java b/infra/schema/src/main/java/com/evolveum/midpoint/schema/MidPointPrismContextFactory.java index 8008eeda2a3..b20fecc94b2 100644 --- a/infra/schema/src/main/java/com/evolveum/midpoint/schema/MidPointPrismContextFactory.java +++ b/infra/schema/src/main/java/com/evolveum/midpoint/schema/MidPointPrismContextFactory.java @@ -126,6 +126,9 @@ private void registerBuiltinSchemas(SchemaRegistry schemaRegistry) throws Schema schemaRegistry.registerPrismSchemasFromWsdlResource("xml/ns/public/model/model-3.wsdl", Arrays.asList(com.evolveum.midpoint.xml.ns._public.model.model_3.ObjectFactory.class.getPackage())); + +// schemaRegistry.registerPrismSchemasFromWsdlResource("xml/ns/public/report/report-3.wsdl", +// Arrays.asList(com.evolveum.midpoint.xml.ns._public.report.report_3.ObjectFactory.class.getPackage())); schemaRegistry.registerPrismSchemaResource("xml/ns/public/resource/annotation-3.xsd", "ra"); diff --git a/infra/schema/src/main/java/com/evolveum/midpoint/schema/util/ReportTypeUtil.java b/infra/schema/src/main/java/com/evolveum/midpoint/schema/util/ReportTypeUtil.java index 370ead6eeed..fced660382a 100644 --- a/infra/schema/src/main/java/com/evolveum/midpoint/schema/util/ReportTypeUtil.java +++ b/infra/schema/src/main/java/com/evolveum/midpoint/schema/util/ReportTypeUtil.java @@ -16,21 +16,28 @@ package com.evolveum.midpoint.schema.util; +import java.io.ByteArrayInputStream; +import java.io.InputStream; import java.util.Collection; -import com.evolveum.midpoint.prism.*; +import javax.xml.namespace.QName; + +import org.apache.commons.codec.binary.Base64; +import org.w3c.dom.Element; + +import com.evolveum.midpoint.prism.Containerable; +import com.evolveum.midpoint.prism.ItemDefinition; +import com.evolveum.midpoint.prism.PrismContainer; +import com.evolveum.midpoint.prism.PrismContainerDefinition; +import com.evolveum.midpoint.prism.PrismContext; +import com.evolveum.midpoint.prism.PrismObject; import com.evolveum.midpoint.prism.delta.ItemDelta; import com.evolveum.midpoint.prism.delta.ObjectDelta; -import com.evolveum.midpoint.prism.path.ItemPath; import com.evolveum.midpoint.prism.schema.PrismSchema; import com.evolveum.midpoint.util.exception.SchemaException; import com.evolveum.midpoint.xml.ns._public.common.common_3.ReportConfigurationType; import com.evolveum.midpoint.xml.ns._public.common.common_3.ReportType; -import org.w3c.dom.Element; - -import javax.xml.namespace.QName; - /** * @author lazyman */ diff --git a/infra/schema/src/main/resources/META-INF/catalog-compile-time.xml b/infra/schema/src/main/resources/META-INF/catalog-compile-time.xml index def1a643198..025fbf99ad1 100644 --- a/infra/schema/src/main/resources/META-INF/catalog-compile-time.xml +++ b/infra/schema/src/main/resources/META-INF/catalog-compile-time.xml @@ -71,6 +71,10 @@ + + + + diff --git a/infra/schema/src/main/resources/META-INF/catalog-runtime.xml b/infra/schema/src/main/resources/META-INF/catalog-runtime.xml index cdee73d5ec6..fedb13884a0 100644 --- a/infra/schema/src/main/resources/META-INF/catalog-runtime.xml +++ b/infra/schema/src/main/resources/META-INF/catalog-runtime.xml @@ -67,6 +67,10 @@ + + + + diff --git a/infra/schema/src/main/resources/META-INF/jax-ws-catalog-compile-time.xml b/infra/schema/src/main/resources/META-INF/jax-ws-catalog-compile-time.xml index 4c38985e474..0787b928df4 100644 --- a/infra/schema/src/main/resources/META-INF/jax-ws-catalog-compile-time.xml +++ b/infra/schema/src/main/resources/META-INF/jax-ws-catalog-compile-time.xml @@ -27,6 +27,10 @@ + + + + diff --git a/infra/schema/src/main/resources/META-INF/jax-ws-catalog-model-context.xml b/infra/schema/src/main/resources/META-INF/jax-ws-catalog-model-context.xml index 015a4a28548..245be418824 100644 --- a/infra/schema/src/main/resources/META-INF/jax-ws-catalog-model-context.xml +++ b/infra/schema/src/main/resources/META-INF/jax-ws-catalog-model-context.xml @@ -19,6 +19,10 @@ + + + + diff --git a/infra/schema/src/main/resources/META-INF/jax-ws-catalog.xml b/infra/schema/src/main/resources/META-INF/jax-ws-catalog.xml index 1f6e6fafd7d..b6a590ecf90 100644 --- a/infra/schema/src/main/resources/META-INF/jax-ws-catalog.xml +++ b/infra/schema/src/main/resources/META-INF/jax-ws-catalog.xml @@ -19,6 +19,10 @@ + + + + diff --git a/infra/schema/src/main/resources/xml/ns/private/fake/fake-1-report.wsdl b/infra/schema/src/main/resources/xml/ns/private/fake/fake-1-report.wsdl new file mode 100644 index 00000000000..cfbd56cc92f --- /dev/null +++ b/infra/schema/src/main/resources/xml/ns/private/fake/fake-1-report.wsdl @@ -0,0 +1,95 @@ + + + + + + + + TODO + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/infra/schema/src/main/resources/xml/ns/private/fake/fakeWrapper-report.wsdl b/infra/schema/src/main/resources/xml/ns/private/fake/fakeWrapper-report.wsdl new file mode 100644 index 00000000000..fcc6fce98d9 --- /dev/null +++ b/infra/schema/src/main/resources/xml/ns/private/fake/fakeWrapper-report.wsdl @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + diff --git a/infra/schema/src/main/resources/xml/ns/private/report/reportWrapper.wsdl b/infra/schema/src/main/resources/xml/ns/private/report/reportWrapper.wsdl new file mode 100644 index 00000000000..88fecc43d76 --- /dev/null +++ b/infra/schema/src/main/resources/xml/ns/private/report/reportWrapper.wsdl @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + diff --git a/infra/schema/src/main/resources/xml/ns/public/report/report-3.wsdl b/infra/schema/src/main/resources/xml/ns/public/report/report-3.wsdl new file mode 100644 index 00000000000..aa7f542086e --- /dev/null +++ b/infra/schema/src/main/resources/xml/ns/public/report/report-3.wsdl @@ -0,0 +1,96 @@ + + + + + + Web service interface for jasper report data source provider + + + + + + + + + + + + + + + + + + + + + + List of objects that match given criteria. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/model/model-client/pom.xml b/model/model-client/pom.xml index b8c67e5afde..1d817ad8472 100644 --- a/model/model-client/pom.xml +++ b/model/model-client/pom.xml @@ -105,6 +105,7 @@ testng test + com.evolveum.midpoint.tools test-ng @@ -221,6 +222,44 @@ -verbose -validate -xjc-Xts + + + + + + target/midpoint-schema/xml/ns/private/report/reportWrapper.wsdl + classpath:xml/ns/private/report/reportWrapper.wsdl + ${basedir}/src/compile/resources/jax-ws-catalog.xml + + -impl + -verbose + -validate + -xjc-Xts + + + + + + target/midpoint-schema/xml/ns/private/fake/fakeWrapper-report.wsdl + ${basedir}/src/compile/resources/jax-ws-catalog.xml + + -impl + -verbose + -validate + -xjc-Xts + + + diff --git a/model/model-client/src/compile/resources/jax-ws-catalog.xml b/model/model-client/src/compile/resources/jax-ws-catalog.xml index 29772d3c998..1c740ebdbee 100644 --- a/model/model-client/src/compile/resources/jax-ws-catalog.xml +++ b/model/model-client/src/compile/resources/jax-ws-catalog.xml @@ -21,6 +21,9 @@ + + + diff --git a/model/model-client/src/main/resources/META-INF/catalog.xml b/model/model-client/src/main/resources/META-INF/catalog.xml index ec23dd83159..0bdfb83ab2f 100644 --- a/model/model-client/src/main/resources/META-INF/catalog.xml +++ b/model/model-client/src/main/resources/META-INF/catalog.xml @@ -55,6 +55,9 @@ + + + diff --git a/model/model-client/src/main/resources/META-INF/jax-ws-catalog.xml b/model/model-client/src/main/resources/META-INF/jax-ws-catalog.xml index e862876bf64..3af4e947ce3 100644 --- a/model/model-client/src/main/resources/META-INF/jax-ws-catalog.xml +++ b/model/model-client/src/main/resources/META-INF/jax-ws-catalog.xml @@ -18,6 +18,9 @@ + + + diff --git a/model/model-impl/src/main/java/com/evolveum/midpoint/model/impl/security/UserProfileServiceImpl.java b/model/model-impl/src/main/java/com/evolveum/midpoint/model/impl/security/UserProfileServiceImpl.java index 26d96377457..f1bf7e7b460 100644 --- a/model/model-impl/src/main/java/com/evolveum/midpoint/model/impl/security/UserProfileServiceImpl.java +++ b/model/model-impl/src/main/java/com/evolveum/midpoint/model/impl/security/UserProfileServiceImpl.java @@ -54,6 +54,9 @@ import com.evolveum.midpoint.xml.ns._public.common.common_3.*; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.core.userdetails.UserDetailsService; +import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.stereotype.Service; import java.util.Collection; @@ -64,7 +67,7 @@ * @author semancik */ @Service(value = "userDetailsService") -public class UserProfileServiceImpl implements UserProfileService { +public class UserProfileServiceImpl implements UserProfileService, UserDetailsService { private static final Trace LOGGER = TraceManager.getTrace(UserProfileServiceImpl.class); @@ -260,4 +263,18 @@ public PrismObject resolveOwner(PrismObject } return owner; } + + @Override + public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { +// TODO Auto-generated method stub + try { + UserDetails detials = getPrincipal(username); + if (detials == null){ + throw new UsernameNotFoundException("User with name " + username + " was not found"); + } + return detials; + } catch (ObjectNotFoundException e) { + throw new UsernameNotFoundException(e.getMessage(), e); + } + } } diff --git a/model/model-intest/src/test/resources/logback-test.xml b/model/model-intest/src/test/resources/logback-test.xml index 8bfa074b20a..3d0161f04a1 100644 --- a/model/model-intest/src/test/resources/logback-test.xml +++ b/model/model-intest/src/test/resources/logback-test.xml @@ -72,6 +72,8 @@ + + diff --git a/model/pom.xml b/model/pom.xml index 4c6bbf47bb9..f70f7090b5e 100644 --- a/model/pom.xml +++ b/model/pom.xml @@ -59,5 +59,6 @@ notifications-impl report-api report-impl + report-ds-impl diff --git a/model/report-api/src/main/java/com/evolveum/midpoint/report/api/ReportPort.java b/model/report-api/src/main/java/com/evolveum/midpoint/report/api/ReportPort.java new file mode 100644 index 00000000000..df77ab0ba51 --- /dev/null +++ b/model/report-api/src/main/java/com/evolveum/midpoint/report/api/ReportPort.java @@ -0,0 +1,9 @@ +package com.evolveum.midpoint.report.api; + +import com.evolveum.midpoint.xml.ns._public.report.report_3.ReportPortType; + +public interface ReportPort { + String CLASS_NAME_WITH_DOT = ReportPortType.class.getName() + "."; + String PROCESS_REPORT = CLASS_NAME_WITH_DOT + "processReport"; + +} diff --git a/model/report-ds-impl/pom.xml b/model/report-ds-impl/pom.xml new file mode 100644 index 00000000000..96d9a890e86 --- /dev/null +++ b/model/report-ds-impl/pom.xml @@ -0,0 +1,135 @@ + + 4.0.0 + + com.evolveum.midpoint + model + 3.1-SNAPSHOT + + com.evolveum.midpoint.model + report-ds-impl + 3.1-SNAPSHOT + Report dataSource + + 1.7 + + + Evolveum + http://www.evolveum.com + + + + Apache License v2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + repo + + + + https://github.com/Evolveum/midpoint.git + git@github.com:Evolveum/midpoint.git + https://fisheye.evolveum.com/browse/midPoint + + + + + evolveum-nexus + Internal Releases + http://nexus.evolveum.com/nexus/content/repositories/releases/ + + + evolveum-nexus + Internal Releases + http://nexus.evolveum.com/nexus/content/repositories/snapshots/ + + + + + Atlassian JIRA + http://jira.evolveum.com/ + + + + + + com.evolveum.midpoint.model + report-impl + 3.1-SNAPSHOT + + + + com.evolveum.midpoint.model + model-client + 3.1-SNAPSHOT + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/model/report-ds-impl/src/compile/resources/catalog.xml b/model/report-ds-impl/src/compile/resources/catalog.xml new file mode 100644 index 00000000000..3aa16062c2f --- /dev/null +++ b/model/report-ds-impl/src/compile/resources/catalog.xml @@ -0,0 +1,86 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/model/report-ds-impl/src/compile/resources/jax-ws-catalog.xml b/model/report-ds-impl/src/compile/resources/jax-ws-catalog.xml new file mode 100644 index 00000000000..0040b0c8d0c --- /dev/null +++ b/model/report-ds-impl/src/compile/resources/jax-ws-catalog.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/model/report-ds-impl/src/main/assembly/bin.xml b/model/report-ds-impl/src/main/assembly/bin.xml new file mode 100644 index 00000000000..c4d49f27d22 --- /dev/null +++ b/model/report-ds-impl/src/main/assembly/bin.xml @@ -0,0 +1,35 @@ + + + + bin + + zip + + false + + + ${project.basedir}/src/main/bin + / + + + ${project.basedir}/target/release + / + + + diff --git a/model/report-ds-impl/src/main/java/com/evolveum/midpoint/report/ds/impl/ClientPasswordHandler.java b/model/report-ds-impl/src/main/java/com/evolveum/midpoint/report/ds/impl/ClientPasswordHandler.java new file mode 100644 index 00000000000..82ba578d73a --- /dev/null +++ b/model/report-ds-impl/src/main/java/com/evolveum/midpoint/report/ds/impl/ClientPasswordHandler.java @@ -0,0 +1,46 @@ +/* + * 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. + */ +package com.evolveum.midpoint.report.ds.impl; + +import java.io.IOException; + +import javax.security.auth.callback.Callback; +import javax.security.auth.callback.CallbackHandler; +import javax.security.auth.callback.UnsupportedCallbackException; + +import org.apache.wss4j.common.ext.WSPasswordCallback; + +/** + * @author semancik + * + */ +public class ClientPasswordHandler implements CallbackHandler { + + private static String password; + + public static void setPassword(String password) { + ClientPasswordHandler.password = password; + } + + @Override + public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { + WSPasswordCallback pc = (WSPasswordCallback) callbacks[0]; + + // set the password for our message. + pc.setPassword(password != null ? password : MidpointDataSourceProvider.ADM_PASSWORD); + } + +} diff --git a/model/report-ds-impl/src/main/java/com/evolveum/midpoint/report/ds/impl/MidpointDataSourceProvider.java b/model/report-ds-impl/src/main/java/com/evolveum/midpoint/report/ds/impl/MidpointDataSourceProvider.java new file mode 100644 index 00000000000..8e5d9f28e47 --- /dev/null +++ b/model/report-ds-impl/src/main/java/com/evolveum/midpoint/report/ds/impl/MidpointDataSourceProvider.java @@ -0,0 +1,120 @@ +package com.evolveum.midpoint.report.ds.impl; + +import java.util.HashMap; +import java.util.Map; + +import javax.xml.ws.BindingProvider; + +import net.sf.jasperreports.engine.JRDataSource; +import net.sf.jasperreports.engine.JRDataSourceProvider; +import net.sf.jasperreports.engine.JRException; +import net.sf.jasperreports.engine.JRField; +import net.sf.jasperreports.engine.JasperReport; +import net.sf.jasperreports.engine.xml.JRXmlWriter; + +import org.apache.commons.codec.binary.Base64; +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.report.impl.MidPointDataSource; +import com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectListType; +import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType; +import com.evolveum.midpoint.xml.ns._public.common.common_3.ReportType; +import com.evolveum.midpoint.xml.ns._public.report.report_3.ReportPortType; +import com.evolveum.midpoint.xml.ns._public.report.report_3.ReportService; + + +public class MidpointDataSourceProvider implements JRDataSourceProvider { + + + // 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 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 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 outProps = new HashMap(); + + 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; + } + + @Override + public boolean supportsGetFieldsOperation() { + // TODO Auto-generated method stub + return false; + } + + @Override + public JRField[] getFields(JasperReport report) throws JRException, UnsupportedOperationException { + // TODO Auto-generated method stub + return null; + } + + @Override + public JRDataSource create(JasperReport report) throws JRException { + System.out.println("creating report port"); + try { + ReportPortType reportPort = createReportPort(null); + + System.out.println("reportport created"); + String jrxml = JRXmlWriter.writeReport(report, "UTF-8"); + byte[] jrxmlBase64 = Base64.encodeBase64(jrxml.getBytes()); + ReportType reportType = new ReportType(); + reportType.setTemplate(jrxmlBase64); + + ObjectListType olt = reportPort.processReport(reportType); + return new MidPointDataSource(olt); + } catch (Exception e){ + System.out.println("exception: " +e); + e.printStackTrace(System.out); + throw e; + } + + } + + @Override + public void dispose(JRDataSource dataSource) throws JRException { + // TODO Auto-generated method stub + + } + + public static void main(String[] args) throws JRException { + MidpointDataSourceProvider dsp = new MidpointDataSourceProvider(); + dsp.create(null); + } +} diff --git a/model/report-impl/pom.xml b/model/report-impl/pom.xml index 710229acd22..d3acb6a4e42 100644 --- a/model/report-impl/pom.xml +++ b/model/report-impl/pom.xml @@ -245,6 +245,61 @@ + diff --git a/model/report-impl/src/main/java/com/evolveum/midpoint/report/impl/ClientPasswordHandler.java b/model/report-impl/src/main/java/com/evolveum/midpoint/report/impl/ClientPasswordHandler.java new file mode 100644 index 00000000000..7ce12cc7777 --- /dev/null +++ b/model/report-impl/src/main/java/com/evolveum/midpoint/report/impl/ClientPasswordHandler.java @@ -0,0 +1,45 @@ +/* + * 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. + */ +package com.evolveum.midpoint.report.impl; + +import java.io.IOException; + +import javax.security.auth.callback.Callback; +import javax.security.auth.callback.CallbackHandler; +import javax.security.auth.callback.UnsupportedCallbackException; + + +/** + * @author semancik + * + */ +public class ClientPasswordHandler implements CallbackHandler { + + private static String password; + + public static void setPassword(String password) { + ClientPasswordHandler.password = password; + } + + @Override + public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { +// WSPasswordCallback pc = (WSPasswordCallback) callbacks[0]; + + // set the password for our message. +// pc.setPassword(password != null ? password : MidPointDataSourceProvider.ADM_PASSWORD); + } + +} diff --git a/model/report-impl/src/main/java/com/evolveum/midpoint/report/impl/MidPointAbstractDataSource.java b/model/report-impl/src/main/java/com/evolveum/midpoint/report/impl/MidPointAbstractDataSource.java new file mode 100644 index 00000000000..9e500ab1432 --- /dev/null +++ b/model/report-impl/src/main/java/com/evolveum/midpoint/report/impl/MidPointAbstractDataSource.java @@ -0,0 +1,90 @@ +package com.evolveum.midpoint.report.impl; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import javax.xml.namespace.QName; + +import net.sf.jasperreports.engine.JRDataSource; +import net.sf.jasperreports.engine.JRException; +import net.sf.jasperreports.engine.JRField; + +import com.evolveum.midpoint.prism.Containerable; +import com.evolveum.midpoint.prism.Item; +import com.evolveum.midpoint.prism.PrismContainer; +import com.evolveum.midpoint.prism.PrismContainerValue; +import com.evolveum.midpoint.prism.PrismObject; +import com.evolveum.midpoint.prism.PrismProperty; +import com.evolveum.midpoint.prism.PrismReference; +import com.evolveum.midpoint.prism.PrismReferenceValue; +import com.evolveum.midpoint.prism.Referencable; +import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType; + +public class MidPointAbstractDataSource implements JRDataSource{ + + List> resultList = null; + Iterator> iterator = null; + PrismObject currentObject = null; + + + @Override + public boolean next() throws JRException { + // TODO Auto-generated method stub + boolean hasNext = false; + if (this.iterator != null) { + hasNext = this.iterator.hasNext(); + + if (hasNext) { + this.currentObject = iterator.next(); + } + } + + return hasNext; + } + + @Override + public Object getFieldValue(JRField jrField) throws JRException { + // TODO Auto-generated method stub + String fieldName = jrField.getName(); + if (fieldName.equals("oid")){ + return currentObject.getOid(); + } + Item i = currentObject.findItem(new QName(fieldName)); + if (i == null){ + return null; + } + + if (i instanceof PrismProperty){ + if (i.isSingleValue()){ + return ((PrismProperty) i).getRealValue(); + } + return ((PrismProperty) i).getRealValues(); + } else if (i instanceof PrismReference){ + if (i.isSingleValue()){ + return ((PrismReference) i).getValue().asReferencable(); + } + + List refs = new ArrayList(); + for (PrismReferenceValue refVal : ((PrismReference) i).getValues()){ + refs.add(refVal.asReferencable()); + } + return refs; + } else if (i instanceof PrismContainer){ + if (i.isSingleValue()){ + return ((PrismContainer) i).getValue().asContainerable(); + } + List containers = new ArrayList(); + for (Object pcv : i.getValues()){ + if (pcv instanceof PrismContainerValue){ + containers.add(((PrismContainerValue) pcv).asContainerable()); + } + } + return containers; + + } else + throw new JRException("Could not get value of the fileld: " + fieldName); + } + + +} diff --git a/model/report-impl/src/main/java/com/evolveum/midpoint/report/impl/MidPointDataSource.java b/model/report-impl/src/main/java/com/evolveum/midpoint/report/impl/MidPointDataSource.java index 1494b487466..e19dff3eef6 100644 --- a/model/report-impl/src/main/java/com/evolveum/midpoint/report/impl/MidPointDataSource.java +++ b/model/report-impl/src/main/java/com/evolveum/midpoint/report/impl/MidPointDataSource.java @@ -19,6 +19,7 @@ import com.evolveum.midpoint.prism.PrismReference; import com.evolveum.midpoint.prism.PrismReferenceValue; import com.evolveum.midpoint.prism.Referencable; +import com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectListType; import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType; import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType; @@ -35,6 +36,14 @@ public MidPointDataSource(List> results) { } } + public MidPointDataSource(ObjectListType results){ + resultList = new ArrayList<>(); + for (ObjectType objType : results.getObject()){ + resultList.add(objType.asPrismObject()); + } + iterator = resultList.iterator(); + } + @Override public boolean next() throws JRException { // TODO Auto-generated method stub diff --git a/model/report-impl/src/main/java/com/evolveum/midpoint/report/impl/MidPointQueryExecutor.java b/model/report-impl/src/main/java/com/evolveum/midpoint/report/impl/MidPointQueryExecutor.java index 0cf1d1b5975..52cd38d73bb 100644 --- a/model/report-impl/src/main/java/com/evolveum/midpoint/report/impl/MidPointQueryExecutor.java +++ b/model/report-impl/src/main/java/com/evolveum/midpoint/report/impl/MidPointQueryExecutor.java @@ -13,6 +13,7 @@ import net.sf.jasperreports.engine.JRException; import net.sf.jasperreports.engine.JRParameter; import net.sf.jasperreports.engine.JRValueParameter; +import net.sf.jasperreports.engine.JasperReport; import net.sf.jasperreports.engine.JasperReportsContext; import net.sf.jasperreports.engine.base.JRBaseParameter; import net.sf.jasperreports.engine.data.JRBeanArrayDataSource; @@ -66,18 +67,42 @@ public class MidPointQueryExecutor extends JRAbstractQueryExecuter{ private static final Trace LOGGER = TraceManager.getTrace(MidPointQueryExecutor.class); - PrismContext prismContext; - ModelService model; - TaskManager taskManager; - ExpressionFactory expressionFactory; - ObjectResolver objectResolver; - ObjectQuery query; - String script; - Class type; - ExpressionVariables variables; - MidpointFunctions midpointFunctions; - AuditService auditService; - ReportFunctions reportFunctions; + private PrismContext prismContext; + private ModelService model; + private TaskManager taskManager; + private ExpressionFactory expressionFactory; + private ObjectResolver objectResolver; + private ObjectQuery query; + private String script; + private Class type; + private ExpressionVariables variables; + private MidpointFunctions midpointFunctions; + private AuditService auditService; + private ReportFunctions reportFunctions; + + public String getScript() { + return script; + } + public ObjectQuery getQuery() { + return query; + } + public Class getType() { + return type; + } + + public ExpressionVariables getVariables() { + return variables; + } + + MidPointQueryExecutor(PrismContext prismContext, TaskManager taskManager, JRDataset dataset) { + super(null, dataset, null); + this.prismContext = prismContext; + this.taskManager = taskManager; +// this.dataset = dataset; + + parseQuery(); + + } @Override protected void parseQuery() { @@ -212,47 +237,15 @@ public JRDataSource createDatasource() throws JRException { try { + if (query == null && script == null){ throw new JRException("Neither query, nor script defined in the report."); } - if (script != null){ - FunctionLibrary functionLib = ExpressionUtil.createBasicFunctionLibrary(prismContext, prismContext.getDefaultProtector()); - FunctionLibrary midPointLib = new FunctionLibrary(); - midPointLib.setVariableName("report"); - midPointLib.setNamespace("http://midpoint.evolveum.com/xml/ns/public/function/report-3"); -// ReportFunctions reportFunctions = new ReportFunctions(prismContext, model, taskManager, auditService); - midPointLib.setGenericFunctions(reportFunctions); - - Collection functions = new ArrayList<>(); - functions.add(functionLib); - - - functions.add(midPointLib); - Jsr223ScriptEvaluator scripts = new Jsr223ScriptEvaluator("Groovy", prismContext, prismContext.getDefaultProtector()); - Object o = scripts.evaluateReportScript(script, variables, objectResolver, functions, "desc", task.getResult()); - if (o != null){ - - if (Collection.class.isAssignableFrom(o.getClass())) { - Collection resultSet = (Collection) o; - if (resultSet != null && !resultSet.isEmpty()){ - if (resultSet.iterator().next() instanceof PrismObject){ - results.addAll((Collection>) o); - } else { - return new JRBeanCollectionDataSource(resultSet); - } - } - - } else { - results.add((PrismObject) o); - } - } - }else{ - - GetOperationOptions options = GetOperationOptions.createRaw(); - options.setResolveNames(true); - results = model.searchObjects(type, query, SelectorOptions.createCollection(options), task, parentResult);; - - } + if (query != null){ + results = ReportUtils.getReportData(model, type, query, task, parentResult); + } else { + results = ReportUtils.getReportData(prismContext, task, reportFunctions, script, variables, objectResolver); + } } catch (SchemaException | ObjectNotFoundException | SecurityViolationException | CommunicationException | ConfigurationException | ExpressionEvaluationException e) { // TODO Auto-generated catch block diff --git a/model/report-impl/src/main/java/com/evolveum/midpoint/report/impl/ReportCreateTaskHandler.java b/model/report-impl/src/main/java/com/evolveum/midpoint/report/impl/ReportCreateTaskHandler.java index 15dfea6ed13..c680bb154a4 100644 --- a/model/report-impl/src/main/java/com/evolveum/midpoint/report/impl/ReportCreateTaskHandler.java +++ b/model/report-impl/src/main/java/com/evolveum/midpoint/report/impl/ReportCreateTaskHandler.java @@ -147,13 +147,13 @@ public class ReportCreateTaskHandler implements TaskHandler, ApplicationContextA private ApplicationContext context; - @PostConstruct - private void initialize() { - if (LOGGER.isTraceEnabled()) { - LOGGER.trace("Registering with taskManager as a handler for " + REPORT_CREATE_TASK_URI); - } - taskManager.registerHandler(REPORT_CREATE_TASK_URI, this); - } +// @PostConstruct +// private void initialize() { +// if (LOGGER.isTraceEnabled()) { +// LOGGER.trace("Registering with taskManager as a handler for " + REPORT_CREATE_TASK_URI); +// } +// taskManager.registerHandler(REPORT_CREATE_TASK_URI, this); +// } @Override public void setApplicationContext(ApplicationContext context) throws BeansException { diff --git a/model/report-impl/src/main/java/com/evolveum/midpoint/report/impl/ReportManagerImpl.java b/model/report-impl/src/main/java/com/evolveum/midpoint/report/impl/ReportManagerImpl.java index e88da92da87..1b3f4ba33c7 100644 --- a/model/report-impl/src/main/java/com/evolveum/midpoint/report/impl/ReportManagerImpl.java +++ b/model/report-impl/src/main/java/com/evolveum/midpoint/report/impl/ReportManagerImpl.java @@ -16,7 +16,10 @@ package com.evolveum.midpoint.report.impl; -import java.io.*; +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.InputStream; +import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.Collection; import java.util.Date; @@ -26,8 +29,6 @@ import javax.xml.datatype.Duration; import javax.xml.datatype.XMLGregorianCalendar; -import com.evolveum.midpoint.schema.util.ReportTypeUtil; - import net.sf.jasperreports.engine.JRException; import net.sf.jasperreports.engine.JasperCompileManager; import net.sf.jasperreports.engine.JasperReport; @@ -39,7 +40,6 @@ import org.apache.commons.lang.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import org.w3c.dom.Node; import com.evolveum.midpoint.model.api.ModelService; import com.evolveum.midpoint.model.api.context.ModelContext; @@ -65,9 +65,9 @@ import com.evolveum.midpoint.schema.result.OperationResult; import com.evolveum.midpoint.schema.result.OperationResultStatus; import com.evolveum.midpoint.schema.util.MiscSchemaUtil; +import com.evolveum.midpoint.schema.util.ReportTypeUtil; import com.evolveum.midpoint.task.api.Task; import com.evolveum.midpoint.task.api.TaskManager; -import com.evolveum.midpoint.util.DOMUtil; import com.evolveum.midpoint.util.exception.CommunicationException; import com.evolveum.midpoint.util.exception.ConfigurationException; import com.evolveum.midpoint.util.exception.ObjectNotFoundException; @@ -151,7 +151,7 @@ private boolean isRaw(Collection> options) @Override public void runReport(PrismObject object, Task task, OperationResult parentResult) { - task.setHandlerUri(ReportCreateTaskHandler.REPORT_CREATE_TASK_URI); + task.setHandlerUri(ReportCreateTaskHandlerNew.REPORT_CREATE_TASK_URI); task.setObjectRef(object.getOid(), ReportType.COMPLEX_TYPE); task.setThreadStopAction(ThreadStopActionType.CLOSE); diff --git a/model/report-impl/src/main/java/com/evolveum/midpoint/report/impl/ReportUtils.java b/model/report-impl/src/main/java/com/evolveum/midpoint/report/impl/ReportUtils.java index c13048e28e1..f16a1c90a0f 100644 --- a/model/report-impl/src/main/java/com/evolveum/midpoint/report/impl/ReportUtils.java +++ b/model/report-impl/src/main/java/com/evolveum/midpoint/report/impl/ReportUtils.java @@ -8,6 +8,8 @@ import java.io.UnsupportedEncodingException; import java.sql.Timestamp; import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Collection; import java.util.Date; import java.util.HashMap; import java.util.List; @@ -29,6 +31,7 @@ import net.sf.jasperreports.engine.JasperCompileManager; import net.sf.jasperreports.engine.JasperReport; import net.sf.jasperreports.engine.base.JRBasePen; +import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource; import net.sf.jasperreports.engine.design.JRDesignBand; import net.sf.jasperreports.engine.design.JRDesignExpression; import net.sf.jasperreports.engine.design.JRDesignField; @@ -60,10 +63,16 @@ import org.w3c.dom.Node; import com.evolveum.midpoint.model.api.ModelService; +import com.evolveum.midpoint.model.common.expression.ExpressionSyntaxException; +import com.evolveum.midpoint.model.common.expression.ExpressionUtil; +import com.evolveum.midpoint.model.common.expression.ExpressionVariables; +import com.evolveum.midpoint.model.common.expression.functions.FunctionLibrary; +import com.evolveum.midpoint.model.common.expression.script.jsr223.Jsr223ScriptEvaluator; import com.evolveum.midpoint.prism.Containerable; import com.evolveum.midpoint.prism.PrismContainer; import com.evolveum.midpoint.prism.PrismContainerDefinition; import com.evolveum.midpoint.prism.PrismContext; +import com.evolveum.midpoint.prism.PrismObject; import com.evolveum.midpoint.prism.PrismProperty; import com.evolveum.midpoint.prism.PrismReferenceValue; import com.evolveum.midpoint.prism.query.ObjectQuery; @@ -76,13 +85,21 @@ import com.evolveum.midpoint.prism.xnode.RootXNode; import com.evolveum.midpoint.prism.xnode.XNode; import com.evolveum.midpoint.schema.DeltaConvertor; +import com.evolveum.midpoint.schema.GetOperationOptions; +import com.evolveum.midpoint.schema.SelectorOptions; import com.evolveum.midpoint.schema.constants.ObjectTypes; import com.evolveum.midpoint.schema.result.OperationResult; +import com.evolveum.midpoint.schema.util.ObjectResolver; import com.evolveum.midpoint.schema.util.ObjectTypeUtil; +import com.evolveum.midpoint.task.api.Task; import com.evolveum.midpoint.task.api.TaskManager; import com.evolveum.midpoint.util.DOMUtil; +import com.evolveum.midpoint.util.exception.CommunicationException; +import com.evolveum.midpoint.util.exception.ConfigurationException; +import com.evolveum.midpoint.util.exception.ExpressionEvaluationException; import com.evolveum.midpoint.util.exception.ObjectNotFoundException; import com.evolveum.midpoint.util.exception.SchemaException; +import com.evolveum.midpoint.util.exception.SecurityViolationException; import com.evolveum.midpoint.util.exception.SystemException; import com.evolveum.midpoint.util.logging.Trace; import com.evolveum.midpoint.util.logging.TraceManager; @@ -120,6 +137,86 @@ public class ReportUtils { .getTrace(ReportUtils.class); + //new + +public static JasperReport loadJasperReport(ReportType reportType) throws SchemaException{ + + if (reportType.getTemplate() == null) { + throw new IllegalStateException("Could not create report. No jasper template defined."); + } + try { + byte[] reportTemplate = Base64.decodeBase64(reportType.getTemplate()); + + InputStream inputStreamJRXML = new ByteArrayInputStream(reportTemplate); + JasperDesign jasperDesign = JRXmlLoader.load(inputStreamJRXML); + LOGGER.trace("load jasper design : {}", jasperDesign); + + if (reportType.getTemplateStyle() != null){ + JRDesignReportTemplate templateStyle = new JRDesignReportTemplate(new JRDesignExpression("$P{" + PARAMETER_TEMPLATE_STYLES + "}")); + jasperDesign.addTemplate(templateStyle); + JRDesignParameter parameter = new JRDesignParameter(); + parameter.setName(PARAMETER_TEMPLATE_STYLES); + parameter.setValueClass(JRTemplate.class); + parameter.setForPrompting(false); + jasperDesign.addParameter(parameter); + } + JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign); + return jasperReport; + } catch (JRException ex){ + LOGGER.error("Couldn't create jasper report design {}", ex.getMessage()); + throw new SchemaException(ex.getMessage(), ex.getCause()); + } + + +} + +public static List> getReportData(PrismContext prismContext, Task task, ReportFunctions reportFunctions, String script, ExpressionVariables variables, ObjectResolver objectResolver) throws ExpressionSyntaxException, ExpressionEvaluationException, ObjectNotFoundException{ + List> results = new ArrayList<>(); + FunctionLibrary functionLib = ExpressionUtil.createBasicFunctionLibrary(prismContext, prismContext.getDefaultProtector()); + FunctionLibrary midPointLib = new FunctionLibrary(); + midPointLib.setVariableName("report"); + midPointLib.setNamespace("http://midpoint.evolveum.com/xml/ns/public/function/report-3"); +// ReportFunctions reportFunctions = new ReportFunctions(prismContext, model, taskManager, auditService); + midPointLib.setGenericFunctions(reportFunctions); + + Collection functions = new ArrayList<>(); + functions.add(functionLib); + + + functions.add(midPointLib); + Jsr223ScriptEvaluator scripts = new Jsr223ScriptEvaluator("Groovy", prismContext, prismContext.getDefaultProtector()); + Object o = scripts.evaluateReportScript(script, variables, objectResolver, functions, "desc", task.getResult()); + if (o != null){ + + if (Collection.class.isAssignableFrom(o.getClass())) { + Collection resultSet = (Collection) o; + if (resultSet != null && !resultSet.isEmpty()){ + if (resultSet.iterator().next() instanceof PrismObject){ + results.addAll((Collection>) o); + } else { +// return new JRBeanCollectionDataSource(resultSet); + } + } + + } else { + results.add((PrismObject) o); + } + } + + return results; + +} + +public static List> getReportData(ModelService model, Class type, ObjectQuery query, Task task, OperationResult parentResult) throws SchemaException, ObjectNotFoundException, SecurityViolationException, CommunicationException, ConfigurationException{ + List> results = new ArrayList<>(); + + GetOperationOptions options = GetOperationOptions.createRaw(); + options.setResolveNames(true); + results = model.searchObjects(type, query, SelectorOptions.createCollection(options), task, parentResult);; + return results; +} + //end of new + public static Class getClassType(QName clazz, String namespace) { Class classType = String.class; @@ -851,6 +948,7 @@ public static String getReportOutputFilePath(ReportType reportType){ } String output = EXPORT_DIR + reportType.getName().getOrig() + " " + getDateTime(); + switch (reportType.getExport()) { case PDF : output = output + ".pdf"; diff --git a/model/report-impl/src/main/java/com/evolveum/midpoint/report/impl/ReportWebService.java b/model/report-impl/src/main/java/com/evolveum/midpoint/report/impl/ReportWebService.java new file mode 100644 index 00000000000..5fc0ffa6b59 --- /dev/null +++ b/model/report-impl/src/main/java/com/evolveum/midpoint/report/impl/ReportWebService.java @@ -0,0 +1,118 @@ +package com.evolveum.midpoint.report.impl; + +import java.util.ArrayList; +import java.util.List; + +import net.sf.jasperreports.engine.JRDataset; +import net.sf.jasperreports.engine.JasperReport; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.evolveum.midpoint.audit.api.AuditService; +import com.evolveum.midpoint.model.api.ModelService; +import com.evolveum.midpoint.prism.PrismContext; +import com.evolveum.midpoint.prism.PrismObject; +import com.evolveum.midpoint.report.api.ReportPort; +import com.evolveum.midpoint.schema.result.OperationResult; +import com.evolveum.midpoint.schema.util.ObjectResolver; +import com.evolveum.midpoint.task.api.Task; +import com.evolveum.midpoint.task.api.TaskManager; +import com.evolveum.midpoint.util.exception.CommunicationException; +import com.evolveum.midpoint.util.exception.ConfigurationException; +import com.evolveum.midpoint.util.exception.ExpressionEvaluationException; +import com.evolveum.midpoint.util.exception.ObjectNotFoundException; +import com.evolveum.midpoint.util.exception.SchemaException; +import com.evolveum.midpoint.util.exception.SecurityViolationException; +import com.evolveum.midpoint.util.logging.Trace; +import com.evolveum.midpoint.util.logging.TraceManager; +import com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectListType; +import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType; +import com.evolveum.midpoint.xml.ns._public.common.common_3.ReportType; +import com.evolveum.midpoint.xml.ns._public.report.report_3.ReportPortType; + +@Service +public class ReportWebService implements ReportPortType, ReportPort { + + private static transient Trace LOGGER = TraceManager.getTrace(ReportWebService.class); + + @Autowired(required = true) + private PrismContext prismContext; + + @Autowired(required = true) + private TaskManager taskManager; + + @Autowired(required = true) + private ModelService model; + + @Autowired(required = true) + private ObjectResolver objectResolver; + + @Autowired(required = true) + private AuditService auditService; + + @Override + public ObjectListType processReport(ReportType report) { + + Task task = taskManager.createTaskInstance("process report"); + OperationResult parentResult = task.getResult(); + + JasperReport jasperReport; + try { + jasperReport = ReportUtils.loadJasperReport(report); + + JRDataset[] datasets = jasperReport.getDatasets(); + + if (datasets.length > 1) { + throw new UnsupportedOperationException("Only one dataset supported"); + } + + JRDataset dataset = datasets[0]; + + MidPointQueryExecutor queryExecutor = new MidPointQueryExecutor(prismContext, taskManager, + dataset); + List results = new ArrayList<>(); + if (queryExecutor.getQuery() != null) { + results = ReportUtils.getReportData(model, queryExecutor.getType(), queryExecutor.getQuery(), + task, parentResult); + } else { + ReportFunctions reportFunctions = new ReportFunctions(prismContext, model, taskManager, + auditService); + results = ReportUtils.getReportData(prismContext, task, reportFunctions, + queryExecutor.getScript(), queryExecutor.getVariables(), objectResolver); + } + + ObjectListType listType = new ObjectListType(); + for (Object o : results) { + if (o instanceof PrismObject) { + listType.getObject().add((ObjectType) ((PrismObject) o).asObjectable()); + } else { + listType.getObject().add((ObjectType) o); + } + } + return listType; + } catch (SchemaException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (ObjectNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (SecurityViolationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (CommunicationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (ConfigurationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (ExpressionEvaluationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + return null; + + } + +} diff --git a/model/report-impl/src/main/resources/ctx-report.xml b/model/report-impl/src/main/resources/ctx-report.xml index 9555c75aebe..5de0c5cadbd 100644 --- a/model/report-impl/src/main/resources/ctx-report.xml +++ b/model/report-impl/src/main/resources/ctx-report.xml @@ -17,13 +17,46 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/model/report-impl/src/main/resources/xml/ns/META-INF/catalog-compile-time.xml b/model/report-impl/src/main/resources/xml/ns/META-INF/catalog-compile-time.xml new file mode 100644 index 00000000000..025fbf99ad1 --- /dev/null +++ b/model/report-impl/src/main/resources/xml/ns/META-INF/catalog-compile-time.xml @@ -0,0 +1,102 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/model/report-impl/src/main/resources/xml/ns/META-INF/catalog-runtime.xml b/model/report-impl/src/main/resources/xml/ns/META-INF/catalog-runtime.xml new file mode 100644 index 00000000000..fedb13884a0 --- /dev/null +++ b/model/report-impl/src/main/resources/xml/ns/META-INF/catalog-runtime.xml @@ -0,0 +1,99 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/model/report-impl/src/main/resources/xml/ns/META-INF/jax-ws-catalog-compile-time.xml b/model/report-impl/src/main/resources/xml/ns/META-INF/jax-ws-catalog-compile-time.xml new file mode 100644 index 00000000000..0c0f7ca50a1 --- /dev/null +++ b/model/report-impl/src/main/resources/xml/ns/META-INF/jax-ws-catalog-compile-time.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + diff --git a/model/report-impl/src/main/resources/xml/ns/META-INF/jax-ws-catalog.xml b/model/report-impl/src/main/resources/xml/ns/META-INF/jax-ws-catalog.xml new file mode 100644 index 00000000000..a79c574fd5c --- /dev/null +++ b/model/report-impl/src/main/resources/xml/ns/META-INF/jax-ws-catalog.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + +