Skip to content

Commit

Permalink
Merge pull request #75 from eea/develop
Browse files Browse the repository at this point in the history
Add embed_content block serializer, ref #274326
  • Loading branch information
avoinea authored Oct 21, 2024
2 parents 382f0e2 + 93895c2 commit af82a63
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 22 deletions.
26 changes: 5 additions & 21 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -89,22 +89,6 @@ pipeline {
sh '''docker pull eeacms/plone-test:5-python3; docker run -i --rm --name="$BUILD_TAG-plone5py3" -e GIT_BRANCH="$BRANCH_NAME" -e ADDONS="$GIT_NAME[test]" -e DEVELOP="src/$GIT_NAME" -e GIT_CHANGE_ID="$CHANGE_ID" eeacms/plone-test:5-python3 -v -vv -s $GIT_NAME'''
}
},
"PloneSaaS": {
node(label: 'docker') {
script {
try {
sh '''docker pull eeacms/plonesaas-devel; docker run -i --name="$BUILD_TAG-plonesaas" -e GIT_NAME="$GIT_NAME" -e GIT_BRANCH="$BRANCH_NAME" -e GIT_CHANGE_ID="$CHANGE_ID" eeacms/plonesaas-devel /debug.sh coverage'''
sh '''mkdir -p xunit-reports; docker cp $BUILD_TAG-plonesaas:/plone/instance/parts/xmltestreport/testreports/. xunit-reports/'''
stash name: "xunit-reports", includes: "xunit-reports/*.xml"
sh '''docker cp $BUILD_TAG-plonesaas:/plone/instance/src/$GIT_NAME/coverage.xml coverage.xml'''
stash name: "coverage.xml", includes: "coverage.xml"
} finally {
sh '''docker rm -v $BUILD_TAG-plonesaas'''
}
junit 'xunit-reports/*.xml'
}
}
},
)
}
}
Expand All @@ -120,14 +104,14 @@ pipeline {
node(label: 'swarm') {
script{
checkout scm
dir("xunit-reports") {
unstash "xunit-reports"
}
unstash "coverage.xml"
// dir("xunit-reports") {
// unstash "xunit-reports"
// }
// unstash "coverage.xml"
def scannerHome = tool 'SonarQubeScanner';
def nodeJS = tool 'NodeJS11';
withSonarQubeEnv('Sonarqube') {
sh '''sed -i "s|/plone/instance/src/$GIT_NAME|$(pwd)|g" coverage.xml'''
// sh '''sed -i "s|/plone/instance/src/$GIT_NAME|$(pwd)|g" coverage.xml'''
sh "export PATH=$PATH:${scannerHome}/bin:${nodeJS}/bin; sonar-scanner -Dsonar.python.xunit.skipDetails=true -Dsonar.python.xunit.reportPath=xunit-reports/*.xml -Dsonar.python.coverage.reportPaths=coverage.xml -Dsonar.sources=./eea -Dsonar.projectKey=$GIT_NAME-$BRANCH_NAME -Dsonar.projectVersion=$BRANCH_NAME-$BUILD_NUMBER"
sh '''try=2; while [ \$try -gt 0 ]; do curl -s -XPOST -u "${SONAR_AUTH_TOKEN}:" "${SONAR_HOST_URL}api/project_tags/set?project=${GIT_NAME}-${BRANCH_NAME}&tags=${SONARQUBE_TAGS},${BRANCH_NAME}" > set_tags_result; if [ \$(grep -ic error set_tags_result ) -eq 0 ]; then try=0; else cat set_tags_result; echo "... Will retry"; sleep 60; try=\$(( \$try - 1 )); fi; done'''
}
Expand Down
5 changes: 5 additions & 0 deletions docs/HISTORY.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Changelog
=========

10.6 - (2024-10-21)
---------------------------
* Change: Add embed_content block serializer
[razvanMiu - refs #274326]

10.5 - (2024-09-27)
---------------------------
* Change: Disable Diazo Theming for flourish browser view
Expand Down
42 changes: 42 additions & 0 deletions eea/api/dataconnector/browser/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from urllib.parse import urlparse
from AccessControl import Unauthorized
from plone import api
from plone.restapi.blocks import iter_block_transform_handlers
from plone.restapi.behaviors import IBlocks
from plone.restapi.interfaces import ISerializeToJson
from plone.restapi.interfaces import IBlockFieldSerializationTransformer
Expand Down Expand Up @@ -213,6 +214,41 @@ def getVisualization(serializer, layout=True):
return response


@implementer(IBlockFieldSerializationTransformer)
@adapter(IBlocks, IBrowserRequest)
class EmbedContentSerializationTransformer:
"""Embed content serialization"""

order = 9999
block_type = "embed_content"

def __init__(self, context, request):
self.context = context
self.request = request

def __call__(self, value):
properties = value.get("properties", {})
content_type = properties.get('@type', None)
block_type = 'none'

if content_type == 'visualization':
block_type = 'embed_visualization'
if content_type == 'tableau_visualization':
block_type = 'embed_tableau_visualization'
if content_type == 'map_visualization':
block_type = 'embed_eea_map_block'
if content_type == 'map_interactive':
block_type = 'embed_maps'

new_value = value.copy()
for handler in iter_block_transform_handlers(
self.context, {**value, "@type": block_type},
IBlockFieldSerializationTransformer):
new_value = handler(new_value)

return new_value


@implementer(IBlockFieldSerializationTransformer)
@adapter(IBlocks, IBrowserRequest)
class EmbedVisualizationSerializationTransformer:
Expand All @@ -227,6 +263,8 @@ def __init__(self, context, request):

def __call__(self, value):
vis_url, uid = getUrlUid(self, value, 'vis_url')
if not uid:
vis_url, uid = getUrlUid(self, value, 'url')

if 'visualization' in value:
del value['visualization']
Expand Down Expand Up @@ -332,6 +370,8 @@ def __init__(self, context, request):

def __call__(self, value):
tableau_vis_url, uid = getUrlUid(self, value, 'tableau_vis_url')
if not uid:
tableau_vis_url, uid = getUrlUid(self, value, 'url')

if 'tableau_visualization' in value:
del value['tableau_visualization']
Expand Down Expand Up @@ -437,6 +477,8 @@ def __init__(self, context, request):

def __call__(self, value):
vis_url, uid = getUrlUid(self, value, 'vis_url')
if not uid:
vis_url, uid = getUrlUid(self, value, 'url')

if 'map_visualization_data' in value:
del value['map_visualization_data']
Expand Down
3 changes: 3 additions & 0 deletions eea/api/dataconnector/browser/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@
/>

<!-- Serializations -->
<subscriber
provides="plone.restapi.interfaces.IBlockFieldSerializationTransformer"
factory=".blocks.EmbedContentSerializationTransformer" />
<subscriber
provides="plone.restapi.interfaces.IBlockFieldSerializationTransformer"
factory=".blocks.EmbedVisualizationSerializationTransformer" />
Expand Down
2 changes: 1 addition & 1 deletion eea/api/dataconnector/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
10.5
10.6

0 comments on commit af82a63

Please sign in to comment.