Search in sources :

Example 46 with PrismContext

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

the class FileTransformer method execute.

public void execute() {
    ApplicationContext context = new ClassPathXmlApplicationContext(CONTEXTS);
    PrismContext prismContext = context.getBean(PrismContext.class);
    File inFile = new File(input);
    File[] files = null;
    if (inFile.isDirectory()) {
        files = inFile.listFiles();
    }
    String output = getOutput(inFile);
    String outLang = getOutputLanguage(outputFormat);
    int errors = 0;
    int processed = 0;
    List<String> failedToParse = new ArrayList<String>();
    if (files != null) {
        processed = files.length;
        for (int i = 0; i < files.length; i++) {
            try {
                transform(prismContext, files[i], output, outLang);
            } catch (SchemaException | IOException e) {
                System.out.println("failed to transform: " + e.getMessage() + ". Stack: " + e);
                errors++;
                failedToParse.add(files[i].getName());
            }
        }
    } else {
        processed = 1;
        try {
            transform(prismContext, inFile, output, outLang);
        } catch (SchemaException | IOException e) {
            errors++;
            failedToParse.add(inFile.getName());
        }
    }
    System.out.println("Processed " + processed + " files, got " + errors + " errors. Files that was not successfully processed " + failedToParse);
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) PrismContext(com.evolveum.midpoint.prism.PrismContext) ArrayList(java.util.ArrayList) IOException(java.io.IOException) File(java.io.File)

Example 47 with PrismContext

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

the class ImportObjects method execute.

public boolean execute() {
    System.out.println("Starting objects import.");
    File objects = new File(filePath);
    if (!objects.exists() || !objects.canRead()) {
        System.out.println("XML file with objects '" + objects.getAbsolutePath() + "' doesn't exist or can't be read.");
        return false;
    }
    InputStream input = null;
    ClassPathXmlApplicationContext context = null;
    try {
        System.out.println("Loading spring contexts.");
        context = new ClassPathXmlApplicationContext(CONTEXTS);
        InputStreamReader reader = new InputStreamReader(new FileInputStream(objects), "utf-8");
        input = new ReaderInputStream(reader, reader.getEncoding());
        final RepositoryService repository = context.getBean("repositoryService", RepositoryService.class);
        PrismContext prismContext = context.getBean(PrismContext.class);
        EventHandler handler = new EventHandler() {

            @Override
            public EventResult preMarshall(Element objectElement, Node postValidationTree, OperationResult objectResult) {
                return EventResult.cont();
            }

            @Override
            public <T extends Objectable> EventResult postMarshall(PrismObject<T> object, Element objectElement, OperationResult objectResult) {
                try {
                    String displayName = getDisplayName(object);
                    System.out.println("Importing object " + displayName);
                    repository.addObject((PrismObject<ObjectType>) object, null, objectResult);
                } catch (Exception ex) {
                    objectResult.recordFatalError("Unexpected problem: " + ex.getMessage(), ex);
                    System.out.println("Exception occurred during import, reason: " + ex.getMessage());
                    ex.printStackTrace();
                }
                objectResult.recordSuccessIfUnknown();
                if (objectResult.isAcceptable()) {
                    // Continue import
                    return EventResult.cont();
                } else {
                    return EventResult.skipObject(objectResult.getMessage());
                }
            }

            @Override
            public void handleGlobalError(OperationResult currentResult) {
            }
        };
        Validator validator = new Validator(prismContext, handler);
        validator.setVerbose(true);
        validator.setValidateSchema(validateSchema);
        OperationResult result = new OperationResult("Import objeccts");
        validator.validate(input, result, OperationConstants.IMPORT_OBJECT);
        result.recomputeStatus();
        if (!result.isSuccess()) {
            System.out.println("Operation result was not success, dumping result.\n" + result.debugDump(3));
        }
    } catch (Exception ex) {
        System.out.println("Exception occurred during import task, reason: " + ex.getMessage());
        ex.printStackTrace();
    } finally {
        IOUtils.closeQuietly(input);
        destroyContext(context);
    }
    System.out.println("Objects import finished.");
    return true;
}
Also used : InputStreamReader(java.io.InputStreamReader) ReaderInputStream(org.apache.commons.io.input.ReaderInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) PrismContext(com.evolveum.midpoint.prism.PrismContext) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) EventHandler(com.evolveum.midpoint.common.validator.EventHandler) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) FileInputStream(java.io.FileInputStream) PrismObject(com.evolveum.midpoint.prism.PrismObject) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) ReaderInputStream(org.apache.commons.io.input.ReaderInputStream) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Objectable(com.evolveum.midpoint.prism.Objectable) File(java.io.File) Validator(com.evolveum.midpoint.common.validator.Validator) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService)

Example 48 with PrismContext

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

the class WebModelServiceUtils method resolveReferenceRaw.

public static <T extends ObjectType> PrismObject<T> resolveReferenceRaw(ObjectReferenceType reference, PageBase page, Task task, OperationResult result) {
    if (reference == null) {
        return null;
    }
    if (reference.asReferenceValue().getObject() != null) {
        return reference.asReferenceValue().getObject();
    }
    PrismContext prismContext = page.getPrismContext();
    if (reference.getType() == null) {
        LOGGER.error("No type in {}", reference);
        return null;
    }
    PrismObjectDefinition<T> definition = prismContext.getSchemaRegistry().findObjectDefinitionByType(reference.getType());
    if (definition == null) {
        LOGGER.error("No definition for {} was found", reference.getType());
        return null;
    }
    return loadObject(definition.getCompileTimeClass(), reference.getOid(), SelectorOptions.createCollection(GetOperationOptions.createRaw()), page, task, result);
}
Also used : PrismContext(com.evolveum.midpoint.prism.PrismContext)

Example 49 with PrismContext

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

the class SearchPanel method updateAdvancedArea.

private void updateAdvancedArea(Component area, AjaxRequestTarget target) {
    Search search = getModelObject();
    PrismContext ctx = getPageBase().getPrismContext();
    search.isAdvancedQueryValid(ctx);
    target.prependJavaScript("storeTextAreaSize('" + area.getMarkupId() + "');");
    target.appendJavaScript("restoreTextAreaSize('" + area.getMarkupId() + "');");
    target.add(get(createComponentPath(ID_FORM, ID_ADVANCED_GROUP)), get(createComponentPath(ID_FORM, ID_SEARCH_CONTAINER)));
}
Also used : PrismContext(com.evolveum.midpoint.prism.PrismContext)

Example 50 with PrismContext

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

the class AbstractRoleMemberPanel method initObjectForAdd.

// TODO: merge this with TreeTablePanel.initObjectForAdd, also see MID-3233
private void initObjectForAdd(ObjectReferenceType parentOrgRef, QName type, QName relation, AjaxRequestTarget target) throws SchemaException {
    getPageBase().hideMainPopup(target);
    PrismContext prismContext = getPageBase().getPrismContext();
    PrismObjectDefinition def = prismContext.getSchemaRegistry().findObjectDefinitionByType(type);
    PrismObject obj = def.instantiate();
    if (parentOrgRef == null) {
        parentOrgRef = createReference(relation);
    }
    ObjectType objType = (ObjectType) obj.asObjectable();
    if (FocusType.class.isAssignableFrom(obj.getCompileTimeClass())) {
        AssignmentType assignment = new AssignmentType();
        assignment.setTargetRef(parentOrgRef);
        ((FocusType) objType).getAssignment().add(assignment);
    }
    // TODO: fix MID-3234
    if (parentOrgRef.getType() != null && OrgType.COMPLEX_TYPE.equals(parentOrgRef.getType())) {
        objType.getParentOrgRef().add(parentOrgRef.clone());
    }
    WebComponentUtil.dispatchToObjectDetailsPage(obj, this);
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) PrismContext(com.evolveum.midpoint.prism.PrismContext) PrismObjectDefinition(com.evolveum.midpoint.prism.PrismObjectDefinition) AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)

Aggregations

PrismContext (com.evolveum.midpoint.prism.PrismContext)104 Test (org.testng.annotations.Test)59 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)15 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)15 QName (javax.xml.namespace.QName)15 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)13 Task (com.evolveum.midpoint.task.api.Task)11 SchemaRegistry (com.evolveum.midpoint.prism.schema.SchemaRegistry)10 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)10 PrismObject (com.evolveum.midpoint.prism.PrismObject)9 SystemException (com.evolveum.midpoint.util.exception.SystemException)9 File (java.io.File)8 PrismPropertyDefinition (com.evolveum.midpoint.prism.PrismPropertyDefinition)7 ArrayList (java.util.ArrayList)7 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)6 AssignmentType (com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)6 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)6 Protector (com.evolveum.midpoint.prism.crypto.Protector)5 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)5 MidPointApplication (com.evolveum.midpoint.web.security.MidPointApplication)5