Skip to content

Commit

Permalink
fix blobs resource
Browse files Browse the repository at this point in the history
  • Loading branch information
lehvolk committed Feb 15, 2018
1 parent 7e55857 commit 75ac0a9
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ object HttpServer : KLogging() {
response.status(HttpURLConnection.HTTP_BAD_REQUEST)
response.body(JsonTransformer.render(e.toVO()))
}
exception(DatabaseNotFoundException::class.java) { e, _, response ->
exception(NotFoundException::class.java) { e, _, response ->
logger.debug("can't handle database", e)
response.status(HttpURLConnection.HTTP_BAD_REQUEST)
response.status(HttpURLConnection.HTTP_NOT_FOUND)
response.body(JsonTransformer.render(e.toVO()))
}
exception(Exception::class.java) { e, _, response ->
Expand Down Expand Up @@ -157,7 +157,7 @@ class InvalidFieldException(cause: Throwable, fieldName: String, fieldValue: Str
override val msg: String = "invalid value of property '$fieldName': '$fieldValue'"
}

class DatabaseNotFoundException(override val msg: String) : RuntimeException(), WithMessage
class NotFoundException(override val msg: String) : RuntimeException(), WithMessage

data class RestError(val errorMessage: String)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.lehvolk.xodus.web.db

import com.lehvolk.xodus.web.DBSummary
import com.lehvolk.xodus.web.DatabaseNotFoundException
import com.lehvolk.xodus.web.NotFoundException
import com.lehvolk.xodus.web.mapper
import com.lehvolk.xodus.web.systemOr
import java.io.File
Expand Down Expand Up @@ -41,20 +41,20 @@ object Databases {
dbs.add(DBSummary(location, key, uuid = uuid))
}
return find(uuid) {
throw DatabaseNotFoundException("Database on '$location' is already registered")
throw NotFoundException("Database on '$location' is already registered")
}
}

fun applyChange(uuid: String, call: DBSummary.() -> Unit): DBSummary {
val dbCopy = find(uuid) {
throw DatabaseNotFoundException("Database not found by id '$uuid'")
throw NotFoundException("Database not found by id '$uuid'")
}
val location = dbCopy.location
saveWith {
dbCopy.call()
}
return find(uuid) {
throw DatabaseNotFoundException("Database on '$location' can't be modified")
throw NotFoundException("Database on '$location' can't be modified")
}
}

Expand All @@ -69,7 +69,7 @@ object Databases {
}

internal fun find(uuid: String, error: () -> Nothing = {
throw DatabaseNotFoundException("Database not found by id '$uuid'")
throw NotFoundException("Database not found by id '$uuid'")
}) = dbs.firstOrNull { it.uuid == uuid } ?: error()


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import jetbrains.exodus.entitystore.*
import jetbrains.exodus.env.Environments
import org.slf4j.LoggerFactory
import java.io.IOException
import java.io.OutputStream
import java.io.InputStream

class StoreService(location: String, key: String) {

Expand Down Expand Up @@ -88,11 +88,11 @@ class StoreService(location: String, key: String) {
}

@Throws(IOException::class)
fun getBlob(id: String, blobName: String, out: OutputStream) {
fun getBlob(id: String, blobName: String): InputStream {
val tx = store.beginReadonlyTransaction()
try {
val entity = getEntity(id, tx)
entity.getBlob(blobName)?.copyTo(out, bufferSize = 4096)
return entity.getBlob(blobName) ?: throw NotFoundException("there is no blob $blobName")
} finally {
tx.commit()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ class Entities : Resource, ResourceSupport {
http.get("/:entityId/blob/:blobName") {
logger.debug { "getting entity by entity id '$entityId'" }
response.header("content-type", "application/octet-stream;charset=utf-8")
storeService.getBlob(entityId, request.params("blobName"),
response.raw().outputStream)
storeService.getBlob(entityId, request.params("blobName"))
}

http.safeGet("/:entityId/links/:linkName") {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.lehvolk.xodus.web.resources

import com.lehvolk.xodus.web.DBSummary
import com.lehvolk.xodus.web.DatabaseNotFoundException
import com.lehvolk.xodus.web.db.Databases
import com.lehvolk.xodus.web.db.JobsService
import com.lehvolk.xodus.web.db.StoreService
Expand Down
2 changes: 1 addition & 1 deletion entity-browser-frontend/app/controller/data-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ angular.module('xodus').controller('DataViewController', [
};

dataViewCtrl.blobLink = function (entity, blob) {
return navigation.api.blobLink(entity, blob.name);
return navigation.api.blobLink(entity.id, blob.name);
};
};

Expand Down
2 changes: 1 addition & 1 deletion entity-browser-frontend/app/templates/data-view.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ <h4 class="panel-title pull-left" style="padding-top: 5.5px;">
</tr>
</thead>
<tbody>
<tr data-ng-repeat="p in item.links ">
<tr data-ng-repeat="p in item.links">
<td>{{p.name}}</td>
<td class="linked-entities">
<linked-entities-view
Expand Down
4 changes: 2 additions & 2 deletions entity-browser-frontend/app/templates/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
</ui-select-choices>
</ui-select>
<div class="input-group-btn">
<button class="btn btn-default " uib-popover-template="'add-new-entity-type.html'"
<a class="btn btn-default" uib-popover-template="'add-new-entity-type.html'"
popover-title="New entity type" popover-placement="bottom-right"
><i class="fa fa-plus js-close-popover" ></i></button>
><i class="fa fa-plus js-close-popover" ></i></a>
</div>
</div>
</div>
Expand Down

0 comments on commit 75ac0a9

Please sign in to comment.