EPerson eUser = EPerson.findByEmail(context, user);
if ((eUser.canLogIn()) && (eUser.checkPassword(pass))) {
context.setCurrentUser(eUser);
loggedUser = eUser.getName();
} else {
throw new EntityException("Bad username or password", user, 403);
}
} catch (SQLException sql) {
// System.out.println(sql.toString());
sql.printStackTrace();
} catch (AuthorizeException auth) {
throw new EntityException("Unauthorised", user, 401);
} catch (NullPointerException ne) {
if (!(user.equals("") && pass.equals(""))) {
throw new EntityException("Bad username or password", user, 403);
}
}
this.collections = "true".equals(reqStor.getStoredValue("collections"));
uparam.setCollections(this.collections);
this.trim = "true".equals(reqStor.getStoredValue("trim"));
uparam.setTrim(this.trim);
this.parents = "true".equals(reqStor.getStoredValue("parents"));
uparam.setParents(this.parents);
this.children = "true".equals(reqStor.getStoredValue("children"));
uparam.setChildren(this.children);
this.groups = "true".equals(reqStor.getStoredValue("groups"));
uparam.setGroups(this.groups);
this.replies = "true".equals(reqStor.getStoredValue("replies"));
uparam.setReplies(this.replies);
// try {
// action = reqStor.getStoredValue("action").toString();
// uparam.setAction(action);
// } catch (NullPointerException ex) {
// action = "";
// }
try {
query = reqStor.getStoredValue("query").toString();
uparam.setQuery(query);
} catch (NullPointerException ex) {
query = "";
}
try {
Object o = reqStor.getStoredValue("fields");
if (o instanceof String) {
fields = new String[]{o.toString()};
} else if (o instanceof String[]) {
fields = (String[]) o;
} else if (o == null) {
fields = null;
}
uparam.setFields(fields);
} catch (NullPointerException ex) {
fields = null;
}
try {
status = reqStor.getStoredValue("status").toString();
uparam.setStatus(status);
} catch (NullPointerException ex) {
status = "";
}
try {
submitter = reqStor.getStoredValue("submitter").toString();
uparam.setSubmitter(submitter);
} catch (NullPointerException ex) {
submitter = "";
}
try {
reviewer = reqStor.getStoredValue("reviewer").toString();
uparam.setReviewer(reviewer);
} catch (NullPointerException ex) {
reviewer = "";
}
try {
String bundleStr = reqStor.getStoredValue("type").toString();
uparam.setType(bundleStr.split(","));
} catch (NullPointerException ex) {
type = null;
}
try {
_order = reqStor.getStoredValue("order").toString();
uparam.setOrder(_order);
} catch (NullPointerException ex) {
_order = "";
}
try {
_sort = reqStor.getStoredValue("sort").toString();
uparam.setSort(_sort);
} catch (NullPointerException ex) {
_sort = "";
} // both parameters are used according to requirements
if (_order.length() > 0 && _sort.equals("")) {
_sort = _order;
}
try {
_start = Integer.parseInt(reqStor.getStoredValue("start").toString());
uparam.setStart(_start);
} catch (NullPointerException ex) {
_start = 0;
}
try {
_limit = Integer.parseInt(reqStor.getStoredValue("limit").toString());
uparam.setLimit(_limit);
} catch (NullPointerException ex) {
_limit = 0;
} // some checking for invalid values
if (_limit < 0) {
_limit = 0;
}
try {
_sdate = reqStor.getStoredValue("startdate").toString();
} catch (NullPointerException ex) {
_sdate = null;
}
try {
_edate = reqStor.getStoredValue("enddate").toString();
} catch (NullPointerException ex) {
_edate = null;
}
try {
withdrawn = reqStor.getStoredValue("withdrawn").toString().equalsIgnoreCase("true");
} catch (NullPointerException ex) {
withdrawn = false;
}
// defining sort fields and values
_sort = _sort.toLowerCase();
String[] sort_arr = _sort.split(",");
for (String option : sort_arr) {
if (option.startsWith("submitter")) {
sortOptions.add(UtilHelper.SORT_SUBMITTER);
} else if (option.startsWith("email")) {
sortOptions.add(UtilHelper.SORT_EMAIL);
} else if (option.startsWith("firstname")) {
sortOptions.add(UtilHelper.SORT_FIRSTNAME);
} else if (option.startsWith("lastname")) {
sortOptions.add(UtilHelper.SORT_LASTNAME);
} else if (option.startsWith("fullname")) {
sortOptions.add(UtilHelper.SORT_FULL_NAME);
} else if (option.startsWith("language")) {
sortOptions.add(UtilHelper.SORT_LANGUAGE);
} else if (option.startsWith("lastmodified")) {
sortOptions.add(UtilHelper.SORT_LASTMODIFIED);
} else if (option.startsWith("countitems")) {
sortOptions.add(UtilHelper.SORT_COUNT_ITEMS);
} else if (option.startsWith("name")) {
sortOptions.add(UtilHelper.SORT_NAME);
} else {
sortOptions.add(UtilHelper.SORT_ID);
}
if ((option.endsWith("_desc") || option.endsWith("_reverse"))) {
int i = sortOptions.get(sortOptions.size() - 1);
sortOptions.remove(sortOptions.size() - 1);
i += 100;
sortOptions.add(i);
}
}
int intcommunity = 0;
int intcollection = 0;
// integer values used in some parts
try {
intcommunity = Integer.parseInt(reqStor.getStoredValue("community").toString());
} catch (NullPointerException nul) {
}
try {
_community = Community.find(context, intcommunity);
} catch (SQLException sql) {
}
try {
intcollection = Integer.parseInt(reqStor.getStoredValue("collection").toString());
} catch (NullPointerException nul) {
}
try {
_collection = Collection.find(context, intcollection);
} catch (SQLException sql) {
}
if ((intcommunity > 0) && (intcollection > 0)) {
throw new EntityException("Bad request", "Community and collection selected", 400);
}
if ((intcommunity > 0) && (_community == null)) {
throw new EntityException("Bad request", "Unknown community", 400);
}
if ((intcollection > 0) && (_collection == null)) {
throw new EntityException("Bad request", "Unknown collection", 400);
}
return uparam;
}