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);
}
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;
}
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);
}
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)));
}
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);
}
Aggregations