use of javax.ws.rs.core.PathSegment in project OpenOLAT by OpenOLAT.
the class CourseResourceFolderWebService method attachFileToCourseFolder.
private Response attachFileToCourseFolder(Long courseId, List<PathSegment> path, String filename, InputStream file, HttpServletRequest request) {
if (!isAuthor(request)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
ICourse course = CoursesWebService.loadCourse(courseId);
if (course == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
VFSContainer container = course.getCourseFolderContainer();
for (PathSegment segment : path) {
VFSItem item = container.resolve(segment.getPath());
if (item instanceof VFSContainer) {
container = (VFSContainer) item;
} else if (item == null) {
// create the folder
container = container.createChildContainer(segment.getPath());
}
}
VFSItem newFile;
UserRequest ureq = RestSecurityHelper.getUserRequest(request);
if (container.resolve(filename) != null) {
VFSItem existingVFSItem = container.resolve(filename);
if (existingVFSItem instanceof VFSContainer) {
// already exists
return Response.ok().build();
}
// check if it's locked
boolean locked = CoreSpringFactory.getImpl(VFSLockManager.class).isLockedForMe(existingVFSItem, ureq.getIdentity(), ureq.getUserSession().getRoles());
if (locked) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
if (existingVFSItem instanceof Versionable && ((Versionable) existingVFSItem).getVersions().isVersioned()) {
Versionable existingVersionableItem = (Versionable) existingVFSItem;
boolean ok = existingVersionableItem.getVersions().addVersion(ureq.getIdentity(), "REST upload", file);
if (ok) {
log.audit("");
}
newFile = (VFSLeaf) existingVersionableItem;
} else {
existingVFSItem.delete();
newFile = container.createChildLeaf(filename);
OutputStream out = ((VFSLeaf) newFile).getOutputStream(false);
FileUtils.copy(file, out);
FileUtils.closeSafely(out);
FileUtils.closeSafely(file);
}
} else if (file != null) {
newFile = container.createChildLeaf(filename);
OutputStream out = ((VFSLeaf) newFile).getOutputStream(false);
FileUtils.copy(file, out);
FileUtils.closeSafely(out);
FileUtils.closeSafely(file);
} else {
newFile = container.createChildContainer(filename);
}
if (newFile instanceof MetaTagged && ((MetaTagged) newFile).getMetaInfo() != null) {
MetaInfo infos = ((MetaTagged) newFile).getMetaInfo();
infos.setAuthor(ureq.getIdentity());
infos.write();
}
return Response.ok().build();
}
use of javax.ws.rs.core.PathSegment in project OpenOLAT by OpenOLAT.
the class CatalogWebService method getCatalogEntryKeyFromPath.
private Long getCatalogEntryKeyFromPath(List<PathSegment> path) {
PathSegment lastPath = path.get(path.size() - 1);
Long key = null;
try {
key = new Long(lastPath.getPath());
} catch (NumberFormatException e) {
key = null;
}
return key;
}
use of javax.ws.rs.core.PathSegment in project microservice_framework by CJSCommonPlatform.
the class UrlLinkFactoryTest method shouldReturnEventStreamsHeadUrlLink.
@SuppressWarnings("unchecked")
@Test
public void shouldReturnEventStreamsHeadUrlLink() throws Exception {
final UUID streamId = UUID.randomUUID();
final String eventStreamPathSegmentValue = "eventstreams";
final String baseURI = "http://localhost:8080/context/";
final String urlString = baseURI + "/HEAD/BACKWARD/2";
final int pageSize = 2;
final UriInfo uriInfo = mock(UriInfo.class);
final UriBuilder uriBuilder = mock(UriBuilder.class);
final List<PathSegment> pathSegmentList = mock(List.class);
final PathSegment eventStreamPathSegment = mock(PathSegment.class);
final PathSegment streamIdPathSegment = mock(PathSegment.class);
when(uriInfo.getBaseUriBuilder()).thenReturn(uriBuilder);
when(uriInfo.getPathSegments()).thenReturn(pathSegmentList);
when(pathSegmentList.get(0)).thenReturn(eventStreamPathSegment);
when(eventStreamPathSegment.getPath()).thenReturn(eventStreamPathSegmentValue);
when(pathSegmentList.get(1)).thenReturn(streamIdPathSegment);
when(streamIdPathSegment.getPath()).thenReturn(streamId.toString());
when(uriBuilder.path(eventStreamPathSegmentValue)).thenReturn(uriBuilder);
when(uriBuilder.path(streamId.toString())).thenReturn(uriBuilder);
when(uriBuilder.path(HEAD)).thenReturn(uriBuilder);
when(uriBuilder.path("BACKWARD")).thenReturn(uriBuilder);
when(uriBuilder.path("2")).thenReturn(uriBuilder);
when(uriBuilder.build()).thenReturn(new URL(urlString).toURI());
when(positionValueFactory.getPositionValue(head())).thenReturn(HEAD);
final URL link = urlLinkFactory.createHeadEventStreamsUrlLink(pageSize, uriInfo);
assertThat(link.toString(), is(urlString));
}
use of javax.ws.rs.core.PathSegment in project microservice_framework by CJSCommonPlatform.
the class UrlLinkFactoryTest method shouldReturnEventStreamsFirstUrlLink.
@SuppressWarnings("unchecked")
@Test
public void shouldReturnEventStreamsFirstUrlLink() throws Exception {
final UUID streamId = UUID.randomUUID();
final String eventStreamPathSegmentValue = "eventstreams";
final String baseURI = "http://localhost:8080/context/";
final String urlString = baseURI + "/1/FORWARD/2";
final int pageSize = 2;
final UriInfo uriInfo = mock(UriInfo.class);
final UriBuilder uriBuilder = mock(UriBuilder.class);
final List<PathSegment> pathSegmentList = mock(List.class);
final PathSegment eventStreamPathSegment = mock(PathSegment.class);
final PathSegment streamIdPathSegment = mock(PathSegment.class);
when(uriInfo.getBaseUriBuilder()).thenReturn(uriBuilder);
when(uriInfo.getPathSegments()).thenReturn(pathSegmentList);
when(pathSegmentList.get(0)).thenReturn(eventStreamPathSegment);
when(eventStreamPathSegment.getPath()).thenReturn(eventStreamPathSegmentValue);
when(pathSegmentList.get(1)).thenReturn(streamIdPathSegment);
when(streamIdPathSegment.getPath()).thenReturn(streamId.toString());
when(uriBuilder.path(eventStreamPathSegmentValue)).thenReturn(uriBuilder);
when(uriBuilder.path(streamId.toString())).thenReturn(uriBuilder);
when(uriBuilder.path(FIRST)).thenReturn(uriBuilder);
when(uriBuilder.path("FORWARD")).thenReturn(uriBuilder);
when(uriBuilder.path("2")).thenReturn(uriBuilder);
when(uriBuilder.build()).thenReturn(new URL(urlString).toURI());
when(positionValueFactory.getPositionValue(first())).thenReturn(FIRST);
final URL link = urlLinkFactory.createFirstEventStreamsUrlLink(pageSize, uriInfo);
assertThat(link.toString(), is(urlString));
}
use of javax.ws.rs.core.PathSegment in project narayana by jbosstm.
the class TxSupport method getUriBuilder.
public static UriBuilder getUriBuilder(UriInfo info, int npaths, String... paths) {
UriBuilder builder = info.getBaseUriBuilder();
if (npaths > 0) {
List<PathSegment> segments = info.getPathSegments();
for (int i = 0; i < npaths; i++) builder.path(segments.get(i).getPath());
} else {
String basePath = info.getMatchedURIs().get(0);
builder.path(basePath);
}
for (String path : paths) builder.path(path);
return builder;
}
Aggregations