use of org.springframework.extensions.webscripts.WebScriptException in project alfresco-remote-api by Alfresco.
the class FileFolderLoaderPost method execute.
public void execute(WebScriptRequest req, WebScriptResponse res) throws IOException {
FileFolderLoader loader = (FileFolderLoader) applicationContext.getBean("fileFolderLoader");
int count = 0;
String folderPath = "";
try {
JSONObject json = new JSONObject(new JSONTokener(req.getContent().getContent()));
folderPath = json.getString(KEY_FOLDER_PATH);
if (folderPath == null) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, KEY_FOLDER_PATH + " not supplied.");
}
int fileCount = 100;
if (json.has(KEY_FILE_COUNT)) {
fileCount = json.getInt(KEY_FILE_COUNT);
}
int filesPerTxn = DEFAULT_FILES_PER_TXN;
if (json.has(KEY_FILES_PER_TXN)) {
filesPerTxn = json.getInt(KEY_FILES_PER_TXN);
}
long minFileSize = DEFAULT_MIN_FILE_SIZE;
if (json.has(KEY_MIN_FILE_SIZE)) {
minFileSize = json.getInt(KEY_MIN_FILE_SIZE);
}
long maxFileSize = DEFAULT_MAX_FILE_SIZE;
if (json.has(KEY_MAX_FILE_SIZE)) {
maxFileSize = json.getInt(KEY_MAX_FILE_SIZE);
}
long maxUniqueDocuments = DEFAULT_MAX_UNIQUE_DOCUMENTS;
if (json.has(KEY_MAX_UNIQUE_DOCUMENTS)) {
maxUniqueDocuments = json.getInt(KEY_MAX_UNIQUE_DOCUMENTS);
}
boolean forceBinaryStorage = DEFAULT_FORCE_BINARY_STORAGE;
if (json.has(KEY_FORCE_BINARY_STORAGE)) {
forceBinaryStorage = json.getBoolean(KEY_FORCE_BINARY_STORAGE);
}
int descriptionCount = DEFAULT_DESCRIPTION_COUNT;
if (json.has(KEY_DESCRIPTION_COUNT)) {
descriptionCount = json.getInt(KEY_DESCRIPTION_COUNT);
}
long descriptionSize = DEFAULT_DESCRIPTION_SIZE;
if (json.has(KEY_DESCRIPTION_SIZE)) {
descriptionSize = json.getLong(KEY_DESCRIPTION_SIZE);
}
// Perform the load
count = loader.createFiles(folderPath, fileCount, filesPerTxn, minFileSize, maxFileSize, maxUniqueDocuments, forceBinaryStorage, descriptionCount, descriptionSize);
} catch (FileNotFoundException e) {
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Folder not found: ", folderPath);
} catch (IOException iox) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not read content from req.", iox);
} catch (JSONException je) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not parse JSON from req.", je);
}
// Write the response
OutputStream os = res.getOutputStream();
try {
JSONObject json = new JSONObject();
json.put(KEY_COUNT, count);
os.write(json.toString().getBytes("UTF-8"));
} catch (JSONException e) {
throw new WebScriptException(Status.STATUS_INTERNAL_SERVER_ERROR, "Failed to write JSON", e);
} finally {
os.close();
}
}
use of org.springframework.extensions.webscripts.WebScriptException in project alfresco-remote-api by Alfresco.
the class QuickShareMetaDataGet method executeImpl.
@Override
protected Map<String, Object> executeImpl(final WebScriptRequest req, Status status, Cache cache) {
if (!isEnabled()) {
throw new WebScriptException(HttpServletResponse.SC_FORBIDDEN, "QuickShare is disabled system-wide");
}
// create map of params (template vars)
Map<String, String> params = req.getServiceMatch().getTemplateVars();
final String sharedId = params.get("shared_id");
if (sharedId == null) {
throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, "A valid sharedId must be specified !");
}
try {
return quickShareService.getMetaData(sharedId);
} catch (InvalidSharedIdException ex) {
logger.error("Unable to find: " + sharedId);
throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find: " + sharedId);
} catch (InvalidNodeRefException inre) {
logger.error("Unable to find: " + sharedId + " [" + inre.getNodeRef() + "]");
throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find: " + sharedId);
}
}
use of org.springframework.extensions.webscripts.WebScriptException in project alfresco-remote-api by Alfresco.
the class ReadGet method executeImpl.
@Override
protected Map<String, Object> executeImpl(final WebScriptRequest req, Status status, Cache cache) {
if (!isEnabled()) {
throw new WebScriptException(HttpServletResponse.SC_FORBIDDEN, "QuickShare is disabled system-wide");
}
// create map of params (template vars)
Map<String, String> params = req.getServiceMatch().getTemplateVars();
final String sharedId = params.get("shared_id");
if (sharedId == null) {
throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, "A valid sharedId must be specified !");
}
try {
boolean canRead = quickShareService.canRead(sharedId);
Map<String, Object> result = new HashMap<String, Object>();
result.put("canRead", canRead);
return result;
} catch (InvalidSharedIdException ex) {
logger.error("Unable to find: " + sharedId);
throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find: " + sharedId);
} catch (InvalidNodeRefException inre) {
logger.error("Unable to find: " + sharedId + " [" + inre.getNodeRef() + "]");
throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find: " + sharedId);
}
}
use of org.springframework.extensions.webscripts.WebScriptException in project alfresco-remote-api by Alfresco.
the class ShareContentGet method executeImpl.
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
if (!isEnabled()) {
throw new WebScriptException(HttpServletResponse.SC_FORBIDDEN, "QuickShare is disabled system-wide");
}
// create map of params (template vars)
Map<String, String> params = req.getServiceMatch().getTemplateVars();
final String sharedId = params.get("shared_id");
if (sharedId == null) {
throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, "A valid sharedId must be specified !");
}
try {
Pair<String, NodeRef> pair = quickShareService.getTenantNodeRefFromSharedId(sharedId);
final String tenantDomain = pair.getFirst();
final NodeRef nodeRef = pair.getSecond();
String siteId = siteService.getSiteShortName(nodeRef);
Map<String, Object> model = new HashMap<String, Object>(3);
model.put("sharedId", sharedId);
model.put("nodeRef", nodeRef.toString());
model.put("siteId", siteId);
model.put("tenantDomain", tenantDomain);
if (logger.isInfoEnabled()) {
logger.info("QuickShare - get shared context: " + sharedId + " [" + model + "]");
}
return model;
} catch (InvalidNodeRefException inre) {
logger.error("Unable to find: " + sharedId + " [" + inre.getNodeRef() + "]");
throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find: " + sharedId);
}
}
use of org.springframework.extensions.webscripts.WebScriptException in project alfresco-remote-api by Alfresco.
the class RatingDelete method executeImpl.
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
Map<String, Object> model = new HashMap<String, Object>();
NodeRef nodeRef = parseRequestForNodeRef(req);
String ratingSchemeName = parseRequestForScheme(req);
Rating deletedRating = ratingService.removeRatingByCurrentUser(nodeRef, ratingSchemeName);
if (deletedRating == null) {
// There was no rating in the specified scheme to delete.
throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, "Unable to delete non-existent rating: " + ratingSchemeName + " from " + nodeRef.toString());
}
model.put(NODE_REF, nodeRef.toString());
model.put(AVERAGE_RATING, ratingService.getAverageRating(nodeRef, ratingSchemeName));
model.put(RATINGS_TOTAL, ratingService.getTotalRating(nodeRef, ratingSchemeName));
model.put(RATINGS_COUNT, ratingService.getRatingsCount(nodeRef, ratingSchemeName));
return model;
}
Aggregations