use of org.springframework.web.bind.annotation.PathVariable in project scoold by Erudika.
the class ApiController method getPostRevisions.
@GetMapping("/posts/{id}/revisions")
public List<Map<String, Object>> getPostRevisions(@PathVariable String id, HttpServletRequest req, HttpServletResponse res) {
Model model = new ExtendedModelMap();
revisionsController.get(id, req, res, model);
Post post = (Post) model.getAttribute("showPost");
if (post == null) {
res.setStatus(HttpStatus.NOT_FOUND.value());
return null;
}
return ((List<Revision>) model.getAttribute("revisionslist")).stream().map(r -> {
Map<String, Object> rev = new LinkedHashMap<>(ParaObjectUtils.getAnnotatedFields(r, false));
rev.put("author", r.getAuthor());
return rev;
}).collect(Collectors.toList());
}
use of org.springframework.web.bind.annotation.PathVariable in project scoold by Erudika.
the class ProfileController method get.
@GetMapping({ "", "/{id}/**" })
public String get(@PathVariable(required = false) String id, HttpServletRequest req, Model model) {
if (!utils.isAuthenticated(req) && StringUtils.isBlank(id)) {
return "redirect:" + SIGNINLINK + "?returnto=" + PROFILELINK;
}
Profile authUser = utils.getAuthUser(req);
Profile showUser;
boolean isMyProfile;
if (StringUtils.isBlank(id) || isMyid(authUser, Profile.id(id))) {
// requested userid !exists or = my userid => show my profile
showUser = authUser;
isMyProfile = true;
} else {
showUser = utils.getParaClient().read(Profile.id(id));
isMyProfile = isMyid(authUser, Profile.id(id));
}
if (showUser == null || !ParaObjectUtils.typesMatch(showUser)) {
return "redirect:" + PROFILELINK;
}
boolean protekted = !utils.isDefaultSpacePublic() && !utils.isAuthenticated(req);
boolean sameSpace = (utils.canAccessSpace(showUser, "default") && utils.canAccessSpace(authUser, "default")) || (authUser != null && showUser.getSpaces().stream().anyMatch(s -> utils.canAccessSpace(authUser, s)));
if (protekted || !sameSpace) {
return "redirect:" + PEOPLELINK;
}
Pager itemcount1 = utils.getPager("page1", req);
Pager itemcount2 = utils.getPager("page2", req);
List<? extends Post> questionslist = getQuestions(authUser, showUser, isMyProfile, itemcount1);
List<? extends Post> answerslist = getAnswers(authUser, showUser, isMyProfile, itemcount2);
model.addAttribute("path", "profile.vm");
model.addAttribute("title", utils.getLang(req).get("profile.title") + " - " + showUser.getName());
model.addAttribute("description", getUserDescription(showUser, itemcount1.getCount(), itemcount2.getCount()));
model.addAttribute("ogimage", avatarRepository.getLink(showUser, AvatarFormat.Profile));
model.addAttribute("includeGMapsScripts", utils.isNearMeFeatureEnabled());
model.addAttribute("showUser", showUser);
model.addAttribute("isMyProfile", isMyProfile);
model.addAttribute("badgesCount", showUser.getBadgesMap().size());
model.addAttribute("canEdit", isMyProfile || canEditProfile(authUser, id));
model.addAttribute("canEditAvatar", Config.getConfigBoolean("avatar_edits_enabled", true));
model.addAttribute("gravatarPicture", gravatarAvatarGenerator.getLink(showUser, AvatarFormat.Profile));
model.addAttribute("isGravatarPicture", gravatarAvatarGenerator.isLink(showUser.getPicture()));
model.addAttribute("itemcount1", itemcount1);
model.addAttribute("itemcount2", itemcount2);
model.addAttribute("questionslist", questionslist);
model.addAttribute("answerslist", answerslist);
model.addAttribute("nameEditsAllowed", Config.getConfigBoolean("name_edits_enabled", true));
return "base";
}
use of org.springframework.web.bind.annotation.PathVariable in project ontrack by nemerosa.
the class ProjectEntityExtensionController method getInformation.
/**
* Gets the list of information extensions for an entity
*/
@RequestMapping(value = "information/{entityType}/{id}", method = RequestMethod.GET)
public Resources<EntityInformation> getInformation(@PathVariable ProjectEntityType entityType, @PathVariable ID id) {
// Gets the entity
ProjectEntity entity = getEntity(entityType, id);
// List of informations to return
List<EntityInformation> informations = extensionManager.getExtensions(EntityInformationExtension.class).stream().map(x -> x.getInformation(entity)).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList());
// OK
return Resources.of(informations, uri(MvcUriComponentsBuilder.on(getClass()).getInformation(entityType, id)));
}
use of org.springframework.web.bind.annotation.PathVariable 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 org.springframework.web.bind.annotation.PathVariable in project zhcet-web by zhcet-amu.
the class CoursesController method getCourses.
@GetMapping
public String getCourses(Model model, @PathVariable Department department, @RequestParam(value = "all", required = false) Boolean all) {
ErrorUtils.requireNonNullDepartment(department);
// Determine if only active courses have to be should
boolean active = !(all != null && all);
model.addAttribute("page_description", "View and manage courses for the Department");
model.addAttribute("department", department);
model.addAttribute("page_title", "Courses : " + department.getName() + " Department");
model.addAttribute("page_subtitle", "Course Management");
model.addAttribute("page_path", getPath(department));
model.addAttribute("all", !active);
List<FloatedCourse> floatedCourses = floatedCourseService.getCurrentFloatedCourses(department);
List<Course> courses = courseService.getAllActiveCourse(department, active);
// Add meta tag and no of registrations to each course
for (FloatedCourse floatedCourse : floatedCourses) {
Stream.of(floatedCourse).map(FloatedCourse::getCourse).map(courses::indexOf).filter(index -> index != -1).map(courses::get).findFirst().ifPresent(course -> {
course.setMeta("Floated");
course.setRegistrations(floatedCourse.getCourseRegistrations().size());
});
}
SortUtils.sortCourses(courses);
model.addAttribute("courses", courses);
return "department/courses";
}
Aggregations