use of java.util.Collections in project CzechIdMng by bcvsolutions.
the class DefaultIdmAuthorizationPolicyService method getDefaultPolicies.
@Override
@Transactional(readOnly = true)
public List<IdmAuthorizationPolicyDto> getDefaultPolicies(Class<? extends Identifiable> entityType) {
IdmRoleDto defaultRole = roleService.getDefaultRole();
if (defaultRole == null) {
LOG.debug("Default role not found, no default authorization policies will be added. Change configuration [{}].", IdmRoleService.PROPERTY_DEFAULT_ROLE);
return Collections.<IdmAuthorizationPolicyDto>emptyList();
}
if (defaultRole.isDisabled()) {
LOG.debug("Default role [{}] is disabled, no default authorization policies will be added.", defaultRole.getCode());
return Collections.<IdmAuthorizationPolicyDto>emptyList();
}
//
UUID defaultRoleId = defaultRole.getId();
IdmAuthorizationPolicyFilter filter = new IdmAuthorizationPolicyFilter();
filter.setDisabled(Boolean.FALSE);
if (entityType != null) {
// optional
filter.setAuthorizableType(entityType.getCanonicalName());
}
// default role policies
filter.setRoleId(defaultRoleId);
List<IdmAuthorizationPolicyDto> defaultPolicies = new ArrayList<>();
defaultPolicies.addAll(find(filter, null).getContent());
// all sub roles policies
roleCompositionService.findAllSubRoles(defaultRoleId).stream().filter(roleComposition -> {
IdmRoleDto subRole = DtoUtils.getEmbedded(roleComposition, IdmRoleComposition_.sub);
return !subRole.isDisabled();
}).forEach(roleComposition -> {
filter.setRoleId(roleComposition.getSub());
defaultPolicies.addAll(find(filter, null).getContent());
});
//
LOG.debug("Found [{}] default policies", defaultPolicies.size());
//
return defaultPolicies;
}
use of java.util.Collections in project cayenne by apache.
the class DataContextFactoryTest method testCreateDataContextWithDedicatedCache.
@Test
public void testCreateDataContextWithDedicatedCache() throws Exception {
final EventManager eventManager = new MockEventManager();
final DataDomain domain = new DataDomain("d1");
domain.setSharedCacheEnabled(false);
Module testModule = binder -> {
binder.bind(JdbcEventLogger.class).to(Slf4jJdbcEventLogger.class);
binder.bind(DataDomain.class).toInstance(domain);
binder.bind(EventManager.class).toInstance(eventManager);
binder.bind(QueryCache.class).toInstance(new MapQueryCache(5));
binder.bind(RuntimeProperties.class).toInstance(new DefaultRuntimeProperties(Collections.<String, String>emptyMap()));
binder.bind(ObjectMapRetainStrategy.class).to(DefaultObjectMapRetainStrategy.class);
binder.bind(ObjectStoreFactory.class).to(DefaultObjectStoreFactory.class);
binder.bind(TransactionFactory.class).to(DefaultTransactionFactory.class);
binder.bind(TransactionManager.class).to(DefaultTransactionManager.class);
binder.bind(DataRowStoreFactory.class).to(DefaultDataRowStoreFactory.class);
binder.bind(EventBridge.class).toProvider(NoopEventBridgeProvider.class);
binder.bind(DataRowStoreFactory.class).to(DefaultDataRowStoreFactory.class);
binder.bind(DataDomainFlushActionFactory.class).to(DefaultDataDomainFlushActionFactory.class);
binder.bind(DbRowOpSorter.class).to(DefaultDbRowOpSorter.class);
binder.bind(EntitySorter.class).to(AshwoodEntitySorter.class);
binder.bind(AdhocObjectFactory.class).to(DefaultAdhocObjectFactory.class);
binder.bind(ClassLoaderManager.class).to(DefaultClassLoaderManager.class);
};
Injector injector = DIBootstrap.createInjector(testModule);
DataContextFactory factory = new DataContextFactory();
injector.injectMembers(factory);
DataContext c3 = (DataContext) factory.createContext();
assertNotNull(c3.getObjectStore().getDataRowCache());
assertNull(domain.getSharedSnapshotCache());
assertNotSame(c3.getObjectStore().getDataRowCache(), domain.getSharedSnapshotCache());
}
use of java.util.Collections in project cayenne by apache.
the class DataChannelProjectSaverTest method testSaveAs.
@Test
public void testSaveAs() throws Exception {
FileProjectSaver saver = new FileProjectSaver(Collections.<ProjectExtension>emptyList());
Module testModule = binder -> {
binder.bind(ClassLoaderManager.class).to(DefaultClassLoaderManager.class);
binder.bind(AdhocObjectFactory.class).to(DefaultAdhocObjectFactory.class);
binder.bind(DataMapLoader.class).to(XMLDataMapLoader.class);
binder.bind(DataChannelDescriptorLoader.class).to(XMLDataChannelDescriptorLoader.class);
binder.bind(ProjectLoader.class).to(DataChannelProjectLoader.class);
binder.bind(ConfigurationNameMapper.class).to(DefaultConfigurationNameMapper.class);
binder.bind(HandlerFactory.class).to(DefaultHandlerFactory.class);
binder.bind(DataChannelMetaData.class).to(NoopDataChannelMetaData.class);
binder.bind(XMLReader.class).toProviderInstance(new XMLReaderProvider(false)).withoutScope();
};
Injector injector = DIBootstrap.createInjector(testModule);
injector.injectMembers(saver);
String testConfigName = "PROJECT2";
String baseUrl = getClass().getPackage().getName().replace('.', '/');
URL url = getClass().getClassLoader().getResource(baseUrl + "/cayenne-" + testConfigName + ".xml");
Resource source = new URLResource(url);
Project project = injector.getInstance(ProjectLoader.class).loadProject(source);
File outFile = setupTestDirectory("testSave");
saver.saveAs(project, new URLResource(outFile.toURI().toURL()));
File rootFile = new File(outFile, "cayenne-PROJECT2.xml");
assertTrue(rootFile.exists());
assertTrue(rootFile.length() > 0);
File map1File = new File(outFile, "testProjectMap2_1.map.xml");
assertTrue(map1File.exists());
assertTrue(map1File.length() > 0);
File map2File = new File(outFile, "testProjectMap2_2.map.xml");
assertTrue(map2File.exists());
assertTrue(map2File.length() > 0);
}
use of java.util.Collections in project sonarqube by SonarSource.
the class ShowAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
RuleKey key = RuleKey.parse(request.mandatoryParam(PARAM_KEY));
try (DbSession dbSession = dbClient.openSession(false)) {
RuleDto rule = dbClient.ruleDao().selectByKey(dbSession, key).orElseThrow(() -> new NotFoundException(format("Rule not found: %s", key)));
List<RuleDefinitionDto> templateRules = ofNullable(rule.getTemplateUuid()).flatMap(templateUuid -> dbClient.ruleDao().selectDefinitionByUuid(rule.getTemplateUuid(), dbSession)).map(Collections::singletonList).orElseGet(Collections::emptyList);
List<RuleParamDto> ruleParameters = dbClient.ruleDao().selectRuleParamsByRuleUuids(dbSession, singletonList(rule.getUuid()));
ShowResponse showResponse = buildResponse(dbSession, request, new SearchAction.SearchResult().setRules(singletonList(rule)).setTemplateRules(templateRules).setRuleParameters(ruleParameters).setTotal(1L));
writeProtobuf(showResponse, request, response);
}
}
use of java.util.Collections in project pravega by pravega.
the class BTreeIndex method get.
/**
* Looks up the value of multiple keys.
*
* @param keys A list of ByteArraySegments representing the keys to look up.
* @param timeout Timeout for the operation.
* @return A CompletableFuture that, when completed normally, will contain a List with ByteArraySegments representing
* the values associated with the given keys. The values in this list will be in the same order as the given Keys, so
* they can be matched to their sought keys by their index. If the operation failed, the Future
* will be completed with the appropriate exception.
*/
public CompletableFuture<List<ByteArraySegment>> get(@NonNull List<ByteArraySegment> keys, @NonNull Duration timeout) {
if (keys.size() == 1) {
// Shortcut for single key.
return get(keys.get(0), timeout).thenApply(Collections::singletonList);
}
// Lookup all the keys in parallel, and make sure to apply their resulting values in the same order that their keys
// where provided to us.
ensureInitialized();
TimeoutTimer timer = new TimeoutTimer(timeout);
PageCollection pageCollection = new PageCollection(this.state.length);
val gets = keys.stream().map(key -> locatePage(key, pageCollection, timer).thenApplyAsync(page -> page.getPage().searchExact(key), this.executor)).collect(Collectors.toList());
return Futures.allOfWithResults(gets);
}
Aggregations