import compbio.cassandra.readers.CassandraReader;
/**
- *
+ * ProteoCache Basic controller. All other controllers should inherit this
+ * controller. Currently BasicController provides user role checks and some
+ * global dates for the system (current and the earliest date of executing job)
*
* @author Alexander Sherstnev
* @version 1.0
public class BasicController {
final protected SimpleDateFormat formaterDDMMYY = DateFormatter.getFormatDDMMYY();
final protected SimpleDateFormat formaterYYMMDD = DateFormatter.getFormatYYMMDD();
- protected Calendar cal = Calendar.getInstance();
- protected String theEaerlistDate = DateFormatter.DateLongToString(CassandraReader.earliestDate(), formaterYYMMDD);
- protected String theCurrentDate = cal.get(Calendar.YEAR) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DAY_OF_MONTH);
+ /**
+ * give the user (principal) name
+ *
+ * @return the user name. If the user uses LDAP credentials LDAP prefix is
+ * set
+ */
protected String getPrincipalName() {
Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
if (principal instanceof UserDetails) {
return principal.toString();
}
+ /**
+ * check whether the current user has standard user permissions (ROLE_USER
+ * or ROLE_LDAP_USER)
+ *
+ * @return true if this is a ROLE_USER/ROLE_LDAP_USER user, false otherwise
+ */
protected boolean isUserRole() {
Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
if (principal instanceof UserDetails) {
return false;
}
+ /**
+ * check whether the current user has administrator permissions (ROLE_ADMIN)
+ *
+ * @return true if this is a ROLE_ADMIN user, false otherwise
+ */
protected boolean isAdminRole() {
Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
if (principal instanceof UserDetails) {
return false;
}
- protected String DateChecking(String trimmeddate1, String trimmeddate2, long longDate1, long longDate2) {
+ /**
+ * check whether provided dates are ordered properly and within permitted
+ * time range
+ *
+ * @param date1
+ * early limit of the time range)
+ *
+ * * @param date2 late limit of the time range)
+ *
+ * * @param longDate1 date 1 in the numerical represenation (in
+ * milliseconds)
+ *
+ * * @param longDate2 date 2 in the numerical represenation (in
+ * milliseconds)
+ *
+ * @return true if these dates are correct, false otherwise
+ */
+ protected String checkDates(String date1, String date2, long longDate1, long longDate2) {
Calendar cal2 = Calendar.getInstance();
- if (trimmeddate1.equalsIgnoreCase("") || trimmeddate2.equalsIgnoreCase(""))
- return "The date cann't be empty";
- else if (!DateFormatter.isThisDateValid(trimmeddate1, formaterYYMMDD)
- || !DateFormatter.isThisDateValid(trimmeddate2, formaterYYMMDD))
- return "The date format in invalid. Try format yyyy/mm/dd";
+ if (date1.equalsIgnoreCase("") || date2.equalsIgnoreCase(""))
+ return "The date can not be empty strinfs";
+ else if (!DateFormatter.isThisDateValid(date1, formaterYYMMDD) || !DateFormatter.isThisDateValid(date2, formaterYYMMDD))
+ return "The date format in invalid. The format yyyy/mm/dd should be used";
else if (longDate2 < CassandraReader.earliestDate())
- return "The date2 is after the earlestDate " + theEaerlistDate;
+ return "The date2 is earlier than the earliest date in the system " + getEarliestDate();
else if (longDate1 > cal2.getTimeInMillis())
- return "The date1 is before the current date " + theCurrentDate;
+ return "The date1 is later than the current date " + getCurrentDate();
else if (longDate1 > longDate2)
- return "Wrong date's diaposon. The date1 is more than date2.";
- else
- return null;
+ return "Wrong date range. The date1 is later than date2.";
+
+ return null;
+ }
+
+ /**
+ * gives the current date in the form of string (yyyy/mm/dd)
+ *
+ * @return the current date
+ */
+ protected String getCurrentDate() {
+ Calendar cal = Calendar.getInstance();
+ String date = cal.get(Calendar.YEAR) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DAY_OF_MONTH);
+ return date;
+ }
+
+ /**
+ * gives the earliest date in the system (through a direct call of a
+ * Cassandra related class) in the form of string (yyyy/mm/dd)
+ *
+ * @return the current date
+ */
+ protected String getEarliestDate() {
+ return DateFormatter.DateLongToString(CassandraReader.earliestDate(), formaterYYMMDD);
}
}
import compbio.cassandra.readers.DailyStatisticsReader;
/**
+ * MVC controller for collecting and showing job statistics
+ *
* @author Alexander Sherstnev
* @author Natasha Sherstneva
- * @version 1.0 Dec 2013
+ *
+ * @version 1.0
+ * @since Dec 2013
*/
@Controller
public class DailyStatisticsController extends BasicController {
final long startTime = System.currentTimeMillis();
DailyStatisticsReader reader = new DailyStatisticsReader();
if (option.equals("AllDates,off")) {
- date1 = theEaerlistDate;
- date2 = theCurrentDate;
+ date1 = getEarliestDate();
+ date2 = getCurrentDate();
}
// dates in string format
// dates in long format
long longDate1 = DateFormatter.DateParsing(date1, formaterYYMMDD);
long longDate2 = DateFormatter.DateParsing(date2, formaterYYMMDD);
- String error = DateChecking(trimmeddate1, trimmeddate2, longDate1, longDate2);
+ String error = checkDates(trimmeddate1, trimmeddate2, longDate1, longDate2);
if (error != null) {
model.put("error", error);
model.put("date1", date1);
thetime = formaterDDMMYY.parse(realdate).getTime();
}
- if (null == JobStatus.getJobStatus(status))
+ if (null == JobStatus.getJobStatus(status))
return "support/Notimplemented";
-
DailyStatisticsReader reader = new DailyStatisticsReader();
// IMPORTANT: input should be suppied in the format: DD/MM/YYYY
DateBean r = reader.readJobByDay(thetime, realdate, JobStatus.getJobStatus(status));
Calendar loccal = Calendar.getInstance();
ExecutionTimeReader reader = new ExecutionTimeReader();
if (alldates.equals("AllDates,off")) {
- date1 = theEaerlistDate;
- date2 = theCurrentDate;
+ date1 = getEarliestDate();
+ date2 = getCurrentDate();
}
// dates in string format
// dates in long format
long longDate1 = DateFormatter.DateParsing(date1, formaterYYMMDD);
long longDate2 = DateFormatter.DateParsing(date2, formaterYYMMDD);
- String error = DateChecking(trimmeddate1, trimmeddate2, longDate1, longDate2);
+ String error = checkDates(trimmeddate1, trimmeddate2, longDate1, longDate2);
if (error != null) {
model.put("error", error);
model.put("date1", date1);