}
@SuppressWarnings("deprecation")
private static void convert(RestResource resource, OldRestRequestConfig oldConfig, RestMethod method) {
RestRequest request = method.addNewRequest(oldConfig.getName());
XmlBeansRestParamsTestPropertyHolder params = new XmlBeansRestParamsTestPropertyHolder(null,
oldConfig.getParameters());
RestParamsPropertyHolder parentParams = method.getOverlayParams();
for (TestProperty prop : params.values()) {
if (!parentParams.containsKey(prop.getName())) {
method.getParams().addParameter((RestParamProperty) prop);
}
request.setPropertyValue(prop.getName(), prop.getValue());
}
params.release();
boolean exists;
for (RestResourceRepresentationConfig rep : oldConfig.getRepresentationList()) {
exists = false;
for (RestRepresentation existing : method.getRepresentations(
RestRepresentation.Type.valueOf(rep.getType().toString()), rep.getMediaType())) {
if (existing.getElement() == null && rep.getElement() == null
|| existing.getElement().equals(rep.getElement())) {
exists = true;
break;
}
}
if (!exists) {
RestRepresentation repr = method.addNewRepresentation(RestRepresentation.Type.valueOf(rep.getType()
.toString()));
repr.setConfig((RestResourceRepresentationConfig) rep.copy());
}
}
RestRequestConfig newConfig = request.getConfig();
newConfig.setRequest(oldConfig.getRequest());
for (AttachmentConfig ac : oldConfig.getAttachmentList()) {
try {
if (ac.isSetData()) {
File temp = File.createTempFile("pattern", ".suffix");
temp.deleteOnExit();
FileOutputStream out = new FileOutputStream(temp);
out.write(ac.getData());
request.attachFile(temp, true);
} else {
request.attachFile(new File(ac.getUrl()), false);
}
} catch (IOException e) {
e.printStackTrace();
}
}
newConfig.setAttachmentArray(oldConfig.getAttachmentArray());
if (oldConfig.isSetFullPath()) {
newConfig.setFullPath(oldConfig.getFullPath());
}
if (oldConfig.isSetMediaType()) {
newConfig.setMediaType(oldConfig.getMediaType());
}
if (oldConfig.isSetPostQueryString()) {
newConfig.setPostQueryString(oldConfig.getPostQueryString());
}
if (oldConfig.isSetAccept()) {
newConfig.setAccept(oldConfig.getAccept());
}
if (oldConfig.isSetDescription()) {
newConfig.setDescription(oldConfig.getDescription());
}
if (oldConfig.isSetId()) {
newConfig.setId(oldConfig.getId());
}
if (oldConfig.isSetSettings()) {
newConfig.setSettings((SettingsConfig) oldConfig.getSettings().copy());
}
if (oldConfig.isSetSslKeystore()) {
newConfig.setSslKeystore(oldConfig.getSslKeystore());
}
if (oldConfig.isSetTimestamp()) {
newConfig.setTimestamp(oldConfig.getTimestamp());
}
if (oldConfig.isSetWadlId()) {
newConfig.setWadlId(oldConfig.getWadlId());
}
request.updateConfig(newConfig);
}