Skip to content

Commit

Permalink
support for generating html report
Browse files Browse the repository at this point in the history
  • Loading branch information
skublik committed Apr 11, 2019
1 parent 133b672 commit 74e65b2
Show file tree
Hide file tree
Showing 11 changed files with 1,719 additions and 742 deletions.

Large diffs are not rendered by default.

Expand Up @@ -37,6 +37,7 @@

import com.evolveum.midpoint.audit.api.AuditEventRecord;
import com.evolveum.midpoint.common.Clock;
import com.evolveum.midpoint.model.api.util.DashboardUtils;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.util.exception.CommunicationException;
import com.evolveum.midpoint.util.exception.ConfigurationException;
Expand Down Expand Up @@ -86,7 +87,7 @@ public class AuditEventRecordProvider extends BaseSortableDataProvider<AuditEven
private static final String AUDIT_RECORDS_ORDER_BY = " order by aer.timestamp desc";
private static final String SET_FIRST_RESULT_PARAMETER = "setFirstResult";
private static final String SET_MAX_RESULTS_PARAMETER = "setMaxResults";
private static final String TIMESTAMP_VALUE_NAME = "aer.timestamp";
// private static final String TIMESTAMP_VALUE_NAME = "aer.timestamp";

public AuditEventRecordProvider(Component component, @Nullable IModel<ObjectCollectionType> objectCollectionModel, @NotNull SerializableSupplier<Map<String, Object>> parametersSupplier) {
super(component);
Expand All @@ -105,7 +106,7 @@ protected int internalSize() {
String query;
String origQuery;
Map<String, Object> parameters = new HashMap<String, Object>();
origQuery = createQuery(getCollectionForQuery(), parameters, false, getPage().getClock());
origQuery = DashboardUtils.createQuery(getCollectionForQuery(), parameters, false, getPage().getClock());
if(StringUtils.isNotBlank(origQuery)) {
query = generateFullQuery(origQuery, false, true);
} else {
Expand All @@ -114,7 +115,6 @@ protected int internalSize() {
}
try {
Task task = getPage().createSimpleTask("internalSize");
System.out.println("XXXXXXXXXx " + query);
return (int) getAuditService().countObjects(query, parameters, task, task.getResult());
} catch (SecurityViolationException | SchemaException | ObjectNotFoundException | ExpressionEvaluationException | CommunicationException | ConfigurationException e) {
// TODO: proper error handling (MID-3536)
Expand All @@ -126,7 +126,7 @@ private List<AuditEventRecordType> listRecords(boolean ordered, long first, long
String query;
String origQuery;
Map<String, Object> parameters = new HashMap<String, Object>();
origQuery = createQuery(getCollectionForQuery(), parameters, false, getPage().getClock());
origQuery = DashboardUtils.createQuery(getCollectionForQuery(), parameters, false, getPage().getClock());
if(StringUtils.isNotBlank(origQuery)) {
query = generateFullQuery(origQuery, ordered, false);
} else {
Expand Down Expand Up @@ -155,39 +155,39 @@ private List<AuditEventRecordType> listRecords(boolean ordered, long first, long
return auditRecordList;
}

public static String createQuery(ObjectCollectionType collectionForQuery, Map<String, Object> parameters,
boolean forDomain, Clock clock) {
if(collectionForQuery == null) {
return null;
}
AuditSearchType auditSearch = collectionForQuery.getAuditSearch();
if(auditSearch != null || StringUtils.isNotBlank(auditSearch.getRecordQuery())) {
Duration interval = auditSearch.getInterval();
if(interval == null) {
return auditSearch.getRecordQuery();
}
String origQuery = auditSearch.getRecordQuery();
if(forDomain) {
origQuery = auditSearch.getDomainQuery();
if(origQuery == null) {
return null;
}
}
String [] partsOfQuery = origQuery.split("where");
if(interval.getSign() == 1) {
interval = interval.negate();
}
Date date = new Date(clock.currentTimeMillis());
interval.addTo(date);
String query = partsOfQuery[0] + "where " + TIMESTAMP_VALUE_NAME + " >= " + ":from" + " ";
parameters.put(PARAMETER_FROM, date);
if(partsOfQuery.length > 1) {
query+= "and" +partsOfQuery[1];
}
return query;
}
return null;
}
// public static String createQuery(ObjectCollectionType collectionForQuery, Map<String, Object> parameters,
// boolean forDomain, Clock clock) {
// if(collectionForQuery == null) {
// return null;
// }
// AuditSearchType auditSearch = collectionForQuery.getAuditSearch();
// if(auditSearch != null || StringUtils.isNotBlank(auditSearch.getRecordQuery())) {
// Duration interval = auditSearch.getInterval();
// if(interval == null) {
// return auditSearch.getRecordQuery();
// }
// String origQuery = auditSearch.getRecordQuery();
// if(forDomain) {
// origQuery = auditSearch.getDomainQuery();
// if(origQuery == null) {
// return null;
// }
// }
// String [] partsOfQuery = origQuery.split("where");
// if(interval.getSign() == 1) {
// interval = interval.negate();
// }
// Date date = new Date(clock.currentTimeMillis());
// interval.addTo(date);
// String query = partsOfQuery[0] + "where " + TIMESTAMP_VALUE_NAME + " >= " + ":from" + " ";
// parameters.put(PARAMETER_FROM, date);
// if(partsOfQuery.length > 1) {
// query+= "and" +partsOfQuery[1];
// }
// return query;
// }
// return null;
// }


@SuppressWarnings("unused")
Expand Down
5 changes: 5 additions & 0 deletions model/model-api/pom.xml
Expand Up @@ -77,6 +77,11 @@
<artifactId>task-api</artifactId>
<version>4.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.evolveum.midpoint.repo</groupId>
<artifactId>repo-common</artifactId>
<version>4.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.evolveum.midpoint.repo</groupId>
<artifactId>security-api</artifactId>
Expand Down
@@ -0,0 +1,79 @@
/**
* Copyright (c) 2010-2019 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.model.api;

import com.evolveum.midpoint.xml.ns._public.common.common_3.DashboardWidgetType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.DisplayType;

/**
* @author skublik
*/
public class DashboardWidget {

private DisplayType display;
private String numberMessage;
private DashboardWidgetType widget;

public DashboardWidget() {
}

public DashboardWidget(DashboardWidgetType widget, DisplayType display, String numberMessage) {
this.widget = widget;
this.display = display;
this.numberMessage = numberMessage;
}

public DisplayType getDisplay() {
return display;
}

public void setDisplay(DisplayType display) {
this.display = display;
}

public String getNumberMessage() {
return numberMessage;
}

public void setNumberMessage(String numberMessage) {
this.numberMessage = numberMessage;
}

public DashboardWidgetType getWidget() {
return widget;
}

public void setWidget(DashboardWidgetType widget) {
this.widget = widget;
}

public String getLabel() {
if(getDisplay() != null && getDisplay().getLabel() != null) {
return getDisplay().getLabel().toString();
} else {
return getWidget().getIdentifier();
}
}

@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("{widgetIdentifier:").append(widget == null ? null : widget.getIdentifier())
.append(", numberMessage:").append(numberMessage)
.append(", display:").append(display).append("}");
return sb.toString();
}
}

0 comments on commit 74e65b2

Please sign in to comment.