Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
assignURI(req.fullURL, req.get('Slug'), function(err, loc) {
if (err !== 201) {
console.log(err)
res.sendStatus(500)
return
}
// Parse the entity response body, the resource to add to the container
var newMember = new rdflib.IndexedFormula();
newMember.uri = loc;
rdflib.parse(req.rawBody, newMember, loc, serialize, function(err, document) {
// document and newMember are the same thing from here on...
if (err) {
// allow the URI to be used again if this is a bad request
console.log(`error parsing POST body for ${loc}, error: ${err}`);
db.releaseURI(loc)
res.sendStatus(400)
return
}
updateInteractionModel(newMember); // newMember is RDFResource, DirectContainer or BasicContainer
addHeaders(req, res, newMember)
// check if the client requested a specific interaction model through a Link header
// if so, override what we found from the RDF content
// TODO: look for Link type=container as well
constructor.prototype.result = function(err, res, body) {
console.log( '270:', this.options );
var h = (res && res.hasOwnProperty('headers')) ? res.headers : null;
var b = (h && h.hasOwnProperty('location')) ? h['location'] : this.uri;
if (this.options.baseUrl === '') this.options.baseUrl = b;
if (err) return this.parseFile();
// console.log( res.headers, res.statusCode );
if (res.statusCode == 200) {
var xmlData = '';
this.options.contentType = this.getType(this.uri, res, this.options.contentType);
if (this.options.contentType === 'application/rdf+xml') {
xmlData = body;
} else {
var graph = new rdflib.IndexedFormula();
// TODO - base parameter
var rawData = rdflib.parse(body, graph, this.uri, this.options.contentType);
xmlData = rdflib.serialize(rawData, graph, this.uri, 'application/rdf+xml');
}
var json = this.parseOWL(xmlData, this.options);
return this.cb(null, json);
}
}
return
}
// Add the membership triple required to realize the containment
if (container.interactionModel === ldp.DirectContainer) {
if (container.isMemberOfRelation) {
newMember.add(rdflib.sym(loc), rdflib.sym(container.isMemberOfRelation), rdflib.sym(container.membershipResource));
} else {
// container uses hasMemberRelation
let data = new rdflib.IndexedFormula();
data.add(rdflib.sym(container.membershipResource), rdflib.sym(container.hasMemberRelation), rdflib.sym(loc));
db.insertData(data, container.membershipResource, status => {});
}
} else {
// update the BasicContainer's member
let data = new rdflib.IndexedFormula();
data.add(rdflib.sym(req.fullURL), LDP('contains'), rdflib.sym(loc));
db.insertData(data, req.fullURL, status => {});
}
// update the membership resource
db.update(newMember, function(err) {
if (err !== 201) {
console.log("Cannot create resource: "+err)
db.releaseURI(loc)
res.sendStatus(500)
return
}
res.location(loc).sendStatus(201)
})
})
})
resource.put(function(req, res, next) {
var serialize
if (req.is(media.turtle)) {
serialize = media.turtle
} else if (req.is(media.jsonld) || req.is(media.json)) {
serialize = media.jsonld
} else {
res.sendStatus(415)
return;
}
var newTriples = new rdflib.IndexedFormula()
rdflib.parse(req.rawBody, newTriples, req.fullURL, serialize, function(err, newTriples) {
if (err) {
console.log(err.stack)
res.sendStatus(500)
return
}
newTriples.uri = req.fullURL
// get the resource to check if it exists and check its ETag
db.read(req.fullURL, function(err, document) {
if (err === 200) {
// the resource exists. update it
putUpdate(req, res, document, newTriples, serialize)
} else if (err === 404) {
// the resource doesn't exist, create it
putCreate(req, res, newTriples)
this.id = rdflib.sym(uri)
this.kb = kb
// These are not valid QNames using prefix http://jazz.net/xmlns/prod/jazz/rtc/ext/1.0/, local part can't have dots?
// These parse ok, but don't serialize, XML qnames can have dots. This is an rdflib defect
kb.removeMany(kb.sym(uri), kb.sym('http://jazz.net/xmlns/prod/jazz/rtc/ext/1.0/com.ibm.team.apt.attribute.complexity'))
kb.removeMany(kb.sym(uri), kb.sym('http://jazz.net/xmlns/prod/jazz/rtc/ext/1.0/com.ibm.team.apt.attribute.acceptance'))
kb.removeMany(kb.sym(uri), kb.sym('http://jazz.net/xmlns/prod/jazz/rtc/cm/1.0/com.ibm.team.workitem.linktype.relatedworkitem.related'))
kb.removeMany(kb.sym(uri), kb.sym('http://jazz.net/xmlns/prod/jazz/rtc/cm/1.0/com.ibm.team.workitem.linktype.resolvesworkitem.resolves'))
kb.removeMany(kb.sym(uri), kb.sym('http://jazz.net/xmlns/prod/jazz/rtc/cm/1.0/com.ibm.team.build.linktype.reportedWorkItems.com.ibm.team.build.common.link.reportedAgainstBuilds'))
kb.removeMany(kb.sym(uri), kb.sym('http://jazz.net/xmlns/prod/jazz/rtc/cm/1.0/com.ibm.team.enterprise.promotion.linktype.promotedBuildMaps.promotedBuildMaps'))
kb.removeMany(kb.sym(uri), kb.sym('http://jazz.net/xmlns/prod/jazz/rtc/cm/1.0/com.ibm.team.enterprise.promotion.linktype.promotionBuildResult.promotionBuildResult'))
kb.removeMany(kb.sym(uri), kb.sym('http://jazz.net/xmlns/prod/jazz/rtc/cm/1.0/com.ibm.team.enterprise.promotion.linktype.promotionDefinition.promotionDefinition'))
kb.removeMany(kb.sym(uri), kb.sym('http://jazz.net/xmlns/prod/jazz/rtc/cm/1.0/com.ibm.team.enterprise.promotion.linktype.resultWorkItem.promoted'))
} else {
this.id = rdflib.blankNode()
this.kb = new rdflib.IndexedFormula()
}
this.etag = undefined
}
request.authGet(queryURI, function(err, response, body) {
if (err || response.statusCode != 200) {
let code = err? 500: response.statusCode;
callback(code, null);
return;
}
if (response.headers['x-com-ibm-team-repository-web-auth-msg'] === 'authfailed') {
callback(401, null);
return;
}
// return the result
var kb = new rdflib.IndexedFormula()
rdflib.parse(body, kb, queryURI, 'application/rdf+xml')
// create an OSLCResource for each result member
// TODO: getting the members must use the discovered member predicate, rdfs:member is the default
let resources = [];
let members = kb.each(kb.sym(queryBase), RDFS('member'));
for (let member of members) {
let memberStatements = kb.statementsMatching(member, undefined, undefined);
let memberKb = new rdflib.IndexedFormula();
memberKb.add(memberStatements);
resources.push(new OSLCResource(member.uri, memberKb));
}
callback(null, resources)
});
}
}
if (response.headers['x-com-ibm-team-repository-web-auth-msg'] === 'authfailed') {
callback(401, null);
return;
}
// return the result
var kb = new rdflib.IndexedFormula()
rdflib.parse(body, kb, queryURI, 'application/rdf+xml')
// create an OSLCResource for each result member
// TODO: getting the members must use the discovered member predicate, rdfs:member is the default
let resources = [];
let members = kb.each(kb.sym(queryBase), RDFS('member'));
for (let member of members) {
let memberStatements = kb.statementsMatching(member, undefined, undefined);
let memberKb = new rdflib.IndexedFormula();
memberKb.add(memberStatements);
resources.push(new OSLCResource(member.uri, memberKb));
}
callback(null, resources)
});
}
request.post(options, function gotCreateResults(err, response, body) {
if (err || response.statusCode != 201) {
let code = err? 500: response.statusCode;
callback(code, null);
return;
}
var kb = new rdflib.IndexedFormula()
var uri = response.headers['location']
rdflib.parse(body, kb, uri, 'application/rdf+xml')
var results = new OSLCResource(uri, kb)
callback(null, results)
})
})
request.authGet(options, function gotResult(err, response, body) {
if (err || response.statusCode != 200) {
let code = err? 500: response.statusCode;
callback(code, null);
return;
}
if (response.headers['x-com-ibm-team-repository-web-auth-msg'] === 'authfailed') {
callback(401, null);
return;
}
if (!response.headers['content-type'].startsWith('application/x-oslc-compact+xml')) {
callback(406, null);
return;
}
var kb = new rdflib.IndexedFormula()
rdflib.parse(body, kb, uri, 'application/rdf+xml')
var results = new Compact(uri, kb)
results.etag = response.headers['etag']
callback(null, results)
})
}