Skip to content

Commit

Permalink
Merge branch 'moellerth/issue3304-ddi-codebook' into dev-2024-2-2
Browse files Browse the repository at this point in the history
  • Loading branch information
tilovillwock committed Oct 28, 2024
2 parents 91cd838 + e37bfd0 commit b3857c6
Show file tree
Hide file tree
Showing 22 changed files with 716 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,19 @@ angular.module('metadatamanagementApp')
});
}]);


/**
* Method to request the endpoint that downloads all variables of the data package as a DDI-formatted XML file.
* We could not put this into the "DataPackageResource"-schema (above), because the URLs would not match.
*/
angular.module('metadatamanagementApp').factory('ExportDdiVariablesResource', ['$http',
function($http) {
return {
exportVariablesAsXml: function(dataPackageId) {
return $http.get('api/data-packages/exportDDI/xml/' + dataPackageId).then(function(response) {
return response.data;
});
}
}
}]);

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<div class="fdz-detail__header-text">
<h1 class="md-headline" display-i18n-string="ctrl.dataPackage.title" ></h1>
<json-content-dialog class="mb0" content="ctrl.dataPackage"
header-title="ctrl.dataPackage.title" ng-if="ctrl.enableJsonView"></json-content-dialog>
header-title="ctrl.dataPackage.title" ng-if="ctrl.enableJsonView"></json-content-dialog>
</div>
<div class="fdz-tag-link-container" ng-if="ctrl.dataPackageTags.length > 0">
<h5>{{'data-package-management.detail.label.tags' | translate}}: </h5>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
'$q',
'dataAcquisitionProjectSearchService',
'ElasticSearchClient',
'ExportDdiVariablesResource',
'Principal',
function ($scope,
$rootScope,
$location,
Expand All @@ -38,7 +40,8 @@
DataPackageAccessWaysResource, $mdDialog,
DataPackageCitationDialogService,
CurrentDataPackageService,
DataAcquisitionProjectResource, $q, dataAcquisitionProjectSearchService, ElasticSearchClient) {
DataAcquisitionProjectResource, $q, dataAcquisitionProjectSearchService, ElasticSearchClient,
ExportDdiVariablesResource, Principal) {
var $ctrl = this;
var initReady = false;
$ctrl.dataPackageIdVersion = {};
Expand All @@ -49,6 +52,7 @@
$ctrl.isPreReleased = false;
$ctrl.variableNotAccessible = false;
$ctrl.disabled = false;
$ctrl.allowedToExportVariableMetadata = false;
$scope.bowser = $rootScope.bowser;
$ctrl.numberOfShoppingCartProducts = ShoppingCartService.count();

Expand Down Expand Up @@ -89,6 +93,7 @@
$ctrl.selectedVersion = $ctrl.dataPackageIdVersion.version;
loadDataPackage($ctrl.dataPackageIdVersion.masterId,
$ctrl.dataPackageIdVersion.version);
$ctrl.allowedToExportVariableMetadata = Principal.isAuthenticated();
initReady = true;
}

Expand Down Expand Up @@ -390,4 +395,31 @@
}
return true;
}

/**
* Checks if the latest version is selected.
* @returns true if the latest version is selected else false
*/
$ctrl.isLatestVersionSelected = function() {
return this.selectedVersion
&& $ctrl.releases
&& $ctrl.releases.length > 0 ? $ctrl.releases[0].version === this.selectedVersion : false;
}

/**
* Exports Variables metadata as DDI Codebook XML.
*/
$ctrl.exportVariables = function() {
ExportDdiVariablesResource.exportVariablesAsXml($ctrl.dataPackage.id).then(function(res) {
var blob = new Blob([res],{
type: "application/xml;charset=utf-8;"
});
var downloadLink = document.createElement('a');
const fileName = 'mdm_export_ddi_variables_' + $ctrl.dataPackage.id.split('$')[0] + '.xml'
downloadLink.setAttribute('download', fileName);
downloadLink.setAttribute('href', window.URL.createObjectURL(blob));
downloadLink.click();
$scope.isDownloadingData = false;
})
}
}]);
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,16 @@
</md-menu-content>
</md-menu>
</md-list-item>
<md-list-item style="flex-flow: row; padding-right: 12px;" class="md-no-proxy">
<md-button class="md-small md-raised md-primary fdz-truncate-string" ng-click="$ctrl.exportVariables()"
ng-hide="!$ctrl.allowedToExportVariableMetadata || !$ctrl.isLatestVersionSelected() || !$ctrl.selectedVersion || $ctrl.noFinalRelease || $ctrl.variableNotAccessible || $ctrl.isPreReleased || ($ctrl.accessWays && $ctrl.accessWays.length === 0) || $ctrl.releases.length === 0"
style="margin-right: 12px; margin-top: 0px; ">
<md-tooltip md-direction="top" md-autohide="true" md-z-index="bowser.mobile || bowser.tablet ? -100 : 100001">
{{'shopping-cart.buttons.export-ddi-variables-tooltip' | translate}}
</md-tooltip>
<span>{{'shopping-cart.buttons.export-ddi-variables' | translate}}</span>
</md-button>
</md-list-item>
</md-list>
</md-card-content>
<md-card-footer style="padding-top: 0px;">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ angular.module('metadatamanagementApp').config([
'related-publications-tooltip': 'Klicken, um weitere Informationen zu Publikationen zu erhalten.',
'data-package-version-tooltip': 'Klicken, um weitere Informationen zur Version von Datenpaketen zu erhalten.',
'analysis-package-version-tooltip': 'Klicken, um weitere Informationen zur Version von Analysepaketen zu erhalten.',
'data-package-access-way-tooltip': 'Klicken, um weitere Informationen zu Zugangswegen zu erhalten.'
'data-package-access-way-tooltip': 'Klicken, um weitere Informationen zu Zugangswegen zu erhalten.',
'export-ddi-variables': 'Variablenmetadaten exportieren',
'export-ddi-variables-tooltip': 'Klicken, um die Variablen-Metadaten als DDI-Codebook-XML herunterzuladen.'
},
'version-info': {
'title': 'Eine Version auswählen',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ angular.module('metadatamanagementApp').config([
'analysis-package-tooltip': 'Click to get more information about analysis packages',
'related-publications-tooltip': 'Click to get more information about publications',
'analysis-package-version-tooltip': 'Click to get more information about versions of analysis packages',
'data-package-access-way-tooltip': 'Click to get more information about access ways'
'data-package-access-way-tooltip': 'Click to get more information about access ways',
'export-ddi-variables': 'Export variable metadata',
'export-ddi-variables-tooltip': 'Click to download the metadata of all variables as a DDI codebook XML.'
},
'version-info': {
'title': 'Select a Version',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@
<h1 class="md-headline" display-i18n-string="ctrl.survey.title" ></h1>
<json-content-dialog class="mb0" content="ctrl.survey"
header-title="ctrl.survey.title" ng-if="ctrl.enableJsonView"></json-content-dialog>
<md-button class="md-primary fdz-small ma0" style="height: fit-content;"
ng-if="ctrl.enableVariableExport"
ng-click="ctrl.exportVariables()">
<md-tooltip md-z-index="bowser.mobile || bowser.tablet ? -100 : 100001">
Daten als XML exportieren
</md-tooltip>
<span class="fdz-no-select">DDI</span>
</md-button>
</div>
</div>
<md-divider></md-divider>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package eu.dzhw.fdz.metadatamanagement.datapackagemanagement.domain.ddicodebook;

import java.util.List;

import javax.xml.bind.annotation.XmlElement;

import lombok.AllArgsConstructor;

/**
* Class representing the DDI catgry element.
*/
@AllArgsConstructor
public class Catgry {

/**
* Constructor needed by JAXB.
*/
public Catgry() {}

@XmlElement(name = "catValu")
String catValu;

@XmlElement(name = "labl")
List<TextElement> labl;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package eu.dzhw.fdz.metadatamanagement.datapackagemanagement.domain.ddicodebook;

import javax.xml.bind.annotation.XmlElement;

import lombok.AllArgsConstructor;

/**
* Class representing the DDI citation element.
*/
@AllArgsConstructor
public class Citation {

/**
* Constructor needed by JAXB.
*/
public Citation() {}

@XmlElement(name = "titlStmt")
TitlStmt titlStmt;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package eu.dzhw.fdz.metadatamanagement.datapackagemanagement.domain.ddicodebook;

import java.util.List;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

/**
* Class representing the root element codebook of the mapping of the DDI Codebook standard.
*/

@XmlRootElement(name = "codeBook")
public class CodeBook {

/**
* Constructor for codebook.
* @param stdyDscr the data package description in form of the DDI stdyDscr element.
* @param fileDscr the dataset metadata in form of the DDI fileDscr element.
* @param dataDscr the variable metadata in form of the DDI dataDscr element.
*/
public CodeBook(StdyDscr stdyDscr, List<FileDscr> fileDscr, DataDscr dataDscr) {
this.stdyDscr = stdyDscr;
this.fileDscr = fileDscr;
this.dataDscr = dataDscr;
}

/**
* Constructor needed by JAXB.
*/
public CodeBook() {}

@XmlElement(name = "stdyDscr")
private StdyDscr stdyDscr;

@XmlElement(name = "fileDscr")
private List<FileDscr> fileDscr;

@XmlElement(name = "dataDscr")
private DataDscr dataDscr;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package eu.dzhw.fdz.metadatamanagement.datapackagemanagement.domain.ddicodebook;

import java.util.List;

import javax.xml.bind.annotation.XmlElement;

import lombok.AllArgsConstructor;

/**
* Class representing the DDI dataDscr element.
*/
@AllArgsConstructor
public class DataDscr {

/**
* Constructor needed by JAXB.
*/
public DataDscr() {}

@XmlElement(name = "var")
List<Var> var;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package eu.dzhw.fdz.metadatamanagement.datapackagemanagement.domain.ddicodebook;

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;

import lombok.AllArgsConstructor;

/**
* Class representing the DDI Codebook fileDscr element.
*/
@AllArgsConstructor
public class FileDscr {

public FileDscr() {}

@XmlAttribute(name = "ID")
String id;

@XmlElement(name = "fileTxt")
FileTxt fileTxt;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package eu.dzhw.fdz.metadatamanagement.datapackagemanagement.domain.ddicodebook;

import javax.xml.bind.annotation.XmlElement;

import lombok.AllArgsConstructor;

/**
* Class representing the DDI fileTxt element.
*/
@AllArgsConstructor
public class FileTxt {

/**
* Constructor needed by JAXB.
*/
public FileTxt() {}

@XmlElement(name = "fileName")
String fileName;

@XmlElement(name = "fileCont")
TextElement fileCont;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package eu.dzhw.fdz.metadatamanagement.datapackagemanagement.domain.ddicodebook;

/**
* Enum representing available language abbreviations.
*/
public enum LanguageEnum {
de("de"), en("en");

/**
* The language string.
*/
public final String languageString;

/**
* Construct the enum.
*
* @param languageString The language string.
*/
LanguageEnum(String languageString) {
this.languageString = languageString;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package eu.dzhw.fdz.metadatamanagement.datapackagemanagement.domain.ddicodebook;

import javax.xml.bind.annotation.XmlElement;

import lombok.AllArgsConstructor;

/**
* Class representing the DDI stdyDscr element.
*/
@AllArgsConstructor
public class StdyDscr {

/**
* Constructor needed by JAXB.
*/
public StdyDscr() {}

@XmlElement(name = "citation")
Citation citation;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package eu.dzhw.fdz.metadatamanagement.datapackagemanagement.domain.ddicodebook;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlValue;

import lombok.AllArgsConstructor;

/**
* General element for a language annotated XML element containing a string,
* e.g. labels (labl in DDI standard).
*/
@AllArgsConstructor
@XmlAccessorType(XmlAccessType.NONE)
public class TextElement {

/**
* Constructor needed by JAXB.
*/
public TextElement() {}

@XmlAttribute(name = "xml:lang")
private LanguageEnum lang;

@XmlValue
private String value;

public String getValue() {
return value;
}

public void setValue(String value) {
this.value = value;
}

}
Loading

0 comments on commit b3857c6

Please sign in to comment.