use of com.evolveum.midpoint.util.exception.SchemaException in project midpoint by Evolveum.
the class ModelWebServiceRaw method invokeAllowingFaults.
public DOMSource invokeAllowingFaults(DOMSource request) throws FaultMessage {
Node rootNode = request.getNode();
Element rootElement;
if (rootNode instanceof Document) {
rootElement = ((Document) rootNode).getDocumentElement();
} else if (rootNode instanceof Element) {
rootElement = (Element) rootNode;
} else {
throw ws.createIllegalArgumentFault("Unexpected DOM node type: " + rootNode);
}
Object requestObject;
try {
requestObject = prismContext.parserFor(rootElement).parseRealValue();
} catch (SchemaException e) {
throw ws.createIllegalArgumentFault("Couldn't parse SOAP request body because of schema exception: " + e.getMessage());
}
Node response;
Holder<OperationResultType> operationResultTypeHolder = new Holder<>();
try {
PrismSerializer<Element> serializer = prismContext.domSerializer().options(SerializationOptions.createSerializeReferenceNames());
if (requestObject instanceof GetObjectType) {
GetObjectType g = (GetObjectType) requestObject;
Holder<ObjectType> objectTypeHolder = new Holder<>();
ws.getObject(g.getObjectType(), g.getOid(), g.getOptions(), objectTypeHolder, operationResultTypeHolder);
GetObjectResponseType gr = new GetObjectResponseType();
gr.setObject(objectTypeHolder.value);
gr.setResult(operationResultTypeHolder.value);
response = serializer.serializeAnyData(gr, ModelPort.GET_OBJECT_RESPONSE);
} else if (requestObject instanceof SearchObjectsType) {
SearchObjectsType s = (SearchObjectsType) requestObject;
Holder<ObjectListType> objectListTypeHolder = new Holder<>();
ws.searchObjects(s.getObjectType(), s.getQuery(), s.getOptions(), objectListTypeHolder, operationResultTypeHolder);
SearchObjectsResponseType sr = new SearchObjectsResponseType();
sr.setObjectList(objectListTypeHolder.value);
sr.setResult(operationResultTypeHolder.value);
response = serializer.serializeAnyData(sr, ModelPort.SEARCH_OBJECTS_RESPONSE);
} else if (requestObject instanceof ExecuteChangesType) {
ExecuteChangesType e = (ExecuteChangesType) requestObject;
ObjectDeltaOperationListType objectDeltaOperationListType = ws.executeChanges(e.getDeltaList(), e.getOptions());
ExecuteChangesResponseType er = new ExecuteChangesResponseType();
er.setDeltaOperationList(objectDeltaOperationListType);
response = serializer.serializeAnyData(er, ModelPort.EXECUTE_CHANGES_RESPONSE);
} else if (requestObject instanceof FindShadowOwnerType) {
FindShadowOwnerType f = (FindShadowOwnerType) requestObject;
Holder<UserType> userTypeHolder = new Holder<>();
ws.findShadowOwner(f.getShadowOid(), userTypeHolder, operationResultTypeHolder);
FindShadowOwnerResponseType fsr = new FindShadowOwnerResponseType();
fsr.setUser(userTypeHolder.value);
fsr.setResult(operationResultTypeHolder.value);
response = serializer.serializeAnyData(fsr, ModelPort.FIND_SHADOW_OWNER_RESPONSE);
} else if (requestObject instanceof TestResourceType) {
TestResourceType tr = (TestResourceType) requestObject;
OperationResultType operationResultType = ws.testResource(tr.getResourceOid());
TestResourceResponseType trr = new TestResourceResponseType();
trr.setResult(operationResultType);
response = serializer.serializeAnyData(trr, ModelPort.TEST_RESOURCE_RESPONSE);
} else if (requestObject instanceof ExecuteScriptsType) {
ExecuteScriptsType es = (ExecuteScriptsType) requestObject;
ExecuteScriptsResponseType esr = ws.executeScripts(es);
response = serializer.serializeAnyData(esr, ModelPort.EXECUTE_SCRIPTS_RESPONSE);
} else if (requestObject instanceof ImportFromResourceType) {
ImportFromResourceType ifr = (ImportFromResourceType) requestObject;
TaskType taskType = ws.importFromResource(ifr.getResourceOid(), ifr.getObjectClass());
ImportFromResourceResponseType ifrr = new ImportFromResourceResponseType();
ifrr.setTask(taskType);
response = serializer.serializeAnyData(ifrr, ModelPort.IMPORT_FROM_RESOURCE_RESPONSE);
} else if (requestObject instanceof NotifyChangeType) {
NotifyChangeType nc = (NotifyChangeType) requestObject;
TaskType taskType = ws.notifyChange(nc.getChangeDescription());
NotifyChangeResponseType ncr = new NotifyChangeResponseType();
ncr.setTask(taskType);
response = serializer.serializeAnyData(ncr, ModelPort.NOTIFY_CHANGE_RESPONSE);
} else {
throw ws.createIllegalArgumentFault("Unsupported request type: " + requestObject);
}
} catch (SchemaException e) {
throwFault(e, operationResultTypeHolder.value);
// not reached
return null;
}
return new DOMSource(response);
}
use of com.evolveum.midpoint.util.exception.SchemaException in project midpoint by Evolveum.
the class AuditController method rollBackTime.
private <O extends ObjectType> PrismObject<O> rollBackTime(PrismObject<O> object, List<AuditEventRecord> changeTrail) throws SchemaException {
for (AuditEventRecord event : changeTrail) {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Applying event {} ({})", event.getEventIdentifier(), XmlTypeConverter.createXMLGregorianCalendar(event.getTimestamp()));
}
Collection<ObjectDeltaOperation<? extends ObjectType>> deltaOperations = event.getDeltas();
if (deltaOperations != null) {
for (ObjectDeltaOperation<? extends ObjectType> deltaOperation : deltaOperations) {
ObjectDelta<O> objectDelta = (ObjectDelta<O>) deltaOperation.getObjectDelta();
if (!isApplicable(deltaOperation, object, event)) {
continue;
}
if (objectDelta.isDelete()) {
throw new SchemaException("Delete delta found in the audit trail. Object history cannot be reconstructed.");
}
if (objectDelta.isAdd()) {
throw new SchemaException("Add delta found in the audit trail. Object history cannot be reconstructed.");
}
ObjectDelta<O> reverseDelta = objectDelta.createReverseDelta();
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Applying delta (reverse):\n{}", reverseDelta.debugDump(1));
}
reverseDelta.applyTo(object);
}
}
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Object after application of event {} ({}):\n{}", event.getEventIdentifier(), XmlTypeConverter.createXMLGregorianCalendar(event.getTimestamp()), object.debugDump(1));
}
}
return object;
}
use of com.evolveum.midpoint.util.exception.SchemaException in project midpoint by Evolveum.
the class SchemaStep method createXmlEditorModel.
private IModel<String> createXmlEditorModel() {
return new IModel<String>() {
@Override
public void detach() {
}
@Override
public String getObject() {
PrismObject<ResourceType> resource = model.getObject();
PrismContainer xmlSchema = resource.findContainer(ResourceType.F_SCHEMA);
if (xmlSchema == null) {
return null;
}
PageBase page = (PageBase) SchemaStep.this.getPage();
try {
return page.getPrismContext().xmlSerializer().serialize(xmlSchema.getValue(), SchemaConstantsGenerated.C_SCHEMA);
} catch (SchemaException | RuntimeException ex) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't serialize resource schema", ex);
return WebComponentUtil.exceptionToString("Couldn't serialize resource schema", ex);
}
}
@Override
public void setObject(String object) {
// ignore (it's interesting that this is called sometimes, even when the ACE is set to be read only)
}
};
}
use of com.evolveum.midpoint.util.exception.SchemaException in project midpoint by Evolveum.
the class ConfigurationStep method createConfigContainerWrappers.
@NotNull
private List<ContainerWrapper> createConfigContainerWrappers() throws SchemaException {
PrismObject<ResourceType> resource = resourceModelNoFetch.getObject();
PrismContainer<ConnectorConfigurationType> configuration = resource.findContainer(ResourceType.F_CONNECTOR_CONFIGURATION);
List<ContainerWrapper> containerWrappers = new ArrayList<>();
if (configuration == null) {
PrismObject<ConnectorType> connector = ResourceTypeUtil.getConnectorIfPresent(resource);
if (connector == null) {
throw new IllegalStateException("No resolved connector object in resource object");
}
ConnectorType connectorType = connector.asObjectable();
PrismSchema schema;
try {
schema = ConnectorTypeUtil.parseConnectorSchema(connectorType, parentPage.getPrismContext());
} catch (SchemaException e) {
throw new SystemException("Couldn't parse connector schema: " + e.getMessage(), e);
}
PrismContainerDefinition<ConnectorConfigurationType> definition = ConnectorTypeUtil.findConfigurationContainerDefinition(connectorType, schema);
// Fixing (errorneously) set maxOccurs = unbounded. See MID-2317 and related issues.
PrismContainerDefinition<ConnectorConfigurationType> definitionFixed = definition.clone();
((PrismContainerDefinitionImpl) definitionFixed).setMaxOccurs(1);
configuration = definitionFixed.instantiate();
}
List<PrismContainerDefinition> containerDefinitions = getSortedConfigContainerDefinitions(configuration);
for (PrismContainerDefinition<?> containerDef : containerDefinitions) {
ItemPath containerPath = new ItemPath(ResourceType.F_CONNECTOR_CONFIGURATION, containerDef.getName());
PrismContainer container = configuration.findContainer(containerDef.getName());
ContainerWrapperFactory cwf = new ContainerWrapperFactory(parentPage);
ContainerWrapper containerWrapper;
if (container != null) {
containerWrapper = cwf.createContainerWrapper(container, ContainerStatus.MODIFYING, containerPath, parentPage.isReadOnly());
} else {
container = containerDef.instantiate();
containerWrapper = cwf.createContainerWrapper(container, ContainerStatus.ADDING, containerPath, parentPage.isReadOnly());
}
containerWrappers.add(containerWrapper);
}
return containerWrappers;
}
use of com.evolveum.midpoint.util.exception.SchemaException in project midpoint by Evolveum.
the class SearchFactory method findObjectDefinition.
private static <T extends ObjectType> PrismObjectDefinition findObjectDefinition(Class<T> type, ResourceShadowDiscriminator discriminator, ModelServiceLocator modelServiceLocator) {
try {
if (Modifier.isAbstract(type.getModifiers())) {
SchemaRegistry registry = modelServiceLocator.getPrismContext().getSchemaRegistry();
return registry.findObjectDefinitionByCompileTimeClass(type);
}
Task task = modelServiceLocator.createSimpleTask(LOAD_OBJECT_DEFINITION);
OperationResult result = task.getResult();
PrismObject empty = modelServiceLocator.getPrismContext().createObject(type);
if (ShadowType.class.equals(type)) {
return modelServiceLocator.getModelInteractionService().getEditShadowDefinition(discriminator, AuthorizationPhaseType.REQUEST, task, result);
} else {
return modelServiceLocator.getModelInteractionService().getEditObjectDefinition(empty, AuthorizationPhaseType.REQUEST, task, result);
}
} catch (SchemaException | ConfigurationException | ObjectNotFoundException ex) {
throw new SystemException(ex);
}
}
Aggregations