getResponse().setStatus(Status.SUCCESS_NO_CONTENT);
}
private ImportContext createImport(Long id) {
//create a new import
ImportContext context;
try {
context = importer.createContext(id);
if (MediaType.APPLICATION_JSON.equals(getRequest().getEntity().getMediaType())) {
//read representation specified by user, use it to read
ImportContext newContext =
(ImportContext) getFormatPostOrPut().toObject(getRequest().getEntity());
WorkspaceInfo targetWorkspace = newContext.getTargetWorkspace();
StoreInfo targetStore = newContext.getTargetStore();
if (targetWorkspace != null) {
// resolve to the 'real' workspace
WorkspaceInfo ws = importer.getCatalog().getWorkspaceByName(
newContext.getTargetWorkspace().getName());
if (ws == null) {
throw new RestletException("Target workspace does not exist : "
+ newContext.getTargetStore().getName(), Status.CLIENT_ERROR_BAD_REQUEST);
}
context.setTargetWorkspace(ws);
}
if (targetStore != null) {
StoreInfo ts = importer.getCatalog().getStoreByName(newContext.getTargetStore().getName(), StoreInfo.class);
if (ts == null) {
throw new RestletException("Target store does not exist : "
+ newContext.getTargetStore().getName(), Status.CLIENT_ERROR_BAD_REQUEST);
}
context.setTargetStore(ts);
}
if (targetStore != null && targetWorkspace == null) {
//take it from the store
context.setTargetWorkspace(targetStore.getWorkspace());
}
context.setData(newContext.getData());
if (newContext.getData() != null) {
importer.init(context, true);
}
}
context.reattach(importer.getCatalog(), true);