Skip to content

Commit

Permalink
Prep support for new ARK-IDs for release via merge to rel/1.0.X
Browse files Browse the repository at this point in the history
  • Loading branch information
RayPlante committed Jul 15, 2019
2 parents 14db45d + b42a784 commit 968be7d
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 13 deletions.
7 changes: 7 additions & 0 deletions src/main/java/gov/nist/oar/rmm/config/AppConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.beans.factory.annotation.Value;

@SpringBootApplication
@RefreshScope
Expand All @@ -37,6 +38,12 @@ public class AppConfig {

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

@Value("${oar.id.ark_naan.default}")
private String defnaan;

/** return the default NAAN associated with ARK identifiers in the repository */
public String getDefaultNAAN() { return defnaan; }

/**
* Main runner of the spring-boot class
* @param args
Expand Down
24 changes: 21 additions & 3 deletions src/main/java/gov/nist/oar/rmm/controllers/SearchController.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public Document search(@ApiIgnore @Valid @RequestParam Map<String, String> param
return repo.find(params);
}

@RequestMapping(value = {"/records/{ediid}"}, method = RequestMethod.GET, produces="application/json")
@RequestMapping(value = {"/records/{id}"}, method = RequestMethod.GET, produces="application/json")
@ApiOperation(value = "Get NERDm record of given id.",nickname = "recordbyId",
notes = "Resource returns a NERDm Record by given ediid.")
/**
Expand All @@ -108,8 +108,26 @@ public Document search(@ApiIgnore @Valid @RequestParam Map<String, String> param
* @return Returns Document
* @throws IOException
*/
public Document record(@PathVariable @Valid String ediid) throws IOException{
logger.info("Get record by id:"+request);
public Document record(@PathVariable @Valid String id) throws IOException{
logger.info("Get record by id: "+id);
return repo.findRecord(id);
}

@RequestMapping(value = {"/records/ark:/{naan:\\d+}/{id}"}, method = RequestMethod.GET, produces="application/json")
@ApiOperation(value = "Get NERDm record of given id.",nickname = "recordbyId",
notes = "Resource returns a NERDm Record by given ediid.")
/**
* Get record for given id
* @param id the local portion of an ARK identifier to match
* @param naan the ARK identifier's naming authority number (NAAN)
* @return Returns Document
* @throws IOException
*/
public Document record(@PathVariable @Valid String id, @PathVariable String naan)
throws IOException
{
String ediid = "ark:/"+naan+"/"+id;
logger.info("Get record by full ARK id: "+ediid);
return repo.findRecord(ediid);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.mongodb.client.model.Filters;

import gov.nist.oar.rmm.config.MongoConfig;
import gov.nist.oar.rmm.config.AppConfig;
import gov.nist.oar.rmm.exceptions.ResourceNotFoundException;
import gov.nist.oar.rmm.repositories.CustomRepository;
import gov.nist.oar.rmm.utilities.ProcessRequest;
Expand All @@ -46,6 +47,9 @@ public class CustomRepositoryImpl implements CustomRepository {
private Logger logger = LoggerFactory.getLogger(CustomRepositoryImpl.class);
@Autowired
MongoConfig mconfig;

@Autowired
AppConfig appconfig;

/* (non-Javadoc)
* @see gov.nist.oar.rmm.repositories.RecordRepository#find()
Expand Down Expand Up @@ -104,21 +108,30 @@ public List<Document> findResourceApis() {
@Override
public Document findRecord(String ediid) {

Pattern p = Pattern.compile("[^a-z0-9]", Pattern.CASE_INSENSITIVE);
Matcher m = p.matcher(ediid);
Pattern legal = Pattern.compile("[^a-z0-9:/-]", Pattern.CASE_INSENSITIVE);
Matcher m = legal.matcher(ediid);
if(m.find())
throw new IllegalArgumentException("check input parameters.");
throw new IllegalArgumentException("Illegal identifier");

MongoCollection<Document> mcollection = mconfig.getRecordCollection();

String useid = ediid;


long count = mcollection.count(Filters.eq("ediid",ediid));
if(count == 0) {
//return new Document("Message", "No record available for given id.");
throw new ResourceNotFoundException("No record available for given id.");
logger.debug("Searching for "+ediid+" as "+useid);
long count = mcollection.count(Filters.eq("ediid",useid));
if(count == 0 && useid.length() < 30 && ! useid.startsWith("ark:")) {
// allow an ediid be an abbreviation of the ARK ID as specified
// by its local portion
useid = "ark:/"+appconfig.getDefaultNAAN()+"/"+ediid;
logger.debug("Searching for "+ediid+" as "+useid);
count = mcollection.count(Filters.eq("ediid", useid));
}
else
return mcollection.find(Filters.eq("ediid",ediid)).first();
if (count == 0) {
//return new Document("Message", "No record available for given id.");
throw new ResourceNotFoundException("No record available for given id.");
}

return mcollection.find(Filters.eq("ediid",useid)).first();

}

Expand Down

0 comments on commit 968be7d

Please sign in to comment.