Skip to content

Commit

Permalink
fixed broken import method which resulted in partially imported data
Browse files Browse the repository at this point in the history
  • Loading branch information
albogdano committed Feb 26, 2021
1 parent 10cb4d7 commit c61fc5c
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions para-server/src/main/java/com/erudika/para/rest/Api1.java
Original file line number Diff line number Diff line change
Expand Up @@ -1025,7 +1025,8 @@ public static Inflector<ContainerRequestContext, Response> restoreHandler(final
public Response apply(ContainerRequestContext ctx) {
App app = (a != null) ? a : getPrincipalApp();
if (app != null) {
ObjectReader reader = ParaObjectUtils.getJsonMapper().readerFor(new TypeReference<List<Sysprop>>() { });
ObjectReader reader = ParaObjectUtils.getJsonMapper().
readerFor(new TypeReference<List<Map<String, Object>>>() { });
int count = 0;
int importBatchSize = Config.getConfigInt("import_batch_size", 100);
String filename = Optional.ofNullable(ctx.getUriInfo().getQueryParameters().getFirst("filename")).
Expand All @@ -1037,12 +1038,12 @@ public Response apply(ContainerRequestContext ctx) {
ZipEntry zipEntry;
List<ParaObject> toCreate = new LinkedList<ParaObject>();
while ((zipEntry = zipIn.getNextEntry()) != null) {
List<ParaObject> objects = reader.readValue(new FilterInputStream(zipIn) {
List<Map<String, Object>> objects = reader.readValue(new FilterInputStream(zipIn) {
public void close() throws IOException {
zipIn.closeEntry();
}
});
toCreate.addAll(objects);
objects.forEach(o -> toCreate.add(ParaObjectUtils.setAnnotatedFields(o)));
if (toCreate.size() >= importBatchSize) {
getDAO().createAll(app.getAppIdentifier(), toCreate);
toCreate.clear();
Expand Down

0 comments on commit c61fc5c

Please sign in to comment.