Search in sources :

Example 41 with Sort

use of org.springframework.data.domain.Sort in project CzechIdMng by bcvsolutions.

the class DefaultAttachmentManager method getAttachmentVersions.

@Override
@Transactional
public List<IdmAttachmentDto> getAttachmentVersions(UUID attachmentId, BasePermission... permission) {
    Assert.notNull(attachmentId);
    // 
    IdmAttachmentFilter filter = new IdmAttachmentFilter();
    filter.setVersionsFor(attachmentId);
    // 
    return find(filter, new PageRequest(0, Integer.MAX_VALUE, new Sort(Direction.DESC, IdmAttachment_.versionNumber.getName())), permission).getContent();
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) Sort(org.springframework.data.domain.Sort) IdmAttachmentFilter(eu.bcvsolutions.idm.core.ecm.api.dto.filter.IdmAttachmentFilter) Transactional(org.springframework.transaction.annotation.Transactional)

Example 42 with Sort

use of org.springframework.data.domain.Sort in project CzechIdMng by bcvsolutions.

the class DefaultAttachmentManager method findLastVersionByOwnerAndName.

private List<IdmAttachmentDto> findLastVersionByOwnerAndName(String ownerType, UUID ownerId, String name, BasePermission... permission) {
    Assert.notNull(ownerType, "Insert type of owner");
    Assert.notNull(ownerId, "Insert ID of owner");
    Assert.notNull(name, "Insert name of attachment");
    // 
    IdmAttachmentFilter filter = new IdmAttachmentFilter();
    filter.setOwnerType(ownerType);
    filter.setOwnerId(ownerId);
    filter.setName(name);
    filter.setLastVersionOnly(Boolean.TRUE);
    // 
    return find(filter, new PageRequest(0, Integer.MAX_VALUE, new Sort(Direction.ASC, IdmAttachment_.name.getName())), permission).getContent();
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) Sort(org.springframework.data.domain.Sort) IdmAttachmentFilter(eu.bcvsolutions.idm.core.ecm.api.dto.filter.IdmAttachmentFilter)

Example 43 with Sort

use of org.springframework.data.domain.Sort in project CzechIdMng by bcvsolutions.

the class ExecuteScriptTaskExecutorTest method testExeciteScriptWithResult.

@Test
public void testExeciteScriptWithResult() {
    // remove previous long running task
    List<IdmLongRunningTaskDto> tasks = longRunningTaskService.find(null).getContent();
    for (IdmLongRunningTaskDto task : tasks) {
        longRunningTaskService.delete(task);
    }
    IdmScriptDto scriptDto = new IdmScriptDto();
    scriptDto.setCode(TEST_SCRIPT_CODE + "_3");
    scriptDto.setName(TEST_SCRIPT_CODE + "_3");
    scriptDto.setCategory(IdmScriptCategory.SYSTEM);
    StringBuilder builder = new StringBuilder();
    builder.append("import eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto;\n");
    builder.append("task.setCounter(0l);\n");
    builder.append("task.setCount(5l);\n");
    builder.append("for (int index = 0; index < 5; index++) {\n");
    builder.append("    IdmIdentityDto dto = new IdmIdentityDto();\n");
    builder.append("    dto.setUsername('test-execute-' + index);\n");
    builder.append("    dto.setLastName('test-execute-' + index);\n");
    builder.append("    dto.setFirstName('' + index);\n");
    builder.append("    identityService.save(dto);\n");
    builder.append("    task.increaseCounter();\n");
    builder.append("    task.updateState();\n");
    builder.append("}\n");
    scriptDto.setScript(builder.toString());
    scriptDto = scriptService.save(scriptDto);
    prepareAuthForTestScript(scriptDto);
    IdmScriptAuthorityDto authDto = new IdmScriptAuthorityDto();
    authDto.setType(ScriptAuthorityType.SERVICE);
    authDto.setClassName("eu.bcvsolutions.idm.core.model.service.impl.DefaultIdmIdentityService");
    authDto.setScript(scriptDto.getId());
    authDto.setService("identityService");
    scriptAuthorityService.save(authDto);
    authDto = new IdmScriptAuthorityDto();
    authDto.setType(ScriptAuthorityType.CLASS_NAME);
    authDto.setClassName("eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto");
    authDto.setScript(scriptDto.getId());
    scriptAuthorityService.save(authDto);
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("scriptCode", TEST_SCRIPT_CODE + "_3");
    taskExecutor.init(parameters);
    LongRunningFutureTask<Boolean> futureTask = manager.execute(taskExecutor);
    try {
        assertEquals(Boolean.TRUE, futureTask.getFutureTask().get());
    } catch (InterruptedException | ExecutionException e) {
        fail(e.getMessage());
    }
    IdmLongRunningTaskDto longRunningTask = longRunningTaskService.get(taskExecutor.getLongRunningTaskId());
    assertEquals(OperationState.EXECUTED, longRunningTask.getResult().getState());
    assertEquals(5, longRunningTask.getCount().longValue());
    assertEquals(5, longRunningTask.getCounter().longValue());
    IdmIdentityFilter identityFilter = new IdmIdentityFilter();
    identityFilter.setText("test-execute-");
    List<IdmIdentityDto> identities = identityService.find(identityFilter, new PageRequest(0, 20, new Sort(Direction.ASC, IdmIdentity_.firstName.getName()))).getContent();
    assertEquals(5, identities.size());
    for (int index = 0; index < 5; index++) {
        assertEquals(String.valueOf(index), identities.get(index).getFirstName());
    }
}
Also used : IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) HashMap(java.util.HashMap) IdmScriptAuthorityDto(eu.bcvsolutions.idm.core.api.dto.IdmScriptAuthorityDto) IdmIdentityFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter) PageRequest(org.springframework.data.domain.PageRequest) IdmScriptDto(eu.bcvsolutions.idm.core.api.dto.IdmScriptDto) Sort(org.springframework.data.domain.Sort) ExecutionException(java.util.concurrent.ExecutionException) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 44 with Sort

use of org.springframework.data.domain.Sort in project spring-data-mongodb by spring-projects.

the class UpdateMapper method getMappedModifier.

private Object getMappedModifier(@Nullable Field field, Modifier modifier) {
    Object value = modifier.getValue();
    if (value instanceof Sort) {
        Document sortObject = getSortObject((Sort) value);
        return field == null || field.getPropertyEntity() == null ? sortObject : getMappedSort(sortObject, field.getPropertyEntity());
    }
    TypeInformation<?> typeHint = field == null ? ClassTypeInformation.OBJECT : field.getTypeHint();
    return converter.convertToMongoType(value, typeHint);
}
Also used : Sort(org.springframework.data.domain.Sort) Document(org.bson.Document)

Example 45 with Sort

use of org.springframework.data.domain.Sort in project spring-data-mongodb by spring-projects.

the class IndexEnsuringQueryCreationListener method onCreation.

/*
	 * (non-Javadoc)
	 * @see org.springframework.data.repository.core.support.QueryCreationListener#onCreation(org.springframework.data.repository.query.RepositoryQuery)
	 */
public void onCreation(PartTreeMongoQuery query) {
    PartTree tree = query.getTree();
    if (!tree.hasPredicate()) {
        return;
    }
    Index index = new Index();
    index.named(query.getQueryMethod().getName());
    Sort sort = tree.getSort();
    for (Part part : tree.getParts()) {
        if (GEOSPATIAL_TYPES.contains(part.getType())) {
            return;
        }
        String property = part.getProperty().toDotPath();
        Direction order = toDirection(sort, property);
        index.on(property, order);
    }
    // Add fixed sorting criteria to index
    if (sort.isSorted()) {
        for (Order order : sort) {
            index.on(order.getProperty(), order.getDirection());
        }
    }
    MongoEntityMetadata<?> metadata = query.getQueryMethod().getEntityInformation();
    indexOperationsProvider.indexOps(metadata.getCollectionName()).ensureIndex(index);
    LOG.debug(String.format("Created %s!", index));
}
Also used : Order(org.springframework.data.domain.Sort.Order) Part(org.springframework.data.repository.query.parser.Part) Sort(org.springframework.data.domain.Sort) Index(org.springframework.data.mongodb.core.index.Index) PartTree(org.springframework.data.repository.query.parser.PartTree) Direction(org.springframework.data.domain.Sort.Direction)

Aggregations

Sort (org.springframework.data.domain.Sort)49 PageRequest (org.springframework.data.domain.PageRequest)29 Pageable (org.springframework.data.domain.Pageable)14 ArrayList (java.util.ArrayList)13 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)7 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)5 List (java.util.List)5 Order (org.springframework.data.domain.Sort.Order)5 BooleanBuilder (com.querydsl.core.BooleanBuilder)4 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)4 Collectors (java.util.stream.Collectors)4 EntityNotFoundException (javax.persistence.EntityNotFoundException)4 ApiOperation (io.swagger.annotations.ApiOperation)3 Date (java.util.Date)3 PageImpl (org.springframework.data.domain.PageImpl)3 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)2 Commentable (com.odysseusinc.arachne.portal.api.v1.dto.Commentable)2 SubmissionInsightDTO (com.odysseusinc.arachne.portal.api.v1.dto.SubmissionInsightDTO)2 CommentTopic (com.odysseusinc.arachne.portal.model.CommentTopic)2 SubmissionInsight (com.odysseusinc.arachne.portal.model.SubmissionInsight)2