Search in sources :

Example 26 with AnyType

use of org.apache.syncope.core.persistence.api.entity.AnyType in project syncope by apache.

the class SyncopeLogic method numbers.

@PreAuthorize("isAuthenticated()")
public NumbersInfo numbers() {
    NumbersInfo numbersInfo = new NumbersInfo();
    numbersInfo.setTotalUsers(userDAO.count());
    numbersInfo.getUsersByRealm().putAll(userDAO.countByRealm());
    numbersInfo.getUsersByStatus().putAll(userDAO.countByStatus());
    numbersInfo.setTotalGroups(groupDAO.count());
    numbersInfo.getGroupsByRealm().putAll(groupDAO.countByRealm());
    Map<AnyType, Integer> anyObjectNumbers = anyObjectDAO.countByType();
    int i = 0;
    for (Iterator<Map.Entry<AnyType, Integer>> itor = anyObjectNumbers.entrySet().iterator(); i < 2 && itor.hasNext(); i++) {
        Map.Entry<AnyType, Integer> entry = itor.next();
        if (i == 0) {
            numbersInfo.setAnyType1(entry.getKey().getKey());
            numbersInfo.setTotalAny1(entry.getValue());
            numbersInfo.getAny1ByRealm().putAll(anyObjectDAO.countByRealm(entry.getKey()));
        } else if (i == 1) {
            numbersInfo.setAnyType2(entry.getKey().getKey());
            numbersInfo.setTotalAny2(entry.getValue());
            numbersInfo.getAny2ByRealm().putAll(anyObjectDAO.countByRealm(entry.getKey()));
        }
    }
    numbersInfo.setTotalResources(resourceDAO.count());
    numbersInfo.setTotalRoles(roleDAO.count());
    numbersInfo.getConfCompleteness().put(NumbersInfo.ConfItem.RESOURCE.name(), numbersInfo.getTotalResources() > 0);
    numbersInfo.getConfCompleteness().put(NumbersInfo.ConfItem.ACCOUNT_POLICY.name(), !policyDAO.find(AccountPolicy.class).isEmpty());
    numbersInfo.getConfCompleteness().put(NumbersInfo.ConfItem.PASSWORD_POLICY.name(), !policyDAO.find(PasswordPolicy.class).isEmpty());
    numbersInfo.getConfCompleteness().put(NumbersInfo.ConfItem.NOTIFICATION.name(), !notificationDAO.findAll().isEmpty());
    numbersInfo.getConfCompleteness().put(NumbersInfo.ConfItem.PULL_TASK.name(), !taskDAO.findAll(TaskType.PULL).isEmpty());
    numbersInfo.getConfCompleteness().put(NumbersInfo.ConfItem.VIR_SCHEMA.name(), !virSchemaDAO.findAll().isEmpty());
    numbersInfo.getConfCompleteness().put(NumbersInfo.ConfItem.ANY_TYPE.name(), !anyObjectNumbers.isEmpty());
    numbersInfo.getConfCompleteness().put(NumbersInfo.ConfItem.SECURITY_QUESTION.name(), !securityQuestionDAO.findAll().isEmpty());
    numbersInfo.getConfCompleteness().put(NumbersInfo.ConfItem.ROLE.name(), numbersInfo.getTotalRoles() > 0);
    return numbersInfo;
}
Also used : AccountPolicy(org.apache.syncope.core.persistence.api.entity.policy.AccountPolicy) NumbersInfo(org.apache.syncope.common.lib.info.NumbersInfo) PasswordPolicy(org.apache.syncope.core.persistence.api.entity.policy.PasswordPolicy) AnyType(org.apache.syncope.core.persistence.api.entity.AnyType) Map(java.util.Map) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 27 with AnyType

use of org.apache.syncope.core.persistence.api.entity.AnyType in project syncope by apache.

the class AnyTypeLogic method delete.

@PreAuthorize("hasRole('" + StandardEntitlement.ANYTYPE_DELETE + "')")
public AnyTypeTO delete(final String key) {
    AnyType anyType = anyTypeDAO.find(key);
    if (anyType == null) {
        LOG.error("Could not find anyType '" + key + "'");
        throw new NotFoundException(key);
    }
    Integer anyObjects = anyObjectDAO.countByType().get(anyType);
    if (anyObjects != null && anyObjects > 0) {
        LOG.error("{} AnyObject instances found for {}, aborting", anyObjects, anyType);
        SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidAnyType);
        sce.getElements().add("AnyObject instances found for " + key);
        throw sce;
    }
    try {
        return binder.delete(anyType);
    } catch (IllegalArgumentException e) {
        SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidRequest);
        sce.getElements().add(e.getMessage());
        throw sce;
    }
}
Also used : SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) AnyType(org.apache.syncope.core.persistence.api.entity.AnyType) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 28 with AnyType

use of org.apache.syncope.core.persistence.api.entity.AnyType in project syncope by apache.

the class AnyTypeLogic method update.

@PreAuthorize("hasRole('" + StandardEntitlement.ANYTYPE_UPDATE + "')")
public AnyTypeTO update(final AnyTypeTO anyTypeTO) {
    AnyType anyType = anyTypeDAO.find(anyTypeTO.getKey());
    if (anyType == null) {
        LOG.error("Could not find anyType '" + anyTypeTO.getKey() + "'");
        throw new NotFoundException(anyTypeTO.getKey());
    }
    binder.update(anyType, anyTypeTO);
    anyType = anyTypeDAO.save(anyType);
    return binder.getAnyTypeTO(anyTypeDAO.save(anyType));
}
Also used : NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) AnyType(org.apache.syncope.core.persistence.api.entity.AnyType) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 29 with AnyType

use of org.apache.syncope.core.persistence.api.entity.AnyType in project syncope by apache.

the class JPAAnyTypeClassDAO method delete.

@Override
public void delete(final String key) {
    AnyTypeClass anyTypeClass = find(key);
    if (anyTypeClass == null) {
        return;
    }
    for (PlainSchema schema : plainSchemaDAO.findByAnyTypeClasses(Collections.singletonList(anyTypeClass))) {
        schema.setAnyTypeClass(null);
    }
    for (DerSchema schema : derSchemaDAO.findByAnyTypeClasses(Collections.singletonList(anyTypeClass))) {
        schema.setAnyTypeClass(null);
    }
    for (VirSchema schema : virSchemaDAO.findByAnyTypeClasses(Collections.singletonList(anyTypeClass))) {
        schema.setAnyTypeClass(null);
    }
    for (AnyType type : anyTypeDAO.findByTypeClass(anyTypeClass)) {
        type.getClasses().remove(anyTypeClass);
    }
    for (TypeExtension typeExt : groupDAO.findTypeExtensions(anyTypeClass)) {
        typeExt.getAuxClasses().remove(anyTypeClass);
        if (typeExt.getAuxClasses().isEmpty()) {
            typeExt.getGroup().getTypeExtensions().remove(typeExt);
            typeExt.setGroup(null);
        }
    }
    for (Provision provision : resourceDAO.findProvisionsByAuxClass(anyTypeClass)) {
        provision.getAuxClasses().remove(anyTypeClass);
    }
    entityManager().remove(anyTypeClass);
}
Also used : Provision(org.apache.syncope.core.persistence.api.entity.resource.Provision) DerSchema(org.apache.syncope.core.persistence.api.entity.DerSchema) VirSchema(org.apache.syncope.core.persistence.api.entity.VirSchema) TypeExtension(org.apache.syncope.core.persistence.api.entity.group.TypeExtension) PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema) AnyTypeClass(org.apache.syncope.core.persistence.api.entity.AnyTypeClass) JPAAnyTypeClass(org.apache.syncope.core.persistence.jpa.entity.JPAAnyTypeClass) AnyType(org.apache.syncope.core.persistence.api.entity.AnyType)

Example 30 with AnyType

use of org.apache.syncope.core.persistence.api.entity.AnyType in project syncope by apache.

the class AnyTypeTest method find.

@Test
public void find() {
    AnyType userType = anyTypeDAO.findUser();
    assertNotNull(userType);
    assertEquals(AnyTypeKind.USER, userType.getKind());
    assertEquals(AnyTypeKind.USER.name(), userType.getKey());
    assertFalse(userType.getClasses().isEmpty());
    AnyType groupType = anyTypeDAO.findGroup();
    assertNotNull(groupType);
    assertEquals(AnyTypeKind.GROUP, groupType.getKind());
    assertEquals(AnyTypeKind.GROUP.name(), groupType.getKey());
    assertFalse(groupType.getClasses().isEmpty());
    AnyType otherType = anyTypeDAO.find("PRINTER");
    assertNotNull(otherType);
    assertEquals(AnyTypeKind.ANY_OBJECT, otherType.getKind());
    assertEquals("PRINTER", otherType.getKey());
}
Also used : AnyType(org.apache.syncope.core.persistence.api.entity.AnyType) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Aggregations

AnyType (org.apache.syncope.core.persistence.api.entity.AnyType)35 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)13 NotFoundException (org.apache.syncope.core.persistence.api.dao.NotFoundException)9 ExternalResource (org.apache.syncope.core.persistence.api.entity.resource.ExternalResource)9 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)7 Collectors (java.util.stream.Collectors)6 AnyTypeDAO (org.apache.syncope.core.persistence.api.dao.AnyTypeDAO)6 AnyTypeClass (org.apache.syncope.core.persistence.api.entity.AnyTypeClass)6 Autowired (org.springframework.beans.factory.annotation.Autowired)6 Component (org.springframework.stereotype.Component)6 ArrayList (java.util.ArrayList)5 StringUtils (org.apache.commons.lang3.StringUtils)5 AnyTypeKind (org.apache.syncope.common.lib.types.AnyTypeKind)5 Realm (org.apache.syncope.core.persistence.api.entity.Realm)5 AnyObject (org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject)5 Group (org.apache.syncope.core.persistence.api.entity.group.Group)5 Provision (org.apache.syncope.core.persistence.api.entity.resource.Provision)5 AbstractTest (org.apache.syncope.core.persistence.jpa.AbstractTest)5 Test (org.junit.jupiter.api.Test)5 Map (java.util.Map)4