use of com.evolveum.midpoint.prism.PrismObject in project midpoint by Evolveum.
the class RoleMemberPanel method createTenantList.
private List<OrgType> createTenantList() {
ObjectQuery query = QueryBuilder.queryFor(OrgType.class, getPrismContext()).item(OrgType.F_TENANT).eq(true).build();
List<PrismObject<OrgType>> orgs = WebModelServiceUtils.searchObjects(OrgType.class, query, new OperationResult("Tenant search"), getPageBase());
List<OrgType> orgTypes = new ArrayList<>();
for (PrismObject<OrgType> org : orgs) {
orgTypes.add(org.asObjectable());
}
return orgTypes;
}
use of com.evolveum.midpoint.prism.PrismObject in project midpoint by Evolveum.
the class NodeDtoProvider method internalIterator.
@Override
public Iterator<? extends NodeDto> internalIterator(long first, long count) {
Collection<String> selectedOids = getSelectedOids();
getAvailableData().clear();
OperationResult result = new OperationResult(OPERATION_LIST_NODES);
Task task = getTaskManager().createTaskInstance(OPERATION_LIST_NODES);
try {
ObjectPaging paging = createPaging(first, count);
ObjectQuery query = getQuery();
if (query == null) {
query = new ObjectQuery();
}
query.setPaging(paging);
List<PrismObject<NodeType>> nodes = getModel().searchObjects(NodeType.class, query, null, task, result);
for (PrismObject<NodeType> node : nodes) {
getAvailableData().add(createNodeDto(node));
}
result.recordSuccess();
} catch (Exception ex) {
LoggingUtils.logUnexpectedException(LOGGER, "Unhandled exception when listing nodes", ex);
result.recordFatalError("Couldn't list nodes.", ex);
}
setSelectedOids(selectedOids);
return getAvailableData().iterator();
}
use of com.evolveum.midpoint.prism.PrismObject in project midpoint by Evolveum.
the class AssignmentEditorDto method getReference.
private PrismObject getReference(ObjectReferenceType ref, OperationResult result, PageBase pageBase) {
OperationResult subResult = result.createSubresult(OPERATION_LOAD_RESOURCE);
subResult.addParam("targetRef", ref.getOid());
PrismObject target = null;
try {
Task task = pageBase.createSimpleTask(OPERATION_LOAD_RESOURCE);
Class type = ObjectType.class;
if (ref.getType() != null) {
type = pageBase.getPrismContext().getSchemaRegistry().determineCompileTimeClass(ref.getType());
}
target = pageBase.getModelService().getObject(type, ref.getOid(), null, task, subResult);
subResult.recordSuccess();
} catch (Exception ex) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't get account construction resource ref", ex);
subResult.recordFatalError("Couldn't get account construction resource ref.", ex);
}
return target;
}
use of com.evolveum.midpoint.prism.PrismObject in project midpoint by Evolveum.
the class InitialDataImport method init.
public void init() throws SchemaException {
LOGGER.info("Starting initial object import (if necessary).");
OperationResult mainResult = new OperationResult(OPERATION_INITIAL_OBJECTS_IMPORT);
Task task = taskManager.createTaskInstance(OPERATION_INITIAL_OBJECTS_IMPORT);
task.setChannel(SchemaConstants.CHANNEL_GUI_INIT_URI);
int count = 0;
int errors = 0;
File[] files = getInitialImportObjects();
LOGGER.debug("Files to be imported: {}.", Arrays.toString(files));
// We need to provide a fake Spring security context here.
// We have to fake it because we do not have anything in the repository yet. And to get
// something to the repository we need a context. Chicken and egg. So we fake the egg.
SecurityContext securityContext = SecurityContextHolder.getContext();
UserType userAdministrator = new UserType();
prismContext.adopt(userAdministrator);
userAdministrator.setName(new PolyStringType(new PolyString("initAdmin", "initAdmin")));
MidPointPrincipal principal = new MidPointPrincipal(userAdministrator);
AuthorizationType superAutzType = new AuthorizationType();
prismContext.adopt(superAutzType, RoleType.class, new ItemPath(RoleType.F_AUTHORIZATION));
superAutzType.getAction().add(AuthorizationConstants.AUTZ_ALL_URL);
Authorization superAutz = new Authorization(superAutzType);
Collection<Authorization> authorities = principal.getAuthorities();
authorities.add(superAutz);
Authentication authentication = new PreAuthenticatedAuthenticationToken(principal, null);
securityContext.setAuthentication(authentication);
for (File file : files) {
try {
LOGGER.debug("Considering initial import of file {}.", file.getName());
PrismObject object = prismContext.parseObject(file);
if (ReportType.class.equals(object.getCompileTimeClass())) {
ReportTypeUtil.applyDefinition(object, prismContext);
}
Boolean importObject = importObject(object, file, task, mainResult);
if (importObject == null) {
continue;
}
if (importObject) {
count++;
} else {
errors++;
}
} catch (Exception ex) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't import file {}", ex, file.getName());
mainResult.recordFatalError("Couldn't import file '" + file.getName() + "'", ex);
}
}
securityContext.setAuthentication(null);
mainResult.recomputeStatus("Couldn't import objects.");
LOGGER.info("Initial object import finished ({} objects imported, {} errors)", count, errors);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Initialization status:\n" + mainResult.debugDump());
}
}
use of com.evolveum.midpoint.prism.PrismObject in project midpoint by Evolveum.
the class PageAccounts method exportPerformed.
private void exportPerformed(AjaxRequestTarget target) {
if (resourceModel.getObject() == null) {
warn(getString("pageAccounts.message.resourceNotSelected"));
refreshEverything(target);
return;
}
String fileName = "accounts-" + WebComponentUtil.formatDate("yyyy-MM-dd-HH-mm-ss", new Date()) + ".xml";
OperationResult result = new OperationResult(OPERATION_EXPORT);
Writer writer = null;
try {
Task task = createSimpleTask(OPERATION_EXPORT);
writer = createWriter(fileName);
writeHeader(writer);
final Writer handlerWriter = writer;
ResultHandler handler = new AbstractSummarizingResultHandler() {
@Override
protected boolean handleObject(PrismObject object, OperationResult parentResult) {
OperationResult result = parentResult.createMinorSubresult(OPERATION_EXPORT_ACCOUNT);
try {
String xml = getPrismContext().serializeObjectToString(object, PrismContext.LANG_XML);
handlerWriter.write(xml);
result.computeStatus();
} catch (Exception ex) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't serialize account", ex);
result.recordFatalError("Couldn't serialize account.", ex);
return false;
}
return true;
}
};
try {
ObjectQuery query = ObjectQuery.createObjectQuery(createResourceAndQueryFilter());
getModelService().searchObjectsIterative(ShadowType.class, query, handler, SelectorOptions.createCollection(GetOperationOptions.createRaw()), task, result);
} finally {
writeFooter(writer);
}
result.recomputeStatus();
} catch (Exception ex) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't export accounts", ex);
error(getString("PageAccounts.exportException", ex.getMessage()));
} finally {
IOUtils.closeQuietly(writer);
}
filesModel.reset();
success(getString("PageAccounts.message.success.export", fileName));
target.add(getFeedbackPanel(), get(createComponentPath(ID_FORM_ACCOUNT, ID_FILES_CONTAINER)));
}
Aggregations