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
semancik committed Dec 12, 2016
2 parents 430ecf5 + e7e34e5 commit 4a5a941
Show file tree
Hide file tree
Showing 18 changed files with 210 additions and 47 deletions.
Expand Up @@ -873,6 +873,7 @@ protected <O extends ObjectType> void validateObject(String lexicalRepresentatio
PrismObject<O> object;
try {
object = getPrismContext().parserFor(lexicalRepresentation).language(language).parse();
object.checkConsistence();
objectHolder.setValue(object);
} catch (RuntimeException | SchemaException e) {
result.recordFatalError("Couldn't parse object: " + e.getMessage(), e);
Expand Down
Expand Up @@ -101,7 +101,7 @@ public Iterator<DebugObjectItem> internalIterator(long first, long count) {
return getAvailableData().iterator();
}

private DebugObjectItem createItem(PrismObject object, OperationResult result) {
private DebugObjectItem createItem(PrismObject<? extends ObjectType> object, OperationResult result) {
DebugObjectItem item = DebugObjectItem.createDebugObjectItem(object);
if (ShadowType.class.isAssignableFrom(object.getCompileTimeClass())) {
PrismReference ref = object.findReference(new ItemPath(ShadowType.F_RESOURCE_REF));
Expand Down
Expand Up @@ -309,14 +309,35 @@ public void populateItem(Item<ICellPopulator<DebugObjectItem>> cellItem, String
final IModel<DebugObjectItem> rowModel) {

TwoValueLinkPanel panel = new TwoValueLinkPanel(componentId,
new PropertyModel<String>(rowModel, DebugObjectItem.F_NAME),
new AbstractReadOnlyModel<String>() {
@Override
public String getObject() {
DebugObjectItem object = rowModel.getObject();
if (object == null) {
return null;
}
StringBuilder sb = new StringBuilder();
sb.append(object.getName());
if (object.getStatus() != null) {
sb.append(" (");
sb.append(object.getStatus());
sb.append(")");
}
return sb.toString();
}
},
new PropertyModel<String>(rowModel, DebugObjectItem.F_OID)) {

@Override
public void onClick(AjaxRequestTarget target) {
DebugObjectItem object = rowModel.getObject();
objectEditPerformed(target, object.getOid(), type);
}

@Override
public boolean isEnabled() {
return rowModel.getObject().getOid() != null;
}
};

cellItem.add(panel);
Expand Down
Expand Up @@ -308,10 +308,10 @@ public void savePerformed(AjaxRequestTarget target) {
validateObject(plainTextarea.getModel().getObject(), objectHolder, dataLanguage, validateSchema.getObject(), result);
}

if (result.isAcceptable()) {
if (result.isAcceptable()) {
PrismObject<ObjectType> newObject = objectHolder.getValue();

ObjectDelta<ObjectType> delta = oldObject.diff(newObject, true, true);
ObjectDelta<ObjectType> delta = oldObject.diff(newObject, true, true);

if (delta.getPrismContext() == null) {
LOGGER.warn("No prism context in delta {} after diff, adding it", delta);
Expand Down
Expand Up @@ -23,6 +23,7 @@
import com.evolveum.midpoint.web.component.menu.cog.InlineMenuItem;
import com.evolveum.midpoint.web.component.util.Selectable;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultStatusType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;

import java.util.ArrayList;
Expand All @@ -40,13 +41,15 @@ public class DebugObjectItem extends Selectable implements InlineMenuable {
public static final String F_RESOURCE_TYPE = "resourceType";
public static final String F_FULL_NAME = "fullName";
public static final String F_DESCRIPTION = "description";
public static final String F_STATUS = "status";

private String oid;
private String name;
private String description;
//todo create subclasses
private String resourceName;
private String resourceType;
private OperationResultStatusType status; // TODO store full operation result here

private String fullName;

Expand Down Expand Up @@ -92,9 +95,13 @@ public String getDescription() {
return description;
}

public static DebugObjectItem createDebugObjectItem(PrismObject object) {
public static DebugObjectItem createDebugObjectItem(PrismObject<? extends ObjectType> object) {
DebugObjectItem item = new DebugObjectItem(object.getOid(), WebComponentUtil.getName(object),
(String) object.getPropertyRealValue(ObjectType.F_DESCRIPTION, String.class));
object.getPropertyRealValue(ObjectType.F_DESCRIPTION, String.class));

if (object.asObjectable().getFetchResult() != null) {
item.setStatus(object.asObjectable().getFetchResult().getStatus());
}

if (UserType.class.isAssignableFrom(object.getCompileTimeClass())) {
PolyString fullName = WebComponentUtil.getValue(object, UserType.F_FULL_NAME, PolyString.class);
Expand All @@ -104,7 +111,15 @@ public static DebugObjectItem createDebugObjectItem(PrismObject object) {
return item;
}

@Override
public OperationResultStatusType getStatus() {
return status;
}

public void setStatus(OperationResultStatusType status) {
this.status = status;
}

@Override
public List<InlineMenuItem> getMenuItems() {
return new ArrayList<InlineMenuItem>();
}
Expand Down
Expand Up @@ -414,7 +414,7 @@ public Map<String, Object> getParameters() {
if (search.getChangedItem().toItemPath() != null) {
ItemPath itemPath = search.getChangedItem().toItemPath();
XPathHolder holder = new XPathHolder(itemPath);
parameters.put("changedItem", holder.toCanonicalPath());
parameters.put("changedItem", holder.toCanonicalPath(null, getPrismContext()));
}
parameters.put("eventType", search.getEventType());
parameters.put("eventStage", search.getEventStage());
Expand Down
Expand Up @@ -36,6 +36,7 @@
import com.evolveum.prism.xml.ns._public.query_3.SearchFilterType;
import com.evolveum.prism.xml.ns._public.types_3.EvaluationTimeType;
import com.evolveum.prism.xml.ns._public.types_3.PolyStringType;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.Nullable;

/**
Expand Down Expand Up @@ -321,7 +322,7 @@ public void checkConsistenceInternal(Itemable rootItem, boolean requireDefinitio

ItemPath myPath = getPath();

if (oid == null && object == null && filter == null) {
if (StringUtils.isBlank(oid) && object == null && filter == null) {
boolean mayBeEmpty = false;
if (getParent() != null && getParent().getDefinition() != null) {
ItemDefinition itemDefinition = getParent().getDefinition();
Expand Down
Expand Up @@ -29,7 +29,11 @@
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import com.evolveum.midpoint.prism.ItemDefinition;
import com.evolveum.midpoint.prism.PrismConstants;
import com.evolveum.midpoint.prism.PrismContainerDefinition;
import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.prism.PrismObjectDefinition;
import com.evolveum.midpoint.prism.path.*;

import com.evolveum.midpoint.util.QNameUtil;
Expand Down Expand Up @@ -381,11 +385,16 @@ private void addPureXpath(StringBuilder sb) {
}
}

public String toCanonicalPath() {
public String toCanonicalPath(Class objectType, PrismContext prismContext) {
StringBuilder sb = new StringBuilder("\\");

boolean first = true;


PrismObjectDefinition objDef = null;
if (objectType != null) {
objDef = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(objectType);
}
ItemDefinition def = null;
for (XPathSegment seg : segments) {

if (seg.isIdValueFilter()) {
Expand All @@ -394,14 +403,32 @@ public String toCanonicalPath() {

} else {

QName qname = seg.getQName();

if (!first) {
sb.append("\\");
if (StringUtils.isBlank(qname.getNamespaceURI()) && objDef != null) {
if (def instanceof PrismContainerDefinition) {
PrismContainerDefinition containerDef = (PrismContainerDefinition) def;
def = containerDef.findItemDefinition(qname);
}

if (def != null) {
qname = def.getName();
}
}
} else {
if (StringUtils.isBlank(qname.getNamespaceURI()) && objDef != null) {
def = objDef.findItemDefinition(qname);
if (def != null) {
qname = def.getName();
}
}
first = false;
}

QName qname = seg.getQName();


sb.append(QNameUtil.qNameToUri(qname));
}
}
Expand Down
Expand Up @@ -23,6 +23,7 @@
import javax.xml.namespace.QName;

import com.evolveum.midpoint.prism.*;
import com.evolveum.midpoint.schema.internals.InternalsConfig;
import com.evolveum.prism.xml.ns._public.types_3.PolyStringType;
import org.apache.commons.lang.Validate;

Expand Down Expand Up @@ -349,7 +350,9 @@ public static Collection<ItemDeltaType> toItemDeltaTypes(ItemDelta delta) throws
}

public static Collection<ItemDeltaType> toItemDeltaTypes(ItemDelta delta, DeltaConversionOptions options) throws SchemaException {
delta.checkConsistence();
if (InternalsConfig.consistencyChecks) {
delta.checkConsistence();
}
if (!delta.isEmpty() && delta.getPrismContext() == null) {
throw new IllegalStateException("Non-empty ItemDelta with no prismContext cannot be converted to ItemDeltaType.");
}
Expand Down
Expand Up @@ -50,6 +50,7 @@
import com.evolveum.midpoint.repo.cache.RepositoryCache;
import com.evolveum.midpoint.schema.*;
import com.evolveum.midpoint.schema.constants.ObjectTypes;
import com.evolveum.midpoint.schema.internals.InternalsConfig;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.result.OperationResultRunner;
import com.evolveum.midpoint.schema.result.OperationResultStatus;
Expand Down Expand Up @@ -409,15 +410,14 @@ public Collection<ObjectDeltaOperation<? extends ObjectType>> executeChanges(fin
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("MODEL.executeChanges(\n deltas:\n{}\n options:{}", DebugUtil.debugDump(deltas, 2), options);
}

OperationResultRunner.run(result, new Runnable() {
@Override
public void run() {
for(ObjectDelta<? extends ObjectType> delta: deltas) {

if (InternalsConfig.consistencyChecks) {
OperationResultRunner.run(result, () -> {
for (ObjectDelta<? extends ObjectType> delta : deltas) {
delta.checkConsistence();
}
}
});
});
}

RepositoryCache.enter();

Expand Down
Expand Up @@ -569,7 +569,9 @@ private <T extends ObjectType> void validateObject(PrismObject<T> object, GetOpe
// Tolerate some raw meat in that case.
tolerateRaw = true;
}
object.checkConsistence(true, !tolerateRaw, ConsistencyCheckScope.THOROUGH);
if (InternalsConfig.consistencyChecks) {
object.checkConsistence(true, !tolerateRaw, ConsistencyCheckScope.THOROUGH);
}
} catch (RuntimeException e) {
result.recordFatalError(e);
throw e;
Expand Down
@@ -1,10 +1,13 @@
package com.evolveum.midpoint.model.impl.util;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;

import javax.annotation.PostConstruct;

import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

Expand Down Expand Up @@ -35,6 +38,9 @@ public class AuditReindexTaskHandler implements TaskHandler {
public static final String HANDLER_URI = ModelPublicConstants.AUDIT_REINDEX_TASK_HANDLER_URI;

private static final String taskName = "AuditReindex";

private int maxResults = 20;
private int firstResult = 0;

@Autowired
protected AuditService auditService;
Expand Down Expand Up @@ -96,9 +102,22 @@ public int getProgress() {
"Unexpected ObjectAlreadyExistsException when updating task progress/expectedTotal",
e);
}

auditService.listRecordsIterative(null, null, resultHandler);

Map<String, Object> params = new HashMap<String, Object>();
while (true) {
params.put("setFirstResult", firstResult);
params.put("setMaxResults", maxResults);
List<AuditEventRecord> records = auditService.listRecords(null, params);
if (CollectionUtils.isNotEmpty(records)){
for (AuditEventRecord record : records) {
resultHandler.handle(record);
runResult.setProgress(resultHandler.getProgress());
}
firstResult += maxResults;
maxResults = ( (expectedTotal.intValue() - firstResult) > maxResults ? maxResults : (expectedTotal.intValue() - firstResult));
} else {
break;
}
}
opResult.recordSuccess();

} catch (ObjectNotFoundException e) {
Expand Down
Expand Up @@ -15,6 +15,7 @@
*/
package com.evolveum.midpoint.audit.api;

import java.beans.Transient;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
Expand Down Expand Up @@ -45,7 +46,9 @@
*
*/
public class AuditEventRecord implements DebugDumpable {



private Long repoId;
/**
* Timestamp when the event occured.
* Timestamp in millis.
Expand Down Expand Up @@ -281,6 +284,15 @@ public String getParameter() {
public void setParameter(String parameter) {
this.parameter = parameter;
}

@Transient
public Long getRepoId() {
return repoId;
}

public void setRepoId(Long repoId) {
this.repoId = repoId;
}

public void checkConsistence() {
if (initiator != null) {
Expand All @@ -301,6 +313,7 @@ public void checkConsistence() {
// throw new IllegalStateException("Status in result (" + result.getStatus() + ") differs from outcome (" + outcome + ")");
// }
// }

}

public AuditEventRecordType createAuditEventRecordType(){
Expand Down

0 comments on commit 4a5a941

Please sign in to comment.