Исходный код вики CatalogCreateDataSetViewCall
Последние авторы
| author | version | line-number | content |
|---|---|---|---|
| 1 | {{groovy}} | ||
| 2 | import org.xwiki.observation.* | ||
| 3 | import org.xwiki.observation.event.* | ||
| 4 | import org.xwiki.bridge.event.* | ||
| 5 | import org.xwiki.model.reference.* | ||
| 6 | import org.xwiki.model.* | ||
| 7 | import com.xpn.xwiki.web.* | ||
| 8 | import com.xpn.xwiki.* | ||
| 9 | import org.xwiki.context.* | ||
| 10 | import org.xwiki.configuration.* | ||
| 11 | import java.io.File | ||
| 12 | import java.util.HashMap | ||
| 13 | import groovy.json.JsonOutput | ||
| 14 | import groovy.xml.XmlUtil | ||
| 15 | import ru.eproj.liferay.MPORESTApiCaller; | ||
| 16 | import ru.eproj.liferay.impl.MPORESTConfigurationImpl2; | ||
| 17 | |||
| 18 | def makeMessage(String msg) { | ||
| 19 | System.out.println('SUZ: ' + msg) | ||
| 20 | def resultJsonData = new HashMap() | ||
| 21 | resultJsonData.put('result', msg) | ||
| 22 | return JsonOutput.toJson(resultJsonData) | ||
| 23 | } | ||
| 24 | |||
| 25 | try { | ||
| 26 | def resultJsonData = new HashMap() //Будущий ответ | ||
| 27 | if(request.get('outputSyntax') != null) { | ||
| 28 | response.setContentType('application/json') | ||
| 29 | } | ||
| 30 | //Параметры, пришедшие из запроса | ||
| 31 | def docID = request.get('docID') | ||
| 32 | def tsName = request.get('tsName') | ||
| 33 | def datasetName = request.get('datasetName') | ||
| 34 | def datasetSlug = request.get('datasetSlug') | ||
| 35 | def olapDatasetURL = request.get('olapDatasetURL') | ||
| 36 | def catalog = request.get('catalog') | ||
| 37 | def details = request.get('details') | ||
| 38 | def dimentionsUri = request.get('dimentionsUri') | ||
| 39 | def document = request.get('document') | ||
| 40 | def host = request.getHeader('Host') | ||
| 41 | |||
| 42 | if (!docID) { | ||
| 43 | println(makeMessage('Error: document not found.')) | ||
| 44 | return | ||
| 45 | } | ||
| 46 | |||
| 47 | def srcDoc = xwiki.getDocument(docID); | ||
| 48 | def srcObj = srcDoc.getObject('SUZ.Indicators.Code.DataSetClass'); | ||
| 49 | if (!srcObj) { | ||
| 50 | println(makeMessage('Error: not found DataSetClass in ' + docID)) | ||
| 51 | return | ||
| 52 | } | ||
| 53 | |||
| 54 | //Взять из настроек параметры | ||
| 55 | def configurationDoc = xwiki.getDocument("SUZ.Code.SUZConfiguration") | ||
| 56 | if (!configurationDoc) { //Не найдена конфигурация СУЗ | ||
| 57 | println(makeMessage('Error: SUZ configuration document not found.')) | ||
| 58 | return | ||
| 59 | } | ||
| 60 | def configurationDocObject = configurationDoc.getObject("SUZ.Code.SUZConfigurationClass", false) | ||
| 61 | if (!configurationDocObject) { // Если в configurationDoc нету configurationDocClass | ||
| 62 | println(makeMessage('Error: SUZ configuration document exist, but SUZConfigurationClass not found.')) | ||
| 63 | return | ||
| 64 | } | ||
| 65 | def URI_PREFIX = configurationDocObject.getProperty("purlServer").value | ||
| 66 | if (!URI_PREFIX) { | ||
| 67 | println(makeMessage('Error: Configuration URIPrefix not found in SUZ configuration document.')) | ||
| 68 | return | ||
| 69 | } | ||
| 70 | def catalogId = "LD" | ||
| 71 | //Список URI для измерений | ||
| 72 | def fromNamedURI = "" | ||
| 73 | if (dimentionsUri && dimentionsUri.trim()) { | ||
| 74 | fromNamedURI = dimentionsUri | ||
| 75 | .split(',') | ||
| 76 | .collect { uri -> "FROM NAMED <${uri.trim()}#>" } | ||
| 77 | .join('\\n') | ||
| 78 | |||
| 79 | fromNamedURI = "\\n${fromNamedURI}\\n" | ||
| 80 | } | ||
| 81 | |||
| 82 | //Подготовка запроса | ||
| 83 | def queryDoc = xwiki.getDocument('SUZ.Catalog.Code.CatalogCreateDataSetViewQuery.WebHome'); | ||
| 84 | if (!queryDoc) { | ||
| 85 | println(makeMessage('Error: not found Query Template')) | ||
| 86 | return | ||
| 87 | } | ||
| 88 | def queryTemplate = queryDoc.getContent() | ||
| 89 | def UUID = catalog + "-" + datasetSlug | ||
| 90 | def dataset_uri = URI_PREFIX + '/data/' + datasetSlug | ||
| 91 | def asset_uri = URI_PREFIX + '/catalog/' + catalogId + '/card/' + datasetSlug //$URI_PREFIX + "/catalog/$catalogId/card/"+ $doc.getValue('datasetSlug')) | ||
| 92 | def query = queryTemplate.replace('[UUID]',UUID).replace('[DATASET_TITLE]', datasetName).replace('[DATASET_URI]', dataset_uri).replace('[ASSET_URI]', asset_uri).replace('[HOST]', host).replace('[PURL]', URI_PREFIX).replace('[OLAP_DATASET_URL]', olapDatasetURL).replace('[FROM_NAMED_URI]', fromNamedURI); | ||
| 93 | //Выполнение запроса | ||
| 94 | def configuration = services.component.getInstance(ConfigurationSource.class, 'xwikiproperties') | ||
| 95 | //Команда для вызова | ||
| 96 | MPORESTApiCaller caller = new MPORESTApiCaller(new MPORESTConfigurationImpl2(configuration)) | ||
| 97 | def graph_uri = 'http://view.hbz.ru/' | ||
| 98 | def ret = caller.sparql_update_execute(graph_uri, query) | ||
| 99 | System.out.println('SUZ: Virtuoso graph: ' + graph_uri + ' updated.') | ||
| 100 | |||
| 101 | resultJsonData.clear() | ||
| 102 | resultJsonData.put('result', 'Update Catalog View success now: ' + xwiki.getDate() + ' ' + ret) | ||
| 103 | String jsonData = JsonOutput.toJson(resultJsonData) | ||
| 104 | println(jsonData) | ||
| 105 | |||
| 106 | } catch(e) { | ||
| 107 | //System.out.println("SUZ: ERROR! : " + e.getMessage()) | ||
| 108 | println(makeMessage('Error: Runtime: ' + e.getMessage())) | ||
| 109 | } | ||
| 110 | {{/groovy}} |