use of com.evolveum.midpoint.prism.PrismProperty in project midpoint by Evolveum.
the class ProvisioningServiceImpl method getTokenProperty.
@SuppressWarnings("rawtypes")
private PrismProperty getTokenProperty(ResourceShadowDiscriminator shadowCoordinates, Task task, OperationResult result) throws ObjectNotFoundException, CommunicationException, SchemaException, ConfigurationException, ExpressionEvaluationException {
PrismProperty tokenProperty = null;
if (task.getExtension() != null) {
tokenProperty = task.getExtensionProperty(SchemaConstants.SYNC_TOKEN);
}
if (tokenProperty != null && (tokenProperty.getAnyRealValue() == null)) {
LOGGER.warn("Sync token exists, but it is empty (null value). Ignoring it.");
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Empty sync token property:\n{}", tokenProperty.debugDump());
}
tokenProperty = null;
}
// if the token is not specified in the task, get the latest token
if (tokenProperty == null) {
tokenProperty = getShadowCache(Mode.STANDARD).fetchCurrentToken(shadowCoordinates, result);
if (tokenProperty == null || tokenProperty.getValue() == null || tokenProperty.getValue().getValue() == null) {
LOGGER.warn("Empty current sync token provided by {}", shadowCoordinates);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Empty current sync token property.");
}
return null;
}
}
return tokenProperty;
}
use of com.evolveum.midpoint.prism.PrismProperty in project midpoint by Evolveum.
the class ReportCreateTaskHandler method run.
@Override
public TaskRunResult run(Task task) {
// TODO Auto-generated method stub
OperationResult parentResult = task.getResult();
OperationResult result = parentResult.createSubresult(ReportCreateTaskHandler.class.getSimpleName() + ".run");
TaskRunResult runResult = new TaskRunResult();
runResult.setOperationResult(result);
recordProgress(task, 0, result);
long progress = task.getProgress();
JRSwapFile swapFile = null;
// http://community.jaspersoft.com/wiki/virtualizers-jasperreports
JRAbstractLRUVirtualizer virtualizer = null;
try {
ReportType parentReport = objectResolver.resolve(task.getObjectRef(), ReportType.class, null, "resolving report", task, result);
Map<String, Object> parameters = completeReport(parentReport, task, result);
JasperReport jasperReport = ReportTypeUtil.loadJasperReport(parentReport);
LOGGER.trace("compile jasper design, create jasper report : {}", jasperReport);
PrismContainer<ReportParameterType> reportParams = (PrismContainer) task.getExtensionItem(ReportConstants.REPORT_PARAMS_PROPERTY_NAME);
if (reportParams != null) {
PrismContainerValue<ReportParameterType> reportParamsValues = reportParams.getValue();
List<Item<?, ?>> items = reportParamsValues.getItems();
if (items != null) {
for (Item item : items) {
PrismProperty pp = (PrismProperty) item;
String paramName = ItemPath.getName(pp.getPath().lastNamed()).getLocalPart();
Object value = null;
if (isSingleValue(paramName, jasperReport.getParameters())) {
value = pp.getRealValues().iterator().next();
} else {
value = pp.getRealValues();
}
parameters.put(paramName, value);
}
}
}
String virtualizerS = parentReport.getVirtualizer();
Integer virtualizerKickOn = parentReport.getVirtualizerKickOn();
Integer maxPages = parentReport.getMaxPages();
Integer timeout = parentReport.getTimeout();
if (maxPages != null && maxPages > 0) {
LOGGER.trace("Setting hardlimit on number of report pages: " + maxPages);
jasperReport.setProperty(MaxPagesGovernor.PROPERTY_MAX_PAGES_ENABLED, Boolean.TRUE.toString());
jasperReport.setProperty(MaxPagesGovernor.PROPERTY_MAX_PAGES, String.valueOf(maxPages));
}
if (timeout != null && timeout > 0) {
LOGGER.trace("Setting timeout on report execution [ms]: " + timeout);
jasperReport.setProperty(TimeoutGovernor.PROPERTY_TIMEOUT_ENABLED, Boolean.TRUE.toString());
jasperReport.setProperty(TimeoutGovernor.PROPERTY_TIMEOUT, String.valueOf(timeout));
}
if (virtualizerS != null && virtualizerKickOn != null && virtualizerKickOn > 0) {
String virtualizerClassName = JASPER_VIRTUALIZER_PKG + "." + virtualizerS;
try {
Class<?> clazz = Class.forName(virtualizerClassName);
if (clazz.equals(JRSwapFileVirtualizer.class)) {
swapFile = new JRSwapFile(TEMP_DIR, 4096, 200);
virtualizer = new JRSwapFileVirtualizer(virtualizerKickOn, swapFile);
} else if (clazz.equals(JRGzipVirtualizer.class)) {
virtualizer = new JRGzipVirtualizer(virtualizerKickOn);
} else if (clazz.equals(JRFileVirtualizer.class)) {
virtualizer = new JRFileVirtualizer(virtualizerKickOn, TEMP_DIR);
} else {
throw new ClassNotFoundException("No support for virtualizer class: " + clazz.getName());
}
LOGGER.trace("Setting explicit Jasper virtualizer: " + virtualizer);
virtualizer.setReadOnly(false);
parameters.put(JRParameter.REPORT_VIRTUALIZER, virtualizer);
} catch (ClassNotFoundException e) {
LOGGER.error("Cannot find Jasper virtualizer: " + e.getMessage());
}
}
LOGGER.trace("All Report parameters : {}", parameters);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters);
LOGGER.trace("fill report : {}", jasperPrint);
String reportFilePath = generateReport(parentReport, jasperPrint);
LOGGER.trace("generate report : {}", reportFilePath);
saveReportOutputType(reportFilePath, parentReport, task, result);
LOGGER.trace("create report output type : {}", reportFilePath);
result.computeStatus();
} catch (Exception ex) {
LOGGER.error("CreateReport: {}", ex.getMessage(), ex);
result.recordFatalError(ex.getMessage(), ex);
runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
runResult.setProgress(progress);
return runResult;
} finally {
if (swapFile != null) {
swapFile.dispose();
}
if (virtualizer != null) {
virtualizer.cleanup();
}
}
// This "run" is finished. But the task goes on ...
runResult.setRunResultStatus(TaskRunResultStatus.FINISHED);
runResult.setProgress(progress);
LOGGER.trace("CreateReportTaskHandler.run stopping");
return runResult;
}
use of com.evolveum.midpoint.prism.PrismProperty in project midpoint by Evolveum.
the class MidPointAbstractDataSource method getFieldValue.
@Override
public Object getFieldValue(JRField jrField) throws JRException {
// TODO Auto-generated method stub
String fieldName = jrField.getName();
if (fieldName.equals("oid")) {
return currentObject.getOid();
}
Item i = currentObject.findItem(new QName(fieldName));
if (i == null) {
return null;
}
if (i instanceof PrismProperty) {
if (i.isSingleValue()) {
return ((PrismProperty) i).getRealValue();
}
return ((PrismProperty) i).getRealValues();
} else if (i instanceof PrismReference) {
if (i.isSingleValue()) {
return ((PrismReference) i).getValue().asReferencable();
}
List<Referencable> refs = new ArrayList<Referencable>();
for (PrismReferenceValue refVal : ((PrismReference) i).getValues()) {
refs.add(refVal.asReferencable());
}
return refs;
} else if (i instanceof PrismContainer) {
if (i.isSingleValue()) {
return ((PrismContainer) i).getValue().asContainerable();
}
List<Containerable> containers = new ArrayList<Containerable>();
for (Object pcv : i.getValues()) {
if (pcv instanceof PrismContainerValue) {
containers.add(((PrismContainerValue) pcv).asContainerable());
}
}
return containers;
} else
throw new JRException("Could not get value of the fileld: " + fieldName);
}
use of com.evolveum.midpoint.prism.PrismProperty in project midpoint by Evolveum.
the class ConnIdConfigurationTransformer method transformConnectorConfiguration.
/**
* Transforms midPoint XML configuration of the connector to the ICF
* configuration.
* <p/>
* The "configuration" part of the XML resource definition will be used.
* <p/>
* The provided ICF APIConfiguration will be modified, some values may be
* overwritten.
*
* @param apiConfig
* ICF connector configuration
* @param resourceType
* midPoint XML configuration
* @throws SchemaException
* @throws ConfigurationException
*/
public APIConfiguration transformConnectorConfiguration(PrismContainerValue configuration) throws SchemaException, ConfigurationException {
APIConfiguration apiConfig = cinfo.createDefaultAPIConfiguration();
ConfigurationProperties configProps = apiConfig.getConfigurationProperties();
// The namespace of all the configuration properties specific to the
// connector instance will have a connector instance namespace. This
// namespace can be found in the resource definition.
String connectorConfNs = connectorType.getNamespace();
PrismContainer configurationPropertiesContainer = configuration.findContainer(SchemaConstants.CONNECTOR_SCHEMA_CONFIGURATION_PROPERTIES_ELEMENT_QNAME);
if (configurationPropertiesContainer == null) {
// Also try this. This is an older way.
configurationPropertiesContainer = configuration.findContainer(new QName(connectorConfNs, SchemaConstants.CONNECTOR_SCHEMA_CONFIGURATION_PROPERTIES_ELEMENT_LOCAL_NAME));
}
transformConnectorConfigurationProperties(configProps, configurationPropertiesContainer, connectorConfNs);
PrismContainer connectorPoolContainer = configuration.findContainer(new QName(SchemaConstants.NS_ICF_CONFIGURATION, ConnectorFactoryConnIdImpl.CONNECTOR_SCHEMA_CONNECTOR_POOL_CONFIGURATION_XML_ELEMENT_NAME));
ObjectPoolConfiguration connectorPoolConfiguration = apiConfig.getConnectorPoolConfiguration();
transformConnectorPoolConfiguration(connectorPoolConfiguration, connectorPoolContainer);
PrismProperty producerBufferSizeProperty = configuration.findProperty(new QName(SchemaConstants.NS_ICF_CONFIGURATION, ConnectorFactoryConnIdImpl.CONNECTOR_SCHEMA_PRODUCER_BUFFER_SIZE_XML_ELEMENT_NAME));
if (producerBufferSizeProperty != null) {
apiConfig.setProducerBufferSize(parseInt(producerBufferSizeProperty));
}
PrismContainer connectorTimeoutsContainer = configuration.findContainer(new QName(SchemaConstants.NS_ICF_CONFIGURATION, ConnectorFactoryConnIdImpl.CONNECTOR_SCHEMA_TIMEOUTS_XML_ELEMENT_NAME));
transformConnectorTimeoutsConfiguration(apiConfig, connectorTimeoutsContainer);
PrismContainer resultsHandlerConfigurationContainer = configuration.findContainer(new QName(SchemaConstants.NS_ICF_CONFIGURATION, ConnectorFactoryConnIdImpl.CONNECTOR_SCHEMA_RESULTS_HANDLER_CONFIGURATION_ELEMENT_LOCAL_NAME));
ResultsHandlerConfiguration resultsHandlerConfiguration = apiConfig.getResultsHandlerConfiguration();
transformResultsHandlerConfiguration(resultsHandlerConfiguration, resultsHandlerConfigurationContainer);
return apiConfig;
}
use of com.evolveum.midpoint.prism.PrismProperty in project midpoint by Evolveum.
the class ConnIdConfigurationTransformer method transformConnectorConfigurationProperties.
private void transformConnectorConfigurationProperties(ConfigurationProperties configProps, PrismContainer<?> configurationPropertiesContainer, String connectorConfNs) throws ConfigurationException, SchemaException {
if (configurationPropertiesContainer == null || configurationPropertiesContainer.getValue() == null) {
throw new SchemaException("No configuration properties container in " + connectorType);
}
int numConfingProperties = 0;
List<QName> wrongNamespaceProperties = new ArrayList<>();
for (PrismProperty prismProperty : configurationPropertiesContainer.getValue().getProperties()) {
QName propertyQName = prismProperty.getElementName();
// namespace.
if (propertyQName.getNamespaceURI() == null || !propertyQName.getNamespaceURI().equals(connectorConfNs)) {
LOGGER.warn("Found element with a wrong namespace ({}) in {}", propertyQName.getNamespaceURI(), connectorType);
wrongNamespaceProperties.add(propertyQName);
} else {
numConfingProperties++;
// Local name of the element is the same as the name
// of ConnId configuration property
String propertyName = propertyQName.getLocalPart();
ConfigurationProperty property = configProps.getProperty(propertyName);
if (property == null) {
throw new ConfigurationException("Unknown configuration property " + propertyName);
}
Class<?> type = property.getType();
if (type.isArray()) {
Object[] connIdArray = convertToConnIdfArray(prismProperty, type.getComponentType());
if (connIdArray != null && connIdArray.length != 0) {
property.setValue(connIdArray);
}
} else {
Object connIdValue = convertToConnIdSingle(prismProperty, type);
if (connIdValue != null) {
property.setValue(connIdValue);
}
}
}
}
// empty configuration is OK e.g. when creating a new resource using wizard
if (numConfingProperties == 0 && !wrongNamespaceProperties.isEmpty()) {
throw new SchemaException("No configuration properties found. Wrong namespace? (expected: " + connectorConfNs + ", present e.g. " + wrongNamespaceProperties.get(0) + ")");
}
}
Aggregations