Skip to content

Commit

Permalink
Merge pull request #488 from codenvy/IDEX-3573
Browse files Browse the repository at this point in the history
IDEX-3573: Remove mime (content) type from the Project API and related code
  • Loading branch information
azatsarynnyy committed Dec 9, 2015
2 parents 2977ace + 20c2784 commit 342002c
Show file tree
Hide file tree
Showing 43 changed files with 218 additions and 595 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ private List<VirtualFile> doGetChildren(VirtualFileImpl virtualFile, java.io.Fil
}


VirtualFileImpl createFile(VirtualFileImpl parent, String name, String mediaType, InputStream content)
VirtualFileImpl createFile(VirtualFileImpl parent, String name, InputStream content)
throws ForbiddenException, ConflictException, ServerException {
checkName(name);

Expand Down Expand Up @@ -497,7 +497,7 @@ VirtualFileImpl createFile(VirtualFileImpl parent, String name, String mediaType
final VirtualFileImpl newVirtualFile = new VirtualFileImpl(newIoFile, newPath, pathToId(newPath), this);
// Update content if any.
if (content != null) {
doUpdateContent(newVirtualFile, mediaType, content);
doUpdateContent(newVirtualFile, content);
}

if (searcherProvider != null) {
Expand Down Expand Up @@ -856,20 +856,7 @@ ContentStream getContent(VirtualFileImpl virtualFile) throws ForbiddenException,
}
}


void updateContent(VirtualFileImpl virtualFile, String mediaType, InputStream content, String lockToken)
throws ForbiddenException, ServerException {
updateContent(virtualFile, mediaType, content, lockToken, true);
}


void updateContent(VirtualFileImpl virtualFile, InputStream content, String lockToken) throws ForbiddenException, ServerException {
updateContent(virtualFile, null, content, lockToken, false);
}


private void updateContent(VirtualFileImpl virtualFile, String mediaType, InputStream content, String lockToken,
boolean updateMediaType) throws ForbiddenException, ServerException {
if (!virtualFile.isFile()) {
throw new ForbiddenException(String.format("Unable update content. Item '%s' is not file. ", virtualFile.getPath()));
}
Expand All @@ -886,11 +873,7 @@ private void updateContent(VirtualFileImpl virtualFile, String mediaType, InputS
throw new ForbiddenException(String.format("Unable update content of file '%s'. File is locked. ", virtualFile.getPath()));
}

if (updateMediaType) {
doUpdateContent(virtualFile, mediaType, content);
} else {
doUpdateContent(virtualFile, content);
}
doUpdateContent(virtualFile, content);

if (searcherProvider != null) {
try {
Expand All @@ -902,17 +885,6 @@ private void updateContent(VirtualFileImpl virtualFile, String mediaType, InputS
eventService.publish(new UpdateContentEvent(workspaceId, virtualFile.getPath()));
}


private void doUpdateContent(VirtualFileImpl virtualFile, String mediaType, InputStream content) throws ServerException {
final PathLockFactory.PathLock lock = pathLockFactory.getLock(virtualFile.getVirtualFilePath(), true).acquire(LOCK_FILE_TIMEOUT);
try {
_doUpdateContent(virtualFile, content);
setProperty(virtualFile, "vfs:mimeType", mediaType);
} finally {
lock.release();
}
}

private void doUpdateContent(VirtualFileImpl virtualFile, InputStream content) throws ServerException {
final PathLockFactory.PathLock lock = pathLockFactory.getLock(virtualFile.getVirtualFilePath(), true).acquire(LOCK_FILE_TIMEOUT);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,6 @@ public ContentStream getContent() throws ForbiddenException, ServerException {
return mountPoint.getContent(this);
}

@Override
public VirtualFile updateContent(String mediaType, InputStream content, String lockToken) throws ForbiddenException, ServerException {
mountPoint.updateContent(this, mediaType, content, lockToken);
return this;
}

@Override
public VirtualFile updateContent(InputStream content, String lockToken) throws ForbiddenException, ServerException {
mountPoint.updateContent(this, content, lockToken);
Expand Down Expand Up @@ -282,9 +276,9 @@ public VirtualFile updateACL(List<AccessControlEntry> acl, boolean override, Str
//

@Override
public VirtualFile createFile(String name, String mediaType, InputStream content)
public VirtualFile createFile(String name, InputStream content)
throws ForbiddenException, ConflictException, ServerException {
return mountPoint.createFile(this, name, mediaType, content);
return mountPoint.createFile(this, name, content);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,18 @@
*******************************************************************************/
package org.eclipse.che.vfs.impl.fs;

import org.eclipse.che.api.vfs.shared.dto.Principal;
import org.eclipse.che.dto.server.DtoFactory;

import com.google.common.collect.Sets;

import org.eclipse.che.api.vfs.shared.dto.Principal;
import org.eclipse.che.dto.server.DtoFactory;
import org.everrest.core.impl.ContainerResponse;
import org.everrest.core.tools.ByteArrayContainerResponseWriter;

import javax.ws.rs.HttpMethod;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

Expand Down Expand Up @@ -110,14 +107,9 @@ public void testGetContentByPath() throws Exception {

public void testUpdateContent() throws Exception {
String requestPath = SERVICE_URI + "content/" + fileId;
Map<String, List<String>> headers = new HashMap<>(1);
headers.put(HttpHeaders.CONTENT_TYPE, Arrays.asList(MediaType.TEXT_PLAIN));
ContainerResponse response = launcher.service(HttpMethod.POST, requestPath, BASE_URI, headers, updateContent, null);
ContainerResponse response = launcher.service(HttpMethod.POST, requestPath, BASE_URI, null, updateContent, null);
assertEquals(204, response.getStatus());
assertTrue(Arrays.equals(updateContent, readFile(filePath)));
Map<String, String[]> expectedProperties = new HashMap<>(1);
expectedProperties.put("vfs:mimeType", new String[]{MediaType.TEXT_PLAIN});
validateProperties(filePath, expectedProperties);
}

public void testUpdateContentFolder() throws Exception {
Expand All @@ -129,25 +121,17 @@ public void testUpdateContentFolder() throws Exception {
}

public void testUpdateContentLocked() throws Exception {
Map<String, List<String>> headers = new HashMap<>(1);
headers.put(HttpHeaders.CONTENT_TYPE, Arrays.asList(MediaType.TEXT_PLAIN));
String requestPath = SERVICE_URI + "content/" + lockedFileId + '?' + "lockToken=" + lockToken;
ContainerResponse response = launcher.service(HttpMethod.POST, requestPath, BASE_URI, headers, updateContent, null);
ContainerResponse response = launcher.service(HttpMethod.POST, requestPath, BASE_URI, null, updateContent, null);
// File is locked.
assertEquals(204, response.getStatus());
assertTrue(Arrays.equals(updateContent, readFile(lockedFilePath))); // content updated
// media type is set
Map<String, String[]> expectedProperties = new HashMap<>(1);
expectedProperties.put("vfs:mimeType", new String[]{MediaType.TEXT_PLAIN});
validateProperties(lockedFilePath, expectedProperties);
}

public void testUpdateContentLockedNoLockToken() throws Exception {
Map<String, List<String>> headers = new HashMap<>(1);
headers.put(HttpHeaders.CONTENT_TYPE, Arrays.asList(MediaType.TEXT_PLAIN));
String requestPath = SERVICE_URI + "content/" + lockedFileId;
ByteArrayContainerResponseWriter writer = new ByteArrayContainerResponseWriter();
ContainerResponse response = launcher.service(HttpMethod.POST, requestPath, BASE_URI, headers, updateContent, writer, null);
ContainerResponse response = launcher.service(HttpMethod.POST, requestPath, BASE_URI, null, updateContent, writer, null);
// File is locked.
assertEquals(403, response.getStatus());
log.info(new String(writer.getBody()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,22 @@
*******************************************************************************/
package org.eclipse.che.vfs.impl.fs;

import com.google.common.collect.Sets;

import org.eclipse.che.api.vfs.shared.dto.Folder;
import org.eclipse.che.api.vfs.shared.dto.Principal;
import org.eclipse.che.commons.env.EnvironmentContext;
import org.eclipse.che.commons.user.UserImpl;
import org.eclipse.che.dto.server.DtoFactory;

import com.google.common.collect.Sets;

import org.everrest.core.impl.ContainerResponse;
import org.everrest.core.tools.ByteArrayContainerResponseWriter;

import java.util.ArrayList;
import javax.ws.rs.HttpMethod;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.ws.rs.HttpMethod;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;

import static org.eclipse.che.api.vfs.shared.dto.VirtualFileSystemInfo.BasicPermissions;

public class CreateTest extends LocalFileSystemTest {
Expand Down Expand Up @@ -66,19 +60,12 @@ public void testCreateFile() throws Exception {
String name = "testCreateFile";
String content = "test create file";
String requestPath = SERVICE_URI + "file/" + folderId + '?' + "name=" + name;
Map<String, List<String>> headers = new HashMap<>();
List<String> contentType = new ArrayList<>();
contentType.add(MediaType.TEXT_PLAIN);
headers.put(HttpHeaders.CONTENT_TYPE, contentType);

ContainerResponse response = launcher.service(HttpMethod.POST, requestPath, BASE_URI, headers, content.getBytes(), null);
ContainerResponse response = launcher.service(HttpMethod.POST, requestPath, BASE_URI, null, content.getBytes(), null);
assertEquals("Error: " + response.getEntity(), 200, response.getStatus());
String expectedPath = folderPath + '/' + name;
assertTrue("File was not created in expected location. ", exists(expectedPath));
assertEquals(content, new String(readFile(expectedPath)));
Map<String, String[]> expectedProperties = new HashMap<>(1);
expectedProperties.put("vfs:mimeType", new String[]{MediaType.TEXT_PLAIN});
validateProperties(expectedPath, expectedProperties);
}

public void testCreateFileAlreadyExists() throws Exception {
Expand All @@ -96,22 +83,15 @@ public void testCreateFileInRoot() throws Exception {
String name = "FileInRoot";
String content = "test create file";
String requestPath = SERVICE_URI + "file/" + ROOT_ID + '?' + "name=" + name;
Map<String, List<String>> headers = new HashMap<>();
List<String> contentType = new ArrayList<>();
contentType.add(MediaType.TEXT_PLAIN);
headers.put(HttpHeaders.CONTENT_TYPE, contentType);

ByteArrayContainerResponseWriter writer = new ByteArrayContainerResponseWriter();
ContainerResponse response =
launcher.service(HttpMethod.POST, requestPath, BASE_URI, headers, content.getBytes(), writer, null);
launcher.service(HttpMethod.POST, requestPath, BASE_URI, null, content.getBytes(), writer, null);
log.info(new String(writer.getBody()));
assertEquals("Error: " + response.getEntity(), 200, response.getStatus());
String expectedPath = '/' + name;
assertTrue("File was not created in expected location. ", exists(expectedPath));
assertEquals(content, new String(readFile(expectedPath)));
Map<String, String[]> expectedProperties = new HashMap<>(1);
expectedProperties.put("vfs:mimeType", new String[]{MediaType.TEXT_PLAIN});
validateProperties(expectedPath, expectedProperties);
}

public void testCreateFileNoContent() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public void testAdd() throws Exception {
TopDocs topDocs = luceneSearcher.search(new PrefixQuery(new Term("path", searchTestPath)), 10);
assertEquals(4, topDocs.totalHits);
searcherManager.release(luceneSearcher);
mountPoint.getVirtualFile(searchTestPath).createFile("new_file.txt", null, new ByteArrayInputStream(DEFAULT_CONTENT_BYTES));
mountPoint.getVirtualFile(searchTestPath).createFile("new_file.txt", new ByteArrayInputStream(DEFAULT_CONTENT_BYTES));

searcherManager.maybeRefresh();
luceneSearcher = searcherManager.acquire();
Expand Down
Loading

0 comments on commit 342002c

Please sign in to comment.