Commit 9587cf0f authored by Gerrit Hübbers's avatar Gerrit Hübbers 🃏
Browse files

Introduce file dto concept

parent 976ffc0f
......@@ -120,8 +120,10 @@ public class BundlesStreamSourceFactory {
}
else if (BundlesSourceType.XML_XSLT_SOURCE == bundlesSourceType) {
XmlXsltDto dto = PersistableHelper.instantiate(data, XmlXsltDto.class);
String xmlContent = dto.getXmlContent();
String xsltContent = dto.getXsltContent();
String xmlContent = dto.getXmlFile().getContent();
log.info("xmlContent=\n{}", xmlContent);
String xsltContent = dto.getXsltFile().getContent();
log.info("xsltContent=\n{}", xsltContent);
result = new XmlXsltBundlesStreamSource(xmlContent, xsltContent, bseId);
}
return result;
......
package org.gesis.dda.publishing.domain.impl;
public class FileDto {
private String name;
private String content;
public FileDto(String name, String content) {
this.name = name;
this.content = content;
}
public String getName() {
return name;
}
public String getContent() {
return content;
}
}
\ No newline at end of file
......@@ -2,20 +2,20 @@ package org.gesis.dda.publishing.domain.impl;
public class XmlXsltDto {
private String xmlContent;
private String xsltContent;
private FileDto xmlFile;
private FileDto xsltFile;
public XmlXsltDto(String xmlContent, String xsltContent) {
this.xmlContent = xmlContent;
this.xsltContent = xsltContent;
public XmlXsltDto(FileDto xmlFile, FileDto xsltFile) {
this.xmlFile = xmlFile;
this.xsltFile = xsltFile;
}
public String getXmlContent() {
return xmlContent;
public FileDto getXmlFile() {
return xmlFile;
}
public String getXsltContent() {
return xsltContent;
public FileDto getXsltFile() {
return xsltFile;
}
}
\ No newline at end of file
......@@ -4,8 +4,8 @@ angular.module('ddaApp').controller('PublicationsSourcesXmlXsltSourceCreateDialo
['$scope', '$stateParams', '$uibModalInstance', '$state', 'BundlesSource',
function($scope, $stateParams, $uibModalInstance, $state, BundlesSource) {
$scope.xmlContent = '';
$scope.xsltContent = '';
$scope.xmlFile = {};
$scope.xsltFile = {};
$scope.clear = function() {
$uibModalInstance.dismiss('cancel');
......@@ -21,8 +21,8 @@ angular.module('ddaApp').controller('PublicationsSourcesXmlXsltSourceCreateDialo
$scope.save = function () {
var dataObject = {
xmlContent: $scope.xmlContent,
xsltContent: $scope.xsltContent
xmlFile: $scope.xmlFile,
xsltFile: $scope.xsltFile
};
console.log(dataObject);
......
......@@ -8,10 +8,10 @@
</div>
<div class="modal-body">
<label>XML file
<input type="file" name="xmlContent" fileread="xmlContent">
<input type="file" name="xmlFile" fileread="xmlFile">
</label>
<label>XSLT file
<input type="file" name="xsltContent" fileread="xsltContent">
<input type="file" name="xsltFile" fileread="xsltFile">
</label>
</div>
<div>{{message}}</div>
......
......@@ -7,17 +7,21 @@ angular.module('ddaApp').controller('PublicationsSourcesXmlXsltSourceEditDialogC
$scope.entity = entity;
$scope.dataDto = {
xmlContent: angular.fromJson(entity.data).xmlContent,
xsltContent: angular.fromJson(entity.data).xsltContent
xmlFile: {
name: angular.fromJson(entity.data).xmlFile.name,
content: angular.fromJson(entity.data).xmlFile.content
},
xsltFile: {
name: angular.fromJson(entity.data).xsltFile.name,
content: angular.fromJson(entity.data).xsltFile.content
}
};
$scope.clear = function() {
$uibModalInstance.dismiss('cancel');
};
$scope.metadataTransformers = MetadataTransformer.query();
$scope.selectedMetadataTransformer = null;
var onSaveSuccess = function (result) {
$uibModalInstance.close(result);
};
......@@ -25,14 +29,8 @@ angular.module('ddaApp').controller('PublicationsSourcesXmlXsltSourceEditDialogC
var onSaveError = function (result) {
};
$scope.save = function () {
console.log($scope.dataDto);
BundlesSource.updateData({id: $scope.entity.id}, $scope.dataDto, onSaveSuccess, onSaveError);
if (null != $scope.selectedMetadataTransformer) {
BundlesSource.updateMetadataTransformer({id: $scope.entity.id}, $scope.selectedMetadataTransformer.id, onSaveSuccess, onSaveError);
}
};
}]);
......@@ -8,14 +8,24 @@
</div>
<div class="modal-body">
<div>
<label>XML
<textarea name="xmlContent" cols=80 rows=10 ng-model="dataDto.xmlContent"></textarea>
<label>XML file name
<input type="text" name="xmlName" ng-model="dataDto.xmlFile.name">
</label>
</div>
<div>
<label>XML content
<textarea name="xmlContent" cols=80 rows=10 ng-model="dataDto.xmlFile.content"></textarea>
</label>
</div>
<div>
<label>XSLT
<textarea name="xsltContent" cols=80 rows=10 ng-model="dataDto.xsltContent"></textarea>
<label>XSLT file name
<input type="text" name="xsltName" ng-model="dataDto.xsltFile.name">
</label>
</div>
<div>
<label>XSLT content
<textarea name="xsltContent" cols=80 rows=10 ng-model="dataDto.xsltFile.content"></textarea>
</label>
</div>
</div>
......
......@@ -79,14 +79,16 @@
<thead>
<tr>
<th><span>Reference</span></th>
<th><span>Metadata transformer</span></th>
<th><span>XML file name</span></th>
<th><span>XSLT file name</span></th>
<th><span>State</span></th>
</tr>
</thead>
<tbody>
<tr ng-repeat="xmlXsltSource in xmlXsltSources track by xmlXsltSource.id">
<td>{{xmlXsltSource.reference}}</td>
<td>{{xmlXsltSource.metadataTransformer.name}}</td>
<td>{{xmlXsltSource.data | jsonstring2object:"xmlFile" | jsonstring2object:"name"}}</td>
<td>{{xmlXsltSource.data | jsonstring2object:"xsltFile" | jsonstring2object:"name"}}</td>
<td>{{xmlXsltSource.bundlesSourceState}}</td>
<td translate="{{'ddaApp.BundlesSourceState.' + bundlesSource.bundlesSourceState}}">{{xmlXsltSource.bundlesSource.bundlesSourceState}}</td>
<td class="text-right">
......
......@@ -413,9 +413,8 @@ angular.module('ddaApp')
resolve: {
entity: function () {
return {
xmlContent: null,
xsltContent: null,
reference: null
xmlFile: null,
xsltFile: null,
};
}
}
......
......@@ -8,13 +8,20 @@ angular.module('ddaApp')
fileread: "="
},
link: function (scope, element, attributes) {
console.log("attributes:");
console.log(attributes);
element.bind("change", function (changeEvent) {
scope.fileread = {};
var reader = new FileReader();
reader.onload = function (loadEvent) {
scope.$apply(function () {
scope.fileread = loadEvent.target.result;
console.log(loadEvent.target);
scope.fileread.content = loadEvent.target.result;
console.log(scope.fileread);
});
}
scope.fileread.name = changeEvent.target.files[0].name;
reader.readAsText(changeEvent.target.files[0]);
});
}
......
package org.gesis.dda.publishing.domain.impl;
import static org.junit.Assert.assertEquals;
import java.io.IOException;
import org.gesis.dda.persist.PersistableHelper;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class XmlXsltDtoTest {
private final static Logger log = LoggerFactory.getLogger(XmlXsltDtoTest.class);
@Test
public void serializeDeserializeGson() throws IOException {
FileDto xmlFileDto = new FileDto("foo.xml", "some xml content");
FileDto xsltFileDto = new FileDto("bar.xslt", "some xslt content");
XmlXsltDto dto = new XmlXsltDto(xmlFileDto, xsltFileDto);
String dtoJsonString = PersistableHelper.getData(dto);
log.info(dtoJsonString);
XmlXsltDto dtoDeserialized = PersistableHelper.instantiate(dtoJsonString, XmlXsltDto.class);
assertEquals(dto.getXmlFile().getName(), dtoDeserialized.getXmlFile().getName());
assertEquals(dto.getXmlFile().getContent(), dtoDeserialized.getXmlFile().getContent());
assertEquals(dto.getXsltFile().getName(), dtoDeserialized.getXsltFile().getName());
assertEquals(dto.getXsltFile().getContent(), dtoDeserialized.getXsltFile().getContent());
}
}
......@@ -20,6 +20,7 @@ import org.gesis.dda.feeder.FeedingContext;
import org.gesis.dda.feeder.impl.FeedingContextFactory;
import org.gesis.dda.feeder.impl.OaiPmhNextFeedingTimeStrategy;
import org.gesis.dda.persist.PersistableHelper;
import org.gesis.dda.publishing.domain.impl.FileDto;
import org.gesis.dda.publishing.domain.impl.KmhopbssDto;
import org.gesis.dda.publishing.domain.impl.UnapiBssConfigDto;
import org.gesis.dda.publishing.domain.impl.XmlFileBssConfigDto;
......@@ -426,7 +427,9 @@ public class FeederServiceIntTest {
log.info("xsltString=\n{}", xsltString);
XmlXsltDto dto = new XmlXsltDto(xmlString, xsltString);
FileDto xmlDto = new FileDto("foo.xml", xmlString);
FileDto xsltDto = new FileDto("bar.xslt", xsltString);
XmlXsltDto dto = new XmlXsltDto(xmlDto, xsltDto);
underTest.setReference(reference);
underTest.setData( PersistableHelper.getData(dto) );
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment