if (wsreq == null) {
throw new CannotTranslateException("wsreq may not be null");
}
final _CreateRequest req = this.repr._newCreateRequest();
final VirtualWorkspace_Type vw = wsreq.getMetadata();
final URI name = vw.getName();
if (name != null) {
req.setName(name.toString());
}
// -------------------------------------------------------------
// Weed out the needed items:
// -------------------------------------------------------------
final Definition def = vw.getDefinition();
if (def == null) {
throw new CannotTranslateException(
"create request definition may not be missing");
}
final VirtualNetwork_Type net;
final Logistics log = vw.getLogistics();
if (log == null) {
net = null;
} else {
net = log.getNetworking();
}
final CustomizeTask_Type[] customizes;
final OptionalParameters_Type optional = wsreq.getOptionalParameters();
if (optional != null) {
customizes = optional.getFilewrite();
req.setMdUserData(optional.getMdServerUserdata());
req.setCredential(optional.getCredentialToCopy());
} else {
customizes = null;
}
// Boolean object can be null for conversion like this (null==false)
final boolean ensDone =
Boolean.TRUE.equals(wsreq.getEnsembleDone());
final boolean partOfEnsemble =
Boolean.TRUE.equals(wsreq.getPartOfEnsemble());
final EndpointReferenceType ensembleEPR = wsreq.getEnsembleEPR();
// it'd be interesting to not require this and use all defaults but
// it is currently required:
final WorkspaceDeployment_Type dep = wsreq.getResourceRequest();
if (dep == null) {
throw new CannotTranslateException(
"create request deployment may not be missing");
}
final PostShutdown_Type post = dep.getPostShutdown();
// -------------------------------------------------------------
// Translate:
// -------------------------------------------------------------
this.trdef.translateDefinitionRelated(req, def, post);
this.trra.translateResourceRelated(req, dep);
if (net != null) {
this.trnet.translateNetworkingRelated(req, net);
}
if (customizes != null && customizes.length > 0) {
final CustomizationRequest[] crs =
new CustomizationRequest[customizes.length];
for (int i = 0; i < customizes.length; i++) {
final _CustomizationRequest cr =
this.repr._newCustomizationRequest();
cr.setContent(customizes[i].getContent());
cr.setPathOnVM(customizes[i].getPathOnVM());
crs[i] = cr;
}
req.setCustomizationRequests(crs);
}
req.setCoScheduleMember(partOfEnsemble);
req.setCoScheduleDone(ensDone);
if (ensembleEPR != null) {
try {
req.setCoScheduleID(EnsembleUtil.getResourceID(ensembleEPR));
} catch (Exception e) {
throw new CannotTranslateException(e.getMessage(), e);
}
}