use of javax.xml.bind.JAXBElement in project midpoint by Evolveum.
the class ProtectedDataType method addContent.
private boolean addContent(Object newObject) {
if (newObject instanceof String) {
String s = (String) newObject;
if (StringUtils.isNotBlank(s)) {
clearValue = (T) s;
}
return true;
} else if (newObject instanceof JAXBElement<?>) {
JAXBElement<?> jaxbElement = (JAXBElement<?>) newObject;
if (QNameUtil.match(F_ENCRYPTED_DATA, jaxbElement.getName())) {
encryptedDataType = (EncryptedDataType) jaxbElement.getValue();
return true;
} else if (QNameUtil.match(F_HASHED_DATA, jaxbElement.getName())) {
hashedDataType = (HashedDataType) jaxbElement.getValue();
return true;
} else {
throw new IllegalArgumentException("Attempt to add unknown JAXB element " + jaxbElement);
}
} else if (newObject instanceof Element) {
Element element = (Element) newObject;
QName elementName = DOMUtil.getQName(element);
if (QNameUtil.match(F_XML_ENC_ENCRYPTED_DATA, elementName)) {
encryptedDataType = convertXmlEncToEncryptedDate(element);
return true;
} else if (QNameUtil.match(F_CLEAR_VALUE, elementName)) {
clearValue = (T) element.getTextContent();
return true;
} else {
throw new IllegalArgumentException("Attempt to add unknown DOM element " + elementName);
}
} else {
throw new IllegalArgumentException("Attempt to add unknown object " + newObject + " (" + newObject.getClass() + ")");
}
}
use of javax.xml.bind.JAXBElement in project midpoint by Evolveum.
the class SearchEvaluator method evaluate.
public <T extends ObjectType> PipelineData evaluate(SearchExpressionType searchExpression, PipelineData input, ExecutionContext context, OperationResult globalResult) throws ScriptExecutionException {
Validate.notNull(searchExpression.getType());
boolean noFetch = expressionHelper.getArgumentAsBoolean(searchExpression.getParameter(), PARAM_NO_FETCH, input, context, false, "search", globalResult);
@SuppressWarnings({ "unchecked", "raw" }) Class<T> objectClass = (Class<T>) ObjectTypes.getObjectTypeFromTypeQName(searchExpression.getType()).getClassDefinition();
ObjectQuery objectQuery = null;
if (searchExpression.getQuery() != null) {
try {
objectQuery = QueryJaxbConvertor.createObjectQuery(objectClass, searchExpression.getQuery(), prismContext);
} catch (SchemaException e) {
throw new ScriptExecutionException("Couldn't parse object query due to schema exception", e);
}
} else if (searchExpression.getSearchFilter() != null) {
// todo resolve variable references in the filter
objectQuery = new ObjectQuery();
try {
ObjectFilter filter = QueryConvertor.parseFilter(searchExpression.getSearchFilter(), objectClass, prismContext);
objectQuery.setFilter(filter);
} catch (SchemaException e) {
throw new ScriptExecutionException("Couldn't parse object filter due to schema exception", e);
}
}
final String variableName = searchExpression.getVariable();
final PipelineData oldVariableValue = variableName != null ? context.getVariable(variableName) : null;
final PipelineData outputData = PipelineData.createEmpty();
final MutableBoolean atLeastOne = new MutableBoolean(false);
ResultHandler<T> handler = (object, parentResult) -> {
context.checkTaskStop();
atLeastOne.setValue(true);
if (searchExpression.getScriptingExpression() != null) {
if (variableName != null) {
context.setVariable(variableName, PipelineData.create(object.getValue()));
}
JAXBElement<?> childExpression = searchExpression.getScriptingExpression();
try {
outputData.addAllFrom(scriptingExpressionEvaluator.evaluateExpression((ScriptingExpressionType) childExpression.getValue(), PipelineData.create(object.getValue()), context, globalResult));
globalResult.setSummarizeSuccesses(true);
globalResult.summarize();
} catch (ScriptExecutionException e) {
// todo think about this
if (context.isContinueOnAnyError()) {
LoggingUtils.logUnexpectedException(LOGGER, "Exception when evaluating item from search result list.", e);
} else {
throw new SystemException(e);
}
}
} else {
outputData.addValue(object.getValue());
}
return true;
};
try {
Collection<SelectorOptions<GetOperationOptions>> options = operationsHelper.createGetOptions(searchExpression.getOptions(), noFetch);
modelService.searchObjectsIterative(objectClass, objectQuery, handler, options, context.getTask(), globalResult);
} catch (SchemaException | ObjectNotFoundException | SecurityViolationException | CommunicationException | ConfigurationException | ExpressionEvaluationException e) {
// TODO continue on any error?
throw new ScriptExecutionException("Couldn't execute searchObjects operation: " + e.getMessage(), e);
}
if (atLeastOne.isFalse()) {
String matching = objectQuery != null ? "matching " : "";
// temporary hack, this will be configurable
context.println("Warning: no " + matching + searchExpression.getType().getLocalPart() + " object found");
}
if (variableName != null) {
context.setVariable(variableName, oldVariableValue);
}
return outputData;
}
use of javax.xml.bind.JAXBElement in project midpoint by Evolveum.
the class ModelWebService method executeScripts.
@Override
public ExecuteScriptsResponseType executeScripts(ExecuteScriptsType parameters) throws FaultMessage {
Task task = createTaskInstance(EXECUTE_SCRIPTS);
auditLogin(task);
OperationResult result = task.getResult();
try {
List<JAXBElement<?>> scriptsToExecute = parseScripts(parameters);
return doExecuteScripts(scriptsToExecute, parameters.getOptions(), task, result);
} catch (Exception ex) {
LoggingUtils.logException(LOGGER, "# MODEL executeScripts() failed", ex);
throwFault(ex, null);
// notreached
return null;
} finally {
auditLogout(task);
}
}
use of javax.xml.bind.JAXBElement in project opennms by OpenNMS.
the class TsrmTicketerPlugin method updateIncidentWithTicket.
private void updateIncidentWithTicket(SHSIMPINCINCIDENTType incident, Ticket ticket) {
if (!StringUtils.isEmpty(ticket.getAttribute(AFFECTED_PERSON))) {
MXStringType affectedPerson = new MXStringType();
affectedPerson.setValue(ticket.getAttribute(AFFECTED_PERSON));
incident.setAFFECTEDPERSON(affectedPerson);
}
if (!StringUtils.isEmpty(ticket.getAttribute(ASSET_NUM))) {
MXStringType assetNum = new MXStringType();
assetNum.setValue(ticket.getAttribute(ASSET_NUM));
incident.setASSETNUM(assetNum);
}
if (!StringUtils.isEmpty(ticket.getAttribute(CLASS_ID))) {
MXStringType classId = new MXStringType();
classId.setValue(ticket.getAttribute(CLASS_ID));
incident.setCLASS(classId);
}
if (!StringUtils.isEmpty(ticket.getAttribute(CLASS_STRUCTURE_ID))) {
MXStringType classStructureId = new MXStringType();
classStructureId.setValue(ticket.getAttribute(CLASS_STRUCTURE_ID));
incident.setCLASSSTRUCTUREID(classStructureId);
}
if (!StringUtils.isEmpty(ticket.getAttribute(COMMODITY))) {
MXStringType commodity = new MXStringType();
commodity.setValue(ticket.getAttribute(COMMODITY));
incident.setCOMMODITY(commodity);
}
if (!StringUtils.isEmpty(ticket.getSummary())) {
MXStringType description = new MXStringType();
description.setValue(ticket.getSummary());
incident.setDESCRIPTION(description);
}
if (!StringUtils.isEmpty(ticket.getDetails())) {
MXStringType longDescription = new MXStringType();
longDescription.setValue(ticket.getDetails());
incident.setDESCRIPTIONLONGDESCRIPTION(longDescription);
}
if (!StringUtils.isEmpty(ticket.getAttribute(LOCATION))) {
MXStringType location = new MXStringType();
location.setValue(ticket.getAttribute(LOCATION));
incident.setLOCATION(location);
}
if (!StringUtils.isEmpty(ticket.getAttribute(OWNER_GROUP))) {
MXStringType ownerGroup = new MXStringType();
ownerGroup.setValue(ticket.getAttribute(OWNER_GROUP));
incident.setOWNERGROUP(ownerGroup);
}
if (!StringUtils.isEmpty(ticket.getUser())) {
if (StringUtils.isEmpty(ticket.getId())) {
MXStringType reportedBy = new MXStringType();
reportedBy.setValue(ticket.getUser());
incident.setREPORTEDBY(reportedBy);
} else {
MXDateTimeType date = new MXDateTimeType();
GregorianCalendar calendarTime = new GregorianCalendar();
calendarTime.setTime(new Date());
XMLGregorianCalendar value;
@SuppressWarnings({ "unchecked", "rawtypes" }) JAXBElement<MXDateTimeType> jaxbElement = new JAXBElement(new QName(MXDateTimeType.class.getName()), MXDateTimeType.class, date);
try {
value = DatatypeFactory.newInstance().newXMLGregorianCalendar(calendarTime);
date.setValue(value);
incident.setCHANGEDATE(jaxbElement);
} catch (DatatypeConfigurationException e) {
LOG.error("Unable to create changedDate", e);
}
}
}
if (!StringUtils.isEmpty(ticket.getAttribute(SHS_CALLER_TYPE))) {
MXStringType shsCallerType = new MXStringType();
shsCallerType.setValue(ticket.getAttribute(SHS_CALLER_TYPE));
incident.setSHSCALLERTYPE(shsCallerType);
}
if (!StringUtils.isEmpty(ticket.getAttribute(SHS_REASON_FOR_OUTAGE))) {
MXStringType shsReasonForOutage = new MXStringType();
shsReasonForOutage.setValue(ticket.getAttribute(SHS_REASON_FOR_OUTAGE));
incident.setSHSREASONFOROUTAGE(shsReasonForOutage);
}
if (!StringUtils.isEmpty(ticket.getAttribute(SHS_RESOLUTION))) {
MXStringType shsResolution = new MXStringType();
shsResolution.setValue(ticket.getAttribute(SHS_RESOLUTION));
incident.setSHSRESOLUTION(shsResolution);
}
if (!StringUtils.isEmpty(ticket.getAttribute(SHS_ROOM_NUMBER))) {
MXStringType shsRoomNumber = new MXStringType();
shsRoomNumber.setValue(ticket.getAttribute(SHS_ROOM_NUMBER));
incident.setSHSROOMNUMBER(shsRoomNumber);
}
if (!StringUtils.isEmpty(ticket.getAttribute(SITE_ID))) {
MXStringType siteId = new MXStringType();
siteId.setValue(ticket.getAttribute(SITE_ID));
incident.setSITEID(siteId);
}
if (!StringUtils.isEmpty(ticket.getAttribute(SOURCE))) {
MXStringType source = new MXStringType();
source.setValue(ticket.getAttribute(SOURCE));
incident.setSOURCE(source);
}
MXStringType status = new MXStringType();
try {
if (ticket.getState().equals(Ticket.State.OPEN)) {
status.setValue(getProperties().getProperty("tsrm.status.open"));
} else if (ticket.getState().equals(Ticket.State.CLOSED)) {
status.setValue(getProperties().getProperty("tsrm.status.close"));
}
} catch (IOException e) {
LOG.error("Unable to load tsrm.status from properties ", e);
}
incident.setSTATUS(status);
if (!StringUtils.isEmpty(ticket.getAttribute(STATUS_IFACE))) {
MXBooleanType statusIface = new MXBooleanType();
statusIface.setValue(Boolean.parseBoolean(ticket.getAttribute(STATUS_IFACE)));
incident.setSTATUSIFACE(statusIface);
}
}
use of javax.xml.bind.JAXBElement in project midpoint by Evolveum.
the class DescriptorLoader method loadData.
public void loadData(MidPointApplication application) {
LOGGER.debug("Loading data from descriptor files.");
try (InputStream baseInput = application.getServletContext().getResourceAsStream(baseFileName);
InputStream customInput = application.getServletContext().getResourceAsStream(customFileName)) {
if (baseInput == null) {
LOGGER.error("Couldn't find " + baseFileName + " file, can't load application menu and other stuff.");
}
JAXBContext context = JAXBContext.newInstance(ObjectFactory.class);
Unmarshaller unmarshaller = context.createUnmarshaller();
JAXBElement<DescriptorType> element = (JAXBElement) unmarshaller.unmarshal(baseInput);
DescriptorType descriptor = element.getValue();
LOGGER.debug("Loading menu bar from " + baseFileName + " .");
DescriptorType customDescriptor = null;
if (customInput != null) {
element = (JAXBElement) unmarshaller.unmarshal(customInput);
customDescriptor = element.getValue();
}
scanPackagesForPages(descriptor.getPackagesToScan(), application);
if (customDescriptor != null) {
scanPackagesForPages(customDescriptor.getPackagesToScan(), application);
}
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("loaded:\n{}", debugDump(1));
}
} catch (Exception ex) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't process application descriptor", ex);
}
}
Aggregations