use of org.mycore.common.MCRUsageException in project mycore by MyCoRe-Org.
the class MCRVersioningMetadataStoreTest method deletedVersions.
@Test
public void deletedVersions() throws Exception {
Element root = new Element("bingo");
Document xml1 = new Document(root);
MCRVersionedMetadata vm = getVersStore().create(new MCRJDOMContent(xml1));
assertFalse(vm.isDeleted());
vm.delete();
assertTrue(vm.isDeleted());
assertFalse(getVersStore().exists(vm.getID()));
vm = getVersStore().retrieve(vm.getID());
assertTrue(vm.isDeletedInRepository());
List<MCRMetadataVersion> versions = vm.listVersions();
MCRMetadataVersion v1 = versions.get(0);
MCRMetadataVersion v2 = versions.get(1);
boolean cannotRestoreDeleted = false;
try {
v2.restore();
} catch (MCRUsageException ex) {
cannotRestoreDeleted = true;
}
assertTrue(cannotRestoreDeleted);
v1.restore();
assertFalse(vm.isDeletedInRepository());
assertEquals(root.getName(), vm.getMetadata().asXML().getRootElement().getName());
}
use of org.mycore.common.MCRUsageException in project mycore by MyCoRe-Org.
the class MCRUploadHandlerManager method getHandler.
public static MCRUploadHandler getHandler(String uploadID) {
long yesterday = System.currentTimeMillis() - 86400000;
MCRUploadHandlerCacheEntry entry = HANDLERS.getIfUpToDate(uploadID, yesterday);
if (entry == null)
throw new MCRUsageException("Upload session " + uploadID + " timed out");
String sessionID = entry.getSessionID();
if (!sessionID.equals(MCRSessionMgr.getCurrentSessionID())) {
MCRSession session = MCRSessionMgr.getSession(sessionID);
if (session != null)
MCRSessionMgr.setCurrentSession(session);
}
return entry.getUploadHandler();
}
use of org.mycore.common.MCRUsageException in project mycore by MyCoRe-Org.
the class MCRQLSearchUtils method buildNameValueQuery.
/**
* Search using name=value pairs from HTTP request
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
public static MCRQuery buildNameValueQuery(HttpServletRequest req) {
MCRAndCondition condition = new MCRAndCondition();
for (Enumeration<String> names = req.getParameterNames(); names.hasMoreElements(); ) {
String name = names.nextElement();
if (name.endsWith(".operator")) {
continue;
}
if (name.contains(".sortField")) {
continue;
}
if (SEARCH_PARAMETER.contains(name)) {
continue;
}
if (name.startsWith("XSL.")) {
continue;
}
String[] values = req.getParameterValues(name);
MCRSetCondition parent = condition;
if ((values.length > 1) || name.contains(",")) {
// Multiple fields with same name, combine with OR
parent = new MCROrCondition();
condition.addChild(parent);
}
for (String fieldName : name.split(",")) {
String operator = getReqParameter(req, fieldName + ".operator", "=");
for (String value : values) {
parent.addChild(new MCRQueryCondition(fieldName, operator, value));
}
}
}
if (condition.getChildren().isEmpty()) {
throw new MCRUsageException("Missing query condition");
}
return new MCRQuery(MCRQueryParser.normalizeCondition(condition));
}
use of org.mycore.common.MCRUsageException in project mycore by MyCoRe-Org.
the class MCRPackerServlet method doGetPost.
@Override
protected void doGetPost(MCRServletJob job) throws IOException {
String packer = job.getRequest().getParameter("packer");
if (packer == null || packer.isEmpty()) {
try {
job.getResponse().sendError(HttpServletResponse.SC_BAD_REQUEST, "No or invalid 'packer' parameter!");
} catch (IOException e) {
LOGGER.error("Error while sending request error to client!", e);
return;
}
}
Map<String, String> jobParameters = resolveJobParameters(job);
try {
MCRJob mcrJob = MCRPackerManager.startPacking(jobParameters);
if (mcrJob == null) {
job.getResponse().sendError(HttpServletResponse.SC_BAD_REQUEST, "No packer parameter!");
}
} catch (MCRAccessException e) {
job.getResponse().sendError(HttpServletResponse.SC_UNAUTHORIZED, e.getMessage());
} catch (MCRUsageException e) {
job.getResponse().sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid Parameters: " + e.getMessage());
}
if (jobParameters.containsKey("redirect")) {
String redirect = jobParameters.get("redirect");
job.getResponse().sendRedirect(job.getResponse().encodeRedirectURL(redirect));
}
}
use of org.mycore.common.MCRUsageException in project mycore by MyCoRe-Org.
the class MCRFile method setContentFrom.
/**
* Reads the content of this file from a source file in the local filesystem and stores it in an MCRContentStore.
*
* @param source
* the file in the local host's filesystem thats content should be imported
*/
public void setContentFrom(File source) throws MCRPersistenceException {
Objects.requireNonNull(source, "source file is null");
if (!source.exists()) {
throw new MCRUsageException("source file does not exist:" + source.getPath());
}
if (!source.canRead()) {
throw new MCRUsageException("source file not readable:" + source.getPath());
}
FileInputStream fin = null;
try {
fin = new FileInputStream(source);
} catch (FileNotFoundException ignored) {
}
// We already checked it exists
setContentFrom(new BufferedInputStream(fin));
}
Aggregations