@@ -6,7 +6,7 @@ import java.net.{URL, URLEncoder}
66
77import javax .inject .Inject
88import javax .mail .internet .MimeUtility
9- import _root_ .util .{FileUtils , JSONLD , Parsers , RequestUtils , SearchUtils }
9+ import _root_ .util .{FileUtils , JSONLD , Parsers , RequestUtils }
1010import com .mongodb .casbah .Imports ._
1111import controllers .Previewers
1212import jsonutils .JsonUtil
@@ -42,7 +42,6 @@ class Files @Inject()(
4242 extractions : ExtractionService ,
4343 dtsrequests: ExtractionRequestsService ,
4444 previews : PreviewService ,
45- threeD : ThreeDService ,
4645 metadataService : MetadataService ,
4746 contextService : ContextLDService ,
4847 thumbnails : ThumbnailService ,
@@ -53,7 +52,8 @@ class Files @Inject()(
5352 appConfig : AppConfigurationService ,
5453 adminsNotifierService : AdminsNotifierService ,
5554 extractionBusService : ExtractionBusService ,
56- esqueue : ElasticsearchQueue ) extends ApiController {
55+ versusService : VersusService ,
56+ searches : SearchService ) extends ApiController {
5757
5858 def get (id : UUID ) = PermissionAction (Permission .ViewFile , Some (ResourceRef (ResourceRef .file, id))) { implicit request =>
5959 Logger .debug(" GET file with id " + id)
@@ -560,9 +560,8 @@ class Files @Inject()(
560560 def reindex (id : UUID ) = PermissionAction (Permission .AddFile , Some (ResourceRef (ResourceRef .file, id))) { implicit request =>
561561 files.get(id) match {
562562 case Some (file) => {
563- val success = esqueue.queue(" index_file" , new ResourceRef (' file , id))
564- if (success) Ok (toJson(Map (" status" -> " reindex successfully queued" )))
565- else BadRequest (toJson(Map (" status" -> " reindex queuing failed, Elasticsearch may be disabled" )))
563+ files.index(id)
564+ Ok (toJson(s " File $id reindexed " ))
566565 }
567566 case None => {
568567 Logger .error(" Error getting file" + id)
@@ -771,52 +770,6 @@ class Files @Inject()(
771770 }
772771 }
773772
774- /**
775- * Add 3D geometry file to file.
776- */
777- def attachGeometry (file_id : UUID , geometry_id : UUID ) = PermissionAction (Permission .AddFile , Some (ResourceRef (ResourceRef .file, file_id)))(parse.json) { implicit request =>
778- request.body match {
779- case JsObject (fields) => {
780- files.get(file_id) match {
781- case Some (file) => {
782- threeD.getGeometry(geometry_id) match {
783- case Some (geometry) =>
784- threeD.updateGeometry(file_id, geometry_id, fields)
785- Ok (toJson(Map (" status" -> " success" )))
786- case None => BadRequest (toJson(" Geometry file not found" ))
787- }
788- }
789- case None => BadRequest (toJson(" File not found " + file_id))
790- }
791- }
792- case _ => Ok (" received something else: " + request.body + '\n ' )
793- }
794- }
795-
796-
797- /**
798- * Add 3D texture to file.
799- */
800- def attachTexture (file_id : UUID , texture_id : UUID ) = PermissionAction (Permission .AddFile , Some (ResourceRef (ResourceRef .file, file_id)))(parse.json) { implicit request =>
801- request.body match {
802- case JsObject (fields) => {
803- files.get((file_id)) match {
804- case Some (file) => {
805- threeD.getTexture(texture_id) match {
806- case Some (texture) => {
807- threeD.updateTexture(file_id, texture_id, fields)
808- Ok (toJson(Map (" status" -> " success" )))
809- }
810- case None => BadRequest (toJson(" Texture file not found" ))
811- }
812- }
813- case None => BadRequest (toJson(" File not found " + file_id))
814- }
815- }
816- case _ => Ok (" received something else: " + request.body + '\n ' )
817- }
818- }
819-
820773 /**
821774 * Add thumbnail to file.
822775 */
@@ -871,113 +824,6 @@ class Files @Inject()(
871824 }
872825 }
873826
874-
875- /**
876- * Find geometry file for given 3D file and geometry filename.
877- */
878- def getGeometry (three_d_file_id : UUID , filename : String ) = PermissionAction (Permission .ViewFile , Some (ResourceRef (ResourceRef .file, three_d_file_id))) { implicit request =>
879- threeD.findGeometry(three_d_file_id, filename) match {
880- case Some (geometry) => {
881-
882- threeD.getGeometryBlob(geometry.id) match {
883-
884- case Some ((inputStream, filename, contentType, contentLength)) => {
885- request.headers.get(RANGE ) match {
886- case Some (value) => {
887- val range : (Long , Long ) = value.substring(" bytes=" .length).split(" -" ) match {
888- case x if x.length == 1 => (x.head.toLong, contentLength - 1 )
889- case x => (x(0 ).toLong, x(1 ).toLong)
890- }
891- range match {
892- case (start, end) =>
893-
894- inputStream.skip(start)
895- import play .api .mvc .{ResponseHeader , SimpleResult }
896- SimpleResult (
897- header = ResponseHeader (PARTIAL_CONTENT ,
898- Map (
899- CONNECTION -> " keep-alive" ,
900- ACCEPT_RANGES -> " bytes" ,
901- CONTENT_RANGE -> " bytes %d-%d/%d" .format(start, end, contentLength),
902- CONTENT_LENGTH -> (end - start + 1 ).toString,
903- CONTENT_TYPE -> contentType
904- )
905- ),
906- body = Enumerator .fromStream(inputStream)
907- )
908- }
909- }
910- case None => {
911- // IMPORTANT: Setting CONTENT_LENGTH header here introduces bug!
912- Ok .chunked(Enumerator .fromStream(inputStream))
913- .withHeaders(CONTENT_TYPE -> contentType)
914- .withHeaders(CONTENT_DISPOSITION -> (FileUtils .encodeAttachment(filename, request.headers.get(" user-agent" ).getOrElse(" " ))))
915-
916- }
917- }
918- }
919- case None => Logger .error(" No geometry file found: " + geometry.id); InternalServerError (" No geometry file found" )
920-
921- }
922- }
923- case None => Logger .error(" Geometry file not found" ); InternalServerError
924- }
925- }
926-
927-
928- /**
929- * Find texture file for given 3D file and texture filename.
930- */
931- def getTexture (three_d_file_id : UUID , filename : String ) = PermissionAction (Permission .ViewFile , Some (ResourceRef (ResourceRef .file, three_d_file_id))) { implicit request =>
932- threeD.findTexture(three_d_file_id, filename) match {
933- case Some (texture) => {
934-
935- threeD.getBlob(texture.id) match {
936-
937- case Some ((inputStream, filename, contentType, contentLength)) => {
938- request.headers.get(RANGE ) match {
939- case Some (value) => {
940- val range : (Long , Long ) = value.substring(" bytes=" .length).split(" -" ) match {
941- case x if x.length == 1 => (x.head.toLong, contentLength - 1 )
942- case x => (x(0 ).toLong, x(1 ).toLong)
943- }
944- range match {
945- case (start, end) =>
946-
947- inputStream.skip(start)
948-
949- SimpleResult (
950- header = ResponseHeader (PARTIAL_CONTENT ,
951- Map (
952- CONNECTION -> " keep-alive" ,
953- ACCEPT_RANGES -> " bytes" ,
954- CONTENT_RANGE -> " bytes %d-%d/%d" .format(start, end, contentLength),
955- CONTENT_LENGTH -> (end - start + 1 ).toString,
956- CONTENT_TYPE -> contentType
957- )
958- ),
959- body = Enumerator .fromStream(inputStream)
960- )
961- }
962- }
963- case None => {
964- // IMPORTANT: Setting CONTENT_LENGTH header here introduces bug!
965- Ok .chunked(Enumerator .fromStream(inputStream))
966- .withHeaders(CONTENT_TYPE -> contentType)
967- // .withHeaders(CONTENT_LENGTH -> contentLength.toString)
968- .withHeaders(CONTENT_DISPOSITION -> (FileUtils .encodeAttachment(filename, request.headers.get(" user-agent" ).getOrElse(" " ))))
969-
970- }
971- }
972- }
973- case None => Logger .error(" No texture file found: " + texture.id.toString()); InternalServerError (" No texture found" )
974-
975- }
976- }
977- case None => Logger .error(" Texture file not found" ); InternalServerError
978- }
979- }
980-
981827 /**
982828 * REST endpoint: PUT: update or change the filename
983829 * args
@@ -1445,13 +1291,6 @@ class Files @Inject()(
14451291 }
14461292
14471293 def jsonPreview (pvId : UUID , pId : String , pPath : String , pMain : String , pvRoute : java.lang.String , pvContentType : String , pvLength : Long ): JsValue = {
1448- if (pId.equals(" X3d" ))
1449- toJson(Map (" pv_id" -> pvId.stringify, " p_id" -> pId, " p_path" -> controllers.routes.Assets .at(pPath).toString,
1450- " p_main" -> pMain, " pv_route" -> pvRoute, " pv_contenttype" -> pvContentType, " pv_length" -> pvLength.toString,
1451- " pv_annotationsEditPath" -> api.routes.Previews .editAnnotation(pvId).toString,
1452- " pv_annotationsListPath" -> api.routes.Previews .listAnnotations(pvId).toString,
1453- " pv_annotationsAttachPath" -> api.routes.Previews .attachAnnotation(pvId).toString))
1454- else
14551294 toJson(Map (" pv_id" -> pvId.stringify, " p_id" -> pId, " p_path" -> controllers.routes.Assets .at(pPath).toString,
14561295 " p_main" -> pMain, " pv_route" -> pvRoute, " pv_contenttype" -> pvContentType, " pv_length" -> pvLength.toString))
14571296 }
@@ -1600,17 +1439,11 @@ class Files @Inject()(
16001439
16011440 // this stmt has to be before files.removeFile
16021441 Logger .debug(" Deleting file from indexes " + file.filename)
1603- current.plugin[VersusPlugin ].foreach {
1604- _.removeFromIndexes(id)
1605- }
1442+ versusService.removeFromIndexes(id)
16061443 Logger .debug(" Deleting file: " + file.filename)
16071444 files.removeFile(id, Utils .baseUrl(request), request.apiKey, request.user)
1608- appConfig.incrementCount(' files , - 1 )
1609- appConfig.incrementCount(' bytes , - file.length)
16101445
1611- current.plugin[ElasticsearchPlugin ].foreach {
1612- _.delete(" data" , " file" , id.stringify)
1613- }
1446+ searches.delete(id.stringify, " file" )
16141447
16151448 adminsNotifierService.sendAdminsNotification(Utils .baseUrl(request), " File" , " removed" , id.stringify, file.filename)
16161449
@@ -1689,11 +1522,7 @@ class Files @Inject()(
16891522
16901523 def index (id : UUID ) {
16911524 files.get(id) match {
1692- case Some (file) => {
1693- current.plugin[ElasticsearchPlugin ].foreach {
1694- _.index(SearchUtils .getElasticsearchObject(file))
1695- }
1696- }
1525+ case Some (file) => searches.index(file)
16971526 case None => Logger .error(" File not found: " + id)
16981527 }
16991528 }
0 commit comments