Search in sources :

Example 26 with ConnObjectTO

use of org.apache.syncope.common.lib.to.ConnObjectTO in project syncope by apache.

the class StatusUtils method getConnectorObjects.

public List<ConnObjectWrapper> getConnectorObjects(final AnyTO any, final Collection<String> resources) {
    final List<ConnObjectWrapper> objects = new ArrayList<>();
    for (String resourceName : resources) {
        ConnObjectTO objectTO = null;
        try {
            objectTO = restClient.readConnObject(resourceName, any.getType(), any.getKey());
        } catch (Exception e) {
            LOG.warn("ConnObject '{}' not found on resource '{}'", any.getKey(), resourceName);
        }
        objects.add(new ConnObjectWrapper(any, resourceName, objectTO));
    }
    return objects;
}
Also used : ArrayList(java.util.ArrayList) ConnObjectTO(org.apache.syncope.common.lib.to.ConnObjectTO)

Example 27 with ConnObjectTO

use of org.apache.syncope.common.lib.to.ConnObjectTO in project syncope by apache.

the class Realm method customResultBody.

@Override
@SuppressWarnings("unchecked")
protected Panel customResultBody(final String panelId, final RealmTO item, final Serializable result) {
    if (!(result instanceof ProvisioningResult)) {
        throw new IllegalStateException("Unsupported result type");
    }
    final MultilevelPanel mlp = new MultilevelPanel(panelId);
    add(mlp);
    final PropagationStatus syncope = new PropagationStatus();
    syncope.setStatus(PropagationTaskExecStatus.SUCCESS);
    syncope.setResource(Constants.SYNCOPE);
    ArrayList<PropagationStatus> propagations = new ArrayList<>();
    propagations.add(syncope);
    propagations.addAll(((ProvisioningResult) result).getPropagationStatuses());
    ListViewPanel.Builder<PropagationStatus> builder = new ListViewPanel.Builder<PropagationStatus>(PropagationStatus.class, pageRef) {

        private static final long serialVersionUID = -6809736686861678498L;

        @Override
        protected Component getValueComponent(final String key, final PropagationStatus bean) {
            if ("afterObj".equalsIgnoreCase(key)) {
                ConnObjectTO afterObj = bean.getAfterObj();
                String remoteId = afterObj == null || afterObj.getAttrs().isEmpty() || !afterObj.getAttr(ConnIdSpecialName.NAME).isPresent() || afterObj.getAttr(ConnIdSpecialName.NAME).get().getValues() == null || afterObj.getAttr(ConnIdSpecialName.NAME).get().getValues().isEmpty() ? StringUtils.EMPTY : afterObj.getAttr(ConnIdSpecialName.NAME).get().getValues().get(0);
                return new Label("field", remoteId);
            } else if ("status".equalsIgnoreCase(key)) {
                return StatusUtils.getStatusImagePanel("field", bean.getStatus());
            } else {
                return super.getValueComponent(key, bean);
            }
        }
    };
    builder.setItems(propagations);
    builder.includes("resource", "afterObj", "status");
    builder.withChecks(ListViewPanel.CheckAvailability.NONE);
    builder.setReuseItem(false);
    builder.addAction(new ActionLink<PropagationStatus>() {

        private static final long serialVersionUID = -3722207913631435501L;

        @Override
        protected boolean statusCondition(final PropagationStatus bean) {
            return !Constants.SYNCOPE.equals(bean.getResource()) && (PropagationTaskExecStatus.CREATED == bean.getStatus() || PropagationTaskExecStatus.SUCCESS == bean.getStatus());
        }

        @Override
        public void onClick(final AjaxRequestTarget target, final PropagationStatus bean) {
            mlp.next(bean.getResource(), new RemoteRealmPanel(bean), target);
        }
    }, ActionLink.ActionType.VIEW, StandardEntitlement.RESOURCE_GET_CONNOBJECT);
    mlp.setFirstLevel(builder.build(MultilevelPanel.FIRST_LEVEL_ID));
    return mlp;
}
Also used : ProvisioningResult(org.apache.syncope.common.lib.to.ProvisioningResult) ArrayList(java.util.ArrayList) Label(org.apache.wicket.markup.html.basic.Label) PropagationStatus(org.apache.syncope.common.lib.to.PropagationStatus) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ConnObjectTO(org.apache.syncope.common.lib.to.ConnObjectTO)

Example 28 with ConnObjectTO

use of org.apache.syncope.common.lib.to.ConnObjectTO in project syncope by apache.

the class ResourceRestClient method listConnObjects.

public Pair<String, List<ConnObjectTO>> listConnObjects(final String resource, final String anyTypeKey, final int size, final String pagedResultCookie, final SortParam<String> sort) {
    ConnObjectTOListQuery.Builder builder = new ConnObjectTOListQuery.Builder().pagedResultsCookie(pagedResultCookie).size(size).orderBy(toOrderBy(sort));
    final List<ConnObjectTO> result = new ArrayList<>();
    String nextPageResultCookie = null;
    PagedConnObjectTOResult list;
    try {
        list = getService(ResourceService.class).listConnObjects(resource, anyTypeKey, builder.build());
        result.addAll(list.getResult());
        nextPageResultCookie = list.getPagedResultsCookie();
    } catch (Exception e) {
        LOG.error("While listing objects on {} for any type {}", resource, anyTypeKey, e);
    }
    return Pair.of(nextPageResultCookie, result);
}
Also used : ConnObjectTOListQuery(org.apache.syncope.common.rest.api.beans.ConnObjectTOListQuery) ArrayList(java.util.ArrayList) ConnObjectTO(org.apache.syncope.common.lib.to.ConnObjectTO) PagedConnObjectTOResult(org.apache.syncope.common.lib.to.PagedConnObjectTOResult)

Example 29 with ConnObjectTO

use of org.apache.syncope.common.lib.to.ConnObjectTO in project syncope by apache.

the class StatusPanel method init.

private void init(final AnyTO any, final IModel<List<StatusBean>> model, final List<Pair<ConnObjectTO, ConnObjectWrapper>> connObjects, final PageReference pageRef, final boolean enableConnObjectLink) {
    final List<StatusBean> statusBeans = new ArrayList<>(connObjects.size() + 1);
    initialStatusBeanMap = new LinkedHashMap<>(connObjects.size() + 1);
    final StatusBean syncope = new StatusBean(any, Constants.SYNCOPE);
    if (any instanceof UserTO) {
        syncope.setConnObjectLink(((UserTO) any).getUsername());
        Status syncopeStatus = Status.UNDEFINED;
        if (((UserTO) any).getStatus() != null) {
            try {
                syncopeStatus = Status.valueOf(((UserTO) any).getStatus().toUpperCase());
            } catch (IllegalArgumentException e) {
                LOG.warn("Unexpected status found: {}", ((UserTO) any).getStatus(), e);
            }
        }
        syncope.setStatus(syncopeStatus);
    } else if (any instanceof GroupTO) {
        syncope.setConnObjectLink(((GroupTO) any).getName());
        syncope.setStatus(Status.ACTIVE);
    }
    statusBeans.add(syncope);
    initialStatusBeanMap.put(syncope.getResource(), syncope);
    connObjects.forEach(pair -> {
        ConnObjectWrapper entry = pair.getRight();
        final StatusBean statusBean = statusUtils.getStatusBean(entry.getAny(), entry.getResourceName(), entry.getConnObjectTO(), any instanceof GroupTO);
        initialStatusBeanMap.put(entry.getResourceName(), statusBean);
        statusBeans.add(statusBean);
    });
    final MultilevelPanel mlp = new MultilevelPanel("resources");
    add(mlp);
    ListViewPanel.Builder<StatusBean> builder = new ListViewPanel.Builder<StatusBean>(StatusBean.class, pageRef) {

        private static final long serialVersionUID = -6809736686861678498L;

        @Override
        protected Component getValueComponent(final String key, final StatusBean bean) {
            if ("status".equalsIgnoreCase(key)) {
                return StatusUtils.getStatusImagePanel("field", bean.getStatus());
            } else {
                return super.getValueComponent(key, bean);
            }
        }
    };
    builder.setModel(model);
    builder.setItems(statusBeans);
    builder.includes("resource", "connObjectLink", "status");
    builder.withChecks(ListViewPanel.CheckAvailability.NONE);
    builder.setReuseItem(false);
    final ActionLink<StatusBean> connObjectLink = new ActionLink<StatusBean>() {

        private static final long serialVersionUID = -3722207913631435501L;

        @Override
        protected boolean statusCondition(final StatusBean bean) {
            final Pair<ConnObjectTO, ConnObjectTO> pair = getConnObjectTO(bean.getKey(), bean.getResource(), connObjects);
            return pair != null && pair.getRight() != null;
        }

        @Override
        public void onClick(final AjaxRequestTarget target, final StatusBean bean) {
            mlp.next(bean.getResource(), new RemoteAnyPanel(bean, connObjects), target);
        }
    };
    if (!enableConnObjectLink) {
        connObjectLink.disable();
    }
    builder.addAction(connObjectLink, ActionLink.ActionType.VIEW, StandardEntitlement.RESOURCE_GET_CONNOBJECT);
    listViewPanel = ListViewPanel.class.cast(builder.build(MultilevelPanel.FIRST_LEVEL_ID));
    mlp.setFirstLevel(listViewPanel);
}
Also used : Status(org.apache.syncope.client.console.commons.status.Status) ArrayList(java.util.ArrayList) GroupTO(org.apache.syncope.common.lib.to.GroupTO) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) MultilevelPanel(org.apache.syncope.client.console.panels.MultilevelPanel) StatusBean(org.apache.syncope.client.console.commons.status.StatusBean) UserTO(org.apache.syncope.common.lib.to.UserTO) ListViewPanel(org.apache.syncope.client.console.panels.ListViewPanel) ConnObjectTO(org.apache.syncope.common.lib.to.ConnObjectTO) ConnObjectWrapper(org.apache.syncope.client.console.commons.status.ConnObjectWrapper) ActionLink(org.apache.syncope.client.console.wicket.markup.html.form.ActionLink)

Example 30 with ConnObjectTO

use of org.apache.syncope.common.lib.to.ConnObjectTO in project syncope by apache.

the class JAXBTest method provisioningResult.

@Test
public void provisioningResult() throws JAXBException {
    JAXBContext context = JAXBContext.newInstance(ProvisioningResult.class);
    Marshaller marshaller = context.createMarshaller();
    Unmarshaller unmarshaller = context.createUnmarshaller();
    GroupTO group = new GroupTO();
    group.setName(UUID.randomUUID().toString());
    group.setRealm(SyncopeConstants.ROOT_REALM);
    group.getVirAttrs().add(new AttrTO.Builder().schema("rvirtualdata").value("rvirtualvalue").build());
    group.getADynMembershipConds().put("USER", "username==a*");
    ProvisioningResult<GroupTO> original = new ProvisioningResult<>();
    original.setEntity(group);
    PropagationStatus status = new PropagationStatus();
    status.setFailureReason("failed");
    status.setBeforeObj(new ConnObjectTO());
    original.getPropagationStatuses().add(status);
    StringWriter writer = new StringWriter();
    marshaller.marshal(original, writer);
    Object actual = unmarshaller.unmarshal(new StringReader(writer.toString()));
    assertEquals(original, actual);
}
Also used : Marshaller(javax.xml.bind.Marshaller) StringWriter(java.io.StringWriter) ProvisioningResult(org.apache.syncope.common.lib.to.ProvisioningResult) StringReader(java.io.StringReader) PropagationStatus(org.apache.syncope.common.lib.to.PropagationStatus) JAXBContext(javax.xml.bind.JAXBContext) ConnObjectTO(org.apache.syncope.common.lib.to.ConnObjectTO) Unmarshaller(javax.xml.bind.Unmarshaller) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Test(org.junit.jupiter.api.Test)

Aggregations

ConnObjectTO (org.apache.syncope.common.lib.to.ConnObjectTO)31 Test (org.junit.jupiter.api.Test)24 UserTO (org.apache.syncope.common.lib.to.UserTO)20 ResourceTO (org.apache.syncope.common.lib.to.ResourceTO)11 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)9 UserPatch (org.apache.syncope.common.lib.patch.UserPatch)9 GroupTO (org.apache.syncope.common.lib.to.GroupTO)9 ArrayList (java.util.ArrayList)8 ProvisioningResult (org.apache.syncope.common.lib.to.ProvisioningResult)8 MembershipTO (org.apache.syncope.common.lib.to.MembershipTO)7 Response (javax.ws.rs.core.Response)6 AttrTO (org.apache.syncope.common.lib.to.AttrTO)6 PasswordPatch (org.apache.syncope.common.lib.patch.PasswordPatch)5 List (java.util.List)4 Optional (java.util.Optional)4 ImplementationTO (org.apache.syncope.common.lib.to.ImplementationTO)4 PropagationStatus (org.apache.syncope.common.lib.to.PropagationStatus)4 IOException (java.io.IOException)3 Map (java.util.Map)3 Set (java.util.Set)3