Search in sources :

Example 6 with PrismContainer

use of com.evolveum.midpoint.prism.PrismContainer in project midpoint by Evolveum.

the class JaxbTestUtil method unmarshalSingleValueContainer.

// element name must correspond to the name that points to the container definition
private <T extends Containerable> PrismContainer<T> unmarshalSingleValueContainer(JAXBElement<T> element) throws JAXBException, SchemaException {
    if (element == null) {
        return null;
    }
    T value = element.getValue();
    // this is a bit tricky - we have to create a container and put the newly obtained value into it
    PrismContainerValue<T> containerValue = value.asPrismContainerValue();
    containerValue.revive(prismContext);
    PrismContainerDefinition<T> definition = prismContext.getSchemaRegistry().findContainerDefinitionByElementName(element.getName());
    if (definition == null) {
        throw new IllegalStateException("There's no container definition for element name " + element.getName());
    }
    containerValue.applyDefinition(definition, false);
    PrismContainer container = definition.instantiate();
    container.add(containerValue);
    return container;
}
Also used : PrismContainer(com.evolveum.midpoint.prism.PrismContainer)

Example 7 with PrismContainer

use of com.evolveum.midpoint.prism.PrismContainer in project midpoint by Evolveum.

the class InOidFilter method match.

@Override
public boolean match(PrismContainerValue value, MatchingRuleRegistry matchingRuleRegistry) throws SchemaException {
    if (value == null) {
        // just for sure
        return false;
    }
    // are we a prism object?
    if (value.getParent() instanceof PrismObject) {
        if (considerOwner) {
            return false;
        }
        String oid = ((PrismObject) (value.getParent())).getOid();
        return StringUtils.isNotBlank(oid) && oids != null && oids.contains(oid);
    }
    final PrismContainerValue pcvToConsider;
    if (considerOwner) {
        if (!(value.getParent() instanceof PrismContainer)) {
            return false;
        }
        PrismContainer container = (PrismContainer) value.getParent();
        if (!(container.getParent() instanceof PrismContainerValue)) {
            return false;
        }
        pcvToConsider = (PrismContainerValue) container.getParent();
    } else {
        pcvToConsider = value;
    }
    return pcvToConsider.getId() != null && oids.contains(pcvToConsider.getId());
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) PrismContainer(com.evolveum.midpoint.prism.PrismContainer)

Example 8 with PrismContainer

use of com.evolveum.midpoint.prism.PrismContainer in project midpoint by Evolveum.

the class PrismIdentifierGenerator method getContainersToGenerateIdsFor.

// TODO: This seems to be wrong. We want to generate IDs for all multivalue containers
// This is maybe some historic code. It has to be cleaned up.
// MID-3869
private List<PrismContainer<?>> getContainersToGenerateIdsFor(PrismObject parent) {
    List<PrismContainer<?>> containers = new ArrayList<>();
    if (ObjectType.class.isAssignableFrom(parent.getCompileTimeClass())) {
        CollectionUtils.addIgnoreNull(containers, parent.findContainer(ObjectType.F_TRIGGER));
        CollectionUtils.addIgnoreNull(containers, parent.findContainer(ObjectType.F_OPERATION_EXECUTION));
    }
    if (LookupTableType.class.isAssignableFrom(parent.getCompileTimeClass())) {
        CollectionUtils.addIgnoreNull(containers, parent.findContainer(LookupTableType.F_ROW));
    }
    if (AccessCertificationCampaignType.class.isAssignableFrom(parent.getCompileTimeClass())) {
        PrismContainer<?> caseContainer = parent.findContainer(AccessCertificationCampaignType.F_CASE);
        CollectionUtils.addIgnoreNull(containers, caseContainer);
        if (caseContainer != null) {
            for (PrismContainerValue<?> casePcv : caseContainer.getValues()) {
                CollectionUtils.addIgnoreNull(containers, casePcv.findContainer(AccessCertificationCaseType.F_WORK_ITEM));
            }
        }
        CollectionUtils.addIgnoreNull(containers, parent.findContainer(AccessCertificationCampaignType.F_STAGE));
    }
    if (FocusType.class.isAssignableFrom(parent.getCompileTimeClass())) {
        CollectionUtils.addIgnoreNull(containers, parent.findContainer(FocusType.F_ASSIGNMENT));
    }
    if (AbstractRoleType.class.isAssignableFrom(parent.getCompileTimeClass())) {
        CollectionUtils.addIgnoreNull(containers, parent.findContainer(AbstractRoleType.F_INDUCEMENT));
        CollectionUtils.addIgnoreNull(containers, parent.findContainer(AbstractRoleType.F_EXCLUSION));
        CollectionUtils.addIgnoreNull(containers, parent.findContainer(AbstractRoleType.F_AUTHORIZATION));
        PrismContainer policyConstraints = parent.findContainer(AbstractRoleType.F_POLICY_CONSTRAINTS);
        if (policyConstraints != null) {
            CollectionUtils.addIgnoreNull(containers, policyConstraints.findContainer(PolicyConstraintsType.F_MAX_ASSIGNEES));
            CollectionUtils.addIgnoreNull(containers, policyConstraints.findContainer(PolicyConstraintsType.F_MIN_ASSIGNEES));
        }
    }
    if (ShadowType.class.isAssignableFrom(parent.getCompileTimeClass())) {
        CollectionUtils.addIgnoreNull(containers, parent.findContainer(ShadowType.F_PENDING_OPERATION));
    }
    if (ResourceType.class.isAssignableFrom(parent.getCompileTimeClass())) {
        CollectionUtils.addIgnoreNull(containers, parent.findContainer(ResourceType.F_ADDITIONAL_CONNECTOR));
    }
    if (UserType.class.isAssignableFrom(parent.getCompileTimeClass())) {
        CollectionUtils.addIgnoreNull(containers, parent.findContainer(new ItemPath(UserType.F_CREDENTIALS, CredentialsType.F_SECURITY_QUESTIONS, SecurityQuestionsCredentialsType.F_QUESTION_ANSWER)));
    }
    return containers;
}
Also used : PrismContainer(com.evolveum.midpoint.prism.PrismContainer) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 9 with PrismContainer

use of com.evolveum.midpoint.prism.PrismContainer in project midpoint by Evolveum.

the class CertificationTest method getOwningCampaignChecked.

private PrismObject<AccessCertificationCampaignType> getOwningCampaignChecked(AccessCertificationCaseType aCase) {
    PrismContainer caseContainer = (PrismContainer) aCase.asPrismContainerValue().getParent();
    assertNotNull("campaign is not fetched (case parent is null)", caseContainer);
    PrismContainerValue campaignValue = (PrismContainerValue) caseContainer.getParent();
    assertNotNull("campaign is not fetched (case container parent is null)", caseContainer);
    PrismObject<AccessCertificationCampaignType> campaign = (PrismObject) campaignValue.getParent();
    assertNotNull("campaign is not fetched (campaign PCV parent is null)", campaign);
    return campaign;
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) PrismContainer(com.evolveum.midpoint.prism.PrismContainer)

Example 10 with PrismContainer

use of com.evolveum.midpoint.prism.PrismContainer in project midpoint by Evolveum.

the class ReportCreateTaskHandler method run.

@Override
public TaskRunResult run(Task task) {
    // TODO Auto-generated method stub
    OperationResult parentResult = task.getResult();
    OperationResult result = parentResult.createSubresult(ReportCreateTaskHandler.class.getSimpleName() + ".run");
    TaskRunResult runResult = new TaskRunResult();
    runResult.setOperationResult(result);
    recordProgress(task, 0, result);
    long progress = task.getProgress();
    JRSwapFile swapFile = null;
    // http://community.jaspersoft.com/wiki/virtualizers-jasperreports
    JRAbstractLRUVirtualizer virtualizer = null;
    try {
        ReportType parentReport = objectResolver.resolve(task.getObjectRef(), ReportType.class, null, "resolving report", task, result);
        Map<String, Object> parameters = completeReport(parentReport, task, result);
        JasperReport jasperReport = ReportTypeUtil.loadJasperReport(parentReport);
        LOGGER.trace("compile jasper design, create jasper report : {}", jasperReport);
        PrismContainer<ReportParameterType> reportParams = (PrismContainer) task.getExtensionItem(ReportConstants.REPORT_PARAMS_PROPERTY_NAME);
        if (reportParams != null) {
            PrismContainerValue<ReportParameterType> reportParamsValues = reportParams.getValue();
            List<Item<?, ?>> items = reportParamsValues.getItems();
            if (items != null) {
                for (Item item : items) {
                    PrismProperty pp = (PrismProperty) item;
                    String paramName = ItemPath.getName(pp.getPath().lastNamed()).getLocalPart();
                    Object value = null;
                    if (isSingleValue(paramName, jasperReport.getParameters())) {
                        value = pp.getRealValues().iterator().next();
                    } else {
                        value = pp.getRealValues();
                    }
                    parameters.put(paramName, value);
                }
            }
        }
        String virtualizerS = parentReport.getVirtualizer();
        Integer virtualizerKickOn = parentReport.getVirtualizerKickOn();
        Integer maxPages = parentReport.getMaxPages();
        Integer timeout = parentReport.getTimeout();
        if (maxPages != null && maxPages > 0) {
            LOGGER.trace("Setting hardlimit on number of report pages: " + maxPages);
            jasperReport.setProperty(MaxPagesGovernor.PROPERTY_MAX_PAGES_ENABLED, Boolean.TRUE.toString());
            jasperReport.setProperty(MaxPagesGovernor.PROPERTY_MAX_PAGES, String.valueOf(maxPages));
        }
        if (timeout != null && timeout > 0) {
            LOGGER.trace("Setting timeout on report execution [ms]: " + timeout);
            jasperReport.setProperty(TimeoutGovernor.PROPERTY_TIMEOUT_ENABLED, Boolean.TRUE.toString());
            jasperReport.setProperty(TimeoutGovernor.PROPERTY_TIMEOUT, String.valueOf(timeout));
        }
        if (virtualizerS != null && virtualizerKickOn != null && virtualizerKickOn > 0) {
            String virtualizerClassName = JASPER_VIRTUALIZER_PKG + "." + virtualizerS;
            try {
                Class<?> clazz = Class.forName(virtualizerClassName);
                if (clazz.equals(JRSwapFileVirtualizer.class)) {
                    swapFile = new JRSwapFile(TEMP_DIR, 4096, 200);
                    virtualizer = new JRSwapFileVirtualizer(virtualizerKickOn, swapFile);
                } else if (clazz.equals(JRGzipVirtualizer.class)) {
                    virtualizer = new JRGzipVirtualizer(virtualizerKickOn);
                } else if (clazz.equals(JRFileVirtualizer.class)) {
                    virtualizer = new JRFileVirtualizer(virtualizerKickOn, TEMP_DIR);
                } else {
                    throw new ClassNotFoundException("No support for virtualizer class: " + clazz.getName());
                }
                LOGGER.trace("Setting explicit Jasper virtualizer: " + virtualizer);
                virtualizer.setReadOnly(false);
                parameters.put(JRParameter.REPORT_VIRTUALIZER, virtualizer);
            } catch (ClassNotFoundException e) {
                LOGGER.error("Cannot find Jasper virtualizer: " + e.getMessage());
            }
        }
        LOGGER.trace("All Report parameters : {}", parameters);
        JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters);
        LOGGER.trace("fill report : {}", jasperPrint);
        String reportFilePath = generateReport(parentReport, jasperPrint);
        LOGGER.trace("generate report : {}", reportFilePath);
        saveReportOutputType(reportFilePath, parentReport, task, result);
        LOGGER.trace("create report output type : {}", reportFilePath);
        result.computeStatus();
    } catch (Exception ex) {
        LOGGER.error("CreateReport: {}", ex.getMessage(), ex);
        result.recordFatalError(ex.getMessage(), ex);
        runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
        runResult.setProgress(progress);
        return runResult;
    } finally {
        if (swapFile != null) {
            swapFile.dispose();
        }
        if (virtualizer != null) {
            virtualizer.cleanup();
        }
    }
    // This "run" is finished. But the task goes on ...
    runResult.setRunResultStatus(TaskRunResultStatus.FINISHED);
    runResult.setProgress(progress);
    LOGGER.trace("CreateReportTaskHandler.run stopping");
    return runResult;
}
Also used : OperationResult(com.evolveum.midpoint.schema.result.OperationResult) JasperReport(net.sf.jasperreports.engine.JasperReport) Item(com.evolveum.midpoint.prism.Item) TaskRunResult(com.evolveum.midpoint.task.api.TaskRunResult) PrismContainer(com.evolveum.midpoint.prism.PrismContainer) JRFileVirtualizer(net.sf.jasperreports.engine.fill.JRFileVirtualizer) ReportType(com.evolveum.midpoint.xml.ns._public.common.common_3.ReportType) ReportParameterType(com.evolveum.midpoint.xml.ns._public.common.common_3.ReportParameterType) JRSwapFileVirtualizer(net.sf.jasperreports.engine.fill.JRSwapFileVirtualizer) JasperPrint(net.sf.jasperreports.engine.JasperPrint) JRSwapFile(net.sf.jasperreports.engine.util.JRSwapFile) JRAbstractLRUVirtualizer(net.sf.jasperreports.engine.fill.JRAbstractLRUVirtualizer) JRGzipVirtualizer(net.sf.jasperreports.engine.fill.JRGzipVirtualizer) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) SystemException(com.evolveum.midpoint.util.exception.SystemException) JRException(net.sf.jasperreports.engine.JRException) PrismProperty(com.evolveum.midpoint.prism.PrismProperty) PrismObject(com.evolveum.midpoint.prism.PrismObject)

Aggregations

PrismContainer (com.evolveum.midpoint.prism.PrismContainer)28 PrismObject (com.evolveum.midpoint.prism.PrismObject)12 PrismContainerValue (com.evolveum.midpoint.prism.PrismContainerValue)9 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)6 PrismProperty (com.evolveum.midpoint.prism.PrismProperty)5 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)5 RunReportPopupPanel (com.evolveum.midpoint.web.page.admin.reports.component.RunReportPopupPanel)5 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)5 Item (com.evolveum.midpoint.prism.Item)4 PrismReference (com.evolveum.midpoint.prism.PrismReference)4 PrismReferenceValue (com.evolveum.midpoint.prism.PrismReferenceValue)4 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)4 ArrayList (java.util.ArrayList)4 Task (com.evolveum.midpoint.task.api.Task)3 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)3 Containerable (com.evolveum.midpoint.prism.Containerable)2 PrismContext (com.evolveum.midpoint.prism.PrismContext)2 PrismPropertyDefinition (com.evolveum.midpoint.prism.PrismPropertyDefinition)2 PrismValue (com.evolveum.midpoint.prism.PrismValue)2 Referencable (com.evolveum.midpoint.prism.Referencable)2