use of com.thoughtworks.go.plugin.access.configrepo.messages.ParseDirectoryResponseMessage in project gocd by gocd.
the class JsonMessageHandler1_0 method responseMessageForParseDirectory.
@Override
public CRParseResult responseMessageForParseDirectory(String responseBody) {
ErrorCollection errors = new ErrorCollection();
try {
ResponseScratch responseMap = parseResponseForMigration(responseBody);
ParseDirectoryResponseMessage parseDirectoryResponseMessage;
if (responseMap.target_version == null) {
errors.addError("Plugin response message", "missing 'target_version' field");
return new CRParseResult(errors);
} else {
int version = responseMap.target_version;
while (version < CURRENT_CONTRACT_VERSION) {
version++;
responseBody = migrate(responseBody, version);
}
// after migration, json should match contract
parseDirectoryResponseMessage = codec.getGson().fromJson(responseBody, ParseDirectoryResponseMessage.class);
parseDirectoryResponseMessage.validateResponse(errors);
errors.addErrors(parseDirectoryResponseMessage.getPluginErrors());
return new CRParseResult(parseDirectoryResponseMessage.getEnvironments(), parseDirectoryResponseMessage.getPipelines(), errors);
}
} catch (Exception ex) {
StringBuilder builder = new StringBuilder();
builder.append("Unexpected error when handling plugin response").append('\n');
builder.append(ex);
// "location" of error is runtime. This is what user will see in config repo errors list.
errors.addError("runtime", builder.toString());
LOGGER.error(builder.toString(), ex);
return new CRParseResult(errors);
}
}
Aggregations