Skip to content

Commit

Permalink
Fix for sharing models for older version. Closes eclipse-vorto#207
Browse files Browse the repository at this point in the history
Signed-off-by: Nagavijay Sivakumar <[email protected]>
  • Loading branch information
Nagavijay Sivakumar authored and shiv12095 committed Jun 7, 2016
1 parent 07ce9d6 commit d8f0479
Showing 1 changed file with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
* Copyright (c) 2015,2016 Bosch Software Innovations GmbH and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
Expand All @@ -22,6 +22,7 @@
import com.google.common.base.Function;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonSyntaxException;

public class StringToUploadResult implements Function<String, UploadResultView> {

Expand All @@ -30,7 +31,43 @@ public class StringToUploadResult implements Function<String, UploadResultView>
@Override
public UploadResultView apply(String input) {
List<UploadResultView> result = gson.fromJson(input, ServerResponseView.class).getObj();
//This is temporary fix to make it compatible with older interfaces
//This check would be removed on latest repository deployments.
if(result == null) {
return handlePreviousVersionUploadResult(input);
}
return result.get(0);
}

/**
* Temporarily handle the Upload result to make it compatible
* with older interfaces.
* @param input json string with older format
* @return uploadresultview
*/
private UploadResultView handlePreviousVersionUploadResult(String input) {
UploadResultView uploadResult = null;
try {
uploadResult = gson.fromJson(input, UploadResultView.class);
if (uploadResult != null) {
return uploadResult;
}
} catch (JsonSyntaxException e) {
e.printStackTrace();
}
return emptyUploadResult();
}


/**
* Return empty error view incase of invalid json or null values.
* @return Empty Upload result with error message.
*/
private UploadResultView emptyUploadResult() {
UploadResultView errorResult = new UploadResultView();
errorResult.setErrorMessage("Error while uploading to remote repository.");
errorResult.setValid(false);
return errorResult;
}

}

0 comments on commit d8f0479

Please sign in to comment.