Search in sources :

Example 1 with ResourceOperationResult

use of com.evolveum.midpoint.web.component.progress.ProgressReportActivityDto.ResourceOperationResult in project midpoint by Evolveum.

the class DefaultGuiProgressListener method updateStatusItemState.

private void updateStatusItemState(ProgressReportActivityDto si, ProgressInformation progressInformation, ModelContext modelContext) {
    si.setActivityType(progressInformation.getActivityType());
    si.setResourceShadowDiscriminator(progressInformation.getResourceShadowDiscriminator());
    if (progressInformation.getResourceShadowDiscriminator() != null) {
        String resourceOid = progressInformation.getResourceShadowDiscriminator().getResourceOid();
        String resourceName = resourceOid != null ? getResourceName(resourceOid) : "";
        si.setResourceName(resourceName);
    }
    if (progressInformation.getStateType() == null) {
        si.setStatus(null);
    } else if (progressInformation.getStateType() == ENTERING) {
        si.setStatus(OperationResultStatusType.IN_PROGRESS);
    } else {
        OperationResult result = progressInformation.getOperationResult();
        if (result != null) {
            OperationResultStatus status = result.getStatus();
            if (status == OperationResultStatus.UNKNOWN) {
                status = result.getComputeStatus();
            }
            si.setStatus(status.createStatusType());
        } else {
            si.setStatus(OperationResultStatusType.UNKNOWN);
        }
    }
    // information about modifications on a resource
    if (progressInformation.getActivityType() == RESOURCE_OBJECT_OPERATION && progressInformation.getStateType() == EXITING && progressInformation.getResourceShadowDiscriminator() != null && progressInformation.getResourceShadowDiscriminator().getResourceOid() != null) {
        ModelProjectionContext mpc = modelContext.findProjectionContext(progressInformation.getResourceShadowDiscriminator());
        if (mpc != null) {
            // it shouldn't be null!
            // operations performed (TODO aggregate them somehow?)
            List<ResourceOperationResult> resourceOperationResultList = new ArrayList<>();
            List<? extends ObjectDeltaOperation> executedDeltas = mpc.getExecutedDeltas();
            for (ObjectDeltaOperation executedDelta : executedDeltas) {
                ObjectDelta delta = executedDelta.getObjectDelta();
                if (delta != null) {
                    OperationResult r = executedDelta.getExecutionResult();
                    OperationResultStatus status = r.getStatus();
                    if (status == OperationResultStatus.UNKNOWN) {
                        status = r.getComputeStatus();
                    }
                    resourceOperationResultList.add(new ResourceOperationResult(delta.getChangeType(), status));
                }
            }
            si.setResourceOperationResultList(resourceOperationResultList);
            // object name
            PrismObject<ShadowType> object = mpc.getObjectNew();
            if (object == null) {
                object = mpc.getObjectOld();
            }
            String name = null;
            if (object != null) {
                if (object.asObjectable().getName() != null) {
                    name = PolyString.getOrig(object.asObjectable().getName());
                } else {
                    // determine from attributes
                    ResourceAttribute nameAttribute = ShadowUtil.getNamingAttribute(object);
                    if (nameAttribute != null) {
                        name = String.valueOf(nameAttribute.getAnyRealValue());
                    }
                }
            }
            if (name != null) {
                si.setResourceObjectName(name);
            }
        }
    }
}
Also used : ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceOperationResult(com.evolveum.midpoint.web.component.progress.ProgressReportActivityDto.ResourceOperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) OperationResultStatus(com.evolveum.midpoint.schema.result.OperationResultStatus) ObjectDeltaOperation(com.evolveum.midpoint.schema.ObjectDeltaOperation) ModelProjectionContext(com.evolveum.midpoint.model.api.context.ModelProjectionContext) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) ResourceAttribute(com.evolveum.midpoint.schema.processor.ResourceAttribute) ResourceOperationResult(com.evolveum.midpoint.web.component.progress.ProgressReportActivityDto.ResourceOperationResult)

Example 2 with ResourceOperationResult

use of com.evolveum.midpoint.web.component.progress.ProgressReportActivityDto.ResourceOperationResult in project midpoint by Evolveum.

the class ProgressPanel method initLayout.

private void initLayout(ProgressReportingAwarePage page) {
    progressForm = new Form<>(ID_PROGRESS_FORM, true);
    add(progressForm);
    contentsPanel = new WebMarkupContainer(ID_CONTENTS_PANEL);
    contentsPanel.setOutputMarkupId(true);
    progressForm.add(contentsPanel);
    ListView statusItemsListView = new ListView<ProgressReportActivityDto>(ID_ACTIVITIES, new AbstractReadOnlyModel<List<ProgressReportActivityDto>>() {

        @Override
        public List<ProgressReportActivityDto> getObject() {
            ProgressDto progressDto = ProgressPanel.this.getModelObject();
            return progressDto.getProgressReportActivities();
        }
    }) {

        protected void populateItem(final ListItem<ProgressReportActivityDto> item) {
            item.add(new Label(ID_ACTIVITY_DESCRIPTION, new AbstractReadOnlyModel<String>() {

                @Override
                public String getObject() {
                    ProgressReportActivityDto si = item.getModelObject();
                    if (si.getActivityType() == RESOURCE_OBJECT_OPERATION && si.getResourceShadowDiscriminator() != null) {
                        ResourceShadowDiscriminator rsd = si.getResourceShadowDiscriminator();
                        return createStringResource(rsd.getKind()).getString() + " (" + rsd.getIntent() + ") on " + // TODO correct i18n
                        si.getResourceName();
                    } else {
                        return createStringResource(si.getActivityType()).getString();
                    }
                }
            }));
            item.add(createImageLabel(ID_ACTIVITY_STATE, new AbstractReadOnlyModel<String>() {

                @Override
                public String getObject() {
                    OperationResultStatusType statusType = item.getModelObject().getStatus();
                    if (statusType == null) {
                        return null;
                    } else {
                        return OperationResultStatusPresentationProperties.parseOperationalResultStatus(statusType).getIcon() + " fa-lg";
                    }
                }
            }, new AbstractReadOnlyModel<String>() {

                @Override
                public String getObject() {
                    // TODO why this does not work???
                    // TODO i18n
                    OperationResultStatusType statusType = item.getModelObject().getStatus();
                    if (statusType == null) {
                        return null;
                    } else {
                        return statusType.toString();
                    }
                }
            }));
            item.add(new Label(ID_ACTIVITY_COMMENT, new AbstractReadOnlyModel<String>() {

                @Override
                public String getObject() {
                    ProgressReportActivityDto si = item.getModelObject();
                    if (si.getResourceName() != null || si.getResourceOperationResultList() != null) {
                        StringBuilder sb = new StringBuilder();
                        boolean first = true;
                        if (si.getResourceOperationResultList() != null) {
                            for (ResourceOperationResult ror : si.getResourceOperationResultList()) {
                                if (!first) {
                                    sb.append(", ");
                                } else {
                                    first = false;
                                }
                                sb.append(createStringResource("ChangeType." + ror.getChangeType()).getString());
                                sb.append(":");
                                sb.append(createStringResource(ror.getResultStatus()).getString());
                            }
                        }
                        if (si.getResourceObjectName() != null) {
                            if (!first) {
                                sb.append(" -> ");
                            }
                            sb.append(si.getResourceObjectName());
                        }
                        return sb.toString();
                    } else {
                        return null;
                    }
                }
            }));
        }

        private Label createImageLabel(String id, IModel<String> cssClass, IModel<String> title) {
            Label label = new Label(id);
            label.add(AttributeModifier.replace("class", cssClass));
            // does not work, currently
            label.add(AttributeModifier.replace("title", title));
            return label;
        }
    };
    contentsPanel.add(statusItemsListView);
    statisticsPanel = new StatisticsPanel(ID_STATISTICS, new StatisticsDtoModel());
    contentsPanel.add(statisticsPanel);
    ListView logItemsListView = new ListView(ID_LOG_ITEMS, new AbstractReadOnlyModel<List>() {

        @Override
        public List getObject() {
            ProgressDto progressDto = ProgressPanel.this.getModelObject();
            return progressDto.getLogItems();
        }
    }) {

        protected void populateItem(ListItem item) {
            item.add(new Label(ID_LOG_ITEM, item.getModel()));
        }
    };
    contentsPanel.add(logItemsListView);
    Label executionTime = new Label(ID_EXECUTION_TIME, new AbstractReadOnlyModel<String>() {

        @Override
        public String getObject() {
            if (operationDurationTime > 0) {
                return createStringResource("ProgressPanel.ExecutionTimeWhenFinished", operationDurationTime).getString();
            } else if (operationStartTime > 0) {
                return createStringResource("ProgressPanel.ExecutionTimeWhenRunning", (System.currentTimeMillis() - operationStartTime) / 1000).getString();
            } else {
                return null;
            }
        }
    });
    contentsPanel.add(executionTime);
    initButtons(progressForm, page);
}
Also used : AbstractReadOnlyModel(org.apache.wicket.model.AbstractReadOnlyModel) IModel(org.apache.wicket.model.IModel) Label(org.apache.wicket.markup.html.basic.Label) OperationResultStatusType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultStatusType) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) ListView(org.apache.wicket.markup.html.list.ListView) List(java.util.List) ResourceShadowDiscriminator(com.evolveum.midpoint.schema.ResourceShadowDiscriminator) ListItem(org.apache.wicket.markup.html.list.ListItem) ResourceOperationResult(com.evolveum.midpoint.web.component.progress.ProgressReportActivityDto.ResourceOperationResult)

Example 3 with ResourceOperationResult

use of com.evolveum.midpoint.web.component.progress.ProgressReportActivityDto.ResourceOperationResult in project midpoint by Evolveum.

the class ProgressPanel method populateStatusItem.

private void populateStatusItem(ListItem<ProgressReportActivityDto> item) {
    item.add(new Label(ID_ACTIVITY_DESCRIPTION, (IModel<String>) () -> {
        ProgressReportActivityDto si = item.getModelObject();
        if (si.getActivityType() == RESOURCE_OBJECT_OPERATION && si.getResourceShadowDiscriminator() != null) {
            ResourceShadowDiscriminator rsd = si.getResourceShadowDiscriminator();
            return createStringResource("ProgressPanel.populateStatusItem.resourceObjectActivity", createStringResource(rsd.getKind()).getString(), rsd.getIntent(), si.getResourceName()).getString();
        } else {
            return createStringResource(si.getActivityType()).getString();
        }
    }));
    item.add(createImageLabel((IModel<String>) () -> {
        OperationResultStatusType statusType = item.getModelObject().getStatus();
        if (statusType == null) {
            return null;
        } else {
            return OperationResultStatusPresentationProperties.parseOperationalResultStatus(statusType).getIcon() + " fa-lg";
        }
    }, (IModel<String>) () -> {
        // TODO why this does not work???
        OperationResultStatusType statusType = item.getModelObject().getStatus();
        if (statusType == null) {
            return null;
        } else {
            return getPageBase().createStringResource(OperationResultStatusPresentationProperties.parseOperationalResultStatus(statusType).getStatusLabelKey()).getString();
        }
    }));
    item.add(new Label(ID_ACTIVITY_COMMENT, (IModel<String>) () -> {
        ProgressReportActivityDto si = item.getModelObject();
        if (si.getResourceName() != null || si.getResourceOperationResultList() != null) {
            StringBuilder sb = new StringBuilder();
            boolean first = true;
            if (si.getResourceOperationResultList() != null) {
                for (ResourceOperationResult ror : si.getResourceOperationResultList()) {
                    if (!first) {
                        sb.append(", ");
                    } else {
                        first = false;
                    }
                    sb.append(createStringResource("ChangeType." + ror.getChangeType()).getString());
                    sb.append(":");
                    sb.append(createStringResource(ror.getResultStatus()).getString());
                }
            }
            if (si.getResourceObjectName() != null) {
                if (!first) {
                    sb.append(" -> ");
                }
                sb.append(si.getResourceObjectName());
            }
            return sb.toString();
        } else {
            return null;
        }
    }));
}
Also used : IModel(org.apache.wicket.model.IModel) Label(org.apache.wicket.markup.html.basic.Label) ResourceShadowDiscriminator(com.evolveum.midpoint.schema.ResourceShadowDiscriminator) ResourceOperationResult(com.evolveum.midpoint.web.component.progress.ProgressReportActivityDto.ResourceOperationResult)

Example 4 with ResourceOperationResult

use of com.evolveum.midpoint.web.component.progress.ProgressReportActivityDto.ResourceOperationResult in project midpoint by Evolveum.

the class ProgressPanel method populateStatusItem.

private void populateStatusItem(ListItem<ProgressReportActivityDto> item) {
    item.add(new Label(ID_ACTIVITY_DESCRIPTION, new IModel<String>() {

        @Override
        public String getObject() {
            ProgressReportActivityDto si = item.getModelObject();
            if (si.getActivityType() == RESOURCE_OBJECT_OPERATION && si.getResourceShadowDiscriminator() != null) {
                ResourceShadowDiscriminator rsd = si.getResourceShadowDiscriminator();
                return createStringResource("ProgressPanel.populateStatusItem.resourceObjectActivity", createStringResource(rsd.getKind()).getString(), rsd.getIntent(), si.getResourceName()).getString();
            } else {
                return createStringResource(si.getActivityType()).getString();
            }
        }
    }));
    item.add(createImageLabel(ID_ACTIVITY_STATE, new IModel<String>() {

        @Override
        public String getObject() {
            OperationResultStatusType statusType = item.getModelObject().getStatus();
            if (statusType == null) {
                return null;
            } else {
                return OperationResultStatusPresentationProperties.parseOperationalResultStatus(statusType).getIcon() + " fa-lg";
            }
        }
    }, new IModel<String>() {

        @Override
        public String getObject() {
            // TODO why this does not work???
            OperationResultStatusType statusType = item.getModelObject().getStatus();
            if (statusType == null) {
                return null;
            } else {
                return getPageBase().createStringResource(OperationResultStatusPresentationProperties.parseOperationalResultStatus(statusType).getStatusLabelKey()).getString();
            }
        }
    }));
    item.add(new Label(ID_ACTIVITY_COMMENT, new IModel<String>() {

        @Override
        public String getObject() {
            ProgressReportActivityDto si = item.getModelObject();
            if (si.getResourceName() != null || si.getResourceOperationResultList() != null) {
                StringBuilder sb = new StringBuilder();
                boolean first = true;
                if (si.getResourceOperationResultList() != null) {
                    for (ResourceOperationResult ror : si.getResourceOperationResultList()) {
                        if (!first) {
                            sb.append(", ");
                        } else {
                            first = false;
                        }
                        sb.append(createStringResource("ChangeType." + ror.getChangeType()).getString());
                        sb.append(":");
                        sb.append(createStringResource(ror.getResultStatus()).getString());
                    }
                }
                if (si.getResourceObjectName() != null) {
                    if (!first) {
                        sb.append(" -> ");
                    }
                    sb.append(si.getResourceObjectName());
                }
                return sb.toString();
            } else {
                return null;
            }
        }
    }));
}
Also used : IModel(org.apache.wicket.model.IModel) Label(org.apache.wicket.markup.html.basic.Label) ResourceShadowDiscriminator(com.evolveum.midpoint.schema.ResourceShadowDiscriminator) ResourceOperationResult(com.evolveum.midpoint.web.component.progress.ProgressReportActivityDto.ResourceOperationResult)

Aggregations

ResourceOperationResult (com.evolveum.midpoint.web.component.progress.ProgressReportActivityDto.ResourceOperationResult)4 ResourceShadowDiscriminator (com.evolveum.midpoint.schema.ResourceShadowDiscriminator)3 Label (org.apache.wicket.markup.html.basic.Label)3 IModel (org.apache.wicket.model.IModel)3 ModelProjectionContext (com.evolveum.midpoint.model.api.context.ModelProjectionContext)1 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)1 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)1 ObjectDeltaOperation (com.evolveum.midpoint.schema.ObjectDeltaOperation)1 ResourceAttribute (com.evolveum.midpoint.schema.processor.ResourceAttribute)1 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)1 OperationResultStatus (com.evolveum.midpoint.schema.result.OperationResultStatus)1 OperationResultStatusType (com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultStatusType)1 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)1 ListItem (org.apache.wicket.markup.html.list.ListItem)1 ListView (org.apache.wicket.markup.html.list.ListView)1 AbstractReadOnlyModel (org.apache.wicket.model.AbstractReadOnlyModel)1