Created
March 3, 2016 07:58
-
-
Save xupyprmv/6d036852e12fa215da27 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* BEGIN Починить все старты маршрутов по идеям */ | |
// Получить все идеи | |
var s = new veda.SearchModel("'rdf:type' == 'mnd-s-asppd:Idea'", null); | |
Object.getOwnPropertyNames(s.results).map( function (res_id) { | |
var res = s.results[res_id]; | |
// console.log(res); | |
// Получить журнал | |
var journal = new veda.IndividualModel(res.id+'j'); | |
journal['v-s:childRecord'].forEach(function (record) { | |
if (record['rdf:type'] && record['rdf:type'][0].id == 'v-s:ProcessStarted') { | |
if (record['v-wf:onProcess'].length == 0 || record['v-s:onDocument'].length == 0) { | |
var processJournalId = record['v-s:processJournal'][0].id; | |
record.defineProperty("v-wf:onProcess"); | |
record.defineProperty("v-s:onDocument"); | |
record["v-wf:onProcess"] = [new veda.IndividualModel(processJournalId.substring(0, processJournalId.length - 1))]; | |
record["v-s:onDocument"] = [res]; | |
} | |
console.log("UPDATE > "+record.id); | |
record.save(); | |
} | |
}); | |
}); | |
/* END Починить все старты маршрутов по идеям */ | |
/* BEGIN Залить все старты маршрутов по идеям */ | |
// Получить все процессы по идеям | |
var process = {}; | |
var s = new veda.SearchModel("'rdf:type' == 'v-wf:Process'", null); | |
Object.getOwnPropertyNames(s.results).map( function (res_id) { | |
var res = s.results[res_id]; | |
//console.log(res); | |
if (res['v-wf:instanceOf'] && res['v-wf:instanceOf'][0] && res['v-wf:instanceOf'][0].id == "d:ProjectNet") { | |
res['v-wf:inVars'].forEach(function (variable) { | |
if (variable['v-wf:variableValue']) { | |
variable['v-wf:variableValue'].forEach(function (value) { | |
if (value['rdf:type']) { | |
value['rdf:type'].forEach(function (type) { | |
if (type.id == "mnd-s-asppd:Idea") { | |
console.log("PROCESS "+res.id+" > "+variable['v-wf:variableValue'][0].id); | |
process[res.id] = variable['v-wf:variableValue'][0].id; | |
} | |
}); | |
} | |
}); | |
} | |
}); | |
} | |
}); | |
console.log(process); | |
// Получить все идеи | |
var s = new veda.SearchModel("'rdf:type' == 'mnd-s-asppd:Idea'", null); | |
Object.getOwnPropertyNames(s.results).map( function (res_id) { | |
var res = s.results[res_id]; | |
// console.log(res); | |
// Получить журнал | |
var journal = new veda.IndividualModel(res.id+'j'); | |
journal['v-s:childRecord'].forEach(function (record) { | |
record['v-wf:onProcess'].forEach(function (p) { | |
delete process[p.id]; | |
}); | |
}); | |
}); | |
// Найти журнал в котором не отмечен старт процесса | |
console.log(process); | |
Object.getOwnPropertyNames(process).map( function (p_id) { | |
var idea = new veda.IndividualModel(process[p_id]); | |
if (!idea['v-s:deleted'] || idea['v-s:deleted'].length==0 || idea['v-s:deleted'][0] != true) { | |
var processJournal = new veda.IndividualModel(p_id+'j'); | |
var ideaJournal = new veda.IndividualModel(process[p_id]+'j'); | |
var journalRecord = new veda.IndividualModel(); | |
journalRecord.defineProperty("rdf:type"); | |
journalRecord.defineProperty("v-s:actor"); | |
journalRecord.defineProperty("v-s:processJournal"); | |
journalRecord.defineProperty("v-wf:onProcess"); | |
journalRecord.defineProperty("v-s:onDocument"); | |
journalRecord.defineProperty("v-s:created"); | |
journalRecord["rdf:type"] = [veda.ontology["v-s:ProcessStarted"]]; | |
journalRecord["v-s:actor"] = idea["v-s:author"]; | |
journalRecord["v-s:processJournal"] = [processJournal]; | |
journalRecord["v-wf:onProcess"] = [new veda.IndividualModel(p_id)]; | |
journalRecord["v-s:onDocument"] = [idea]; | |
journalRecord["v-s:created"] = processJournal["v-s:childRecord"][0]["v-s:created"]; | |
console.log("INSERT> "+idea.id+" <-> "+processJournal.id); | |
console.log(journalRecord); | |
journalRecord.save(); | |
ideaJournal['v-s:childRecord'] = ideaJournal['v-s:childRecord'].concat([journalRecord]); | |
ideaJournal.save(); | |
} | |
}); | |
/* END Залить все старты маршрутов по идеям */ | |
/* BEGIN Починить все сссылки на родителя в маршрутах */ | |
// Получить все процессы по идеям | |
var process = {}; | |
var s = new veda.SearchModel("'rdf:type' == 'v-wf:Process'", null); | |
Object.getOwnPropertyNames(s.results).map( function (res_id) { | |
var res = s.results[res_id]; | |
if (res['v-wf:instanceOf'] && res['v-wf:instanceOf'][0] && res['v-wf:instanceOf'][0].id == "d:ProjectNet") { | |
res['v-wf:inVars'].forEach(function (variable) { | |
if (variable['v-wf:variableValue']) { | |
variable['v-wf:variableValue'].forEach(function (value) { | |
if (value['rdf:type']) { | |
value['rdf:type'].forEach(function (type) { | |
if (type.id == "mnd-s-asppd:Idea") { | |
// Рекурсивная функция | |
function goJournal(journal, path) { | |
if (journal['v-s:parentJournal'].length > 0) { | |
var parJid = journal['v-s:parentJournal'][0].id; | |
if (parJid.substring(parJid.length - 1, parJid.length) != 'j') { | |
console.log("UPDATE LINK:"+journalId+" parent: "+journal['v-s:parentJournal'][0].id+" --> "+(variable['v-wf:variableValue'][0].id+'j')); | |
journal['v-s:parentJournal'] = [new veda.IndividualModel(variable['v-wf:variableValue'][0].id+'j')]; | |
journal.save(); | |
} | |
} else { | |
console.log("NO LINK :"+ path+" > "+journalId); | |
// Проставить в нем ссылку на родительский | |
} | |
// Залезть в дочерний маршрут | |
if (journal['v-s:subJournal']) { | |
journal['v-s:subJournal'].forEach(function(subj) { | |
goJournal(subj, path+" > "+journalId); | |
}); | |
} | |
} | |
var journalId = res.id+'j'; | |
var journal = new veda.IndividualModel(journalId); | |
goJournal(journal, ''); | |
} | |
}); | |
} | |
}); | |
} | |
}); | |
} | |
}); | |
/* END Починить все сссылки на родителя в маршрутах */ | |
/* BEGIN Починить все ответы на задачи */ | |
var s = new veda.SearchModel("'rdf:type' == 'v-wf:DecisionForm'", null); | |
Object.getOwnPropertyNames(s.results).map( function (res_id) { | |
var res = s.results[res_id]; | |
res['v-wf:takenDecision'].forEach(function (decision) { | |
if (!decision["v-s:parent"] || decision["v-s:parent"].length == 0 || decision["v-s:parent"][0].id != res.id) { | |
decision.defineProperty("v-s:parent"); | |
decision["v-s:parent"] = [res]; | |
console.log("UPDATE > "+decision.id); | |
decision.save(); | |
} | |
}); | |
}); | |
/* END Починить все ответы на задачи */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment