use of javax.validation.constraints.NotNull in project graylog2-server by Graylog2.
the class RestTools method buildExternalUri.
public static URI buildExternalUri(@NotNull MultivaluedMap<String, String> httpHeaders, @NotNull URI defaultUri) {
Optional<URI> externalUri = Optional.empty();
final List<String> headers = httpHeaders.get(HttpConfiguration.OVERRIDE_HEADER);
if (headers != null && !headers.isEmpty()) {
externalUri = headers.stream().filter(s -> {
try {
if (Strings.isNullOrEmpty(s)) {
return false;
}
final URI uri = new URI(s);
if (!uri.isAbsolute()) {
return true;
}
switch(uri.getScheme()) {
case "http":
case "https":
return true;
}
return false;
} catch (URISyntaxException e) {
return false;
}
}).map(URI::create).findFirst();
}
final URI uri = externalUri.orElse(defaultUri);
// Make sure we return an URI object with a trailing slash
if (!uri.toString().endsWith("/")) {
return URI.create(uri.toString() + "/");
}
return uri;
}
use of javax.validation.constraints.NotNull in project CzechIdMng by bcvsolutions.
the class SysRemoteServerController method getConnectorTypes.
/**
* Returns connector types registered on given remote server.
*
* @return connector types
*/
@ResponseBody
@RequestMapping(method = RequestMethod.GET, value = "/{backendId}/connector-types")
@PreAuthorize("hasAuthority('" + AccGroupPermission.REMOTESERVER_READ + "')")
@ApiOperation(value = "Get supported connector types", nickname = "getConnectorTypes", tags = { SysRemoteServerController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = AccGroupPermission.REMOTESERVER_READ, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = AccGroupPermission.REMOTESERVER_READ, description = "") }) })
public Resources<ConnectorTypeDto> getConnectorTypes(@ApiParam(value = "Remote server uuid identifier or code.", required = true) @PathVariable @NotNull String backendId) {
SysConnectorServerDto connectorServer = getDto(backendId);
if (connectorServer == null) {
throw new EntityNotFoundException(getService().getEntityClass(), backendId);
}
//
try {
List<IcConnectorInfo> connectorInfos = Lists.newArrayList();
for (IcConfigurationService config : icConfiguration.getIcConfigs().values()) {
connectorServer.setPassword(remoteServerService.getPassword(connectorServer.getId()));
Set<IcConnectorInfo> availableRemoteConnectors = config.getAvailableRemoteConnectors(connectorServer);
if (CollectionUtils.isNotEmpty(availableRemoteConnectors)) {
connectorInfos.addAll(availableRemoteConnectors);
}
}
// Find connector types for existing connectors.
List<ConnectorTypeDto> connectorTypes = connectorManager.getSupportedTypes().stream().filter(connectorType -> {
return connectorInfos.stream().anyMatch(connectorInfo -> connectorType.getConnectorName().equals(connectorInfo.getConnectorKey().getConnectorName()));
}).map(connectorType -> {
// Find connector info and set version to the connectorTypeDto.
IcConnectorInfo info = connectorInfos.stream().filter(connectorInfo -> connectorType.getConnectorName().equals(connectorInfo.getConnectorKey().getConnectorName())).findFirst().orElse(null);
ConnectorTypeDto connectorTypeDto = connectorManager.convertTypeToDto(connectorType);
connectorTypeDto.setLocal(true);
if (info != null) {
connectorTypeDto.setVersion(info.getConnectorKey().getBundleVersion());
connectorTypeDto.setName(info.getConnectorDisplayName());
}
return connectorTypeDto;
}).collect(Collectors.toList());
// Find connectors without extension (specific connector type).
List<ConnectorTypeDto> defaultConnectorTypes = connectorInfos.stream().map(info -> {
ConnectorTypeDto connectorTypeDto = connectorManager.convertIcConnectorInfoToDto(info);
connectorTypeDto.setLocal(true);
return connectorTypeDto;
}).filter(type -> {
return !connectorTypes.stream().anyMatch(supportedType -> supportedType.getConnectorName().equals(type.getConnectorName()) && supportedType.isHideParentConnector());
}).collect(Collectors.toList());
connectorTypes.addAll(defaultConnectorTypes);
return new Resources<>(connectorTypes.stream().sorted(Comparator.comparing(ConnectorTypeDto::getOrder)).collect(Collectors.toList()));
} catch (IcInvalidCredentialException e) {
throw new ResultCodeException(AccResultCode.REMOTE_SERVER_INVALID_CREDENTIAL, ImmutableMap.of("server", e.getHost() + ":" + e.getPort()), e);
} catch (IcServerNotFoundException e) {
throw new ResultCodeException(AccResultCode.REMOTE_SERVER_NOT_FOUND, ImmutableMap.of("server", e.getHost() + ":" + e.getPort()), e);
} catch (IcCantConnectException e) {
throw new ResultCodeException(AccResultCode.REMOTE_SERVER_CANT_CONNECT, ImmutableMap.of("server", e.getHost() + ":" + e.getPort()), e);
} catch (IcRemoteServerException e) {
throw new ResultCodeException(AccResultCode.REMOTE_SERVER_UNEXPECTED_ERROR, ImmutableMap.of("server", e.getHost() + ":" + e.getPort()), e);
}
}
use of javax.validation.constraints.NotNull in project mica2 by obiba.
the class AbstractGitPersistableService method findEntityState.
@NotNull
public T findEntityState(T1 gitPersistable, Supplier<T> stateSupplier) {
T defaultState;
if (gitPersistable.isNew()) {
defaultState = stateSupplier.get();
defaultState.setId(generateId(gitPersistable));
getEntityStateRepository().save(defaultState);
gitPersistable.setId(defaultState.getId());
return defaultState;
}
T existingState = getEntityStateRepository().findOne(gitPersistable.getId());
if (existingState == null) {
defaultState = stateSupplier.get();
defaultState.setId(gitPersistable.getId());
getEntityStateRepository().save(defaultState);
return defaultState;
}
return existingState;
}
use of javax.validation.constraints.NotNull in project mica2 by obiba.
the class UserProfileService method currentUserIs.
public boolean currentUserIs(@NotNull String role) {
org.apache.shiro.subject.Subject subject = SecurityUtils.getSubject();
if (subject == null || subject.getPrincipal() == null) {
return false;
}
String username = subject.getPrincipal().toString();
if (username.equals("administrator")) {
return true;
}
ObibaRealm.Subject profile = getProfile(username);
return profile != null && profile.getGroups() != null && profile.getGroups().stream().filter(g -> g.equals(role)).count() > 0;
}
use of javax.validation.constraints.NotNull in project mica2 by obiba.
the class AttachmentDtos method asFileDto.
@NotNull
Mica.FileDto asFileDto(AttachmentState state, boolean publishedFileSystem, boolean detailed) {
Mica.FileDto.Builder builder = asFileDto(state).toBuilder();
if (publishedFileSystem) {
builder.clearRevisionStatus();
Attachment attachment = state.getAttachment();
if (!Strings.isNullOrEmpty(attachment.getType()))
builder.setMediaType(attachment.getType());
if (attachment.getDescription() != null)
builder.addAllDescription(localizedStringDtos.asDto(attachment.getDescription()));
} else {
builder.setState(asDto(state, detailed));
builder.setPermissions(permissionsDtos.asDto(state));
}
if (builder.getType() == Mica.FileType.FOLDER) {
// get the number of files in the folder
builder.setSize(fileSystemService.countAttachmentStates(state.getPath(), publishedFileSystem));
}
return builder.build();
}
Aggregations