use of io.milton.http.exceptions.BadRequestException in project lobcder by skoulouzis.
the class WebDataDirResource method moveTo.
@Override
public void moveTo(CollectionResource toCollection, String name) throws ConflictException, NotAuthorizedException, BadRequestException {
WebDataDirResource toWDDR = (WebDataDirResource) toCollection;
Logger.getLogger(WebDataDirResource.class.getName()).log(Level.FINEST, "moveTo({0}, ''{1}'') for {2}", new Object[] { toWDDR.getPath(), name, getPath() });
try (Connection connection = getCatalogue().getConnection()) {
try {
Permissions destPerm = getCatalogue().getPermissions(toWDDR.getLogicalData().getUid(), toWDDR.getLogicalData().getOwner(), connection);
LogicalData parentLD = getCatalogue().getLogicalDataByUid(getLogicalData().getParentRef());
Permissions parentPerm = getCatalogue().getPermissions(parentLD.getUid(), parentLD.getOwner());
if (!(getPrincipal().canWrite(destPerm) && getPrincipal().canWrite(parentPerm))) {
throw new NotAuthorizedException(this);
}
getCatalogue().moveEntry(getLogicalData(), toWDDR.getLogicalData(), name, connection);
connection.commit();
connection.close();
} catch (SQLException e) {
Logger.getLogger(WebDataDirResource.class.getName()).log(Level.SEVERE, null, e);
if (connection != null && !connection.isClosed()) {
connection.rollback();
connection.close();
}
throw new BadRequestException(this, e.getMessage());
}
} catch (SQLException e1) {
Logger.getLogger(WebDataDirResource.class.getName()).log(Level.SEVERE, null, e1);
throw new BadRequestException(this, e1.getMessage());
}
}
use of io.milton.http.exceptions.BadRequestException in project lobcder by skoulouzis.
the class WebDataDirResource method sendContent.
@Override
public void sendContent(OutputStream out, Range range, Map<String, String> params, String contentType) throws IOException, NotAuthorizedException, BadRequestException {
Logger.getLogger(WebDataDirResource.class.getName()).log(Level.FINEST, "sendContent({0}) for {1}", new Object[] { contentType, getPath() });
try (Connection connection = getCatalogue().getConnection()) {
try (PrintStream ps = new PrintStream(out)) {
HtmlCanvas html = new HtmlCanvas();
html.table(border("1")).tr().th().content("Name").th().content("Size").th().content("Modification Date").th().content("Creation Date").th().content("Owner").th().content("Content Type").th().content("Type").th().content("Is Supervised").th().content("Uid");
String ref;
for (LogicalData ld : getCatalogue().getChildrenByParentRef(getLogicalData().getUid(), connection)) {
if (ld.isFolder()) {
ref = "../dav" + getPath() + "/" + ld.getName();
// if (ld.getUid() != 1) {
// } else {
// }
} else {
ref = "../dav" + getPath() + "/" + ld.getName();
}
html._tr().tr().td().a(href(ref)).img(src("").alt(ld.getName()))._a()._td().td().content(String.valueOf(ld.getLength())).td().content(new Date(ld.getModifiedDate()).toString()).td().content(new Date(ld.getCreateDate()).toString()).td().content(ld.getOwner()).td().content(ld.getContentTypesAsString()).td().content(ld.getType()).td().content(ld.getSupervised().toString()).td().content(ld.getUid().toString());
}
html._tr()._table();
ps.println(html.toHtml());
getCatalogue().addViewForRes(getLogicalData().getUid(), connection);
connection.commit();
connection.close();
} catch (Exception e) {
if (connection != null && !connection.isClosed()) {
connection.rollback();
connection.close();
}
throw e;
}
} catch (Exception e) {
Logger.getLogger(WebDataDirResource.class.getName()).log(Level.SEVERE, null, e);
throw new BadRequestException(this);
}
}
use of io.milton.http.exceptions.BadRequestException in project lobcder by skoulouzis.
the class WebDataDirResource method createCollection.
@Override
public CollectionResource createCollection(String newName) throws NotAuthorizedException, ConflictException, BadRequestException {
Logger.getLogger(WebDataDirResource.class.getName()).log(Level.FINEST, "createCollection {0} in {1}", new Object[] { newName, getPath() });
try (Connection connection = getCatalogue().getConnection()) {
try {
Path newCollectionPath = Path.path(getPath(), newName);
Long newFolderEntryId = getCatalogue().getLogicalDataUidByParentRefAndName(getLogicalData().getUid(), newName, connection);
if (newFolderEntryId != null) {
throw new ConflictException(this, newName);
} else {
// collection does not exists, create a new one
// newCollectionPath, Constants.LOGICAL_FOLDER,
LogicalData newFolderEntry = new LogicalData();
newFolderEntry.setType(Constants.LOGICAL_FOLDER);
newFolderEntry.setParentRef(getLogicalData().getUid());
newFolderEntry.setName(newName);
newFolderEntry.setCreateDate(System.currentTimeMillis());
newFolderEntry.setModifiedDate(System.currentTimeMillis());
newFolderEntry.setLastAccessDate(System.currentTimeMillis());
newFolderEntry.setTtlSec(getLogicalData().getTtlSec());
newFolderEntry.setOwner(getPrincipal().getUserId());
getCatalogue().setPermissions(getCatalogue().registerDirLogicalData(newFolderEntry, connection).getUid(), new Permissions(getPrincipal(), getPermissions()), connection);
newFolderEntry = inheritProperties(newFolderEntry, connection);
connection.commit();
connection.close();
WebDataDirResource res = new WebDataDirResource(newFolderEntry, newCollectionPath, getCatalogue(), authList);
return res;
}
} catch (SQLException e) {
Logger.getLogger(WebDataDirResource.class.getName()).log(Level.SEVERE, null, e);
if (connection != null && !connection.isClosed()) {
connection.rollback();
connection.close();
}
throw new BadRequestException(this, e.getMessage());
}
} catch (SQLException e1) {
Logger.getLogger(WebDataDirResource.class.getName()).log(Level.SEVERE, null, e1);
throw new BadRequestException(this, e1.getMessage());
}
}
use of io.milton.http.exceptions.BadRequestException in project lobcder by skoulouzis.
the class WebDataFileResource method copyTo.
@Override
public void copyTo(CollectionResource collectionResource, String name) throws NotAuthorizedException, BadRequestException, ConflictException {
WebDataDirResource toWDDR = (WebDataDirResource) collectionResource;
Logger.getLogger(WebDataFileResource.class.getName()).log(Level.FINEST, "copyTo(''{0}'', ''{1}'') for {2}", new Object[] { toWDDR.getPath(), name, getPath() });
try (Connection connection = getCatalogue().getConnection()) {
try {
Permissions newParentPerm = getCatalogue().getPermissions(toWDDR.getLogicalData().getUid(), toWDDR.getLogicalData().getOwner(), connection);
if (!getPrincipal().canWrite(newParentPerm)) {
throw new NotAuthorizedException(this);
}
getCatalogue().copyFile(getLogicalData(), toWDDR.getLogicalData(), name, getPrincipal(), connection);
connection.commit();
} catch (SQLException | NotAuthorizedException e) {
Logger.getLogger(WebDataFileResource.class.getName()).log(Level.SEVERE, null, e);
connection.rollback();
throw new BadRequestException(this, e.getMessage());
}
} catch (SQLException e) {
Logger.getLogger(WebDataFileResource.class.getName()).log(Level.SEVERE, null, e);
throw new BadRequestException(this, e.getMessage());
}
}
use of io.milton.http.exceptions.BadRequestException in project lobcder by skoulouzis.
the class WebDataFileResource method moveTo.
@Override
public void moveTo(CollectionResource collectionResource, String name) throws ConflictException, NotAuthorizedException, BadRequestException {
WebDataDirResource toWDDR = (WebDataDirResource) collectionResource;
Logger.getLogger(WebDataFileResource.class.getName()).log(Level.FINEST, "moveTo(''{0}'', ''{1}'') for {2}", new Object[] { toWDDR.getPath(), name, getPath() });
try (Connection connection = getCatalogue().getConnection()) {
try {
Permissions destPerm = getCatalogue().getPermissions(toWDDR.getLogicalData().getUid(), toWDDR.getLogicalData().getOwner(), connection);
LogicalData parentLD = getCatalogue().getLogicalDataByUid(getLogicalData().getParentRef());
Permissions parentPerm = getCatalogue().getPermissions(parentLD.getUid(), parentLD.getOwner());
if (!(getPrincipal().canWrite(destPerm) && getPrincipal().canWrite(parentPerm))) {
throw new NotAuthorizedException(this);
}
getCatalogue().moveEntry(getLogicalData(), toWDDR.getLogicalData(), name, connection);
connection.commit();
} catch (Exception e) {
Logger.getLogger(WebDataFileResource.class.getName()).log(Level.SEVERE, null, e);
connection.rollback();
throw new BadRequestException(this, e.getMessage());
}
} catch (SQLException e) {
Logger.getLogger(WebDataFileResource.class.getName()).log(Level.SEVERE, null, e);
throw new BadRequestException(this, e.getMessage());
}
}
Aggregations