* Deep clone of a Service.
*
* @param service
*/
public Service duplicateService(Service service) {
Service newService = new Service();
newService.setHangTime(service.getHangTime());
newService.setHttpMethod(service.getHttpMethod());
newService.setServiceName(service.getServiceName());
newService.setServiceResponseTypeByString(service.getServiceResponseTypeAsString());
newService.setDefaultRealUrlIndex(service.getDefaultRealUrlIndex());
newService.setUrl(service.getUrl());
// We don't do this because the Default scenario ID is not guaranteed to
// be the same as the duplicate items are created.
// newService.setDefaultScenarioId(service.getDefaultScenarioId());
newService.setDescription(service.getDescription());
// Meta data
for (Url url : service.getRealServiceUrls()) {
newService.saveOrUpdateRealServiceUrl(url);
}
// Why save, and save again below?
// - The first save gets a Service ID created.
// - Scenario's refer to the Service ID
newService = this.saveOrUpdateService(newService);
// Now add scenarios
for (Scenario scenario : service.getScenarios()) {
Scenario newScenario = new Scenario();
newScenario.setHttpResponseStatusCode(scenario.getHttpResponseStatusCode());
newScenario.setMatchStringArg(scenario.getMatchStringArg());
newScenario.setResponseHeader(scenario.getResponseHeader());
newScenario.setResponseMessage(scenario.getResponseMessage());
newScenario.setScenarioName(scenario.getScenarioName());
newScenario.setTag(scenario.getTag());
newService.saveOrUpdateScenario(newScenario);
}
// Save AGAIN.
newService = this.saveOrUpdateService(newService);
return newService;