Commit 35a3b0feece3a64fc7da28ee40a228145c30456b

Authored by Fernando Ribeiro
1 parent e3220b7ca4
Exists in master

Added the changes made by Tiago with new validation profiles and correction of existing ones

config/validator.xml
1 1 <?xml version="1.0" encoding="UTF-8" ?>
2   -<configuration lastChangeDate="2014-01-28T12:00:00" xmlns="http://www.rcaap.pt/xsd/validator" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.rcaap.pt/xsd/validator validator.xsd ">
  2 +<configuration lastChangeDate="2014-01-28T12:00:00" xmlns="http://www.rcaap.pt/xsd/validator"
  3 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4 + xsi:schemaLocation="http://www.rcaap.pt/xsd/validator validator.xsd ">
3 5  
4 6 <!-- Platforms information. For each platform, one or more profiles must
5 7 be declared. -->
6 8 <platforms>
7 9  
8 10 <platform id="dspace" name="DSpace">
9   - <profile refid="driver" />
10   - <profile refid="openaire" />
11   - <profile refid="fct" />
12   - <profile refid="thesis" />
13   - <profile refid="fits" />
14   - <profile refid="embargoed_access" />
  11 + <profile refid="driver"/>
  12 + <profile refid="openaire"/>
  13 + <profile refid="fct"/>
  14 + <!--<profile refid="thesis"/>-->
  15 + <profile refid="fits"/>
  16 + <profile refid="embargoed_access"/>
  17 + <profile refid="legalthesis"/>
  18 + <profile refid="embargoed_rights"/>
15 19 </platform>
16 20  
17 21 <platform id="ojs" name="Open Journal System">
18   - <profile refid="driver" />
19   - <profile refid="openaire" />
  22 + <profile refid="driver"/>
  23 + <profile refid="openaire"/>
20 24 </platform>
21 25  
22 26 <platform id="eprints" name="EPrints">
23   - <profile refid="driver" />
  27 + <profile refid="driver"/>
24 28 </platform>
25 29  
26 30 <platform id="other" name="Other">
27   - <profile refid="driver" />
28   - <profile refid="embargoed_access" />
  31 + <profile refid="driver"/>
  32 + <profile refid="embargoed_access"/>
29 33 </platform>
30 34 </platforms>
31 35  
... ... @@ -92,17 +96,17 @@
92 96 <check refid="list_fct_project_ids" />
93 97  
94 98 </profile>
95   -
  99 + <!--
96 100 <profile id="thesis" name="THESIS">
97 101 <translation element="name" lang="pt">Teses e Dissertações</translation>
98 102 <translation element="name" lang="en">Thesis</translation>
99 103 <translation element="description" lang="pt">Valida o conteúdo do repositório de acordo com depósito legal de teses e dissertações</translation>
100 104 <translation element="description" lang="en">Validates repository content accordingly with thesis legal deposit</translation>
101 105  
102   - <!--<preCondition refid="master_thesis_dc_type" />
  106 + <!-<preCondition refid="master_thesis_dc_type" />
103 107 <preCondition refid="doctoral_thesis_dc_type" /> -->
104 108  
105   - <!-- chenaged to only one pre condition. The two previous conditions can't match at the same time-->
  109 + <!-- chenaged to only one pre condition. The two previous conditions can't match at the same time->
106 110 <preCondition refid="thesis_dc_type" />
107 111  
108 112  
... ... @@ -110,6 +114,38 @@
110 114 <check refid="description_exists" />
111 115  
112 116 </profile>
  117 + -->
  118 +
  119 + <profile id="legalthesis" name="LEGALTHESIS">
  120 + <translation element="name" lang="pt">Depósito Legal de Teses e Dissertações (TID)</translation>
  121 + <translation element="name" lang="en">Legal Deposit of Thesis and Dissertations (TID)</translation>
  122 + <translation element="description" lang="pt">Valida o conteúdo do repositório de acordo com depósito legal
  123 + de teses e dissertações
  124 + </translation>
  125 + <translation element="description" lang="en">Validates repository content accordingly with thesis legal
  126 + deposit
  127 + </translation>
  128 +
  129 + <preCondition refid="thesis_dc_type"/>
  130 +
  131 +
  132 + <check refid="author_exists"/>
  133 + <check refid="description_exists"/>
  134 + <check refid="date_exists_and_is_valid"/>
  135 + <check refid="tid_exists"/>
  136 +
  137 + </profile>
  138 +
  139 +
  140 + <profile id="embargoed_rights" name="EMBARGOEDRIGHTS">
  141 + <translation element="name" lang="pt">Incoerências de Embargo</translation>
  142 + <translation element="name" lang="en">Embargo Incoherence</translation>
  143 + <translation element="description" lang="pt">Lista os documentos em acesso embargado sem data ou com data ultrapassada.</translation>
  144 + <translation element="description" lang="en">List all embargoed records without date or with a past date.</translation>
  145 +
  146 + <check refid="date_exists_and_is_valid"/>
  147 + <check refid="embargo_date" />
  148 + </profile>
113 149  
114 150 <profile id="fits" name="FITS">
115 151 <translation element="name" lang="pt">Ficheiros e Formatos</translation>
... ... @@ -192,7 +228,7 @@
192 228 </parameter>
193 229 </preCondition>
194 230  
195   - <preCondition id="doctoral_thesis_dc_type">
  231 + <preCondition id="doctoral_thesis_dc_type">
196 232 <class>pt.keep.metarepository.core.validator2.pre_conditions.AtLeastOneMetadataFieldByContent</class>
197 233 <parameter key="field">
198 234 <value>type</value>
... ... @@ -236,6 +272,55 @@
236 272 </parameter>
237 273 </check>
238 274  
  275 + <check id="tid_exists" severity="ERROR">
  276 + <translation element="body" lang="pt">A indicação “sem TID” é identificada quando não existe um TID
  277 + associado ao registo no elemento dc.identifier.tid em teses/dissertações com data de defesa igual ou superior a 7 de Agosto de 2013.
  278 + Se apenas o ano ou ano e mês foi indicado, então verifica-se o TID para data de defesa igual ou superior a 2013 ou Agosto de 2013 respectivamente.
  279 + </translation>
  280 + <translation element="body" lang="en">A error message “without TID” appears when an associated TID
  281 + to the register in the dc.identifier.tid element in thesis/dissertations defended in or after August 7, 2013 does not exist.
  282 + If only the year or month and year is specified, The TID is checked for defense dates greater than or equal to 2013 or August 2013 respectively.
  283 + </translation>
  284 + <translation element="description" lang="pt">Verifica TID em teses/dissertações com data de defesa igual ou superior a 7 de Agosto de 2013.</translation>
  285 + <translation element="description" lang="en">Checks if there a TID in thesis/dissertations defended in or after August 7, 2013.
  286 + </translation>
  287 + <translation element="severity" lang="pt">Sem TID &lt;a target="_blank" href="/validator2/help#tid_exists"&gt;&lt;span
  288 + class="glyphicon glyphicon-question-sign"&gt;&lt;/span&gt;&lt;/a&gt;</translation>
  289 + <translation element="severity" lang="en">Without TID &lt;a target="_blank"
  290 + href="/validator2/help#tid_exists"&gt;&lt;span class="glyphicon glyphicon-question-sign"&gt;&lt;/span&gt;&lt;/a&gt;</translation>
  291 + <class>pt.uminho.sdum.validador2.check.CheckTid</class>
  292 + <parameter key="field">
  293 + <value>tid</value>
  294 + </parameter>
  295 + </check>
  296 +
  297 + <check id="embargo_date" severity="ERROR">
  298 + <translation element="body" lang="pt">
  299 + A indicação "Incoerência de Embargo" aparece quando um Item tem "embargoedAccess" no registo no elemento dc.rghts
  300 + e no entanto não tem uma data de embargo posterior à data de hoje.
  301 + </translation>
  302 + <translation element="body" lang="en">
  303 + The "Embargo Incoherence" note appears when an Item has "embargoedAccess" in the dc.rights property,
  304 + but has no dc.date.embargo, or it has a past date
  305 + </translation>
  306 + <translation element="description" lang="pt">
  307 + Verifica anomalias na data de embargo.
  308 + </translation>
  309 + <translation element="description" lang="en">
  310 + Checks for anomalies in the embargo date
  311 + </translation>
  312 +
  313 + <translation element="severity" lang="pt">Incoerência de Embargo &lt;a target="_blank" href="/validator2/help#embargo_date"&gt;&lt;span
  314 + class="glyphicon glyphicon-question-sign"&gt;&lt;/span&gt;&lt;/a&gt;</translation>
  315 +
  316 + <translation element="severity" lang="en">Embargo Incoherence &lt;a target="_blank"
  317 + href="/validator2/help#embargo_date"&gt;&lt;span class="glyphicon glyphicon-question-sign"&gt;&lt;/span&gt;&lt;/a&gt;</translation>
  318 + <class>pt.uminho.sdum.validador2.check.Embargo</class>
  319 + <parameter key="field">
  320 + <value>embargo</value>
  321 + </parameter>
  322 + </check>
  323 +
239 324 <check id="date_exists_and_is_valid" severity="ERROR">
240 325 <translation element="body" lang="pt">A indicação do erro “sem data ou formato de data inválida” surge quando o registo não tem um elemento dc.date definido, ou quando se encontra definido não está de acordo com um formato conhecido. Este campo é de preenchimento obrigatório, podendo deixar-se o mês e/ou o dia em branco se não se aplicar. A data associada ao registo deverá estar relacionada com a data de publicação, podendo existir outras, como a data de disponibilização, data de fim de embargo, etc.</translation>
241 326 <translation element="body" lang="en">A warning message “without date or invalid date format” appears when the register does not include the dc.date element defined, or when it appears defined but not in an appropriate format. This is a mandatory field, the month and/or the day could be left in blank if were not used. The associated date to the register should be the publication date. However, there are another dates such as: the available date or the end of embargo period date, etc.</translation>
... ... @@ -314,7 +399,7 @@
314 399 <translation element="description" lang="en">Checks if there language is valid</translation>
315 400 <translation element="severity" lang="pt">Idioma inválido &lt;a target="_blank" href="/validator2/help#language_is_valid"&gt;&lt;span class="glyphicon glyphicon-question-sign"&gt;&lt;/span&gt;&lt;/a&gt;</translation>
316 401 <translation element="severity" lang="en">Invalid language &lt;a target="_blank" href="/validator2/help#language_is_valid"&gt;&lt;span class="glyphicon glyphicon-question-sign"&gt;&lt;/span&gt;&lt;/a&gt;</translation>
317   - <class>pt.keep.metarepository.core.validator2.checks.AtLeastOneMetadataFieldByContent</class>
  402 + <class>pt.uminho.sdum.validador2.check.AllMetadataFieldByContent</class>
318 403 <parameter key="field">
319 404 <value>language</value>
320 405 </parameter>
... ... @@ -344,7 +429,7 @@
344 429 <value>openAccess</value>
345 430 <value>embargoedAccess</value>
346 431 <value>restrictedAccess</value>
347   - <value>closedAccess</value>
  432 + <value>embargoedAccess</value>
348 433 </parameter>
349 434 </check>
350 435  
... ... @@ -456,7 +541,7 @@
456 541 </parameter>
457 542  
458 543 </check>
459   -
  544 +
460 545 <check id="list_fct_project_ids" severity="OTHER" other_severity="fct_project_ids">
461 546 <translation element="description" lang="pt">Lista os documentos de projectos financiados pela FCT</translation>
462 547 <translation element="description" lang="en">List records from projects that are financed by FCT</translation>
... ...
src/pt/uminho/sdum/utils/DateUtils.java
... ... @@ -0,0 +1,82 @@
  1 +package pt.uminho.sdum.utils;
  2 +
  3 +import java.text.DateFormat;
  4 +import java.text.ParseException;
  5 +import java.text.SimpleDateFormat;
  6 +import java.util.Date;
  7 +import java.util.Iterator;
  8 +import java.util.LinkedList;
  9 +import java.util.List;
  10 +
  11 +/**
  12 + * @author tmmguimaraes on 28/04/2016.
  13 + */
  14 +public class DateUtils {
  15 +/**
  16 + *Discovers the dc.date.issue from the dc.date list
  17 + **/
  18 +
  19 + private static SimpleDateFormat dfYMD = new SimpleDateFormat("yyyy-MM-dd");
  20 + private static SimpleDateFormat dfYM = new SimpleDateFormat("yyyy-MM");
  21 + private static SimpleDateFormat dfY = new SimpleDateFormat("yyyy");
  22 +
  23 + public static String getDcDateIssueFromOai(List<String> oaiList) {
  24 +
  25 + String res = "";
  26 + Date today = new Date();
  27 + DateFormat dfComplete = new SimpleDateFormat("yyyy-MM-dd");
  28 + DateFormat dfYearOnly = new SimpleDateFormat("yyyy");
  29 + DateFormat dfYearMon = new SimpleDateFormat("yyyy-MM");
  30 + Iterator<String> iterator = oaiList.iterator();
  31 + while (res.equals("") && iterator.hasNext()) {
  32 + try {
  33 + String str = iterator.next();
  34 + Date date;
  35 + int length = str.length();
  36 + if (!(length > 10)) {
  37 +
  38 + if (length == 10)
  39 + date = dfComplete.parse(str);
  40 + else if (length == 7)
  41 + date = dfYearMon.parse(str);
  42 + else //if (length==4)
  43 + date = dfYearOnly.parse(str);
  44 +
  45 + if (date.before(today))
  46 + res = str;
  47 + }
  48 + } catch (ParseException e) {
  49 + e.printStackTrace();
  50 + }
  51 + }
  52 +
  53 +
  54 + return res;
  55 + }
  56 + public static List<String> getListUserInputDate(List<String> list){
  57 + List<String> res = new LinkedList<>();
  58 +
  59 + for(String s : list)
  60 + if(s.length() <= 10)
  61 + res.add(s);
  62 +
  63 + return res;
  64 + }
  65 +
  66 + public static Date parseDate(String date){
  67 + try{
  68 + int length = date.length();
  69 + switch (length) {
  70 + case 10 :
  71 + return dfYMD.parse(date);
  72 + case 7:
  73 + return dfYM.parse(date);
  74 + default:
  75 + return dfY.parse(date);
  76 + }
  77 + } catch (ParseException e){
  78 + e.printStackTrace();
  79 + return null;
  80 + }
  81 + }
  82 +}
... ...
src/pt/uminho/sdum/utils/DateValidator.java
... ... @@ -0,0 +1,58 @@
  1 +package pt.uminho.sdum.utils;
  2 +
  3 +import java.text.ParseException;
  4 +import java.text.SimpleDateFormat;
  5 +import java.util.Date;
  6 +
  7 +/**
  8 + * Returns null if not parsed
  9 + * Created by tmmguimaraes on 21/04/2016.
  10 + */
  11 +public class DateValidator {
  12 +
  13 + private Date dYMD=null;
  14 + private Date dYM=null;
  15 + private Date dY=null;
  16 +
  17 + private SimpleDateFormat dfYMD = new SimpleDateFormat("yyyy-MM-dd");
  18 + private SimpleDateFormat dfYM = new SimpleDateFormat("yyyy-MM");
  19 + private SimpleDateFormat dfY = new SimpleDateFormat("yyyy");
  20 + /**
  21 + * yyyy-MM-dd for 1st string
  22 + * yyyy-MM for 2nd string
  23 + * yyyy for 3rd string
  24 + * No protection, use with care;
  25 + */
  26 + public DateValidator(String sYMD, String sYM, String sY ){
  27 + try{
  28 +
  29 + dYMD = dfYMD.parse(sYMD);
  30 + dYM = dfYM.parse(sYM);
  31 + dY = dfY.parse(sY);
  32 + } catch (ParseException e){
  33 + e.printStackTrace();
  34 + }
  35 + }
  36 +
  37 +
  38 + //returns false if it fails to parse the date
  39 + public boolean verify(String sQueryDate){
  40 + Date dQueryDate;
  41 + try {
  42 + dQueryDate = dfYMD.parse(sQueryDate);
  43 + return dQueryDate.after(dYMD);
  44 + } catch (ParseException e) {
  45 + try {
  46 + dQueryDate = dfYM.parse(sQueryDate);
  47 + return dQueryDate.after(dYM);
  48 + } catch (ParseException e2) {
  49 + try {
  50 + dQueryDate = dfY.parse(sQueryDate);
  51 + return dQueryDate.after(dY);
  52 + } catch (ParseException e3) {
  53 + return false;
  54 + }
  55 + }
  56 + }
  57 + }
  58 +}
... ...
src/pt/uminho/sdum/validador2/check/AllMetadataFieldByContent.java
... ... @@ -0,0 +1,119 @@
  1 +package pt.uminho.sdum.validador2.check;
  2 +
  3 +import org.apache.commons.lang.StringUtils;
  4 +import org.apache.log4j.Logger;
  5 +import pt.keep.metarepository.core.configuration.ConfigurationManager;
  6 +import pt.keep.metarepository.core.harvester.server.data.Metadata;
  7 +import pt.keep.metarepository.core.harvester.server.data.Record;
  8 +import pt.keep.metarepository.core.validator2.application.CheckResult;
  9 +import pt.keep.metarepository.core.validator2.checks.CheckInterface;
  10 +import pt.keep.metarepository.core.validator2.profiles.data.Check;
  11 +import pt.keep.metarepository.core.validator2.profiles.data.Parameter;
  12 +import pt.keep.metarepository.core.validator2.registration.ValidationRequestInfo;
  13 +
  14 +import java.util.Iterator;
  15 +import java.util.List;
  16 +
  17 +/**
  18 + * based on pt.keep.metarepository.core.validator2.checks.AtLeastOneMetadataFieldByContent.java
  19 + *
  20 + * @author tmmguimaraes on 20/05/2016.
  21 + */
  22 +public class AllMetadataFieldByContent extends CheckInterface {
  23 + private Logger logger = Logger.getLogger(getClass());
  24 +
  25 + public CheckResult check(ValidationRequestInfo validationRequest,
  26 + Record record, Check check) {
  27 + CheckResult res = new CheckResult(false);
  28 + Check checkValidated = ConfigurationManager.getValidatorChecks().get(
  29 + check.getId());
  30 +
  31 + boolean okValue = true;
  32 +
  33 + if (checkValidated != null) {
  34 + logger.debug("<" + record.getHeader().getIdentifier() + ">");
  35 + List<Parameter> parameters = check.getParameter();
  36 + Metadata metadata = record.getMetadata();
  37 + List<String> metadataValues;
  38 +
  39 + String field = parameters.get(0).getValue().get(0);
  40 + String checkOperator = getCheckOperator(parameters);
  41 + List<String> checkValues = getCheckValues(parameters);
  42 + metadataValues = getListOfValuesForMetadataField(metadata, field);
  43 +
  44 +
  45 +
  46 + Iterator<String> iterator = metadataValues.iterator();
  47 + while (okValue && iterator.hasNext()) {
  48 + String metadataValue = iterator.next();
  49 + logger.debug("\t<" + field + "><" + checkOperator + "><"
  50 + + checkValues + ">");
  51 + if ("contains".equalsIgnoreCase(checkOperator)) {
  52 + okValue = StringUtils.isNotBlank(metadataValue)
  53 + && checkValues.contains(metadataValue);
  54 + logger.debug("\t\t<check>");
  55 +
  56 + } else if ("starts_with".equalsIgnoreCase(checkOperator)
  57 + && StringUtils.isNotBlank(metadataValue)) {
  58 + okValue = false;
  59 + Iterator<String> checkIt = checkValues.iterator();
  60 + while (!okValue && checkIt.hasNext()) {
  61 + String checkValue = checkIt.next();
  62 + okValue = metadataValue.startsWith(checkValue);
  63 + logger.debug("\t\t<check>");
  64 + }
  65 +
  66 + } else if ("ends_with".equalsIgnoreCase(checkOperator)
  67 + && StringUtils.isNotBlank(metadataValue)) {
  68 + okValue = false;
  69 + Iterator<String> checkIt = checkValues.iterator();
  70 + while (!okValue && checkIt.hasNext()) {
  71 + String checkValue = checkIt.next();
  72 + okValue = metadataValue.endsWith(checkValue);
  73 + logger.debug("\t\t<check>");
  74 + }
  75 +
  76 + } else if ("matches".equalsIgnoreCase(checkOperator)
  77 + && StringUtils.isNotBlank(metadataValue)) {
  78 + okValue = false;
  79 + Iterator<String> checkIt = checkValues.iterator();
  80 + while (!okValue && checkIt.hasNext()) {
  81 + String checkValue = checkIt.next();
  82 + okValue = metadataValue.matches(checkValue);
  83 + logger.debug("\t\t<check>");
  84 + }
  85 + }
  86 + }
  87 + } else {
  88 + logger.error("Check \"" + check.getId() + "\" (class="
  89 + + check.getClazz() + ") is not valid!");
  90 + }
  91 +
  92 + res.setOk(okValue);
  93 +
  94 + return res;
  95 + }
  96 +
  97 + public boolean areParametersValid(List<Parameter> parameters) {
  98 + boolean res = false;
  99 + int parametersOk = 0;
  100 + if (parameters.size() == 3) {
  101 + for (Parameter param : parameters) {
  102 + if ("field".equalsIgnoreCase(param.getKey().value())
  103 + && param.getValue().size() == 1) {
  104 + parametersOk++;
  105 + } else if ("operator".equalsIgnoreCase(param.getKey().value())
  106 + && param.getValue().size() == 1) {
  107 + parametersOk++;
  108 + } else if ("value".equalsIgnoreCase(param.getKey().value())
  109 + && param.getValue().size() > 0) {
  110 + parametersOk++;
  111 + }
  112 + }
  113 + if (parametersOk == 3) {
  114 + res = true;
  115 + }
  116 + }
  117 + return res;
  118 + }
  119 +}
... ...
src/pt/uminho/sdum/validador2/check/CheckTid.java
... ... @@ -0,0 +1,51 @@
  1 +package pt.uminho.sdum.validador2.check;
  2 +
  3 +
  4 +import pt.keep.metarepository.core.harvester.server.data.Metadata;
  5 +import pt.keep.metarepository.core.harvester.server.data.Record;
  6 +import pt.keep.metarepository.core.validator2.application.CheckResult;
  7 +import pt.keep.metarepository.core.validator2.checks.CheckInterface;
  8 +import pt.keep.metarepository.core.validator2.profiles.data.Check;
  9 +import pt.keep.metarepository.core.validator2.profiles.data.Parameter;
  10 +import pt.keep.metarepository.core.validator2.registration.ValidationRequestInfo;
  11 +import pt.uminho.sdum.utils.DateUtils;
  12 +import pt.uminho.sdum.utils.DateValidator;
  13 +
  14 +import java.util.ArrayList;
  15 +import java.util.List;
  16 +
  17 +/**
  18 + * Checks if thesis issued after 2013-08-06 have TID
  19 + * @author tmmguimaraes on 26/04/2016.
  20 + */
  21 +public class CheckTid extends CheckInterface {
  22 + @Override
  23 + public CheckResult check(ValidationRequestInfo validationRequest, Record record, Check check) {
  24 + DateValidator dateValidator = new DateValidator("2013-08-06", "2013-07", "2012");
  25 + CheckResult checkResult = new CheckResult(true);
  26 + Metadata metadata = record.getMetadata();
  27 +
  28 + if(dateValidator.verify(DateUtils.getDcDateIssueFromOai(metadata.getDateList()))) {
  29 + List<String> tids = getTID(metadata);
  30 + if(tids.isEmpty())
  31 + checkResult.setOk(false);
  32 + }
  33 +
  34 + return checkResult;
  35 + }
  36 +
  37 + @Override
  38 + public boolean areParametersValid(List<Parameter> parameters) {
  39 + return parameters.size() == 1;
  40 + }
  41 +
  42 + private List<String> getTID(Metadata metadata) {
  43 + List<String> lTid = new ArrayList<>();
  44 +
  45 + for (String identifier : metadata.getIdentifierList())
  46 + if (identifier.length() == 9 && identifier.matches("[0-9]+"))
  47 + lTid.add(identifier);
  48 +
  49 + return lTid;
  50 + }
  51 +}
... ...
src/pt/uminho/sdum/validador2/check/Embargo.java
... ... @@ -0,0 +1,47 @@
  1 +package pt.uminho.sdum.validador2.check;
  2 +
  3 +import pt.keep.metarepository.core.harvester.server.data.Metadata;
  4 +import pt.keep.metarepository.core.harvester.server.data.Record;
  5 +import pt.keep.metarepository.core.validator2.application.CheckResult;
  6 +import pt.keep.metarepository.core.validator2.checks.CheckInterface;
  7 +import pt.keep.metarepository.core.validator2.profiles.data.Check;
  8 +import pt.keep.metarepository.core.validator2.profiles.data.Parameter;
  9 +import pt.keep.metarepository.core.validator2.registration.ValidationRequestInfo;
  10 +import pt.uminho.sdum.utils.DateUtils;
  11 +
  12 +import java.util.Date;
  13 +import java.util.Iterator;
  14 +import java.util.List;
  15 +
  16 +/**
  17 + * @author tmmguimaraes on 04/05/2016.
  18 + */
  19 +public class Embargo extends CheckInterface {
  20 + @Override
  21 + public CheckResult check(ValidationRequestInfo validationRequest, Record record, Check check) {
  22 +
  23 + CheckResult checkResult = new CheckResult(true);
  24 + Metadata metadata = record.getMetadata();
  25 + if (!metadata.getRightsList().isEmpty()
  26 + && metadata.getRightsList().get(0).equals("embargoedAccess")) {
  27 +
  28 + List<String> dates = DateUtils.getListUserInputDate(metadata.getDateList());
  29 + Iterator<String> iterator = dates.iterator();
  30 + Date today = new Date();
  31 + boolean allBeforeToday = true;
  32 + while (allBeforeToday && iterator.hasNext()){
  33 + Date date = DateUtils.parseDate( iterator.next());
  34 + if(date != null) //it's only false when there is a malformed date
  35 + allBeforeToday = date.before(today);
  36 + }
  37 + checkResult.setOk(!allBeforeToday);
  38 + }
  39 +
  40 + return checkResult;
  41 + }
  42 +
  43 + @Override
  44 + public boolean areParametersValid(List<Parameter> parameters) {
  45 + return parameters.size() == 1;
  46 + }
  47 +}
... ...