Skip to content

Commit 968be7d

Browse files
committed
Prep support for new ARK-IDs for release via merge to rel/1.0.X
2 parents 14db45d + b42a784 commit 968be7d

3 files changed

Lines changed: 51 additions & 13 deletions

File tree

src/main/java/gov/nist/oar/rmm/config/AppConfig.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.springframework.web.servlet.config.annotation.CorsRegistry;
2323
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
2424
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
25+
import org.springframework.beans.factory.annotation.Value;
2526

2627
@SpringBootApplication
2728
@RefreshScope
@@ -37,6 +38,12 @@ public class AppConfig {
3738

3839
private static Logger log = LoggerFactory.getLogger(AppConfig.class);
3940

41+
@Value("${oar.id.ark_naan.default}")
42+
private String defnaan;
43+
44+
/** return the default NAAN associated with ARK identifiers in the repository */
45+
public String getDefaultNAAN() { return defnaan; }
46+
4047
/**
4148
* Main runner of the spring-boot class
4249
* @param args

src/main/java/gov/nist/oar/rmm/controllers/SearchController.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public Document search(@ApiIgnore @Valid @RequestParam Map<String, String> param
9999
return repo.find(params);
100100
}
101101

102-
@RequestMapping(value = {"/records/{ediid}"}, method = RequestMethod.GET, produces="application/json")
102+
@RequestMapping(value = {"/records/{id}"}, method = RequestMethod.GET, produces="application/json")
103103
@ApiOperation(value = "Get NERDm record of given id.",nickname = "recordbyId",
104104
notes = "Resource returns a NERDm Record by given ediid.")
105105
/**
@@ -108,8 +108,26 @@ public Document search(@ApiIgnore @Valid @RequestParam Map<String, String> param
108108
* @return Returns Document
109109
* @throws IOException
110110
*/
111-
public Document record(@PathVariable @Valid String ediid) throws IOException{
112-
logger.info("Get record by id:"+request);
111+
public Document record(@PathVariable @Valid String id) throws IOException{
112+
logger.info("Get record by id: "+id);
113+
return repo.findRecord(id);
114+
}
115+
116+
@RequestMapping(value = {"/records/ark:/{naan:\\d+}/{id}"}, method = RequestMethod.GET, produces="application/json")
117+
@ApiOperation(value = "Get NERDm record of given id.",nickname = "recordbyId",
118+
notes = "Resource returns a NERDm Record by given ediid.")
119+
/**
120+
* Get record for given id
121+
* @param id the local portion of an ARK identifier to match
122+
* @param naan the ARK identifier's naming authority number (NAAN)
123+
* @return Returns Document
124+
* @throws IOException
125+
*/
126+
public Document record(@PathVariable @Valid String id, @PathVariable String naan)
127+
throws IOException
128+
{
129+
String ediid = "ark:/"+naan+"/"+id;
130+
logger.info("Get record by full ARK id: "+ediid);
113131
return repo.findRecord(ediid);
114132
}
115133

src/main/java/gov/nist/oar/rmm/repositories/impl/CustomRepositoryImpl.java

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import com.mongodb.client.model.Filters;
3232

3333
import gov.nist.oar.rmm.config.MongoConfig;
34+
import gov.nist.oar.rmm.config.AppConfig;
3435
import gov.nist.oar.rmm.exceptions.ResourceNotFoundException;
3536
import gov.nist.oar.rmm.repositories.CustomRepository;
3637
import 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

Comments
 (0)