Skip to content

Commit

Permalink
Debug pages will correctly show errored entries (as " (FATAL_ERROR)")
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Dec 12, 2016
1 parent 7b4b859 commit 917f1f1
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 11 deletions.
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 @@ -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 @@ -57,6 +57,7 @@
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;
import com.evolveum.prism.xml.ns._public.types_3.PolyStringType;
import org.hibernate.Criteria;
import org.hibernate.LockMode;
import org.hibernate.LockOptions;
Expand Down Expand Up @@ -213,7 +214,7 @@ public <T extends ObjectType> PrismObject<T> getObjectInternal(Session session,
}

LOGGER.trace("Transforming data to JAXB type.");
PrismObject<T> prismObject = updateLoadedObject(fullObject, type, oid, options, session, operationResult);
PrismObject<T> prismObject = updateLoadedObject(fullObject, type, oid, options, null, session, operationResult);
validateObjectType(prismObject, type);

// this was implemented to allow report parsing errors as warnings to upper layers;
Expand Down Expand Up @@ -265,7 +266,7 @@ public <F extends FocusType> PrismObject<F> searchShadowOwnerAttempt(String shad
}

GetObjectResult focus = focuses.get(0);
owner = updateLoadedObject(focus, (Class<F>) FocusType.class, null, options, session, result);
owner = updateLoadedObject(focus, (Class<F>) FocusType.class, null, options, null, session, result);

session.getTransaction().commit();

Expand Down Expand Up @@ -304,7 +305,7 @@ public PrismObject<UserType> listAccountShadowOwnerAttempt(String accountOid, Op
}

GetObjectResult user = users.get(0);
userType = updateLoadedObject(user, UserType.class, null, null, session, result);
userType = updateLoadedObject(user, UserType.class, null, null, null, session, result);

session.getTransaction().commit();
} catch (SchemaException | RuntimeException ex) {
Expand Down Expand Up @@ -397,7 +398,21 @@ private <T extends ObjectType> List<PrismObject<T>> queryResultToPrismObjects(Li
List<PrismObject<T>> rv = new ArrayList<>();
if (objects != null) {
for (GetObjectResult object : objects) {
PrismObject<T> prismObject = updateLoadedObject(object, type, oid, options, session, result);
Holder<PrismObject<T>> partialValueHolder = new Holder<>();
PrismObject<T> prismObject;
try {
prismObject = updateLoadedObject(object, type, oid, options, partialValueHolder, session, result);
} catch (Throwable t) {
if (!partialValueHolder.isEmpty()) {
prismObject = partialValueHolder.getValue();
} else {
prismObject = prismContext.createObject(type);
prismObject.setOid(oid); // most probably null
prismObject.asObjectable().setName(PolyStringType.fromOrig("Unreadable object"));
}
result.recordFatalError("Couldn't retrieve " + type + " " + oid + ": " + t.getMessage(), t);
prismObject.asObjectable().setFetchResult(result.createOperationResultType());
}
rv.add(prismObject);
}
}
Expand Down Expand Up @@ -445,6 +460,7 @@ public <C extends Containerable> SearchResultList<C> searchContainersAttempt(Cla
*/
private <T extends ObjectType> PrismObject<T> updateLoadedObject(GetObjectResult result, Class<T> type,
String oid, Collection<SelectorOptions<GetOperationOptions>> options,
Holder<PrismObject<T>> partialValueHolder,
Session session, OperationResult operationResult) throws SchemaException {

String xml = RUtil.getXmlFromByteArray(result.getFullObject(), getConfiguration().isUseZip());
Expand Down Expand Up @@ -502,6 +518,9 @@ private <T extends ObjectType> PrismObject<T> updateLoadedObject(GetObjectResult
caseHelper.updateLoadedCampaign(prismObject, options, session);
}

if (partialValueHolder != null) {
partialValueHolder.setValue(prismObject);
}
nameResolutionHelper.resolveNamesIfRequested(session, prismObject.getValue(), options);
validateObjectType(prismObject, type);

Expand Down Expand Up @@ -565,7 +584,7 @@ public <T extends ShadowType> List<PrismObject<T>> listResourceObjectShadowsAtte

if (shadows != null) {
for (GetObjectResult shadow : shadows) {
PrismObject<T> prismObject = updateLoadedObject(shadow, resourceObjectShadowType, null, null, session, result);
PrismObject<T> prismObject = updateLoadedObject(shadow, resourceObjectShadowType, null, null, null, session, result);
list.add(prismObject);
}
}
Expand Down Expand Up @@ -643,7 +662,8 @@ public <T extends ObjectType> void searchObjectsIterativeAttempt(Class<T> type,
while (iterator.hasNext()) {
GetObjectResult object = iterator.next();

PrismObject<T> prismObject = updateLoadedObject(object, type, null, options, session, result);
// TODO treat exceptions encountered within the next call
PrismObject<T> prismObject = updateLoadedObject(object, type, null, options, null, session, result);
if (!handler.handle(prismObject, result)) {
break;
}
Expand Down

0 comments on commit 917f1f1

Please sign in to comment.