private void mountFiles(String path, Class<?> clazz) { try { List<Resource> list = new ArrayList<>(); String packagePath = clazz.getPackage().getName().replace('.', '/'); PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); Resource[] res = resolver.getResources("classpath:" + packagePath + "/*.png"); if (res != null) { list.addAll(Arrays.asList(res)); } res = resolver.getResources("classpath:" + packagePath + "/*.gif"); if (res != null) { list.addAll(Arrays.asList(res)); } for (Resource resource : list) { URI uri = resource.getURI(); File file = new File(uri.toString()); mountResource( path + "/" + file.getName(), new SharedResourceReference(clazz, file.getName())); } } catch (Exception ex) { LoggingUtils.logUnexpectedException(LOGGER, "Couldn't mount files", ex); } }
private void deleteDefinitionPerformed( AjaxRequestTarget target, AccessCertificationDefinitionType definition) { OperationResult result = new OperationResult(OPERATION_DELETE_DEFINITION); try { Task task = createSimpleTask(OPERATION_DELETE_DEFINITION); ObjectDelta<AccessCertificationDefinitionType> delta = ObjectDelta.createDeleteDelta( AccessCertificationDefinitionType.class, definition.getOid(), getPrismContext()); getModelService() .executeChanges(WebComponentUtil.createDeltaCollection(delta), null, task, result); } catch (Exception ex) { result.recordPartialError("Couldn't delete campaign definition.", ex); LoggingUtils.logUnexpectedException(LOGGER, "Couldn't delete campaign definition", ex); } result.computeStatusIfUnknown(); if (result.isSuccess()) { result.recordStatus( OperationResultStatus.SUCCESS, "The definition has been successfully deleted."); } getDefinitionsTable().clearCache(); showResult(result); target.add(getFeedbackPanel(), getDefinitionsTable()); }
private void savePerformed(boolean raw, String operationName, AjaxRequestTarget target) { clearOldFeedback(); OperationResult result = new OperationResult(operationName); if (!validateInput(raw)) { error(getString("pageImportObject.message.nullFile")); target.add(getFeedbackPanel()); return; } InputStream stream = null; try { Task task = createSimpleTask(operationName); stream = getInputStream(raw); getModelService().importObjectsFromStream(stream, model.getObject(), task, result); result.recomputeStatus(); } catch (Exception ex) { result.recordFatalError("Couldn't import file.", ex); LoggingUtils.logUnexpectedException(LOGGER, "Couldn't import file", ex); } finally { if (stream != null) { IOUtils.closeQuietly(stream); } } showResult(result); target.add(PageImportObject.this); }
public static InputStream createReport( ReportOutputType report, AjaxDownloadBehaviorFromStream ajaxDownloadBehaviorFromStream, PageBase pageBase) { OperationResult result = new OperationResult(OPERATION_DOWNLOAD_REPORT); ReportManager reportManager = pageBase.getReportManager(); if (report == null) { return null; } String contentType = reportExportTypeMap.get(report.getExportType()); if (StringUtils.isEmpty(contentType)) { contentType = "multipart/mixed; charset=UTF-8"; } ajaxDownloadBehaviorFromStream.setContentType(contentType); InputStream input = null; try { input = reportManager.getReportOutputData(report.getOid(), result); } catch (Exception e) { pageBase.error( pageBase.getString("pageCreatedReports.message.downloadError") + " " + e.getMessage()); LoggingUtils.logUnexpectedException(LOGGER, "Couldn't download report.", e); LOGGER.trace(result.debugDump()); } finally { result.computeStatusIfUnknown(); } if (WebComponentUtil.showResultInPage(result)) { pageBase.showResult(result); } return input; }
private ObjectQuery getAssociationsSearchQuery( PrismContext prismContext, PrismObject resource, QName objectClass, ShadowKindType kind, String intent) { try { ObjectFilter andFilter = AndFilter.createAnd( EqualFilter.createEqual( ShadowType.F_OBJECT_CLASS, ShadowType.class, prismContext, objectClass), EqualFilter.createEqual(ShadowType.F_KIND, ShadowType.class, prismContext, kind), // EqualFilter.createEqual(ShadowType.F_INTENT, ShadowType.class, // prismContext, intent), RefFilter.createReferenceEqual( new ItemPath(ShadowType.F_RESOURCE_REF), ShadowType.class, prismContext, resource.getOid())); ObjectQuery query = ObjectQuery.createObjectQuery(andFilter); return query; } catch (SchemaException ex) { LoggingUtils.logUnexpectedException(LOGGER, "Unable to create associations search query", ex); return null; } }
private void savePerformed(AjaxRequestTarget target, boolean decision) { LOGGER.debug("Saving work item changes."); OperationResult result = new OperationResult(OPERATION_SAVE_WORK_ITEM); try { WorkItemDto dto = workItemDtoModel.getObject(); getWorkflowService() .approveOrRejectWorkItem(dto.getWorkItemId(), decision, dto.getApproverComment(), result); } catch (Exception ex) { result.recordFatalError("Couldn't save work item.", ex); LoggingUtils.logUnexpectedException(LOGGER, "Couldn't save work item", ex); } result.computeStatusIfUnknown(); if (!result.isSuccess()) { showResult(result, false); target.add(getFeedbackPanel()); } else { showResult(result); redirectBack(); } }
static { List<LocaleDescriptor> locales = new ArrayList<>(); try { ClassLoader classLoader = MidPointApplication.class.getClassLoader(); Enumeration<URL> urls = classLoader.getResources(LOCALIZATION_DESCRIPTOR); while (urls.hasMoreElements()) { final URL url = urls.nextElement(); LOGGER.debug("Found localization descriptor {}.", new Object[] {url.toString()}); Properties properties = new Properties(); Reader reader = null; try { reader = new InputStreamReader(url.openStream(), "utf-8"); properties.load(reader); Map<String, Map<String, String>> localeMap = new HashMap<>(); Set<String> keys = (Set) properties.keySet(); for (String key : keys) { String[] array = key.split("\\."); if (array.length != 2) { continue; } String locale = array[0]; Map<String, String> map = localeMap.get(locale); if (map == null) { map = new HashMap<>(); localeMap.put(locale, map); } map.put(key, properties.getProperty(key)); } for (String key : localeMap.keySet()) { Map<String, String> localeDefinition = localeMap.get(key); if (!localeDefinition.containsKey(key + PROP_NAME) || !localeDefinition.containsKey(key + PROP_FLAG)) { continue; } LocaleDescriptor descriptor = new LocaleDescriptor( localeDefinition.get(key + PROP_NAME), localeDefinition.get(key + PROP_FLAG), localeDefinition.get(key + PROP_DEFAULT), WebComponentUtil.getLocaleFromString(key)); locales.add(descriptor); } } catch (Exception ex) { LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load localization", ex); } finally { IOUtils.closeQuietly(reader); } } Collections.sort(locales); } catch (Exception ex) { LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load locales", ex); } AVAILABLE_LOCALES = Collections.unmodifiableList(locales); }
private List<ContainerWrapper> createContainers(PageBase pageBase) { result = new OperationResult(CREATE_CONTAINERS); List<ContainerWrapper> containers = new ArrayList<ContainerWrapper>(); try { Class clazz = object.getCompileTimeClass(); if (ShadowType.class.isAssignableFrom(clazz)) { PrismContainer attributes = object.findContainer(ShadowType.F_ATTRIBUTES); ContainerStatus status = attributes != null ? getStatus() : ContainerStatus.ADDING; if (attributes == null) { PrismContainerDefinition definition = object.getDefinition().findContainerDefinition(ShadowType.F_ATTRIBUTES); attributes = definition.instantiate(); } ContainerWrapper container = new ContainerWrapper( this, attributes, status, new ItemPath(ShadowType.F_ATTRIBUTES), pageBase); addSubresult(container.getResult()); container.setMain(true); containers.add(container); if (hasResourceCapability( ((ShadowType) object.asObjectable()).getResource(), ActivationCapabilityType.class)) { containers.addAll( createCustomContainerWrapper(object, ShadowType.F_ACTIVATION, pageBase)); } if (hasResourceCapability( ((ShadowType) object.asObjectable()).getResource(), CredentialsCapabilityType.class)) { containers.addAll( createCustomContainerWrapper(object, ShadowType.F_CREDENTIALS, pageBase)); } PrismContainer<ShadowAssociationType> associationContainer = object.findOrCreateContainer(ShadowType.F_ASSOCIATION); container = new ContainerWrapper( this, associationContainer, ContainerStatus.MODIFYING, new ItemPath(ShadowType.F_ASSOCIATION), pageBase); addSubresult(container.getResult()); containers.add(container); } else if (ResourceType.class.isAssignableFrom(clazz)) { containers = createResourceContainers(pageBase); } else if (ReportType.class.isAssignableFrom(clazz)) { containers = createReportContainers(pageBase); } else { ContainerWrapper container = new ContainerWrapper(this, object, getStatus(), null, pageBase); addSubresult(container.getResult()); containers.add(container); containers.addAll(createContainerWrapper(object, null, pageBase)); } } catch (Exception ex) { // TODO: shouldn't be this exception thrown???? LoggingUtils.logUnexpectedException(LOGGER, "Error occurred during container wrapping", ex); result.recordFatalError( "Error occurred during container wrapping, reason: " + ex.getMessage(), ex); } Collections.sort(containers, new ItemWrapperComparator()); result.recomputeStatus(); result.recordSuccessIfUnknown(); return containers; }
private WorkItemDto loadWorkItemDtoIfNecessary() { if (workItemDtoModel.isLoaded()) { return workItemDtoModel.getObject(); } Task task = createSimpleTask(OPERATION_LOAD_WORK_ITEM); OperationResult result = task.getResult(); WorkItemDto workItemDto = null; try { final ObjectQuery query = QueryBuilder.queryFor(WorkItemType.class, getPrismContext()) .item(F_WORK_ITEM_ID) .eq(taskId) .build(); final Collection<SelectorOptions<GetOperationOptions>> options = resolveItemsNamed(F_ASSIGNEE_REF); List<WorkItemType> workItems = getModelService().searchContainers(WorkItemType.class, query, options, task, result); if (workItems.size() > 1) { throw new SystemException("More than one work item with ID of " + taskId); } else if (workItems.size() == 0) { throw new SystemException("No work item with ID of " + taskId); } final WorkItemType workItem = workItems.get(0); final String taskOid = workItem.getTaskRef() != null ? workItem.getTaskRef().getOid() : null; TaskType taskType = null; List<TaskType> relatedTasks = new ArrayList<>(); if (taskOid != null) { final Collection<SelectorOptions<GetOperationOptions>> getTaskOptions = resolveItemsNamed(new ItemPath(F_WORKFLOW_CONTEXT, F_REQUESTER_REF)); getTaskOptions.addAll(retrieveItemsNamed(new ItemPath(F_WORKFLOW_CONTEXT, F_WORK_ITEM))); try { taskType = getModelService() .getObject(TaskType.class, taskOid, getTaskOptions, task, result) .asObjectable(); } catch (AuthorizationException e) { LoggingUtils.logExceptionOnDebugLevel( LOGGER, "Access to the task {} was denied", e, taskOid); } if (taskType != null && taskType.getParent() != null) { final ObjectQuery relatedTasksQuery = QueryBuilder.queryFor(TaskType.class, getPrismContext()) .item(F_PARENT) .eq(taskType.getParent()) .build(); List<PrismObject<TaskType>> relatedTaskObjects = getModelService() .searchObjects(TaskType.class, relatedTasksQuery, null, task, result); for (PrismObject<TaskType> relatedObject : relatedTaskObjects) { relatedTasks.add(relatedObject.asObjectable()); } } } workItemDto = new WorkItemDto(workItem, taskType, relatedTasks); workItemDto.prepareDeltaVisualization( "pageWorkItem.delta", getPrismContext(), getModelInteractionService(), task, result); result.recordSuccessIfUnknown(); } catch (CommonException | RuntimeException ex) { result.recordFatalError("Couldn't get work item.", ex); LoggingUtils.logUnexpectedException(LOGGER, "Couldn't get work item.", ex); } showResult(result, false); if (!result.isSuccess()) { throw getRestartResponseException(PageDashboard.class); } return workItemDto; }