Skip to content

Commit

Permalink
Merge branch 'feature/biocollect-6.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
temi committed May 11, 2022
2 parents a5e06f3 + 99f84ab commit 2806193
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 13 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ plugins {
id 'com.craigburke.client-dependencies' version '1.4.0'
}

version "3.3.1"
version "3.4-biocollect-6.0-SNAPSHOT"
group "au.org.ala"
description "Ecodata"

Expand Down
1 change: 1 addition & 0 deletions grails-app/conf/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ app:
- 'url'
- 'imageUrl'
- 'logoUrl'
- 'fullSizeImageUrl'
allowedHostName: 'ala.org.au'

info:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class CommentController {
response.addHeader("location", grailsApplication.config.grails.serverURL + "/comment/" + comment.getId().toString())
response.addHeader("entityId", comment.getId().toString())
response.setContentType("application/json")
render model as JSON
render new JSON(model)
} else {
response.sendError(SC_INTERNAL_SERVER_ERROR, 'Failed saving data to database');
}
Expand Down Expand Up @@ -105,7 +105,7 @@ class CommentController {
result.success = true;
}

render(text: result as JSON, contentType: 'application/json');
render(text: new JSON(result), contentType: 'application/json');
} else {
response.sendError(SC_UNAUTHORIZED, 'Only comment owner can update this comment.');
}
Expand Down Expand Up @@ -146,7 +146,7 @@ class CommentController {
Comment c = Comment.get(params.id);
if (c) {
Map mapOfProperties = commentService.getCommentProperties(c)
render text: mapOfProperties as JSON, contentType: 'application/json'
render text: new JSON(mapOfProperties), contentType: 'application/json'
} else {
response.sendError(SC_NOT_FOUND, "Comment not found");
}
Expand Down
4 changes: 4 additions & 0 deletions grails-app/domain/au/org/ala/ecodata/Document.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class Document {
String type // image, document, sound, etc
String role // eg primary, carousel, photoPoint
List<String> labels = [] // allow for searching on custom attributes
String citation
String doiLink

String status = ACTIVE
String projectId
Expand Down Expand Up @@ -169,6 +171,8 @@ class Document {
externalUrl nullable: true
projectActivityId nullable: true
labels nullable: true
citation nullable: true
doiLink nullable: true
isSciStarter nullable: true
hosted nullable: true
identifier nullable: true
Expand Down
10 changes: 8 additions & 2 deletions grails-app/services/au/org/ala/ecodata/DocumentService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,17 @@ class DocumentService {
Document.findAllByProjectActivityIdAndStatus(id, ACTIVE).collect { toMap(it, levelOfDetail) }
}

String findImageUrlForProjectId(id, levelOfDetail = []){
String findImageUrlForProjectId(id, boolean isThumbnail = true){
Document primaryImageDoc;
Document logoDoc = Document.findByProjectIdAndRoleAndStatus(id, LOGO, ACTIVE);
String urlImage;
urlImage = logoDoc?.url ? logoDoc.getThumbnailUrl() : ''
urlImage = logoDoc?.url
if (urlImage) {
if (isThumbnail) {
urlImage = logoDoc.getThumbnailUrl()
}
}

if(!urlImage){
primaryImageDoc = Document.findByProjectIdAndIsPrimaryProjectImage(id, true)
urlImage = primaryImageDoc?.url;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

package au.org.ala.ecodata

import com.vividsolutions.jts.geom.Coordinate

import grails.converters.JSON
import grails.core.GrailsApplication
import grails.util.Environment
Expand All @@ -27,8 +27,6 @@ import org.apache.http.client.CredentialsProvider
import org.apache.http.impl.client.BasicCredentialsProvider
import org.apache.http.impl.nio.client.HttpAsyncClientBuilder
import org.elasticsearch.ElasticsearchException
import org.elasticsearch.action.DocWriteResponse
import org.elasticsearch.action.bulk.BulkItemResponse
import org.elasticsearch.action.bulk.BulkProcessor
import org.elasticsearch.action.bulk.BulkRequest
import org.elasticsearch.action.bulk.BulkResponse
Expand Down Expand Up @@ -70,7 +68,6 @@ import static au.org.ala.ecodata.ElasticIndex.*
import static au.org.ala.ecodata.Status.DELETED
import static grails.async.Promises.task
import static org.elasticsearch.index.query.QueryBuilders.*

/**
* ElasticSearch service. This service is responsible for indexing documents as well as handling searches (queries).
*
Expand Down Expand Up @@ -953,6 +950,7 @@ class ElasticSearchService {
projectMap.links = documentService.findAllLinksForProjectId(project.projectId)
projectMap.isMobileApp = documentService.isMobileAppForProject(projectMap);
projectMap.imageUrl = documentService.findImageUrlForProjectId(project.projectId);
projectMap.fullSizeImageUrl = documentService.findImageUrlForProjectId(project.projectId, false)
projectMap.logoAttribution = documentService.getLogoAttributionForProjectId(project.projectId)
projectMap.admins = permissionService.getAllAdminsForProject(project.projectId)?.collect {
it.userId
Expand Down
54 changes: 54 additions & 0 deletions scripts/releases/biocollect-6.0/migrateHubsToBS4Config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
var updated = 0;
var hubs = db.hub.find({});
print(`Count ${hubs.count()}`)
while (hubs.hasNext()) {
var hub = hubs.next();
var updateProps = {},
type;

print(`Hub - ${hub.urlPath}`);

if (hub.urlPath === 'merit' || hub.urlPath === undefined)
continue;

if (hub.skin !== 'bs4') {
updateProps.skin = 'bs4';
print(`Hub ${hub.urlPath} - ${hub.hubId} - has skin ${hub.skin}`);
}

type = hub.templateConfiguration && hub.templateConfiguration.header && hub.templateConfiguration.header.type;
if (type === 'biocollect' || type === "") {
updateProps["templateConfiguration.header.type"] = 'custom'
print(`Hub ${hub.urlPath} - ${hub.hubId} - has header ${type}`);
}

copyStyleSheet(hub, updateProps);

if (Object.keys(updateProps).length) {
db.hub.update({hubId: hub.hubId}, {$set: updateProps});
updated++;
}
}

function copyStyleSheet (hub, updateProps) {
var config = hub.templateConfiguration;
var styles = config.styles;

if(!styles.homepageButtonBackgroundColor && styles.navBackgroundColor){
updateProps["templateConfiguration.styles.homepageButtonBackgroundColor"] = styles.navBackgroundColor;
}

if(!styles.homepageButtonTextColor && styles.navTextColor){
updateProps["templateConfiguration.styles.homepageButtonTextColor"] = styles.navTextColor;
}

if(!styles.primaryDarkColor && styles.primaryButtonBackgroundColor) {
updateProps["templateConfiguration.styles.primaryDarkColor"] = styles.primaryButtonBackgroundColor;
updateProps["templateConfiguration.styles.primaryColor"] = styles.primaryButtonBackgroundColor;
}

if (!styles.darkColor && styles.defaultButtonBackgroundColor)
updateProps["templateConfiguration.styles.darkColor"] = styles.defaultButtonBackgroundColor;
}

print(`Updated ${updated} hubs`);
34 changes: 31 additions & 3 deletions src/test/groovy/au/org/ala/ecodata/DocumentServiceSpec.groovy
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package au.org.ala.ecodata

import grails.test.mongodb.MongoSpec
import grails.testing.gorm.DomainUnitTest
import grails.testing.services.ServiceUnitTest
import spock.lang.Specification
import grails.util.Holders

/**
* Tests the DocumentService.
* Images for orientation testing are from: https://github.com/recurser/exif-orientation-examples
* The test landscape image is by Pierre Bouillot.
* The test portrait image is by John Salvino.
*/
class DocumentServiceSpec extends Specification implements ServiceUnitTest<DocumentService> {
class DocumentServiceSpec extends MongoSpec implements ServiceUnitTest<DocumentService>, DomainUnitTest<Document> {

DocumentService service = new DocumentService()
File tempUploadDir
Expand All @@ -24,8 +26,9 @@ class DocumentServiceSpec extends Specification implements ServiceUnitTest<Docum
tempArchiveDir.mkdirs()
new File(tempUploadDir, "test").mkdir()

grailsApplication.config.app = [file: [archive: [path: tempArchiveDir.getAbsolutePath()], upload: [path: tempUploadDir.getAbsolutePath()]]]
grailsApplication.config.app = [file: [archive: [path: tempArchiveDir.getAbsolutePath()], upload: [path: tempUploadDir.getAbsolutePath()]], uploads: [url: '/document/download/']]
service.grailsApplication = grailsApplication
Holders.config.app = grailsApplication.config.app
}

def cleanup() {
Expand Down Expand Up @@ -126,4 +129,29 @@ class DocumentServiceSpec extends Specification implements ServiceUnitTest<Docum
"/etc/" | "file" | false
}

def "findImageUrlForProjectId should provide provide thumbnail url as well as full image url"(){
setup:
def projectId = 'abc'
def url
Document d = new Document(documentId: 'doc1', filepath: '2022-03', filename: 'Landscape_1.jpg', name:'Test Image', projectId: projectId, type: Document.DOCUMENT_TYPE_IMAGE, role: Document.ROLE_LOGO, status: Status.ACTIVE)
d.save(flush: true, failOnError: true)
service.saveFile(d.filepath, d.filename, fileAsStream(d.filename), false, Document.DOCUMENT_TYPE_IMAGE)

when:
url = service.findImageUrlForProjectId(projectId)

then:
url.contains('thumb_')

when:
url = service.findImageUrlForProjectId(projectId, false)

then:
!url.contains('thumb_')
url.endsWith('2022-03' + File.separator + "Landscape_1.jpg")

cleanup:
d.delete(flush: true)
}

}

0 comments on commit 2806193

Please sign in to comment.