diff --git a/bundles/org.eclipse.vorto.repository/src/org/eclipse/vorto/repository/function/StringToUploadResult.java b/bundles/org.eclipse.vorto.repository/src/org/eclipse/vorto/repository/function/StringToUploadResult.java index be680f7df9..de61ad313d 100644 --- a/bundles/org.eclipse.vorto.repository/src/org/eclipse/vorto/repository/function/StringToUploadResult.java +++ b/bundles/org.eclipse.vorto.repository/src/org/eclipse/vorto/repository/function/StringToUploadResult.java @@ -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. @@ -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 { @@ -30,7 +31,43 @@ public class StringToUploadResult implements Function @Override public UploadResultView apply(String input) { List 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; + } + }