use of javax.ws.rs.core.EntityTag in project syncope by apache.
the class SyncopeEnduserSession method getService.
public <T> T getService(final String etag, final Class<T> serviceClass) {
T serviceInstance = getService(serviceClass);
WebClient.client(serviceInstance).match(new EntityTag(etag), false).type(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON);
return serviceInstance;
}
use of javax.ws.rs.core.EntityTag in project OpenOLAT by OpenOLAT.
the class RepositoryEntryResource method getById.
/**
* get a resource in the repository
* @response.representation.200.qname {http://www.example.com}repositoryEntryVO
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc Get the repository resource
* @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_REPOENTRYVO}
* @response.representation.404.doc The repository entry not found
* @param repoEntryKey The key or soft key of the repository entry
* @param request The REST request
* @return
*/
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getById(@PathParam("repoEntryKey") String repoEntryKey, @Context Request request) {
RepositoryEntry re = lookupRepositoryEntry(repoEntryKey);
if (re == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
Date lastModified = re.getLastModified();
Response.ResponseBuilder response;
if (lastModified == null) {
EntityTag eTag = ObjectFactory.computeEtag(re);
response = request.evaluatePreconditions(eTag);
if (response == null) {
RepositoryEntryVO vo = ObjectFactory.get(re);
response = Response.ok(vo).tag(eTag).lastModified(lastModified);
}
} else {
EntityTag eTag = ObjectFactory.computeEtag(re);
response = request.evaluatePreconditions(lastModified, eTag);
if (response == null) {
RepositoryEntryVO vo = ObjectFactory.get(re);
response = Response.ok(vo).tag(eTag).lastModified(lastModified);
}
}
return response.build();
}
use of javax.ws.rs.core.EntityTag in project muikku by otavanopisto.
the class UserRESTService method findStudent.
@GET
@Path("/students/{ID}")
@RESTPermit(handling = Handling.INLINE)
public Response findStudent(@Context Request request, @PathParam("ID") String id) {
if (!sessionController.isLoggedIn()) {
return Response.status(Status.FORBIDDEN).build();
}
SchoolDataIdentifier studentIdentifier = SchoolDataIdentifier.fromId(id);
if (studentIdentifier == null) {
return Response.status(Response.Status.BAD_REQUEST).entity(String.format("Invalid studentIdentifier %s", id)).build();
}
UserEntity userEntity = userEntityController.findUserEntityByUserIdentifier(studentIdentifier);
if (userEntity == null) {
return Response.status(Status.NOT_FOUND).entity("UserEntity not found").build();
}
// Bug fix #2966: REST endpoint should only return students
EnvironmentUser environmentUser = environmentUserController.findEnvironmentUserByUserEntity(userEntity);
if (environmentUser != null) {
EnvironmentRoleEntity userRole = environmentUser.getRole();
if (userRole == null || userRole.getArchetype() != EnvironmentRoleArchetype.STUDENT) {
return Response.status(Status.NOT_FOUND).build();
}
}
EntityTag tag = new EntityTag(DigestUtils.md5Hex(String.valueOf(userEntity.getVersion())));
ResponseBuilder builder = request.evaluatePreconditions(tag);
if (builder != null) {
return builder.build();
}
CacheControl cacheControl = new CacheControl();
cacheControl.setMustRevalidate(true);
// TODO: There's no permission handling, this is relying on schooldatacontroller to check for permission
User user = userController.findUserByIdentifier(studentIdentifier);
if (user == null) {
return Response.status(Status.NOT_FOUND).entity("User not found").build();
}
String emailAddress = userEmailEntityController.getUserDefaultEmailAddress(userEntity, true);
Date studyStartDate = user.getStudyStartDate() != null ? Date.from(user.getStudyStartDate().toInstant()) : null;
Date studyEndDate = user.getStudyEndDate() != null ? Date.from(user.getStudyEndDate().toInstant()) : null;
Date studyTimeEnd = user.getStudyTimeEnd() != null ? Date.from(user.getStudyTimeEnd().toInstant()) : null;
Student student = new Student(studentIdentifier.toId(), user.getFirstName(), user.getLastName(), user.getNickName(), user.getStudyProgrammeName(), false, user.getNationality(), user.getLanguage(), user.getMunicipality(), user.getSchool(), emailAddress, studyStartDate, studyEndDate, studyTimeEnd, user.getCurriculumIdentifier(), userEntity.getUpdatedByStudent());
return Response.ok(student).cacheControl(cacheControl).tag(tag).build();
}
use of javax.ws.rs.core.EntityTag in project muikku by otavanopisto.
the class MetaRESTService method getResources.
@GET
@Path("/resources")
@RESTPermit(handling = Handling.UNSECURED)
public Response getResources(@Context Request request, @QueryParam("format") String format) {
EntityTag tag = new EntityTag(ETAG);
ResponseBuilder builder = request.evaluatePreconditions(tag);
if (builder != null) {
return builder.build();
}
List<String> resources = new ArrayList<>();
ResourceMethodRegistry registry = (ResourceMethodRegistry) dispatcher.getRegistry();
Set<Entry<String, java.util.List<org.jboss.resteasy.core.ResourceInvoker>>> entries = registry.getBounded().entrySet();
for (Entry<String, java.util.List<org.jboss.resteasy.core.ResourceInvoker>> entry : entries) {
String path = entry.getKey();
resources.add(path);
}
CacheControl cacheControl = new CacheControl();
cacheControl.setMaxAge(-1);
cacheControl.setPrivate(false);
cacheControl.setMustRevalidate(false);
Collections.sort(resources);
if (StringUtils.isNotBlank(format) && "js".equals(format)) {
try {
return Response.ok(String.format("var META_RESOURCES = %s", new ObjectMapper().writeValueAsString(resources)), "text/javascript").cacheControl(cacheControl).tag(tag).build();
} catch (JsonProcessingException e) {
return Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
}
} else {
return Response.ok(resources).cacheControl(cacheControl).tag(tag).build();
}
}
use of javax.ws.rs.core.EntityTag in project muikku by otavanopisto.
the class ForumRESTService method findArea.
@GET
@Path("/areas/{AREAID}")
@RESTPermit(handling = Handling.INLINE)
public Response findArea(@Context Request request, @PathParam("AREAID") Long areaId) {
ForumArea forumArea = forumController.getForumArea(areaId);
if (forumArea != null) {
if (!(forumArea instanceof EnvironmentForumArea)) {
logger.severe(String.format("Trying to access forum %d via incorrect REST endpoint", forumArea.getId()));
return Response.status(Status.NOT_FOUND).build();
}
if (sessionController.hasEnvironmentPermission(ForumResourcePermissionCollection.FORUM_ACCESSENVIRONMENTFORUM)) {
Long numThreads = forumController.getThreadCount(forumArea);
EntityTag tag = new EntityTag(DigestUtils.md5Hex(String.valueOf(forumArea.getVersion()) + String.valueOf(numThreads)));
ResponseBuilder builder = request.evaluatePreconditions(tag);
if (builder != null) {
return builder.build();
}
CacheControl cacheControl = new CacheControl();
cacheControl.setMustRevalidate(true);
ForumAreaRESTModel result = new ForumAreaRESTModel(forumArea.getId(), forumArea.getName(), forumArea.getDescription(), forumArea.getGroup() != null ? forumArea.getGroup().getId() : null, numThreads);
return Response.ok(result).cacheControl(cacheControl).tag(tag).build();
} else {
return Response.status(Status.FORBIDDEN).build();
}
} else {
return Response.status(Status.NOT_FOUND).build();
}
}
Aggregations