Skip to content
This repository was archived by the owner on May 24, 2022. It is now read-only.

Commit 0126030

Browse files
committed
Merge pull request #8 from zazi/reutilize_input_schema
[DD-1169] reutilize input schema
2 parents 07693a3 + 18cf3a2 commit 0126030

File tree

11 files changed

+238
-141
lines changed

11 files changed

+238
-141
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ prototype.projectID=819f2f6e-98ed-90e2-372e-71a0a1eec786
7171
# if multiple projects deliver the mappings for the task
7272
prototype.projectIDs=9d6ec288-f1bf-4f96-78f6-5399e3050125,69664ba5-bbe5-6f35-7a77-47bacf9d3731
7373
74+
# if an existing input should be utilised at input data model creation
75+
prototype.inputSchemaID=Schema-cb8f4b96-9ab2-4972-88f8-143656199518
76+
7477
# the output data model refers to the output schema as well
7578
prototype.outputDataModelID=DataModel-cf998267-392a-4d87-a33a-88dd1bffb016
7679

conf/config.properties.template

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ prototype.dataModelID=bbd368e8-b75c-0e64-b96a-ab812a700b4f
2626
prototype.projectID=819f2f6e-98ed-90e2-372e-71a0a1eec786
2727
# if multiple projects deliver the mappings for the task
2828
prototype.projectIDs=9d6ec288-f1bf-4f96-78f6-5399e3050125,69664ba5-bbe5-6f35-7a77-47bacf9d3731
29+
# if an existing input should be utilised at input data model creation
30+
prototype.inputSchemaID=Schema-cb8f4b96-9ab2-4972-88f8-143656199518
2931
prototype.outputDataModelID=DataModel-cf998267-392a-4d87-a33a-88dd1bffb016
3032

3133
# enables init part (i.e. resource + data model creation)

src/main/java/de/tu_dortmund/ub/data/dswarm/DswarmBackendStatics.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ public final class DswarmBackendStatics {
99
public static final String RESOURCES_ENDPOINT = "resources";
1010
public static final String CONFIGURATIONS_ENDPOINT = "configurations";
1111
public static final String PROJECTS_ENDPOINT = "projects";
12+
public static final String SCHEMAS_ENDPOINT = "schemas";
1213
public static final String TASKS_ENDPOINT = "tasks";
1314

1415
public static final String UUID_IDENTIFIER = "uuid";
1516
public static final String MAPPINGS_IDENTIFIER = "mappings";
1617
public static final String DATA_RESOURCE_IDENTIFIER = "data_resource";
18+
public static final String SCHEMA_IDENTIFIER = "schema";
1719
public static final String NAME_IDENTIFIER = "name";
1820
public static final String DESCRIPTION_IDENTIFIER = "description";
1921
public static final String TASK_IDENTIFIER = "task";
@@ -28,5 +30,6 @@ public final class DswarmBackendStatics {
2830
public static final String DO_INGEST_ON_THE_FLY = "do_ingest_on_the_fly";
2931
public static final String DO_EXPORT_ON_THE_FLY = "do_export_on_the_fly";
3032
public static final String DO_VERSIONING_ON_RESULT_IDENTIFIER = "do_versioning_on_result";
33+
public static final String UTILISE_EXISTING_INPUT_IDENTIFIER = "utilise_existing_input_schema";
3134
public static final String DO_DATA_MODEL_INGEST_IDENTIFIER = "doIngest";
3235
}

src/main/java/de/tu_dortmund/ub/data/dswarm/Export.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,23 +63,23 @@ public String call() {
6363

6464
LOG.info(String.format("[%s] Starting 'XML-Export (Task)' ...", serviceName));
6565

66-
// init process values
67-
String message = null;
68-
6966
try {
7067

7168
TPUUtil.initSchemaIndices(serviceName, config);
7269

7370
// export and save to results folder
7471
exportDataModel(exportDataModelID, serviceName);
7572

73+
return null;
7674
} catch (final Exception e) {
7775

78-
LOG.error(String.format("[%s] Exporting and saving datamodel '%s' failed with a %s", serviceName, exportDataModelID, e.getClass()
79-
.getSimpleName()), e);
80-
}
76+
final String message = String
77+
.format("[%s] Exporting and saving datamodel '%s' failed with a %s", serviceName, exportDataModelID, e.getClass()
78+
.getSimpleName());
79+
LOG.error(message, e);
8180

82-
return message;
81+
throw new RuntimeException(message, e);
82+
}
8383
}
8484

8585
/**
@@ -121,6 +121,10 @@ private void exportDataModel(final String dataModelID, final String serviceName)
121121
default: {
122122

123123
LOG.error(String.format("[%s] %d : %s", serviceName, statusCode, httpResponse.getStatusLine().getReasonPhrase()));
124+
125+
final String response = TPUUtil.getResponseMessage(httpResponse);
126+
127+
throw new Exception("something went wrong at data model export: " + response);
124128
}
125129
}
126130

src/main/java/de/tu_dortmund/ub/data/dswarm/Ingest.java

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ of this software and associated documentation files (the "Software"), to deal
2525
package de.tu_dortmund.ub.data.dswarm;
2626

2727
import java.io.File;
28-
import java.io.StringWriter;
2928
import java.util.Properties;
3029
import java.util.concurrent.Callable;
3130

3231
import javax.json.Json;
3332
import javax.json.JsonReader;
3433

34+
import de.tu_dortmund.ub.data.util.TPUUtil;
3535
import org.apache.commons.io.IOUtils;
3636
import org.apache.http.HttpEntity;
3737
import org.apache.http.client.methods.CloseableHttpResponse;
@@ -43,7 +43,6 @@ of this software and associated documentation files (the "Software"), to deal
4343
import org.apache.http.entity.mime.content.StringBody;
4444
import org.apache.http.impl.client.CloseableHttpClient;
4545
import org.apache.http.impl.client.HttpClients;
46-
import org.apache.http.util.EntityUtils;
4746
import org.slf4j.Logger;
4847
import org.slf4j.LoggerFactory;
4948

@@ -95,9 +94,6 @@ public String call() {
9594
final String dataModelID = this.dataModelID;
9695
final String updateResourceID = resourceID;
9796

98-
// init process values
99-
final String message = null;
100-
10197
try {
10298
// build a InputDataModel for the resource
10399
final String name = String.format("resource for project '%s'", resource);
@@ -129,14 +125,18 @@ public String call() {
129125

130126
// no need to clean up resources or datamodels anymore
131127

128+
LOG.info(String.format("[%s] Finished 'Ingest (Task)' no. '%d' ...", serviceName, cnt));
129+
130+
return null;
132131
} catch (final Exception e) {
133132

134-
LOG.error(String.format("[%s] Processing resource '%s' failed with a %s", serviceName, resource, e.getClass().getSimpleName()), e);
135-
}
133+
final String message = String.format("[%s] Processing resource '%s' failed with a %s", serviceName, resource,
134+
e.getClass().getSimpleName());
136135

137-
LOG.info(String.format("[%s] Finished 'Ingest (Task)' no. '%d' ...", serviceName, cnt));
136+
LOG.error(message, e);
138137

139-
return message;
138+
throw new RuntimeException(message, e);
139+
}
140140
}
141141

142142
/**
@@ -178,6 +178,10 @@ private String updateDataModelContent(final String inputDataModelID, final Strin
178178
default: {
179179

180180
LOG.error(message);
181+
182+
final String response = TPUUtil.getResponseMessage(httpResponse);
183+
184+
throw new Exception("something went wrong at data model export: " + message + " " + response);
181185
}
182186
}
183187
}
@@ -227,36 +231,30 @@ private String uploadFileAndUpdateResource(final String resourceUUID, final Stri
227231
try (final CloseableHttpResponse httpResponse = httpclient.execute(httpPut)) {
228232

229233
final int statusCode = httpResponse.getStatusLine().getStatusCode();
230-
final HttpEntity httpEntity = httpResponse.getEntity();
231234

232235
final String message = String.format("[%s] %d : %s", serviceName, statusCode, httpResponse.getStatusLine()
233236
.getReasonPhrase());
234237

238+
final String response = TPUUtil.getResponseMessage(httpResponse);
239+
235240
switch (statusCode) {
236241

237242
case 200: {
238243

239244
LOG.info(message);
240-
final StringWriter writer = new StringWriter();
241-
IOUtils.copy(httpEntity.getContent(), writer, APIStatics.UTF_8);
242-
final String responseJson = writer.toString();
243-
writer.flush();
244-
writer.close();
245245

246-
LOG.debug(String.format("[%s] responseJson : %s", serviceName, responseJson));
246+
LOG.debug(String.format("[%s] responseJson : %s", serviceName, response));
247247

248-
return responseJson;
248+
return response;
249249
}
250250
default: {
251251

252252
LOG.error(message);
253+
254+
throw new Exception("something went wrong at data model export: " + message + " " + response);
253255
}
254256
}
255-
256-
EntityUtils.consume(httpEntity);
257257
}
258258
}
259-
260-
return null;
261259
}
262260
}

0 commit comments

Comments
 (0)