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();
}
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();
}
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());
}
}
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);
}
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));
}
Aggregations