Search in sources :

Example 16 with AnyObjectPatch

use of org.apache.syncope.common.lib.patch.AnyObjectPatch in project syncope by apache.

the class CamelAnyObjectProvisioningManager method unlink.

@Override
public String unlink(final AnyObjectPatch anyObjectPatch) {
    PollingConsumer pollingConsumer = getConsumer("direct:unlinkAnyObjectPort");
    sendMessage("direct:unlinkAnyObject", anyObjectPatch);
    Exchange exchange = pollingConsumer.receive();
    if (exchange.getProperty(Exchange.EXCEPTION_CAUGHT) != null) {
        throw (RuntimeException) exchange.getProperty(Exchange.EXCEPTION_CAUGHT);
    }
    return exchange.getIn().getBody(AnyObjectPatch.class).getKey();
}
Also used : Exchange(org.apache.camel.Exchange) PollingConsumer(org.apache.camel.PollingConsumer) AnyObjectPatch(org.apache.syncope.common.lib.patch.AnyObjectPatch)

Example 17 with AnyObjectPatch

use of org.apache.syncope.common.lib.patch.AnyObjectPatch in project syncope by apache.

the class AnyObjectITCase method update.

@Test
public void update() {
    AnyObjectTO anyObjectTO = getSampleTO("update");
    anyObjectTO = createAnyObject(anyObjectTO).getEntity();
    assertEquals(1, anyObjectTO.getPlainAttrs().size());
    AnyObjectPatch anyObjectPatch = new AnyObjectPatch();
    anyObjectPatch.setKey(anyObjectTO.getKey());
    String newLocation = "new" + getUUIDString();
    anyObjectPatch.getPlainAttrs().add(attrAddReplacePatch("location", newLocation));
    anyObjectTO = updateAnyObject(anyObjectPatch).getEntity();
    assertEquals(newLocation, anyObjectTO.getPlainAttr("location").get().getValues().get(0));
}
Also used : AnyObjectTO(org.apache.syncope.common.lib.to.AnyObjectTO) AnyObjectPatch(org.apache.syncope.common.lib.patch.AnyObjectPatch) Test(org.junit.jupiter.api.Test)

Example 18 with AnyObjectPatch

use of org.apache.syncope.common.lib.patch.AnyObjectPatch in project syncope by apache.

the class DefaultAnyObjectProvisioningManager method update.

@Transactional(propagation = Propagation.REQUIRES_NEW)
@Override
public Pair<AnyObjectPatch, List<PropagationStatus>> update(final AnyObjectPatch anyObjectPatch, final Set<String> excludedResources, final boolean nullPriorityAsync) {
    WorkflowResult<AnyObjectPatch> updated = awfAdapter.update(anyObjectPatch);
    List<PropagationTaskTO> tasks = propagationManager.getUpdateTasks(AnyTypeKind.ANY_OBJECT, updated.getResult().getKey(), false, null, updated.getPropByRes(), anyObjectPatch.getVirAttrs(), excludedResources);
    PropagationReporter propagationReporter = taskExecutor.execute(tasks, nullPriorityAsync);
    return Pair.of(updated.getResult(), propagationReporter.getStatuses());
}
Also used : PropagationTaskTO(org.apache.syncope.common.lib.to.PropagationTaskTO) PropagationReporter(org.apache.syncope.core.provisioning.api.propagation.PropagationReporter) AnyObjectPatch(org.apache.syncope.common.lib.patch.AnyObjectPatch) Transactional(org.springframework.transaction.annotation.Transactional)

Example 19 with AnyObjectPatch

use of org.apache.syncope.common.lib.patch.AnyObjectPatch in project syncope by apache.

the class AnyOperations method patch.

public static AnyObjectTO patch(final AnyObjectTO anyObjectTO, final AnyObjectPatch anyObjectPatch) {
    AnyObjectTO result = SerializationUtils.clone(anyObjectTO);
    patch(anyObjectTO, anyObjectPatch, result);
    if (anyObjectPatch.getName() != null) {
        result.setName(anyObjectPatch.getName().getValue());
    }
    // 1. relationships
    anyObjectPatch.getRelationships().forEach(relPatch -> {
        if (relPatch.getRelationshipTO() == null) {
            LOG.warn("Invalid {} specified: {}", RelationshipPatch.class.getName(), relPatch);
        } else {
            result.getRelationships().remove(relPatch.getRelationshipTO());
            if (relPatch.getOperation() == PatchOperation.ADD_REPLACE) {
                result.getRelationships().add(relPatch.getRelationshipTO());
            }
        }
    });
    // 2. memberships
    anyObjectPatch.getMemberships().forEach(membPatch -> {
        if (membPatch.getGroup() == null) {
            LOG.warn("Invalid {} specified: {}", MembershipPatch.class.getName(), membPatch);
        } else {
            Optional<MembershipTO> memb = result.getMemberships().stream().filter(membership -> membPatch.getGroup().equals(membership.getGroupKey())).findFirst();
            if (memb.isPresent()) {
                result.getMemberships().remove(memb.get());
            }
            if (membPatch.getOperation() == PatchOperation.ADD_REPLACE) {
                MembershipTO newMembershipTO = new MembershipTO.Builder().group(membPatch.getGroup()).build();
                // 3. plain attributes
                newMembershipTO.getPlainAttrs().addAll(membPatch.getPlainAttrs());
                // 4. virtual attributes
                newMembershipTO.getVirAttrs().addAll(membPatch.getVirAttrs());
                result.getMemberships().add(newMembershipTO);
            }
        }
    });
    return result;
}
Also used : StringPatchItem(org.apache.syncope.common.lib.patch.StringPatchItem) AttrTO(org.apache.syncope.common.lib.to.AttrTO) AnyObjectPatch(org.apache.syncope.common.lib.patch.AnyObjectPatch) LoggerFactory(org.slf4j.LoggerFactory) AnyTO(org.apache.syncope.common.lib.to.AnyTO) HashMap(java.util.HashMap) SerializationUtils(org.apache.commons.lang3.SerializationUtils) BooleanReplacePatchItem(org.apache.syncope.common.lib.patch.BooleanReplacePatchItem) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) RelationshipPatch(org.apache.syncope.common.lib.patch.RelationshipPatch) StringUtils(org.apache.commons.lang3.StringUtils) GroupPatch(org.apache.syncope.common.lib.patch.GroupPatch) MembershipPatch(org.apache.syncope.common.lib.patch.MembershipPatch) Pair(org.apache.commons.lang3.tuple.Pair) Map(java.util.Map) AbstractReplacePatchItem(org.apache.syncope.common.lib.patch.AbstractReplacePatchItem) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) AnyPatch(org.apache.syncope.common.lib.patch.AnyPatch) Logger(org.slf4j.Logger) Collection(java.util.Collection) Set(java.util.Set) GroupTO(org.apache.syncope.common.lib.to.GroupTO) AttrPatch(org.apache.syncope.common.lib.patch.AttrPatch) PasswordPatch(org.apache.syncope.common.lib.patch.PasswordPatch) RelationshipTO(org.apache.syncope.common.lib.to.RelationshipTO) PatchOperation(org.apache.syncope.common.lib.types.PatchOperation) Optional(java.util.Optional) StringReplacePatchItem(org.apache.syncope.common.lib.patch.StringReplacePatchItem) UserTO(org.apache.syncope.common.lib.to.UserTO) AnyObjectTO(org.apache.syncope.common.lib.to.AnyObjectTO) AnyObjectTO(org.apache.syncope.common.lib.to.AnyObjectTO) MembershipPatch(org.apache.syncope.common.lib.patch.MembershipPatch) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) RelationshipPatch(org.apache.syncope.common.lib.patch.RelationshipPatch)

Example 20 with AnyObjectPatch

use of org.apache.syncope.common.lib.patch.AnyObjectPatch in project syncope by apache.

the class RemediationLogic method remedy.

@PreAuthorize("hasRole('" + StandardEntitlement.REMEDIATION_REMEDY + "')")
public ProvisioningResult<?> remedy(final String key, final AnyPatch anyPatch, final boolean nullPriorityAsync) {
    Remediation remediation = remediationDAO.find(key);
    if (remediation == null) {
        LOG.error("Could not find remediation '" + key + "'");
        throw new NotFoundException(key);
    }
    ProvisioningResult<?> result;
    switch(remediation.getAnyType().getKind()) {
        case USER:
        default:
            result = userLogic.update((UserPatch) anyPatch, nullPriorityAsync);
            break;
        case GROUP:
            result = groupLogic.update((GroupPatch) anyPatch, nullPriorityAsync);
            break;
        case ANY_OBJECT:
            result = anyObjectLogic.update((AnyObjectPatch) anyPatch, nullPriorityAsync);
    }
    remediationDAO.delete(remediation);
    return result;
}
Also used : NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) Remediation(org.apache.syncope.core.persistence.api.entity.Remediation) AnyObjectPatch(org.apache.syncope.common.lib.patch.AnyObjectPatch) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) GroupPatch(org.apache.syncope.common.lib.patch.GroupPatch) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

AnyObjectPatch (org.apache.syncope.common.lib.patch.AnyObjectPatch)23 AnyObjectTO (org.apache.syncope.common.lib.to.AnyObjectTO)14 List (java.util.List)5 AttrPatch (org.apache.syncope.common.lib.patch.AttrPatch)5 MembershipTO (org.apache.syncope.common.lib.to.MembershipTO)5 Map (java.util.Map)4 Pair (org.apache.commons.lang3.tuple.Pair)4 GroupPatch (org.apache.syncope.common.lib.patch.GroupPatch)4 UserPatch (org.apache.syncope.common.lib.patch.UserPatch)4 AttrTO (org.apache.syncope.common.lib.to.AttrTO)4 PatchOperation (org.apache.syncope.common.lib.types.PatchOperation)4 Test (org.junit.jupiter.api.Test)4 Collection (java.util.Collection)3 HashMap (java.util.HashMap)3 Optional (java.util.Optional)3 Set (java.util.Set)3 SerializationUtils (org.apache.commons.lang3.SerializationUtils)3 StringUtils (org.apache.commons.lang3.StringUtils)3 AnyPatch (org.apache.syncope.common.lib.patch.AnyPatch)3 MembershipPatch (org.apache.syncope.common.lib.patch.MembershipPatch)3