Search in sources :

Example 6 with OrderByClause

use of org.apache.syncope.core.persistence.api.dao.search.OrderByClause in project syncope by apache.

the class ReportLogic method listExecutions.

@PreAuthorize("hasRole('" + StandardEntitlement.REPORT_READ + "')")
@Override
public Pair<Integer, List<ExecTO>> listExecutions(final String key, final int page, final int size, final List<OrderByClause> orderByClauses) {
    Report report = reportDAO.find(key);
    if (report == null) {
        throw new NotFoundException("Report " + key);
    }
    Integer count = reportExecDAO.count(key);
    List<ExecTO> result = reportExecDAO.findAll(report, page, size, orderByClauses).stream().map(reportExec -> binder.getExecTO(reportExec)).collect(Collectors.toList());
    return Pair.of(count, result);
}
Also used : ReportExecExportFormat(org.apache.syncope.common.lib.types.ReportExecExportFormat) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) Date(java.util.Date) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Autowired(org.springframework.beans.factory.annotation.Autowired) TextSerializer(org.apache.syncope.core.logic.cocoon.TextSerializer) ByteArrayInputStream(java.io.ByteArrayInputStream) Pair(org.apache.commons.lang3.tuple.Pair) Map(java.util.Map) XMLGenerator(org.apache.cocoon.sax.component.XMLGenerator) Method(java.lang.reflect.Method) Triple(org.apache.commons.lang3.tuple.Triple) XMLSerializer(org.apache.cocoon.sax.component.XMLSerializer) ExecTO(org.apache.syncope.common.lib.to.ExecTO) MimeConstants(org.apache.xmlgraphics.util.MimeConstants) BulkActionResult(org.apache.syncope.common.lib.to.BulkActionResult) JobNamer(org.apache.syncope.core.provisioning.api.job.JobNamer) Pipeline(org.apache.cocoon.pipeline.Pipeline) Collectors(java.util.stream.Collectors) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) StandardCharsets(java.nio.charset.StandardCharsets) IOUtils(org.apache.commons.io.IOUtils) EntityFactory(org.apache.syncope.core.persistence.api.entity.EntityFactory) List(java.util.List) JobAction(org.apache.syncope.common.lib.types.JobAction) ReportTO(org.apache.syncope.common.lib.to.ReportTO) ConfDAO(org.apache.syncope.core.persistence.api.dao.ConfDAO) XSLTTransformer(org.apache.syncope.core.logic.cocoon.XSLTTransformer) SAXPipelineComponent(org.apache.cocoon.sax.SAXPipelineComponent) StandardEntitlement(org.apache.syncope.common.lib.types.StandardEntitlement) ZipInputStream(java.util.zip.ZipInputStream) ReportExecStatus(org.apache.syncope.common.lib.types.ReportExecStatus) FopSerializer(org.apache.syncope.core.logic.cocoon.FopSerializer) StreamSource(javax.xml.transform.stream.StreamSource) OrderByClause(org.apache.syncope.core.persistence.api.dao.search.OrderByClause) HashMap(java.util.HashMap) ArrayUtils(org.apache.commons.lang3.ArrayUtils) JobKey(org.quartz.JobKey) ReportExecDAO(org.apache.syncope.core.persistence.api.dao.ReportExecDAO) SchedulerException(org.quartz.SchedulerException) ReportDataBinder(org.apache.syncope.core.provisioning.api.data.ReportDataBinder) ClientExceptionType(org.apache.syncope.common.lib.types.ClientExceptionType) JobTO(org.apache.syncope.common.lib.to.JobTO) OutputStream(java.io.OutputStream) Report(org.apache.syncope.core.persistence.api.entity.Report) ReportDAO(org.apache.syncope.core.persistence.api.dao.ReportDAO) NonCachingPipeline(org.apache.cocoon.pipeline.NonCachingPipeline) Component(org.springframework.stereotype.Component) ReportExec(org.apache.syncope.core.persistence.api.entity.ReportExec) JobType(org.apache.syncope.common.lib.types.JobType) Transactional(org.springframework.transaction.annotation.Transactional) ExecTO(org.apache.syncope.common.lib.to.ExecTO) Report(org.apache.syncope.core.persistence.api.entity.Report) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 7 with OrderByClause

use of org.apache.syncope.core.persistence.api.dao.search.OrderByClause in project syncope by apache.

the class AnySearchTest method groupOrderBy.

@Test
public void groupOrderBy() {
    AnyCond idLeafCond = new AnyCond(AnyCond.Type.LIKE);
    idLeafCond.setSchema("name");
    idLeafCond.setExpression("%r");
    SearchCond searchCondition = SearchCond.getLeafCond(idLeafCond);
    assertTrue(searchCondition.isValid());
    OrderByClause orderByClause = new OrderByClause();
    orderByClause.setField("name");
    List<Group> groups = searchDAO.search(searchCondition, Collections.singletonList(orderByClause), AnyTypeKind.GROUP);
    assertEquals(searchDAO.count(SyncopeConstants.FULL_ADMIN_REALMS, searchCondition, AnyTypeKind.GROUP), groups.size());
}
Also used : Group(org.apache.syncope.core.persistence.api.entity.group.Group) OrderByClause(org.apache.syncope.core.persistence.api.dao.search.OrderByClause) SearchCond(org.apache.syncope.core.persistence.api.dao.search.SearchCond) AnyCond(org.apache.syncope.core.persistence.api.dao.search.AnyCond) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Example 8 with OrderByClause

use of org.apache.syncope.core.persistence.api.dao.search.OrderByClause in project syncope by apache.

the class AnySearchTest method issueSYNCOPE983.

@Test
public void issueSYNCOPE983() {
    AttributeCond fullnameLeafCond = new AttributeCond(AttributeCond.Type.LIKE);
    fullnameLeafCond.setSchema("surname");
    fullnameLeafCond.setExpression("%o%");
    List<OrderByClause> orderByClauses = new ArrayList<>();
    OrderByClause orderByClause = new OrderByClause();
    orderByClause.setField("surname");
    orderByClause.setDirection(OrderByClause.Direction.ASC);
    orderByClauses.add(orderByClause);
    orderByClause = new OrderByClause();
    orderByClause.setField("username");
    orderByClause.setDirection(OrderByClause.Direction.DESC);
    orderByClauses.add(orderByClause);
    List<User> users = searchDAO.search(SyncopeConstants.FULL_ADMIN_REALMS, SearchCond.getLeafCond(fullnameLeafCond), -1, -1, orderByClauses, AnyTypeKind.USER);
    assertFalse(users.isEmpty());
}
Also used : OrderByClause(org.apache.syncope.core.persistence.api.dao.search.OrderByClause) User(org.apache.syncope.core.persistence.api.entity.user.User) AttributeCond(org.apache.syncope.core.persistence.api.dao.search.AttributeCond) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Example 9 with OrderByClause

use of org.apache.syncope.core.persistence.api.dao.search.OrderByClause in project syncope by apache.

the class AbstractService method doSearch.

@SuppressWarnings("unchecked")
protected ListResponse<R> doSearch(final Resource type, final SCIMSearchRequest request) {
    if (type == null) {
        throw new UnsupportedOperationException();
    }
    if (request.getCount() > confManager().get().getFilterMaxResults()) {
        throw new BadRequestException(ErrorType.tooMany, "Too many results requested");
    }
    SearchCondVisitor visitor = new SearchCondVisitor(type, confManager().get());
    int startIndex = request.getStartIndex() <= 1 ? 1 : (request.getStartIndex() / AnyDAO.DEFAULT_PAGE_SIZE) + 1;
    int itemsPerPage = request.getCount() <= 1 ? AnyDAO.DEFAULT_PAGE_SIZE : request.getCount();
    List<OrderByClause> sort;
    if (request.getSortBy() == null) {
        sort = Collections.<OrderByClause>emptyList();
    } else {
        OrderByClause clause = new OrderByClause();
        clause.setField(visitor.createAttributeCond(request.getSortBy()).getSchema());
        clause.setDirection(request.getSortOrder() == null || request.getSortOrder() == SortOrder.ascending ? OrderByClause.Direction.ASC : OrderByClause.Direction.DESC);
        sort = Collections.singletonList(clause);
    }
    Pair<Integer, ? extends List<? extends AnyTO>> result = anyLogic(type).search(StringUtils.isBlank(request.getFilter()) ? null : SearchCondConverter.convert(visitor, request.getFilter()), startIndex, itemsPerPage, sort, SyncopeConstants.ROOT_REALM, false);
    if (result.getLeft() > confManager().get().getFilterMaxResults()) {
        throw new BadRequestException(ErrorType.tooMany, "Too many results found");
    }
    ListResponse<R> response = new ListResponse<>(result.getLeft(), startIndex == 1 ? 1 : startIndex - 1, itemsPerPage);
    result.getRight().forEach(anyTO -> {
        SCIMResource resource = null;
        if (anyTO instanceof UserTO) {
            resource = binder().toSCIMUser((UserTO) anyTO, uriInfo.getAbsolutePathBuilder().path(anyTO.getKey()).build().toASCIIString(), request.getAttributes(), request.getExcludedAttributes());
        } else if (anyTO instanceof GroupTO) {
            resource = binder().toSCIMGroup((GroupTO) anyTO, uriInfo.getAbsolutePathBuilder().path(anyTO.getKey()).build().toASCIIString(), request.getAttributes(), request.getExcludedAttributes());
        }
        if (resource != null) {
            response.getResources().add((R) resource);
        }
    });
    return response;
}
Also used : SCIMResource(org.apache.syncope.ext.scimv2.api.data.SCIMResource) ListResponse(org.apache.syncope.ext.scimv2.api.data.ListResponse) GroupTO(org.apache.syncope.common.lib.to.GroupTO) OrderByClause(org.apache.syncope.core.persistence.api.dao.search.OrderByClause) UserTO(org.apache.syncope.common.lib.to.UserTO) BadRequestException(org.apache.syncope.ext.scimv2.api.BadRequestException) SearchCondVisitor(org.apache.syncope.core.logic.scim.SearchCondVisitor)

Example 10 with OrderByClause

use of org.apache.syncope.core.persistence.api.dao.search.OrderByClause in project syncope by apache.

the class ResourceTest method delete.

@Test
public void delete() {
    ExternalResource resource = resourceDAO.find("resource-testdb");
    assertNotNull(resource);
    // -------------------------------------
    // Get originally associated connector
    // -------------------------------------
    ConnInstance connector = resource.getConnector();
    assertNotNull(connector);
    // -------------------------------------
    // -------------------------------------
    // Get originally associated users
    // -------------------------------------
    List<User> users = userDAO.findByResource(resource);
    assertNotNull(users);
    Set<String> userKeys = users.stream().map(Entity::getKey).collect(Collectors.toSet());
    // -------------------------------------
    // Get tasks
    List<PropagationTask> propagationTasks = taskDAO.findAll(TaskType.PROPAGATION, resource, null, null, null, -1, -1, Collections.<OrderByClause>emptyList());
    assertFalse(propagationTasks.isEmpty());
    // delete resource
    resourceDAO.delete(resource.getKey());
    // close the transaction
    resourceDAO.flush();
    // resource must be removed
    ExternalResource actual = resourceDAO.find("resource-testdb");
    assertNull(actual);
    // resource must be not referenced any more from users
    userKeys.stream().map(key -> userDAO.find(key)).map(actualUser -> {
        assertNotNull(actualUser);
        return actualUser;
    }).forEachOrdered((actualUser) -> {
        userDAO.findAllResources(actualUser).forEach(res -> assertFalse(res.getKey().equalsIgnoreCase(resource.getKey())));
    });
    // resource must be not referenced any more from the connector
    ConnInstance actualConnector = connInstanceDAO.find(connector.getKey());
    assertNotNull(actualConnector);
    actualConnector.getResources().forEach(res -> assertFalse(res.getKey().equalsIgnoreCase(resource.getKey())));
    // there must be no tasks
    propagationTasks.forEach(task -> assertNull(taskDAO.find(task.getKey())));
}
Also used : JPAMappingItem(org.apache.syncope.core.persistence.jpa.entity.resource.JPAMappingItem) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) OrderByClause(org.apache.syncope.core.persistence.api.dao.search.OrderByClause) Autowired(org.springframework.beans.factory.annotation.Autowired) Entity(org.apache.syncope.core.persistence.api.entity.Entity) PropagationTask(org.apache.syncope.core.persistence.api.entity.task.PropagationTask) TaskDAO(org.apache.syncope.core.persistence.api.dao.TaskDAO) PasswordPolicy(org.apache.syncope.core.persistence.api.entity.policy.PasswordPolicy) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) JPAOrgUnit(org.apache.syncope.core.persistence.jpa.entity.resource.JPAOrgUnit) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Mapping(org.apache.syncope.core.persistence.api.entity.resource.Mapping) UserDAO(org.apache.syncope.core.persistence.api.dao.UserDAO) Set(java.util.Set) User(org.apache.syncope.core.persistence.api.entity.user.User) ConnInstanceDAO(org.apache.syncope.core.persistence.api.dao.ConnInstanceDAO) Collectors(java.util.stream.Collectors) AnyTypeDAO(org.apache.syncope.core.persistence.api.dao.AnyTypeDAO) ConnInstance(org.apache.syncope.core.persistence.api.entity.ConnInstance) MappingItem(org.apache.syncope.core.persistence.api.entity.resource.MappingItem) Test(org.junit.jupiter.api.Test) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) List(java.util.List) Provision(org.apache.syncope.core.persistence.api.entity.resource.Provision) MappingPurpose(org.apache.syncope.common.lib.types.MappingPurpose) ObjectClass(org.identityconnectors.framework.common.objects.ObjectClass) PolicyDAO(org.apache.syncope.core.persistence.api.dao.PolicyDAO) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) VirSchemaDAO(org.apache.syncope.core.persistence.api.dao.VirSchemaDAO) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest) Collections(java.util.Collections) ExternalResourceDAO(org.apache.syncope.core.persistence.api.dao.ExternalResourceDAO) TaskType(org.apache.syncope.common.lib.types.TaskType) Transactional(org.springframework.transaction.annotation.Transactional) User(org.apache.syncope.core.persistence.api.entity.user.User) PropagationTask(org.apache.syncope.core.persistence.api.entity.task.PropagationTask) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) ConnInstance(org.apache.syncope.core.persistence.api.entity.ConnInstance) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Aggregations

OrderByClause (org.apache.syncope.core.persistence.api.dao.search.OrderByClause)19 Collectors (java.util.stream.Collectors)6 ArrayList (java.util.ArrayList)5 List (java.util.List)5 SearchCond (org.apache.syncope.core.persistence.api.dao.search.SearchCond)5 Method (java.lang.reflect.Method)4 ArrayUtils (org.apache.commons.lang3.ArrayUtils)4 Pair (org.apache.commons.lang3.tuple.Pair)4 ExternalResourceDAO (org.apache.syncope.core.persistence.api.dao.ExternalResourceDAO)4 NotFoundException (org.apache.syncope.core.persistence.api.dao.NotFoundException)4 AbstractTest (org.apache.syncope.core.persistence.jpa.AbstractTest)4 Test (org.junit.jupiter.api.Test)4 Autowired (org.springframework.beans.factory.annotation.Autowired)4 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)4 Component (org.springframework.stereotype.Component)4 Transactional (org.springframework.transaction.annotation.Transactional)4 Map (java.util.Map)3 StringUtils (org.apache.commons.lang3.StringUtils)3 Triple (org.apache.commons.lang3.tuple.Triple)3 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)3