Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Evolveum/midpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
katkav committed May 27, 2020
2 parents 0c55567 + c6909a7 commit 746b92c
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 44 deletions.
Expand Up @@ -298,7 +298,21 @@ protected void createReportPerformed(SearchFilterType filter, List<Integer> inde
objectCollection.setView(resolveSelectedColumn(indexOfColumns, view.toGuiObjectListViewType()));
}
CollectionRefSpecificationType collection = new CollectionRefSpecificationType();
collection.setBaseCollectionRef(view.getCollection());
if (view.getCollection() != null && view.getCollection().getCollectionRef() != null) {
if (!QNameUtil.match(view.getCollection().getCollectionRef().getType(), ArchetypeType.COMPLEX_TYPE)) {
collection.setBaseCollectionRef(view.getCollection());
} else {
CollectionRefSpecificationType baseCollection = new CollectionRefSpecificationType();
try {
baseCollection.setFilter(getPageBase().getQueryConverter().createSearchFilterType(view.getFilter()));
collection.setBaseCollectionRef(baseCollection);
} catch (SchemaException e) {
LOGGER.error("Couldn't create filter for archetype");
getPageBase().error(getString("MainObjectListPanel.message.error.createArchetypeFilter"));
target.add(getPageBase().getFeedbackPanel());
}
}
}
if (filter != null) {
collection.setFilter(filter);
} else if (view.getCollection() == null) {
Expand Down Expand Up @@ -393,8 +407,14 @@ public void onClick(AjaxRequestTarget target) {

private GuiObjectListViewType resolveSelectedColumn(List<Integer> indexOfColumns, GuiObjectListViewType view){
List<GuiObjectColumnType> newColumns = new ArrayList<>();
List<GuiObjectColumnType> oldColumns;
if (view.getColumn().isEmpty()) {
oldColumns = getDefaultView().getColumn();
} else {
oldColumns = view.getColumn();
}
for (Integer index : indexOfColumns) {
newColumns.add(view.getColumn().get(index-2));
newColumns.add(oldColumns.get(index-2).clone());
}
view.getColumn().clear();
view.getColumn().addAll(newColumns);
Expand Down
Expand Up @@ -272,6 +272,7 @@ protected WebPage getLinkRef() {
if (!isViewOfWidgetNull(model)) {
getPageBase().getModelInteractionService().applyView(compiledView, model.getObject().getPresentation().getView());
}
compiledView.setCollection(model.getObject().getData().getCollection());
compiledView.setViewIdentifier(model.getObject().getIdentifier());
getPageBase().getCompiledGuiProfile().getObjectCollectionViews().add(compiledView);
} catch (SchemaException | CommunicationException | ConfigurationException | SecurityViolationException | ExpressionEvaluationException
Expand Down
Expand Up @@ -8,14 +8,7 @@
package com.evolveum.midpoint.web.util;

import java.io.IOException;
import java.text.DecimalFormat;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;

import org.apache.catalina.connector.ClientAbortException;
Expand All @@ -26,25 +19,26 @@
import com.evolveum.midpoint.util.logging.TraceManager;

/**
* //TODO - After upgrading to javax.servlet version API 3.0, add response status code logging
*
* In this filter, all incoming requests are captured and we measure server response times (using System.nanoTime() for now),
* this may be later adjusted using Java SIMON API (but this API is based on System.nanoTime() as well).
*
* Right now, we are logging this request/response information
* Requested URL
* Request method (GET/POST)
* Request session id
*
* Requests for .css or various image files are filtered and not recorded.
*
* @author lazyman
* @author shood
* In this filter, all incoming requests are captured and we measure server response times
* using {@link System#nanoTime()}.
* ight now we are logging this request/response information:
* <ul>
* <li>Requested URL</li>
* <li>Request method (GET/POST)</li>
* <li>Request session id</li>
* </ul>
* <p>
* Requests for .css or various image files are filtered and not recorded.
* <p>
* @author lazyman
* @author shood
*/
// TODO - After upgrading to javax.servlet version API 3.0, add response status code logging
// 2020: we are on API>3 now, but what was the original idea? Was it meant for exception logging?
// Also, elapsedTime should be calculated also for exception scenario and perhaps put into different statistics?
public class MidPointProfilingServletFilter implements Filter {

private static final Trace LOGGER = TraceManager.getTrace(MidPointProfilingServletFilter.class);
private static DecimalFormat df = new DecimalFormat("0.00");

protected FilterConfig config;

Expand All @@ -53,7 +47,7 @@ public void destroy() {
}

@Override
public void init(FilterConfig config) throws ServletException {
public void init(FilterConfig config) {
this.config = config;
}

Expand All @@ -73,10 +67,10 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha

long elapsedTime = System.nanoTime() - startTime;

if(request instanceof HttpServletRequest){
String uri = ((HttpServletRequest)request).getRequestURI();
if (request instanceof HttpServletRequest) {
String uri = ((HttpServletRequest) request).getRequestURI();

if(uri.startsWith("/midpoint/admin")){
if (uri.startsWith("/midpoint/admin")) {
prepareRequestProfilingEvent(request, elapsedTime, uri);
}
}
Expand All @@ -87,18 +81,18 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha
logException(e);
throw e;
}
}
}
}

private void prepareRequestProfilingEvent(ServletRequest request, long elapsed, String uri){
String info = ((HttpServletRequest)request).getMethod();
String sessionId = ((HttpServletRequest)request).getRequestedSessionId();
private void prepareRequestProfilingEvent(ServletRequest request, long elapsed, String uri) {
String info = ((HttpServletRequest) request).getMethod();
String sessionId = ((HttpServletRequest) request).getRequestedSessionId();

ProfilingDataLog event = new ProfilingDataLog(info, uri, sessionId, elapsed, System.currentTimeMillis());
ProfilingDataManager.getInstance().prepareRequestProfilingEvent(event);
}

private void logException(Throwable t) throws IOException, ServletException {
private void logException(Throwable t) {
if (t instanceof ClientAbortException) {
if (LOGGER.isDebugEnabled()) {
// client abort exceptions are quite OK as they are not an application/server problem
Expand Down
Expand Up @@ -399,20 +399,30 @@ public List<PrismObject<ObjectType>> searchObjectFromCollection(CollectionRefSpe
searchFilter = collection.getFilter();
} else {
searchFilter = collectionConfig.getFilter();
if (collectionConfig.getBaseCollectionRef() != null && collectionConfig.getBaseCollectionRef().getCollectionRef() != null) {
ObjectReferenceType ref = collectionConfig.getBaseCollectionRef().getCollectionRef();
Class<ObjectType> refType = prismContext.getSchemaRegistry().determineClassForType(ref.getType());
ObjectCollectionType collection = (ObjectCollectionType) modelService
.getObject(refType, ref.getOid(), null, task, result).asObjectable();

searchFilterForMerge = collection.getFilter();
Class<ObjectType> typeFromBaseCollection = (Class<ObjectType>) prismContext.getSchemaRegistry()
.getCompileTimeClassForObjectType(collection.getType());
if (collectionConfig.getBaseCollectionRef() != null &&
(collectionConfig.getBaseCollectionRef().getCollectionRef() != null || collectionConfig.getBaseCollectionRef().getFilter() != null)) {
Class<ObjectType> typeFromBaseCollection = null;
if (collectionConfig.getBaseCollectionRef().getCollectionRef() != null) {
ObjectReferenceType ref = collectionConfig.getBaseCollectionRef().getCollectionRef();
Class<ObjectType> refType = prismContext.getSchemaRegistry().determineClassForType(ref.getType());
ObjectCollectionType collection = (ObjectCollectionType) modelService
.getObject(refType, ref.getOid(), null, task, result).asObjectable();

searchFilterForMerge = collection.getFilter();
typeFromBaseCollection = (Class<ObjectType>) prismContext.getSchemaRegistry()
.getCompileTimeClassForObjectType(collection.getType());
} else {
searchFilterForMerge = collectionConfig.getBaseCollectionRef().getFilter();
}
if (typeForFilter == null) {
if (typeFromBaseCollection == null) {
LOGGER.error("Type of objects is null");
throw new IllegalArgumentException("Type of objects is null");
}
type = typeFromBaseCollection;
} else {
type = prismContext.getSchemaRegistry().determineClassForType(typeForFilter);
if (!typeFromBaseCollection.isAssignableFrom(type)) {
if (typeFromBaseCollection != null && !typeFromBaseCollection.isAssignableFrom(type)) {
LOGGER.error("Type of objects from filter don't inherit from type from base collection");
throw new IllegalArgumentException("Type of objects from filter don't inherit from type from base collection");
}
Expand Down

0 comments on commit 746b92c

Please sign in to comment.