Search in sources :

Example 96 with Pair

use of org.apache.beam.repackaged.core.org.apache.commons.lang3.tuple.Pair in project syncope by apache.

the class CamelUserProvisioningManager method update.

@Transactional(propagation = Propagation.REQUIRES_NEW)
@Override
@SuppressWarnings("unchecked")
public Pair<UserPatch, List<PropagationStatus>> update(final UserPatch userPatch, final ProvisioningReport result, final Boolean enabled, final Set<String> excludedResources, final boolean nullPriorityAsync) {
    PollingConsumer pollingConsumer = getConsumer("direct:updateInPullPort");
    Map<String, Object> props = new HashMap<>();
    props.put("key", userPatch.getKey());
    props.put("result", result);
    props.put("enabled", enabled);
    props.put("excludedResources", excludedResources);
    props.put("nullPriorityAsync", nullPriorityAsync);
    sendMessage("direct:updateUserInPull", userPatch, props);
    Exchange exchange = pollingConsumer.receive();
    Exception ex = (Exception) exchange.getProperty(Exchange.EXCEPTION_CAUGHT);
    if (ex != null) {
        LOG.error("Update of user {} failed, trying to pull its status anyway (if configured)", nullPriorityAsync, ex);
        result.setStatus(ProvisioningReport.Status.FAILURE);
        result.setMessage("Update failed, trying to pull status anyway (if configured)\n" + ex.getMessage());
        WorkflowResult<Pair<UserPatch, Boolean>> updated = new WorkflowResult<>(Pair.of(userPatch, false), new PropagationByResource(), new HashSet<>());
        sendMessage("direct:userInPull", updated, props);
        exchange = pollingConsumer.receive();
    }
    return exchange.getIn().getBody(Pair.class);
}
Also used : Exchange(org.apache.camel.Exchange) PollingConsumer(org.apache.camel.PollingConsumer) WorkflowResult(org.apache.syncope.core.provisioning.api.WorkflowResult) HashMap(java.util.HashMap) PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource) Pair(org.apache.commons.lang3.tuple.Pair) Transactional(org.springframework.transaction.annotation.Transactional)

Example 97 with Pair

use of org.apache.beam.repackaged.core.org.apache.commons.lang3.tuple.Pair in project syncope by apache.

the class CreateProducer method process.

@SuppressWarnings("unchecked")
@Override
public void process(final Exchange exchange) throws Exception {
    if ((exchange.getIn().getBody() instanceof WorkflowResult)) {
        Object actual = exchange.getProperty("actual");
        Set<String> excludedResources = exchange.getProperty("excludedResources", Set.class);
        Boolean nullPriorityAsync = exchange.getProperty("nullPriorityAsync", Boolean.class);
        if (actual instanceof UserTO) {
            WorkflowResult<Pair<String, Boolean>> created = (WorkflowResult<Pair<String, Boolean>>) exchange.getIn().getBody();
            List<PropagationTaskTO> tasks = getPropagationManager().getUserCreateTasks(created.getResult().getKey(), ((UserTO) actual).getPassword(), created.getResult().getValue(), created.getPropByRes(), ((UserTO) actual).getVirAttrs(), excludedResources);
            PropagationReporter propagationReporter = getPropagationTaskExecutor().execute(tasks, nullPriorityAsync);
            exchange.getOut().setBody(Pair.of(created.getResult().getKey(), propagationReporter.getStatuses()));
        } else if (actual instanceof AnyTO) {
            WorkflowResult<String> created = (WorkflowResult<String>) exchange.getIn().getBody();
            if (actual instanceof GroupTO && isPull()) {
                Map<String, String> groupOwnerMap = exchange.getProperty("groupOwnerMap", Map.class);
                Optional<AttrTO> groupOwner = ((GroupTO) actual).getPlainAttr(StringUtils.EMPTY);
                if (groupOwner.isPresent()) {
                    groupOwnerMap.put(created.getResult(), groupOwner.get().getValues().iterator().next());
                }
                List<PropagationTaskTO> tasks = getPropagationManager().getCreateTasks(AnyTypeKind.GROUP, created.getResult(), created.getPropByRes(), ((AnyTO) actual).getVirAttrs(), excludedResources);
                getPropagationTaskExecutor().execute(tasks, nullPriorityAsync);
                exchange.getOut().setBody(Pair.of(created.getResult(), null));
            } else {
                List<PropagationTaskTO> tasks = getPropagationManager().getCreateTasks(actual instanceof AnyObjectTO ? AnyTypeKind.ANY_OBJECT : AnyTypeKind.GROUP, created.getResult(), created.getPropByRes(), ((AnyTO) actual).getVirAttrs(), excludedResources);
                PropagationReporter propagationReporter = getPropagationTaskExecutor().execute(tasks, nullPriorityAsync);
                exchange.getOut().setBody(Pair.of(created.getResult(), propagationReporter.getStatuses()));
            }
        }
    }
}
Also used : AnyTO(org.apache.syncope.common.lib.to.AnyTO) WorkflowResult(org.apache.syncope.core.provisioning.api.WorkflowResult) PropagationTaskTO(org.apache.syncope.common.lib.to.PropagationTaskTO) Optional(java.util.Optional) PropagationReporter(org.apache.syncope.core.provisioning.api.propagation.PropagationReporter) GroupTO(org.apache.syncope.common.lib.to.GroupTO) AnyObjectTO(org.apache.syncope.common.lib.to.AnyObjectTO) UserTO(org.apache.syncope.common.lib.to.UserTO) List(java.util.List) Map(java.util.Map) Pair(org.apache.commons.lang3.tuple.Pair)

Example 98 with Pair

use of org.apache.beam.repackaged.core.org.apache.commons.lang3.tuple.Pair in project syncope by apache.

the class UpdateProducer method process.

@SuppressWarnings("unchecked")
@Override
public void process(final Exchange exchange) throws Exception {
    if ((exchange.getIn().getBody() instanceof WorkflowResult)) {
        Object actual = exchange.getProperty("actual");
        Boolean nullPriorityAsync = exchange.getProperty("nullPriorityAsync", Boolean.class);
        Set<String> excludedResources = exchange.getProperty("excludedResources", Set.class);
        if (actual instanceof UserPatch || isPull()) {
            WorkflowResult<Pair<UserPatch, Boolean>> updated = (WorkflowResult<Pair<UserPatch, Boolean>>) exchange.getIn().getBody();
            List<PropagationTaskTO> tasks;
            if (isPull()) {
                boolean passwordNotNull = updated.getResult().getKey().getPassword() != null;
                tasks = getPropagationManager().getUserUpdateTasks(updated, passwordNotNull, excludedResources);
            } else {
                tasks = getPropagationManager().getUserUpdateTasks(updated);
            }
            PropagationReporter propagationReporter = getPropagationTaskExecutor().execute(tasks, nullPriorityAsync);
            exchange.getOut().setBody(Pair.of(updated.getResult().getLeft(), propagationReporter.getStatuses()));
        } else if (actual instanceof AnyPatch) {
            WorkflowResult<? extends AnyPatch> updated = (WorkflowResult<? extends AnyPatch>) exchange.getIn().getBody();
            List<PropagationTaskTO> tasks = getPropagationManager().getUpdateTasks(actual instanceof AnyObjectPatch ? AnyTypeKind.ANY_OBJECT : AnyTypeKind.GROUP, updated.getResult().getKey(), false, null, updated.getPropByRes(), ((AnyPatch) actual).getVirAttrs(), excludedResources);
            PropagationReporter propagationReporter = getPropagationTaskExecutor().execute(tasks, nullPriorityAsync);
            exchange.getOut().setBody(Pair.of(updated.getResult(), propagationReporter.getStatuses()));
        }
    }
}
Also used : WorkflowResult(org.apache.syncope.core.provisioning.api.WorkflowResult) PropagationTaskTO(org.apache.syncope.common.lib.to.PropagationTaskTO) PropagationReporter(org.apache.syncope.core.provisioning.api.propagation.PropagationReporter) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) AnyPatch(org.apache.syncope.common.lib.patch.AnyPatch) List(java.util.List) AnyObjectPatch(org.apache.syncope.common.lib.patch.AnyObjectPatch) Pair(org.apache.commons.lang3.tuple.Pair)

Example 99 with Pair

use of org.apache.beam.repackaged.core.org.apache.commons.lang3.tuple.Pair in project syncope by apache.

the class ResourceWizardBuilder method buildModelSteps.

@Override
protected WizardModel buildModelSteps(final Serializable modelObject, final WizardModel wizardModel) {
    ResourceTO resourceTO = ResourceTO.class.cast(modelObject);
    wizardModel.add(new ResourceDetailsPanel(resourceTO, createFlag));
    wizardModel.add(new ResourceConnConfPanel(resourceTO, createFlag) {

        private static final long serialVersionUID = -1128269449868933504L;

        @Override
        protected Pair<Boolean, String> check(final AjaxRequestTarget target) {
            return resourceRestClient.check(modelObject);
        }

        @Override
        protected void onComponentTag(final ComponentTag tag) {
            tag.append("class", "scrollable-tab-content", " ");
        }
    });
    wizardModel.add(new ResourceConnCapabilitiesPanel(resourceTO, connectorRestClient.read(resourceTO.getConnector()).getCapabilities()));
    wizardModel.add(new ResourceSecurityPanel(resourceTO));
    return wizardModel;
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ResourceTO(org.apache.syncope.common.lib.to.ResourceTO) ComponentTag(org.apache.wicket.markup.ComponentTag) Pair(org.apache.commons.lang3.tuple.Pair)

Example 100 with Pair

use of org.apache.beam.repackaged.core.org.apache.commons.lang3.tuple.Pair in project syncope by apache.

the class NotificationManagerImpl method createTasks.

@Override
public List<NotificationTask> createTasks(final AuditElements.EventCategoryType type, final String category, final String subcategory, final String event, final Result condition, final Object before, final Object output, final Object... input) {
    Any<?> any = null;
    if (before instanceof UserTO) {
        any = userDAO.find(((UserTO) before).getKey());
    } else if (output instanceof UserTO) {
        any = userDAO.find(((UserTO) output).getKey());
    } else if (output instanceof Pair && ((Pair) output).getRight() instanceof UserTO) {
        any = userDAO.find(((UserTO) ((Pair) output).getRight()).getKey());
    } else if (output instanceof ProvisioningResult && ((ProvisioningResult) output).getEntity() instanceof UserTO) {
        any = userDAO.find(((ProvisioningResult) output).getEntity().getKey());
    } else if (before instanceof AnyObjectTO) {
        any = anyObjectDAO.find(((AnyObjectTO) before).getKey());
    } else if (output instanceof AnyObjectTO) {
        any = anyObjectDAO.find(((AnyObjectTO) output).getKey());
    } else if (output instanceof ProvisioningResult && ((ProvisioningResult) output).getEntity() instanceof AnyObjectTO) {
        any = anyObjectDAO.find(((ProvisioningResult) output).getEntity().getKey());
    } else if (before instanceof GroupTO) {
        any = groupDAO.find(((GroupTO) before).getKey());
    } else if (output instanceof GroupTO) {
        any = groupDAO.find(((GroupTO) output).getKey());
    } else if (output instanceof ProvisioningResult && ((ProvisioningResult) output).getEntity() instanceof GroupTO) {
        any = groupDAO.find(((ProvisioningResult) output).getEntity().getKey());
    }
    AnyType anyType = any == null ? null : any.getType();
    LOG.debug("Search notification for [{}]{}", anyType, any);
    List<NotificationTask> notifications = new ArrayList<>();
    for (Notification notification : notificationDAO.findAll()) {
        if (LOG.isDebugEnabled()) {
            notification.getAbouts().forEach(about -> {
                LOG.debug("Notification about {} defined: {}", about.getAnyType(), about.get());
            });
        }
        if (notification.isActive()) {
            String currentEvent = AuditLoggerName.buildEvent(type, category, subcategory, event, condition);
            if (!notification.getEvents().contains(currentEvent)) {
                LOG.debug("No events found about {}", any);
            } else if (anyType == null || any == null || !notification.getAbout(anyType).isPresent() || searchDAO.matches(any, SearchCondConverter.convert(notification.getAbout(anyType).get().get()))) {
                LOG.debug("Creating notification task for event {} about {}", currentEvent, any);
                final Map<String, Object> model = new HashMap<>();
                model.put("type", type);
                model.put("category", category);
                model.put("subcategory", subcategory);
                model.put("event", event);
                model.put("condition", condition);
                model.put("before", before);
                model.put("output", output);
                model.put("input", input);
                if (any instanceof User) {
                    model.put("user", userDataBinder.getUserTO((User) any, true));
                } else if (any instanceof Group) {
                    model.put("group", groupDataBinder.getGroupTO((Group) any, true));
                } else if (any instanceof AnyObject) {
                    model.put("group", anyObjectDataBinder.getAnyObjectTO((AnyObject) any, true));
                }
                NotificationTask notificationTask = getNotificationTask(notification, any, model);
                notificationTask = taskDAO.save(notificationTask);
                notifications.add(notificationTask);
            }
        } else {
            LOG.debug("Notification {} is not active, task will not be created", notification.getKey());
        }
    }
    return notifications;
}
Also used : Group(org.apache.syncope.core.persistence.api.entity.group.Group) NotificationTask(org.apache.syncope.core.persistence.api.entity.task.NotificationTask) User(org.apache.syncope.core.persistence.api.entity.user.User) ProvisioningResult(org.apache.syncope.common.lib.to.ProvisioningResult) ArrayList(java.util.ArrayList) Notification(org.apache.syncope.core.persistence.api.entity.Notification) GroupTO(org.apache.syncope.common.lib.to.GroupTO) AnyObjectTO(org.apache.syncope.common.lib.to.AnyObjectTO) AnyObject(org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject) UserTO(org.apache.syncope.common.lib.to.UserTO) AnyType(org.apache.syncope.core.persistence.api.entity.AnyType) Map(java.util.Map) HashMap(java.util.HashMap) Pair(org.apache.commons.lang3.tuple.Pair)

Aggregations

Pair (org.apache.commons.lang3.tuple.Pair)685 ArrayList (java.util.ArrayList)209 List (java.util.List)154 Test (org.junit.Test)150 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)142 HashMap (java.util.HashMap)123 Collectors (java.util.stream.Collectors)123 Map (java.util.Map)112 Message (com.microsoft.azure.sdk.iot.device.Message)71 IOException (java.io.IOException)70 MutablePair (org.apache.commons.lang3.tuple.MutablePair)64 java.util (java.util)55 IotHubTransportMessage (com.microsoft.azure.sdk.iot.device.transport.IotHubTransportMessage)52 Set (java.util.Set)49 StringUtils (org.apache.commons.lang3.StringUtils)48 File (java.io.File)46 Optional (java.util.Optional)45 Arrays (java.util.Arrays)44 HashSet (java.util.HashSet)40 Test (org.junit.jupiter.api.Test)39