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
mederly committed Aug 24, 2015
2 parents fe6310b + 584545d commit 90d4c82
Show file tree
Hide file tree
Showing 7 changed files with 233 additions and 142 deletions.
36 changes: 25 additions & 11 deletions config/initial-objects/090-report-audit.xml

Large diffs are not rendered by default.

33 changes: 21 additions & 12 deletions config/initial-objects/100-report-reconciliation.xml

Large diffs are not rendered by default.

27 changes: 21 additions & 6 deletions config/initial-objects/110-report-user-list.xml

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Expand Up @@ -34,9 +34,11 @@
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.core.UriBuilder;
import javax.ws.rs.core.UriInfo;
import javax.xml.namespace.QName;

import org.apache.commons.lang.Validate;
import org.apache.cxf.jaxrs.ext.MessageContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -369,15 +371,23 @@ public <T extends ObjectType> Response modifyObjectPatch(@PathParam("type") Stri
public Response notifyChange(ResourceObjectShadowChangeDescriptionType changeDescription,
@Context UriInfo uriInfo, @Context MessageContext mc) {
LOGGER.info("model rest service for notify change operation start");

Validate.notNull(changeDescription, "Chnage description must not be null");
Task task = taskManager.createTaskInstance("notifyChange");
initRequest(task, mc);
OperationResult parentResult = task.getResult();

Response response;
try {
model.notifyChange(changeDescription, parentResult, task);
response = Response.seeOther((uriInfo.getBaseUriBuilder().path(this.getClass(), "getObject").build(ObjectTypes.TASK.getRestType(), task.getOid()))).build();
return Response.ok().build();
// String oldShadowOid = changeDescription.getOldShadowOid();
// if (oldShadowOid != null){
// URI resourceURI = uriInfo.getAbsolutePathBuilder().path(oldShadowOid).build(oldShadowOid);
// return Response.accepted().location(resourceURI).build();
// } else {
// changeDescription.get
// }
// response = Response.seeOther((uriInfo.getBaseUriBuilder().path(this.getClass(), "getObject").build(ObjectTypes.TASK.getRestType(), task.getOid()))).build();
} catch (ObjectAlreadyExistsException e) {
response = Response.status(Status.CONFLICT).entity(e.getMessage()).type(MediaType.TEXT_HTML).build();
} catch (ObjectNotFoundException e) {
Expand Down
Expand Up @@ -15,6 +15,8 @@
*/
package com.evolveum.midpoint.report.impl;

import com.evolveum.midpoint.prism.path.ItemPathSegment;
import com.evolveum.midpoint.prism.path.NameItemPathSegment;
import java.io.File;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
Expand Down Expand Up @@ -43,28 +45,26 @@
import com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType;
import com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType;
import com.evolveum.prism.xml.ns._public.types_3.RawType;
import java.lang.reflect.Method;
import java.util.MissingResourceException;

/**
* Utility methods for report. Mostly pretty print functions. Do not use any
* "prism" object and anything related to them. Methods has to work with both,
* common schema types and extended schema types (prism)
*
*
* @author Katarina Valalikova
* @author Martin Lizner
*
*
*/

public class ReportUtils {

private static String MIDPOINT_HOME = System.getProperty("midpoint.home");
private static String EXPORT_DIR = MIDPOINT_HOME + "export/";


private static final Trace LOGGER = TraceManager
.getTrace(ReportUtils.class);


public static Timestamp convertDateTime(XMLGregorianCalendar dateTime) {
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
try {
Expand All @@ -76,7 +76,6 @@ public static Timestamp convertDateTime(XMLGregorianCalendar dateTime) {
return timestamp;
}


public static String getDateTime() {
Date createDate = new Date(System.currentTimeMillis());
SimpleDateFormat formatDate = new SimpleDateFormat("dd-MM-yyyy hh-mm-ss");
Expand Down Expand Up @@ -141,8 +140,6 @@ public static String getReportOutputFilePath(ReportType reportType) {
return output;
}



public static String getPropertyString(String key) {
return getPropertyString(key, null);
}
Expand Down Expand Up @@ -173,7 +170,6 @@ public static String prettyPrintForReport(ProtectedStringType pst) {
return "*****";
}


public static String prettyPrintForReport(OperationResultType ort) {
StringBuilder sb = new StringBuilder();
if (ort.getOperation() != null) {
Expand Down Expand Up @@ -216,102 +212,121 @@ public static String prettyPrintForReport(Collection prismValueList) {
- Credit goes to Evolveum
*/
public static String prettyPrintForReport(Object value) {
if (value == null){
return "";
}


if (value instanceof MetadataType){
return "";
}

//special handling for byte[], some problems with jasper when printing
if (byte[].class.equals(value.getClass())){
return prettyPrintForReport((byte[]) value);
}

String str = PrettyPrinter.prettyPrint(value);
if (str.length() > 1000){
return str.substring(0, 1000);
}
return str;
if (value == null) {
return "";
}

if (value instanceof MetadataType) {
return "";
}

//special handling for byte[], some problems with jasper when printing
if (byte[].class.equals(value.getClass())) {
return prettyPrintForReport((byte[]) value);
}

// 1. Try to find prettyPrintForReport in this class first
for (Method method : ReportUtils.class.getMethods()) {
if (method.getName().equals("prettyPrintForReport")) {
Class<?>[] parameterTypes = method.getParameterTypes();
if (parameterTypes.length == 1 && parameterTypes[0].equals(value.getClass())) {
try {
return (String) method.invoke(null, value);
} catch (Throwable e) {
return "###INTERNAL#ERROR### " + e.getClass().getName() + ": " + e.getMessage() + "; prettyPrintForReport method for value " + value;
}
}
}
}

// 2. Default to PrettyPrinter.prettyPrint
String str = PrettyPrinter.prettyPrint(value);
if (str.length() > 1000) {
return str.substring(0, 1000);
}
return str;

}
private static String printItemDeltaValues(ItemDeltaType itemDelta){
List values = itemDelta.getValue();
StringBuilder sb = new StringBuilder();
for (Object value : values){
String v = printItemDeltaValue(itemDelta.getPath(), value);
if (StringUtils.isNotBlank(v)){
sb.append(v);
sb.append(", ");
}
}
sb.setLength(Math.max(sb.length() - 2, 0)); // delete last delimiter
return sb.toString();

private static String printItemDeltaValues(ItemDeltaType itemDelta) {
List values = itemDelta.getValue();
StringBuilder sb = new StringBuilder();
for (Object value : values) {
String v = printItemDeltaValue(itemDelta.getPath(), value);
if (StringUtils.isNotBlank(v)) {
sb.append(v);
sb.append(", ");
}
}
sb.setLength(Math.max(sb.length() - 2, 0)); // delete last delimiter
return sb.toString();
}

private static String printItemDeltaValue(ItemPathType itemPath, Object value){
if (value instanceof MetadataType){
return "";
} else if (value instanceof RawType){
try {

if (isMetadata(itemPath)){
return "";
}
return prettyPrintForReport(((RawType) value).getParsedRealValue(null, itemPath.getItemPath()));
} catch (SchemaException e) {
return "###INTERNAL#ERROR### " + e.getClass().getName() + ": " + e.getMessage() + "; prettyPrintForReport method for value " + value;
} catch (RuntimeException e){
return "###INTERNAL#ERROR### " + e.getClass().getName() + ": " + e.getMessage() + "; prettyPrintForReport method for value " + value;
} catch (Exception e){
return "###INTERNAL#ERROR### " + e.getClass().getName() + ": " + e.getMessage() + "; prettyPrintForReport method for value " + value;
}
} else {
return prettyPrintForReport(value);
}


private static String printItemDeltaValue(ItemPathType itemPath, Object value) {
if (value instanceof MetadataType) {
return "";
} else if (value instanceof RawType) {
try {

if (isMetadata(itemPath)) {
return "";
}
return prettyPrintForReport(((RawType) value).getParsedRealValue(null, itemPath.getItemPath()));
} catch (SchemaException e) {
return "###INTERNAL#ERROR### " + e.getClass().getName() + ": " + e.getMessage() + "; prettyPrintForReport method for value " + value;
} catch (RuntimeException e) {
return "###INTERNAL#ERROR### " + e.getClass().getName() + ": " + e.getMessage() + "; prettyPrintForReport method for value " + value;
} catch (Exception e) {
return "###INTERNAL#ERROR### " + e.getClass().getName() + ": " + e.getMessage() + "; prettyPrintForReport method for value " + value;
}
} else {
return prettyPrintForReport(value);
}
}
private static String printItemDeltaOldValues(ItemPathType itemPath, List values){
StringBuilder sb = new StringBuilder();
for (Object value : values){
String v = printItemDeltaValue(itemPath, value);
if (StringUtils.isNotBlank(v)){
sb.append(v);
sb.append(", ");
}
}
sb.setLength(Math.max(sb.length() - 2, 0)); // delete last delimiter
return sb.toString();

private static String printItemDeltaOldValues(ItemPathType itemPath, List values) {
StringBuilder sb = new StringBuilder();
for (Object value : values) {
String v = printItemDeltaValue(itemPath, value);
if (StringUtils.isNotBlank(v)) {
sb.append(v);
sb.append(", ");
}
}
sb.setLength(Math.max(sb.length() - 2, 0)); // delete last delimiter
return sb.toString();

}
private static boolean isMetadata(ItemDeltaType itemDelta){
List values = itemDelta.getValue();
for (Object v : values){
if (v instanceof MetadataType){
return true;
} else if (v instanceof RawType){
return isMetadata(itemDelta.getPath());
}
}
return false;

private static boolean isMetadata(ItemDeltaType itemDelta) {
List values = itemDelta.getValue();
for (Object v : values) {
if (v instanceof MetadataType) {
return true;
} else if (v instanceof RawType) {
return isMetadata(itemDelta.getPath());
}
}

return false;
}

private static boolean isMetadata(ItemPathType itemPath){
return com.evolveum.midpoint.prism.path.ItemPath.getFirstName(itemPath.getItemPath()).getLocalPart().equals("metadata");

private static boolean isMetadata(ItemPathType itemPath) {
boolean retMeta = false;
for (ItemPathSegment ips : itemPath.getItemPath().getSegments()) {
if (ips instanceof NameItemPathSegment && "metadata".equals(((NameItemPathSegment) ips).getName().getLocalPart())) {
return true;
}
}
return retMeta;
}

public static String prettyPrintForReport(ItemDeltaType itemDelta) {
StringBuilder sb = new StringBuilder();
boolean displayNA = false;
if (isMetadata(itemDelta)){
return sb.toString();

if (isMetadata(itemDelta)) {
return sb.toString();
}

sb.append(">>> ");
Expand All @@ -326,8 +341,8 @@ public static String prettyPrintForReport(ItemDeltaType itemDelta) {
sb.append(", ");
displayNA = true;
}
if (itemDelta.getModificationType() == ModificationTypeType.REPLACE){

if (itemDelta.getModificationType() == ModificationTypeType.REPLACE) {
sb.append("Replace: ");
sb.append("{");
sb.append(printItemDeltaValues(itemDelta));
Expand Down Expand Up @@ -364,12 +379,10 @@ public static String prettyPrintForReport(ItemDeltaType itemDelta) {
return sb.toString();
}


public static String getBusinessDisplayName(ObjectReferenceType ort){
return ort.getDescription();
public static String getBusinessDisplayName(ObjectReferenceType ort) {
return ort.getDescription();
}


private static String printChangeType(ObjectDeltaType delta, String opName) {
StringBuilder sb = new StringBuilder();
sb.append(opName);
Expand All @@ -383,19 +396,17 @@ private static String printChangeType(ObjectDeltaType delta, String opName) {
return sb.toString();
}


public static String printDelta(List<ObjectDeltaType> delta) {
StringBuilder sb = new StringBuilder();
for (ObjectDeltaType d : delta){
sb.append(printDelta(d));
sb.append("\n");
}
return sb.toString();
StringBuilder sb = new StringBuilder();
for (ObjectDeltaType d : delta) {
sb.append(printDelta(d));
sb.append("\n");
}
return sb.toString();
}

public static String printDelta(ObjectDeltaType delta) {
StringBuilder sb = new StringBuilder();
Boolean isMeta;

switch (delta.getChangeType()) {
case MODIFY:
Expand Down
32 changes: 32 additions & 0 deletions samples/rest/notify-change-modify-password.xml
@@ -0,0 +1,32 @@
<?xml version="1.0"?>
<!--
~ Copyright (c) 2010-2014 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.
-->

<resourceObjectShadowChangeDescription xmlns:apit='http://midpoint.evolveum.com/xml/ns/public/common/api-types-3'
xmlns='http://midpoint.evolveum.com/xml/ns/public/common/common-3'
xmlns:t="http://prism.evolveum.com/xml/ns/public/types-3">
<oldShadowOid>66edcfea-ee9b-4e49-aa08-4871e4efbccc</oldShadowOid>
<objectDelta>
<t:oid>66edcfea-ee9b-4e49-aa08-4871e4efbccc</t:oid>
<t:changeType>modify</t:changeType>
<t:objectType>ShadowType</t:objectType>
<t:itemDelta>
<t:modificationType>replace</t:modificationType>
<t:path>credentials/password/value</t:path>
<t:value>paSSword123</t:value>
</t:itemDelta>
</objectDelta>
</resourceObjectShadowChangeDescription>

0 comments on commit 90d4c82

Please sign in to comment.