3131import com .mongodb .client .model .Filters ;
3232
3333import gov .nist .oar .rmm .config .MongoConfig ;
34+ import gov .nist .oar .rmm .config .AppConfig ;
3435import gov .nist .oar .rmm .exceptions .ResourceNotFoundException ;
3536import gov .nist .oar .rmm .repositories .CustomRepository ;
3637import gov .nist .oar .rmm .utilities .ProcessRequest ;
@@ -46,6 +47,9 @@ public class CustomRepositoryImpl implements CustomRepository {
4647 private Logger logger = LoggerFactory .getLogger (CustomRepositoryImpl .class );
4748 @ Autowired
4849 MongoConfig mconfig ;
50+
51+ @ Autowired
52+ AppConfig appconfig ;
4953
5054 /* (non-Javadoc)
5155 * @see gov.nist.oar.rmm.repositories.RecordRepository#find()
@@ -104,21 +108,30 @@ public List<Document> findResourceApis() {
104108 @ Override
105109 public Document findRecord (String ediid ) {
106110
107- Pattern p = Pattern .compile ("[^a-z0-9]" , Pattern .CASE_INSENSITIVE );
108- Matcher m = p .matcher (ediid );
111+ Pattern legal = Pattern .compile ("[^a-z0-9:/- ]" , Pattern .CASE_INSENSITIVE );
112+ Matcher m = legal .matcher (ediid );
109113 if (m .find ())
110- throw new IllegalArgumentException ("check input parameters. " );
114+ throw new IllegalArgumentException ("Illegal identifier " );
111115
112116 MongoCollection <Document > mcollection = mconfig .getRecordCollection ();
117+
118+ String useid = ediid ;
113119
114-
115- long count = mcollection .count (Filters .eq ("ediid" ,ediid ));
116- if (count == 0 ) {
117- //return new Document("Message", "No record available for given id.");
118- throw new ResourceNotFoundException ("No record available for given id." );
120+ logger .debug ("Searching for " +ediid +" as " +useid );
121+ long count = mcollection .count (Filters .eq ("ediid" ,useid ));
122+ if (count == 0 && useid .length () < 30 && ! useid .startsWith ("ark:" )) {
123+ // allow an ediid be an abbreviation of the ARK ID as specified
124+ // by its local portion
125+ useid = "ark:/" +appconfig .getDefaultNAAN ()+"/" +ediid ;
126+ logger .debug ("Searching for " +ediid +" as " +useid );
127+ count = mcollection .count (Filters .eq ("ediid" , useid ));
119128 }
120- else
121- return mcollection .find (Filters .eq ("ediid" ,ediid )).first ();
129+ if (count == 0 ) {
130+ //return new Document("Message", "No record available for given id.");
131+ throw new ResourceNotFoundException ("No record available for given id." );
132+ }
133+
134+ return mcollection .find (Filters .eq ("ediid" ,useid )).first ();
122135
123136 }
124137
0 commit comments