labelingsystem-server  Version 0.1.0.0
Transformer Class Reference

Static Public Member Functions

static String vocabulary_POST (String json, String id) throws IOException, UniqueIdentifierException, ParseException
 
static JSONObject vocabulary_GET (String json, String id, String fields, String statisticsBool, String creatorInfoBool) throws IOException, UniqueIdentifierException, ParseException, TransformRdfToApiJsonException
 
static JSONObject revision_GET (String json, String id) throws IOException, UniqueIdentifierException, ParseException, TransformRdfToApiJsonException
 
static JSONObject empty_JSON (String item) throws IOException, UniqueIdentifierException, ParseException
 
static String agent_POST (String json, String id) throws IOException, UniqueIdentifierException, ParseException
 
static JSONObject agent_GET (String json, String id) throws IOException, UniqueIdentifierException, ParseException, TransformRdfToApiJsonException
 
static String label_POST (String json, String id, String creator) throws IOException, UniqueIdentifierException, ParseException
 
static JSONObject label_GET (String json, String id, String fields, List< RetcatItem > retcatlist, String equalConceptsBool, String revisionsBool, String creatorInfoBool, List< InheritFromVocab > inheritFromVocab) throws IOException, UniqueIdentifierException, ParseException, RepositoryException, MalformedQueryException, QueryEvaluationException, SesameSparqlException, ResourceNotAvailableException, TransformRdfToApiJsonException
 
static HashMap< String, String > getLabelDifference (String json_old, String json_new) throws ParseException, RevisionTypeException
 
static void writeVocabularyStatisticsToDatabase (String vocabulary) throws org.eclipse.rdf4j.repository.RepositoryException, org.eclipse.rdf4j.query.MalformedQueryException, org.eclipse.rdf4j.query.QueryEvaluationException, SparqlParseException, SparqlQueryException, IOException, ClassNotFoundException, SQliteException, StatisticsException
 

Member Function Documentation

◆ agent_GET()

static JSONObject agent_GET ( String  json,
String  id 
) throws IOException, UniqueIdentifierException, ParseException, TransformRdfToApiJsonException
static
518  {
519  JSONObject agentObject = null;
520  try {
521  //init
522  RDF rdf = new RDF();
523  // parse json
524  JSONObject jsonObject = (JSONObject) new JSONParser().parse(json);
525  jsonObject.put("agent", jsonObject.remove(rdf.getPrefixItem("ls_age" + ":" + id)));
526  // get items
527  agentObject = (JSONObject) jsonObject.get(rdf.getPrefixItem("agent"));
528  // change dc:identifier
529  JSONArray identifierArray = (JSONArray) agentObject.get(rdf.getPrefixItem("dc:identifier"));
530  if (identifierArray != null && !identifierArray.isEmpty()) {
531  for (Object element : identifierArray) {
532  agentObject.remove(rdf.getPrefixItem("dc:identifier"));
533  JSONObject obj = (JSONObject) element;
534  String value = (String) obj.get("value");
535  agentObject.put(rdf.getPrefixItem("id"), value);
536  }
537  }
538  // change foaf:title
539  JSONArray titleArray = (JSONArray) agentObject.get(rdf.getPrefixItem("foaf:title"));
540  if (titleArray != null && !titleArray.isEmpty()) {
541  for (Object element : titleArray) {
542  agentObject.remove(rdf.getPrefixItem("foaf:title"));
543  JSONObject obj = (JSONObject) element;
544  String value = (String) obj.get("value");
545  agentObject.put(rdf.getPrefixItem("title"), value);
546  }
547  }
548  // change foaf:firstName
549  JSONArray firstNameArray = (JSONArray) agentObject.get(rdf.getPrefixItem("foaf:firstName"));
550  if (firstNameArray != null && !firstNameArray.isEmpty()) {
551  for (Object element : firstNameArray) {
552  agentObject.remove(rdf.getPrefixItem("foaf:mbox"));
553  JSONObject obj = (JSONObject) element;
554  String value = (String) obj.get("value");
555  agentObject.put(rdf.getPrefixItem("firstName"), value);
556  }
557  }
558  // change foaf:lastName
559  JSONArray lastNameArray = (JSONArray) agentObject.get(rdf.getPrefixItem("foaf:lastName"));
560  if (lastNameArray != null && !lastNameArray.isEmpty()) {
561  for (Object element : lastNameArray) {
562  agentObject.remove(rdf.getPrefixItem("foaf:lastName"));
563  JSONObject obj = (JSONObject) element;
564  String value = (String) obj.get("value");
565  agentObject.put(rdf.getPrefixItem("lastName"), value);
566  }
567  }
568  // change dct:publisher
569  JSONArray publisherArray = (JSONArray) agentObject.get(rdf.getPrefixItem("dct:publisher"));
570  if (publisherArray != null && !publisherArray.isEmpty()) {
571  for (Object element : publisherArray) {
572  agentObject.remove(rdf.getPrefixItem("dct:publisher"));
573  JSONObject obj = (JSONObject) element;
574  String value = (String) obj.get("value");
575  agentObject.put(rdf.getPrefixItem("orcid"), value);
576  }
577  }
578  // change dct:isPartOf
579  JSONArray partOfArray = (JSONArray) agentObject.get(rdf.getPrefixItem("dct:isPartOf"));
580  if (partOfArray != null && !partOfArray.isEmpty()) {
581  for (Object element : partOfArray) {
582  agentObject.remove(rdf.getPrefixItem("dct:isPartOf"));
583  JSONObject obj = (JSONObject) element;
584  String value = (String) obj.get("value");
585  agentObject.put(rdf.getPrefixItem("affiliation"), value);
586  }
587  }
588  // delete items
589  agentObject.remove(rdf.getPrefixItem("rdf:type"));
590  agentObject.remove(rdf.getPrefixItem("dc:identifier"));
591  agentObject.remove(rdf.getPrefixItem("foaf:title"));
592  agentObject.remove(rdf.getPrefixItem("foaf:firstName"));
593  agentObject.remove(rdf.getPrefixItem("foaf:lastName"));
594  agentObject.remove(rdf.getPrefixItem("dct:publisher"));
595  agentObject.remove(rdf.getPrefixItem("dct:isPartOf"));
596  // deposits
597  agentObject.remove(rdf.getPrefixItem("ls:sameAs"));
598  agentObject.remove(rdf.getPrefixItem("foaf:accountName"));
599  agentObject.remove(rdf.getPrefixItem("ls:inGroup"));
600  agentObject.remove(rdf.getPrefixItem("foaf:mbox"));
601  agentObject.remove(rdf.getPrefixItem("foaf:homepage"));
602  agentObject.remove(rdf.getPrefixItem("foaf:img"));
603  agentObject.remove(rdf.getPrefixItem("geo:lat"));
604  agentObject.remove(rdf.getPrefixItem("geo:lon"));
605  } catch (Exception e) {
606  int errorLine = -1;
607  for (StackTraceElement element : e.getStackTrace()) {
608  errorLine = element.getLineNumber();
609  if (element.getClassName().equals(Transformer.class.getName())) {
610  break;
611  }
612  }
613  throw new TransformRdfToApiJsonException(e.toString() + " in line " + String.valueOf(errorLine));
614  }
615  // return
616  return agentObject;
617  }

Referenced by AgentsResource.getAgent(), AgentsResource.getAgent_JSON(), AgentsResource.getAgents(), AuthResource.loginUser(), AgentsResource.postAgent(), AuthResource.statusUser(), and AgentsResource.updateAgent().

◆ agent_POST()

static String agent_POST ( String  json,
String  id 
) throws IOException, UniqueIdentifierException, ParseException
static
442  {
443  //init
444  RDF rdf = new RDF();
445  // parse json
446  JSONObject rdfObject = new JSONObject();
447  JSONObject agentObject = (JSONObject) new JSONParser().parse(json);
448  // change title
449  String titleString = (String) agentObject.get("title");
450  if (titleString != null && !titleString.isEmpty()) {
451  agentObject.remove("title");
452  JSONArray titleArrayNew = new JSONArray();
453  JSONObject titleObject = new JSONObject();
454  titleObject.put("type", "literal");
455  titleObject.put("value", titleString);
456  titleArrayNew.add(titleObject);
457  agentObject.put(rdf.getPrefixItem("foaf:title"), titleArrayNew);
458  }
459  // change firstName
460  String firstNameString = (String) agentObject.get("firstName");
461  if (firstNameString != null && !firstNameString.isEmpty()) {
462  agentObject.remove("firstName");
463  JSONArray firstNameArrayNew = new JSONArray();
464  JSONObject firstNameObject = new JSONObject();
465  firstNameObject.put("type", "literal");
466  firstNameObject.put("value", firstNameString);
467  firstNameArrayNew.add(firstNameObject);
468  agentObject.put(rdf.getPrefixItem("foaf:firstName"), firstNameArrayNew);
469  }
470  // change lastName
471  String lastNameString = (String) agentObject.get("lastName");
472  if (lastNameString != null && !lastNameString.isEmpty()) {
473  agentObject.remove("lastName");
474  JSONArray lastNameArrayNew = new JSONArray();
475  JSONObject lastNameObject = new JSONObject();
476  lastNameObject.put("type", "literal");
477  lastNameObject.put("value", lastNameString);
478  lastNameArrayNew.add(lastNameObject);
479  agentObject.put(rdf.getPrefixItem("foaf:lastName"), lastNameArrayNew);
480  }
481  // change orcid
482  String orcidString = (String) agentObject.get("orcid");
483  if (orcidString != null && !orcidString.isEmpty()) {
484  agentObject.remove("orcid");
485  JSONArray orcidArrayNew = new JSONArray();
486  JSONObject orcidObject = new JSONObject();
487  orcidObject.put("type", "uri");
488  orcidObject.put("value", orcidString);
489  orcidArrayNew.add(orcidObject);
490  agentObject.put(rdf.getPrefixItem("dct:publisher"), orcidArrayNew);
491  }
492  // change affiliation
493  String affiliationString = (String) agentObject.get("affiliation");
494  if (affiliationString != null && !affiliationString.isEmpty()) {
495  agentObject.remove("affiliation");
496  JSONArray affiliationArrayNew = new JSONArray();
497  JSONObject affiliationObject = new JSONObject();
498  affiliationObject.put("type", "uri");
499  affiliationObject.put("value", affiliationString);
500  affiliationArrayNew.add(affiliationObject);
501  agentObject.put(rdf.getPrefixItem("dct:isPartOf"), affiliationArrayNew);
502  }
503  // delete items
504  agentObject.remove("id");
505  agentObject.remove("title");
506  agentObject.remove("firstName");
507  agentObject.remove("lastName");
508  agentObject.remove("affiliation");
509  agentObject.remove("orcid");
510  agentObject.remove("role");
511  agentObject.remove("status");
512  agentObject.remove("pwd");
513  // add object
514  rdfObject.put(rdf.getPrefixItem("ls_age" + ":" + id), agentObject);
515  return rdfObject.toJSONString();
516  }

Referenced by AgentsResource.postAgent(), and AgentsResource.updateAgent().

◆ empty_JSON()

static JSONObject empty_JSON ( String  item) throws IOException, UniqueIdentifierException, ParseException
static
437  {
438  JSONObject jsonObject = new JSONObject();
439  return jsonObject;
440  }

Referenced by AgentsResource.deleteAgent(), LabelsResource.deleteLabel(), and VocabsResource.deleteVocabulary().

◆ getLabelDifference()

static HashMap<String, String> getLabelDifference ( String  json_old,
String  json_new 
) throws ParseException, RevisionTypeException
static
1393  {
1394  HashMap<String, String> hm = new HashMap();
1395  try {
1396  // jsons
1397  JSONObject oldObject = (JSONObject) new JSONParser().parse(json_old);
1398  JSONObject newObject = (JSONObject) new JSONParser().parse(json_new);
1399  // objects
1400  String oldDescription = (String) oldObject.get("description");
1401  String newDescription = (String) newObject.get("description");
1402  JSONArray oldTranslations = (JSONArray) oldObject.get("translations");
1403  JSONArray newTranslations = (JSONArray) newObject.get("translations");
1404  JSONArray oldBroader = (JSONArray) oldObject.get("broader");
1405  JSONArray newBroader = (JSONArray) newObject.get("broader");
1406  JSONArray oldNarrower = (JSONArray) oldObject.get("narrower");
1407  JSONArray newNarrower = (JSONArray) newObject.get("narrower");
1408  JSONArray oldRelated = (JSONArray) oldObject.get("related");
1409  JSONArray newRelated = (JSONArray) newObject.get("related");
1410  JSONArray oldBroadMatch = (JSONArray) oldObject.get("broadMatch");
1411  JSONArray newBroadMatch = (JSONArray) newObject.get("broadMatch");
1412  JSONArray oldNarrowMatch = (JSONArray) oldObject.get("narrowMatch");
1413  JSONArray newNarrowMatch = (JSONArray) newObject.get("narrowMatch");
1414  JSONArray oldRelatedMatch = (JSONArray) oldObject.get("relatedMatch");
1415  JSONArray newRelatedMatch = (JSONArray) newObject.get("relatedMatch");
1416  JSONArray oldCloseMatch = (JSONArray) oldObject.get("closeMatch");
1417  JSONArray newCloseMatch = (JSONArray) newObject.get("closeMatch");
1418  JSONArray oldExactMatch = (JSONArray) oldObject.get("exactMatch");
1419  JSONArray newExactMatch = (JSONArray) newObject.get("exactMatch");
1420  JSONArray oldSeeAlso = (JSONArray) oldObject.get("seeAlso");
1421  JSONArray newSeeAlso = (JSONArray) newObject.get("seeAlso");
1422  int z = 0;
1423  z = 1;
1424  // description
1425  if (oldDescription == null && newDescription != null) {
1426  hm.put("objectType", "description");
1427  hm.put("action", "add");
1428  hm.put("valueBefore", "");
1429  hm.put("valueAfter", newDescription);
1430  } else if (oldDescription != null && newDescription == null) {
1431  hm.put("objectType", "description");
1432  hm.put("action", "delete");
1433  hm.put("valueBefore", oldDescription);
1434  hm.put("valueAfter", "");
1435  } else if (oldDescription != newDescription) {
1436  hm.put("objectType", "description");
1437  hm.put("action", "modify");
1438  hm.put("valueBefore", oldDescription);
1439  hm.put("valueAfter", newDescription);
1440  }
1441  z = 1;
1442  // translation
1443  if (oldTranslations != null && newTranslations != null) { // not empty
1444  if (!oldTranslations.equals(newTranslations)) {
1445  if (oldTranslations.size() == newTranslations.size()) { // value changed
1446  hm.put("objectType", "translation");
1447  hm.put("action", "modify");
1448  JSONArray oldTranslationsTmp = oldTranslations;
1449  JSONArray newTranslationsTmp = newTranslations;
1450  oldTranslationsTmp.removeAll(newTranslationsTmp);
1451  for (Object item : oldTranslationsTmp) {
1452  JSONObject tmp = (JSONObject) item;
1453  hm.put("valueBefore", tmp.get("value") + " (" + tmp.get("lang") + ")");
1454  }
1455  for (Object item : newTranslationsTmp) {
1456  JSONObject tmp = (JSONObject) item;
1457  hm.put("valueAfter", tmp.get("value") + " (" + tmp.get("lang") + ")");
1458  }
1459  } else if (oldTranslations.size() > newTranslations.size()) { // deleted
1460  hm.put("objectType", "translation");
1461  hm.put("action", "delete");
1462  for (Object item : oldTranslations) {
1463  if (!newTranslations.contains(item)) {
1464  JSONObject tmp = (JSONObject) item;
1465  hm.put("valueBefore", tmp.get("value") + " (" + tmp.get("lang") + ")");
1466  hm.put("valueAfter", "");
1467  break;
1468  }
1469  }
1470  } else { // added
1471  hm.put("objectType", "translation");
1472  hm.put("action", "add");
1473  for (Object item : newTranslations) {
1474  if (!oldTranslations.contains(item)) {
1475  JSONObject tmp = (JSONObject) item;
1476  hm.put("valueBefore", "");
1477  hm.put("valueAfter", tmp.get("value") + " (" + tmp.get("lang") + ")");
1478  break;
1479  }
1480  }
1481  }
1482  }
1483  } else if (oldTranslations == null && newTranslations != null) { // value to empty
1484  for (Object item : newTranslations) {
1485  JSONObject tmp = (JSONObject) item;
1486  hm.put("objectType", "translation");
1487  hm.put("action", "add");
1488  hm.put("valueBefore", "");
1489  hm.put("valueAfter", tmp.get("value") + " (" + tmp.get("lang") + ")");
1490  }
1491  } else if (oldTranslations != null && newTranslations == null) { // empty to value
1492  for (Object item : oldTranslations) {
1493  JSONObject tmp = (JSONObject) item;
1494  hm.put("objectType", "translation");
1495  hm.put("action", "delete");
1496  hm.put("valueBefore", tmp.get("value") + " (" + tmp.get("lang") + ")");
1497  hm.put("valueAfter", "");
1498  }
1499  }
1500  z = 1;
1501  // broader
1502  if (oldBroader != null && newBroader != null) { // not empty
1503  if (!oldBroader.equals(newBroader)) {
1504  if (oldBroader.size() == newBroader.size()) { // value changed
1505  hm.put("objectType", "broader");
1506  hm.put("action", "modify");
1507  JSONArray oldBroaderTmp = oldBroader;
1508  JSONArray newBroaderTmp = newBroader;
1509  oldBroaderTmp.removeAll(newBroaderTmp);
1510  for (Object item : oldBroader) {
1511  String tmp = (String) item;
1512  hm.put("valueBefore", tmp);
1513  hm.put("bidirectional", tmp);
1514  hm.put("bidirectional-del", tmp);
1515  }
1516  for (Object item : newBroader) {
1517  String tmp = (String) item;
1518  hm.put("valueAfter", tmp);
1519  hm.put("bidirectional-add", tmp);
1520  }
1521  } else if (oldBroader.size() > newBroader.size()) { // deleted
1522  hm.put("objectType", "broader");
1523  hm.put("action", "delete");
1524  for (Object item : oldBroader) {
1525  if (!newBroader.contains(item)) {
1526  String tmp = (String) item;
1527  hm.put("valueBefore", tmp);
1528  hm.put("valueAfter", "");
1529  hm.put("bidirectional", tmp);
1530  break;
1531  }
1532  }
1533  } else { // added
1534  hm.put("objectType", "broader");
1535  hm.put("action", "add");
1536  for (Object item : newBroader) {
1537  if (!oldBroader.contains(item)) {
1538  String tmp = (String) item;
1539  hm.put("valueBefore", "");
1540  hm.put("valueAfter", tmp);
1541  hm.put("bidirectional", tmp);
1542  break;
1543  }
1544  }
1545  }
1546  }
1547  } else if (oldBroader == null && newBroader != null) { // value to empty
1548  for (Object item : newBroader) {
1549  String tmp = (String) item;
1550  hm.put("objectType", "broader");
1551  hm.put("action", "add");
1552  hm.put("valueBefore", "");
1553  hm.put("valueAfter", tmp);
1554  hm.put("bidirectional", tmp);
1555  }
1556  } else if (oldBroader != null && newBroader == null) { // empty to value
1557  for (Object item : oldBroader) {
1558  String tmp = (String) item;
1559  hm.put("objectType", "broader");
1560  hm.put("action", "delete");
1561  hm.put("valueBefore", tmp);
1562  hm.put("valueAfter", "");
1563  hm.put("bidirectional", tmp);
1564  }
1565  }
1566  z = 1;
1567  // narrower
1568  if (oldNarrower != null && newNarrower != null) { // not empty
1569  if (!oldNarrower.equals(newNarrower)) {
1570  if (oldNarrower.size() == newNarrower.size()) { // value changed
1571  hm.put("objectType", "narrower");
1572  hm.put("action", "modify");
1573  JSONArray oldNarrowerTmp = oldNarrower;
1574  JSONArray newNarrowerTmp = newNarrower;
1575  oldNarrowerTmp.removeAll(newNarrowerTmp);
1576  for (Object item : oldNarrower) {
1577  String tmp = (String) item;
1578  hm.put("valueBefore", tmp);
1579  hm.put("bidirectional", tmp);
1580  hm.put("bidirectional-del", tmp);
1581  }
1582  for (Object item : newNarrower) {
1583  String tmp = (String) item;
1584  hm.put("valueAfter", tmp);
1585  hm.put("bidirectional-add", tmp);
1586  }
1587  } else if (oldNarrower.size() > newNarrower.size()) { // deleted
1588  hm.put("objectType", "narrower");
1589  hm.put("action", "delete");
1590  for (Object item : oldNarrower) {
1591  if (!newNarrower.contains(item)) {
1592  String tmp = (String) item;
1593  hm.put("valueBefore", tmp);
1594  hm.put("valueAfter", "");
1595  hm.put("bidirectional", tmp);
1596  break;
1597  }
1598  }
1599  } else { // added
1600  hm.put("objectType", "narrower");
1601  hm.put("action", "add");
1602  for (Object item : newNarrower) {
1603  if (!oldNarrower.contains(item)) {
1604  String tmp = (String) item;
1605  hm.put("valueBefore", "");
1606  hm.put("valueAfter", tmp);
1607  hm.put("bidirectional", tmp);
1608  break;
1609  }
1610  }
1611  }
1612  }
1613  } else if (oldNarrower == null && newNarrower != null) { // value to empty
1614  for (Object item : newNarrower) {
1615  String tmp = (String) item;
1616  hm.put("objectType", "narrower");
1617  hm.put("action", "add");
1618  hm.put("valueBefore", "");
1619  hm.put("valueAfter", tmp);
1620  hm.put("bidirectional", tmp);
1621  }
1622  } else if (oldNarrower != null && newNarrower == null) { // empty to value
1623  for (Object item : oldNarrower) {
1624  String tmp = (String) item;
1625  hm.put("objectType", "narrower");
1626  hm.put("action", "delete");
1627  hm.put("valueBefore", tmp);
1628  hm.put("valueAfter", "");
1629  hm.put("bidirectional", tmp);
1630  }
1631  }
1632  z = 1;
1633  // related
1634  if (oldRelated != null && newRelated != null) { // not empty
1635  if (!oldRelated.equals(newRelated)) {
1636  if (oldRelated.size() == newRelated.size()) { // value changed
1637  hm.put("objectType", "related");
1638  hm.put("action", "modify");
1639  JSONArray oldRelatedTmp = oldRelated;
1640  JSONArray newRelatedTmp = newRelated;
1641  oldRelatedTmp.removeAll(newRelatedTmp);
1642  for (Object item : oldRelated) {
1643  String tmp = (String) item;
1644  hm.put("valueBefore", tmp);
1645  hm.put("bidirectional", tmp);
1646  hm.put("bidirectional-del", tmp);
1647  }
1648  for (Object item : newRelated) {
1649  String tmp = (String) item;
1650  hm.put("valueAfter", tmp);
1651  hm.put("bidirectional-add", tmp);
1652  }
1653  } else if (oldRelated.size() > newRelated.size()) { // deleted
1654  hm.put("objectType", "related");
1655  hm.put("action", "delete");
1656  for (Object item : oldRelated) {
1657  if (!newRelated.contains(item)) {
1658  String tmp = (String) item;
1659  hm.put("valueBefore", tmp);
1660  hm.put("valueAfter", "");
1661  hm.put("bidirectional", tmp);
1662  break;
1663  }
1664  }
1665  } else { // added
1666  hm.put("objectType", "related");
1667  hm.put("action", "add");
1668  for (Object item : newRelated) {
1669  if (!oldRelated.contains(item)) {
1670  String tmp = (String) item;
1671  hm.put("valueBefore", "");
1672  hm.put("valueAfter", tmp);
1673  hm.put("bidirectional", tmp);
1674  break;
1675  }
1676  }
1677  }
1678  }
1679  } else if (oldRelated == null && newRelated != null) { // value to empty
1680  for (Object item : newRelated) {
1681  String tmp = (String) item;
1682  hm.put("objectType", "related");
1683  hm.put("action", "add");
1684  hm.put("valueBefore", "");
1685  hm.put("valueAfter", tmp);
1686  hm.put("bidirectional", tmp);
1687  }
1688  } else if (oldRelated != null && newRelated == null) { // empty to value
1689  for (Object item : oldRelated) {
1690  String tmp = (String) item;
1691  hm.put("objectType", "related");
1692  hm.put("action", "delete");
1693  hm.put("valueBefore", tmp);
1694  hm.put("valueAfter", "");
1695  hm.put("bidirectional", tmp);
1696  }
1697  }
1698  z = 1;
1699  // broadMatch
1700  if (oldBroadMatch != null && newBroadMatch != null) { // not empty
1701  if (!oldBroadMatch.equals(newBroadMatch)) {
1702  if (oldBroadMatch.size() == newBroadMatch.size()) { // value changed
1703  hm.put("objectType", "broadMatch");
1704  hm.put("action", "modify");
1705  JSONArray oldBroadMatchTmp = oldBroadMatch;
1706  JSONArray newBroadMatchTmp = newBroadMatch;
1707  oldBroadMatchTmp.removeAll(newBroadMatchTmp);
1708  for (Object item : oldBroadMatchTmp) {
1709  JSONObject tmp = (JSONObject) item;
1710  hm.put("valueBefore", tmp.get("uri") + " (" + tmp.get("type") + ")");
1711  }
1712  for (Object item : newBroadMatchTmp) {
1713  JSONObject tmp = (JSONObject) item;
1714  hm.put("valueAfter", tmp.get("uri") + " (" + tmp.get("type") + ")");
1715  }
1716  } else if (oldBroadMatch.size() > newBroadMatch.size()) { // deleted
1717  hm.put("objectType", "broadMatch");
1718  hm.put("action", "delete");
1719  for (Object item : oldBroadMatch) {
1720  if (!newBroadMatch.contains(item)) {
1721  JSONObject tmp = (JSONObject) item;
1722  hm.put("valueBefore", tmp.get("uri") + " (" + tmp.get("type") + ")");
1723  hm.put("valueAfter", "");
1724  break;
1725  }
1726  }
1727  } else { // added
1728  hm.put("objectType", "broadMatch");
1729  hm.put("action", "add");
1730  for (Object item : newBroadMatch) {
1731  if (!oldBroadMatch.contains(item)) {
1732  JSONObject tmp = (JSONObject) item;
1733  hm.put("valueBefore", "");
1734  hm.put("valueAfter", tmp.get("uri") + " (" + tmp.get("type") + ")");
1735  break;
1736  }
1737  }
1738  }
1739  }
1740  } else if (oldBroadMatch == null && newBroadMatch != null) { // value to empty
1741  for (Object item : newBroadMatch) {
1742  JSONObject tmp = (JSONObject) item;
1743  hm.put("objectType", "broadMatch");
1744  hm.put("action", "add");
1745  hm.put("valueBefore", "");
1746  hm.put("valueAfter", tmp.get("uri") + " (" + tmp.get("type") + ")");
1747  }
1748  } else if (oldBroadMatch != null && newBroadMatch == null) { // empty to value
1749  for (Object item : oldBroadMatch) {
1750  JSONObject tmp = (JSONObject) item;
1751  hm.put("objectType", "broadMatch");
1752  hm.put("action", "delete");
1753  hm.put("valueBefore", tmp.get("uri") + " (" + tmp.get("type") + ")");
1754  hm.put("valueAfter", "");
1755  }
1756  }
1757  z = 1;
1758  // narrowMatch
1759  if (oldNarrowMatch != null && newNarrowMatch != null) { // not empty
1760  if (!oldNarrowMatch.equals(newNarrowMatch)) {
1761  if (oldNarrowMatch.size() == newNarrowMatch.size()) { // value changed
1762  hm.put("objectType", "narrowMatch");
1763  hm.put("action", "modify");
1764  JSONArray oldNarrowMatchTmp = oldNarrowMatch;
1765  JSONArray newNarrowMatchTmp = newNarrowMatch;
1766  oldNarrowMatchTmp.removeAll(newNarrowMatchTmp);
1767  for (Object item : oldNarrowMatchTmp) {
1768  JSONObject tmp = (JSONObject) item;
1769  hm.put("valueBefore", tmp.get("uri") + " (" + tmp.get("type") + ")");
1770  }
1771  for (Object item : newNarrowMatchTmp) {
1772  JSONObject tmp = (JSONObject) item;
1773  hm.put("valueAfter", tmp.get("uri") + " (" + tmp.get("type") + ")");
1774  }
1775  } else if (oldNarrowMatch.size() > newNarrowMatch.size()) { // deleted
1776  hm.put("objectType", "narrowMatch");
1777  hm.put("action", "delete");
1778  for (Object item : oldNarrowMatch) {
1779  if (!newNarrowMatch.contains(item)) {
1780  JSONObject tmp = (JSONObject) item;
1781  hm.put("valueBefore", tmp.get("uri") + " (" + tmp.get("type") + ")");
1782  hm.put("valueAfter", "");
1783  break;
1784  }
1785  }
1786  } else { // added
1787  hm.put("objectType", "narrowMatch");
1788  hm.put("action", "add");
1789  for (Object item : newNarrowMatch) {
1790  if (!oldNarrowMatch.contains(item)) {
1791  JSONObject tmp = (JSONObject) item;
1792  hm.put("valueBefore", "");
1793  hm.put("valueAfter", tmp.get("uri") + " (" + tmp.get("type") + ")");
1794  break;
1795  }
1796  }
1797  }
1798  }
1799  } else if (oldNarrowMatch == null && newNarrowMatch != null) { // value to empty
1800  for (Object item : newNarrowMatch) {
1801  JSONObject tmp = (JSONObject) item;
1802  hm.put("objectType", "narrowMatch");
1803  hm.put("action", "add");
1804  hm.put("valueBefore", "");
1805  hm.put("valueAfter", tmp.get("uri") + " (" + tmp.get("type") + ")");
1806  }
1807  } else if (oldNarrowMatch != null && newNarrowMatch == null) { // empty to value
1808  for (Object item : oldNarrowMatch) {
1809  JSONObject tmp = (JSONObject) item;
1810  hm.put("objectType", "narrowMatch");
1811  hm.put("action", "delete");
1812  hm.put("valueBefore", tmp.get("uri") + " (" + tmp.get("type") + ")");
1813  hm.put("valueAfter", "");
1814  }
1815  }
1816  z = 1;
1817  // relatedMatch
1818  if (oldRelatedMatch != null && newRelatedMatch != null) { // not empty
1819  if (!oldRelatedMatch.equals(newRelatedMatch)) {
1820  if (oldRelatedMatch.size() == newRelatedMatch.size()) { // value changed
1821  hm.put("objectType", "relatedMatch");
1822  hm.put("action", "modify");
1823  JSONArray oldRelatedMatchTmp = oldRelatedMatch;
1824  JSONArray newRelatedMatchTmp = newRelatedMatch;
1825  oldRelatedMatchTmp.removeAll(newRelatedMatchTmp);
1826  for (Object item : oldRelatedMatchTmp) {
1827  JSONObject tmp = (JSONObject) item;
1828  hm.put("valueBefore", tmp.get("uri") + " (" + tmp.get("type") + ")");
1829  }
1830  for (Object item : newRelatedMatchTmp) {
1831  JSONObject tmp = (JSONObject) item;
1832  hm.put("valueAfter", tmp.get("uri") + " (" + tmp.get("type") + ")");
1833  }
1834  } else if (oldRelatedMatch.size() > newRelatedMatch.size()) { // deleted
1835  hm.put("objectType", "relatedMatch");
1836  hm.put("action", "delete");
1837  for (Object item : oldRelatedMatch) {
1838  if (!newRelatedMatch.contains(item)) {
1839  JSONObject tmp = (JSONObject) item;
1840  hm.put("valueBefore", tmp.get("uri") + " (" + tmp.get("type") + ")");
1841  hm.put("valueAfter", "");
1842  break;
1843  }
1844  }
1845  } else { // added
1846  hm.put("objectType", "relatedMatch");
1847  hm.put("action", "add");
1848  for (Object item : newRelatedMatch) {
1849  if (!oldRelatedMatch.contains(item)) {
1850  JSONObject tmp = (JSONObject) item;
1851  hm.put("valueBefore", "");
1852  hm.put("valueAfter", tmp.get("uri") + " (" + tmp.get("type") + ")");
1853  break;
1854  }
1855  }
1856  }
1857  }
1858  } else if (oldRelatedMatch == null && newRelatedMatch != null) { // value to empty
1859  for (Object item : newRelatedMatch) {
1860  JSONObject tmp = (JSONObject) item;
1861  hm.put("objectType", "relatedMatch");
1862  hm.put("action", "add");
1863  hm.put("valueBefore", "");
1864  hm.put("valueAfter", tmp.get("uri") + " (" + tmp.get("type") + ")");
1865  }
1866  } else if (oldRelatedMatch != null && newRelatedMatch == null) { // empty to value
1867  for (Object item : oldRelatedMatch) {
1868  JSONObject tmp = (JSONObject) item;
1869  hm.put("objectType", "relatedMatch");
1870  hm.put("action", "delete");
1871  hm.put("valueBefore", tmp.get("uri") + " (" + tmp.get("type") + ")");
1872  hm.put("valueAfter", "");
1873  }
1874  }
1875  z = 1;
1876  // closeMatch
1877  if (oldCloseMatch != null && newCloseMatch != null) { // not empty
1878  if (!oldCloseMatch.equals(newCloseMatch)) {
1879  if (oldCloseMatch.size() == newCloseMatch.size()) { // value changed
1880  hm.put("objectType", "closeMatch");
1881  hm.put("action", "modify");
1882  JSONArray oldCloseMatchTmp = oldCloseMatch;
1883  JSONArray newCloseMatchTmp = newCloseMatch;
1884  oldCloseMatchTmp.removeAll(newCloseMatchTmp);
1885  for (Object item : oldCloseMatchTmp) {
1886  JSONObject tmp = (JSONObject) item;
1887  hm.put("valueBefore", tmp.get("uri") + " (" + tmp.get("type") + ")");
1888  }
1889  for (Object item : newCloseMatchTmp) {
1890  JSONObject tmp = (JSONObject) item;
1891  hm.put("valueAfter", tmp.get("uri") + " (" + tmp.get("type") + ")");
1892  }
1893  } else if (oldCloseMatch.size() > newCloseMatch.size()) { // deleted
1894  hm.put("objectType", "closeMatch");
1895  hm.put("action", "delete");
1896  for (Object item : oldCloseMatch) {
1897  if (!newCloseMatch.contains(item)) {
1898  JSONObject tmp = (JSONObject) item;
1899  hm.put("valueBefore", tmp.get("uri") + " (" + tmp.get("type") + ")");
1900  hm.put("valueAfter", "");
1901  break;
1902  }
1903  }
1904  } else { // added
1905  hm.put("objectType", "closeMatch");
1906  hm.put("action", "add");
1907  for (Object item : newCloseMatch) {
1908  if (!oldCloseMatch.contains(item)) {
1909  JSONObject tmp = (JSONObject) item;
1910  hm.put("valueBefore", "");
1911  hm.put("valueAfter", tmp.get("uri") + " (" + tmp.get("type") + ")");
1912  break;
1913  }
1914  }
1915  }
1916  }
1917  } else if (oldCloseMatch == null && newCloseMatch != null) { // value to empty
1918  for (Object item : newCloseMatch) {
1919  JSONObject tmp = (JSONObject) item;
1920  hm.put("objectType", "closeMatch");
1921  hm.put("action", "add");
1922  hm.put("valueBefore", "");
1923  hm.put("valueAfter", tmp.get("uri") + " (" + tmp.get("type") + ")");
1924  }
1925  } else if (oldCloseMatch != null && newCloseMatch == null) { // empty to value
1926  for (Object item : oldCloseMatch) {
1927  JSONObject tmp = (JSONObject) item;
1928  hm.put("objectType", "closeMatch");
1929  hm.put("action", "delete");
1930  hm.put("valueBefore", tmp.get("uri") + " (" + tmp.get("type") + ")");
1931  hm.put("valueAfter", "");
1932  }
1933  }
1934  z = 1;
1935  // exactMatch
1936  if (oldExactMatch != null && newExactMatch != null) { // not empty
1937  if (!oldExactMatch.equals(newExactMatch)) {
1938  if (oldExactMatch.size() == newExactMatch.size()) { // value changed
1939  hm.put("objectType", "exactMatch");
1940  hm.put("action", "modify");
1941  JSONArray oldExactMatchTmp = oldExactMatch;
1942  JSONArray newExactMatchTmp = newExactMatch;
1943  oldExactMatchTmp.removeAll(newExactMatchTmp);
1944  for (Object item : oldExactMatchTmp) {
1945  JSONObject tmp = (JSONObject) item;
1946  hm.put("valueBefore", tmp.get("uri") + " (" + tmp.get("type") + ")");
1947  }
1948  for (Object item : newExactMatchTmp) {
1949  JSONObject tmp = (JSONObject) item;
1950  hm.put("valueAfter", tmp.get("uri") + " (" + tmp.get("type") + ")");
1951  }
1952  } else if (oldExactMatch.size() > newExactMatch.size()) { // deleted
1953  hm.put("objectType", "exactMatch");
1954  hm.put("action", "delete");
1955  for (Object item : oldExactMatch) {
1956  if (!newExactMatch.contains(item)) {
1957  JSONObject tmp = (JSONObject) item;
1958  hm.put("valueBefore", tmp.get("uri") + " (" + tmp.get("type") + ")");
1959  hm.put("valueAfter", "");
1960  break;
1961  }
1962  }
1963  } else { // added
1964  hm.put("objectType", "exactMatch");
1965  hm.put("action", "add");
1966  for (Object item : newExactMatch) {
1967  if (!oldExactMatch.contains(item)) {
1968  JSONObject tmp = (JSONObject) item;
1969  hm.put("valueBefore", "");
1970  hm.put("valueAfter", tmp.get("uri") + " (" + tmp.get("type") + ")");
1971  break;
1972  }
1973  }
1974  }
1975  }
1976  } else if (oldExactMatch == null && newExactMatch != null) { // value to empty
1977  for (Object item : newExactMatch) {
1978  JSONObject tmp = (JSONObject) item;
1979  hm.put("objectType", "exactMatch");
1980  hm.put("action", "add");
1981  hm.put("valueBefore", "");
1982  hm.put("valueAfter", tmp.get("uri") + " (" + tmp.get("type") + ")");
1983  String tmpUriSplit[] = tmp.get("uri").toString().split("/");
1984  hm.put("bidirectional", tmpUriSplit[tmpUriSplit.length - 1]);
1985  }
1986  } else if (oldExactMatch != null && newExactMatch == null) { // empty to value
1987  for (Object item : oldExactMatch) {
1988  JSONObject tmp = (JSONObject) item;
1989  hm.put("objectType", "exactMatch");
1990  hm.put("action", "delete");
1991  hm.put("valueBefore", tmp.get("uri") + " (" + tmp.get("type") + ")");
1992  hm.put("valueAfter", "");
1993  String tmpUriSplit[] = tmp.get("uri").toString().split("/");
1994  hm.put("bidirectional", tmpUriSplit[tmpUriSplit.length - 1]);
1995  }
1996  }
1997  z = 1;
1998  // seeAlso
1999  if (oldSeeAlso != null && newSeeAlso != null) { // not empty
2000  if (!oldSeeAlso.equals(newSeeAlso)) {
2001  if (oldSeeAlso.size() == newSeeAlso.size()) { // value changed
2002  hm.put("objectType", "seeAlso");
2003  hm.put("action", "modify");
2004  JSONArray oldSeeAlsoTmp = oldSeeAlso;
2005  JSONArray newSeeAlsoTmp = newSeeAlso;
2006  oldSeeAlsoTmp.removeAll(newSeeAlsoTmp);
2007  for (Object item : oldSeeAlsoTmp) {
2008  JSONObject tmp = (JSONObject) item;
2009  hm.put("valueBefore", tmp.get("uri") + " (" + tmp.get("type") + ")");
2010  }
2011  for (Object item : newSeeAlsoTmp) {
2012  JSONObject tmp = (JSONObject) item;
2013  hm.put("valueAfter", tmp.get("uri") + " (" + tmp.get("type") + ")");
2014  }
2015  } else if (oldSeeAlso.size() > newSeeAlso.size()) { // deleted
2016  hm.put("objectType", "seeAlso");
2017  hm.put("action", "delete");
2018  for (Object item : oldSeeAlso) {
2019  if (!newSeeAlso.contains(item)) {
2020  JSONObject tmp = (JSONObject) item;
2021  hm.put("valueBefore", tmp.get("uri") + " (" + tmp.get("type") + ")");
2022  hm.put("valueAfter", "");
2023  break;
2024  }
2025  }
2026  } else { // added
2027  hm.put("objectType", "seeAlso");
2028  hm.put("action", "add");
2029  for (Object item : newSeeAlso) {
2030  if (!oldSeeAlso.contains(item)) {
2031  JSONObject tmp = (JSONObject) item;
2032  hm.put("valueBefore", "");
2033  hm.put("valueAfter", tmp.get("uri") + " (" + tmp.get("type") + ")");
2034  break;
2035  }
2036  }
2037  }
2038  }
2039  } else if (oldSeeAlso == null && newSeeAlso != null) { // value to empty
2040  for (Object item : newSeeAlso) {
2041  JSONObject tmp = (JSONObject) item;
2042  hm.put("objectType", "seeAlso");
2043  hm.put("action", "add");
2044  hm.put("valueBefore", "");
2045  hm.put("valueAfter", tmp.get("uri") + " (" + tmp.get("type") + ")");
2046  }
2047  } else if (oldSeeAlso != null && newSeeAlso == null) { // empty to value
2048  for (Object item : oldSeeAlso) {
2049  JSONObject tmp = (JSONObject) item;
2050  hm.put("objectType", "seeAlso");
2051  hm.put("action", "delete");
2052  hm.put("valueBefore", tmp.get("uri") + " (" + tmp.get("type") + ")");
2053  hm.put("valueAfter", "");
2054  }
2055  }
2056  z = 1;
2057  return hm;
2058  } catch (Exception e) {
2059  int errorLine = -1;
2060  for (StackTraceElement element : e.getStackTrace()) {
2061  errorLine = element.getLineNumber();
2062  if (element.getClassName().equals(Transformer.class.getName())) {
2063  break;
2064  }
2065  }
2066  return hm;
2067  }
2068  }

Referenced by LabelsResource.updateLabel().

◆ label_GET()

static JSONObject label_GET ( String  json,
String  id,
String  fields,
List< RetcatItem >  retcatlist,
String  equalConceptsBool,
String  revisionsBool,
String  creatorInfoBool,
List< InheritFromVocab inheritFromVocab 
) throws IOException, UniqueIdentifierException, ParseException, RepositoryException, MalformedQueryException, QueryEvaluationException, SesameSparqlException, ResourceNotAvailableException, TransformRdfToApiJsonException
static
908  {
909  JSONObject labelObject = null;
910  try {
911  //init
912  RDF rdf = new RDF();
913  // parse json
914  JSONObject jsonObject = (JSONObject) new JSONParser().parse(json);
915  jsonObject.put("label", jsonObject.remove(rdf.getPrefixItem("ls_lab" + ":" + id)));
916  // get items
917  labelObject = (JSONObject) jsonObject.get(rdf.getPrefixItem("label"));
918  // change dc:identifier
919  JSONArray identifierArray = (JSONArray) labelObject.get(rdf.getPrefixItem("dc:identifier"));
920  if (identifierArray != null && !identifierArray.isEmpty()) {
921  for (Object element : identifierArray) {
922  labelObject.remove(rdf.getPrefixItem("dc:identifier"));
923  JSONObject obj = (JSONObject) element;
924  String value = (String) obj.get("value");
925  labelObject.put(rdf.getPrefixItem("id"), value);
926  }
927  }
928  // change dc:creator
929  JSONArray creatorArray = (JSONArray) labelObject.get(rdf.getPrefixItem("dc:creator"));
930  if (creatorArray != null && !creatorArray.isEmpty()) {
931  for (Object element : creatorArray) {
932  labelObject.remove(rdf.getPrefixItem("dc:creator"));
933  JSONObject obj = (JSONObject) element;
934  String value = (String) obj.get("value");
935  labelObject.put(rdf.getPrefixItem("creator"), value);
936  }
937  }
938  // change skos:inScheme
939  JSONArray vocabArray = (JSONArray) labelObject.get(rdf.getPrefixItem("skos:inScheme"));
940  String vocabID = "";
941  if (vocabArray != null && !vocabArray.isEmpty()) {
942  for (Object element : vocabArray) {
943  labelObject.remove(rdf.getPrefixItem("skos:inScheme"));
944  JSONObject obj = (JSONObject) element;
945  String value = (String) obj.get("value");
946  String arrayNew;
947  if (value.contains(ConfigProperties.getPropertyParam("vocabulary")+"/")) {
948  arrayNew = value.split(ConfigProperties.getPropertyParam("vocabulary")+"/")[1];
949  } else {
950  arrayNew = value;
951  }
952  if (fields == null || fields.contains("vocabID")) {
953  labelObject.put(rdf.getPrefixItem("vocabID"), arrayNew);
954  }
955  vocabID = arrayNew;
956  }
957  }
958  // change ls:thumbnail
959  JSONArray thumbnailArray = (JSONArray) labelObject.get(rdf.getPrefixItem("ls:thumbnail"));
960  String thumbnail = "";
961  String language = "";
962  if (thumbnailArray != null && !thumbnailArray.isEmpty()) {
963  labelObject.remove(rdf.getPrefixItem("ls:thumbnail"));
964  for (Object element : thumbnailArray) {
965  JSONObject obj = (JSONObject) element;
966  String value = (String) obj.get("value");
967  String lang = (String) obj.get("lang");
968  thumbnail = value + "@" + lang;
969  language = lang;
970  labelObject.put("thumbnail", value);
971  labelObject.put("language", lang);
972  }
973  }
974  // change skos:scopeNote
975  JSONArray scopeNoteArray = (JSONArray) labelObject.get(rdf.getPrefixItem("skos:scopeNote"));
976  if (scopeNoteArray != null && !scopeNoteArray.isEmpty()) {
977  labelObject.remove(rdf.getPrefixItem("skos:scopeNote"));
978  for (Object element : scopeNoteArray) {
979  JSONObject obj = (JSONObject) element;
980  String value = (String) obj.get("value");
981  labelObject.put("description", value);
982  }
983  }
984  // change skos:prefLabel
985  JSONArray prefLabelArray = (JSONArray) labelObject.get(rdf.getPrefixItem("skos:prefLabel"));
986  if (prefLabelArray != null && !prefLabelArray.isEmpty()) {
987  JSONArray arrayNew = new JSONArray();
988  labelObject.remove(rdf.getPrefixItem("skos:prefLabel"));
989  for (Object element : prefLabelArray) {
990  JSONObject obj = (JSONObject) element;
991  String value = (String) obj.get("value");
992  String lang = (String) obj.get("lang");
993  JSONObject objTmp = new JSONObject();
994  objTmp.put("value", value);
995  objTmp.put("lang", lang);
996  String prefLabel = value + "@" + lang;
997  if (!thumbnail.equals(prefLabel)) {
998  arrayNew.add(objTmp);
999  }
1000  }
1001  if (arrayNew.size() > 0) {
1002  labelObject.put(rdf.getPrefixItem("translations"), arrayNew);
1003  }
1004  }
1005  // change dc:language
1006  JSONArray languageArray = (JSONArray) labelObject.get(rdf.getPrefixItem("dc:language"));
1007  if (languageArray != null && !languageArray.isEmpty()) {
1008  for (Object element : languageArray) {
1009  labelObject.remove(rdf.getPrefixItem("dc:language"));
1010  JSONObject obj = (JSONObject) element;
1011  String value = (String) obj.get("value");
1012  labelObject.put("language", value);
1013  }
1014  } else {
1015  labelObject.put("language", language);
1016  }
1017  // change skos:related
1018  JSONArray relatedArray = (JSONArray) labelObject.get(rdf.getPrefixItem("skos:related"));
1019  if (relatedArray != null && !relatedArray.isEmpty()) {
1020  JSONArray arrayNew = new JSONArray();
1021  labelObject.remove(rdf.getPrefixItem("skos:related"));
1022  for (Object element : relatedArray) {
1023  JSONObject obj = (JSONObject) element;
1024  String value = (String) obj.get("value");
1025  value = value.replace(rdf.getPrefixItem("ls_lab:"), "");
1026  arrayNew.add(value);
1027  }
1028  if (fields == null || fields.contains("related")) {
1029  labelObject.put(rdf.getPrefixItem("related"), arrayNew);
1030  }
1031  }
1032  // change skos:broader
1033  JSONArray broaderArray = (JSONArray) labelObject.get(rdf.getPrefixItem("skos:broader"));
1034  if (broaderArray != null && !broaderArray.isEmpty()) {
1035  JSONArray arrayNew = new JSONArray();
1036  labelObject.remove(rdf.getPrefixItem("skos:broader"));
1037  for (Object element : broaderArray) {
1038  JSONObject obj = (JSONObject) element;
1039  String value = (String) obj.get("value");
1040  value = value.replace(rdf.getPrefixItem("ls_lab:"), "");
1041  arrayNew.add(value);
1042  }
1043  if (fields == null || fields.contains("broader")) {
1044  labelObject.put(rdf.getPrefixItem("broader"), arrayNew);
1045  }
1046  }
1047  // change skos:narrower
1048  JSONArray narrowerArray = (JSONArray) labelObject.get(rdf.getPrefixItem("skos:narrower"));
1049  if (narrowerArray != null && !narrowerArray.isEmpty()) {
1050  JSONArray arrayNew = new JSONArray();
1051  labelObject.remove(rdf.getPrefixItem("skos:narrower"));
1052  for (Object element : narrowerArray) {
1053  JSONObject obj = (JSONObject) element;
1054  String value = (String) obj.get("value");
1055  value = value.replace(rdf.getPrefixItem("ls_lab:"), "");
1056  arrayNew.add(value);
1057  }
1058  if (fields == null || fields.contains("narrower")) {
1059  labelObject.put(rdf.getPrefixItem("narrower"), arrayNew);
1060  }
1061  }
1062  // change skos:closeMatch
1063  JSONArray closeMatchArray = (JSONArray) labelObject.get(rdf.getPrefixItem("skos:closeMatch"));
1064  if (closeMatchArray != null && !closeMatchArray.isEmpty()) {
1065  JSONArray arrayNew = new JSONArray();
1066  labelObject.remove(rdf.getPrefixItem("skos:closeMatch"));
1067  for (Object element : closeMatchArray) {
1068  JSONObject obj = (JSONObject) element;
1069  String value = (String) obj.get("value");
1070  JSONObject tmpObject = new JSONObject();
1071  tmpObject.put("uri", value);
1072  // get retcat info
1073  boolean match = false;
1074  for (RetcatItem item : retcatlist) {
1075  if (value.contains(item.getPrefix())) {
1076  match = true;
1077  tmpObject.put("type", item.getType());
1078  }
1079  }
1080  if (!match) {
1081  tmpObject.put("type", "wayback");
1082  }
1083  arrayNew.add(tmpObject);
1084  }
1085  if (fields == null || fields.contains("closeMatch")) {
1086  labelObject.put(rdf.getPrefixItem("closeMatch"), arrayNew);
1087  }
1088  }
1089  // change skos:exactMatch
1090  JSONArray exactMatchArray = (JSONArray) labelObject.get(rdf.getPrefixItem("skos:exactMatch"));
1091  List<String> equalConcepts = new ArrayList();
1092  if (exactMatchArray != null && !exactMatchArray.isEmpty()) {
1093  JSONArray arrayNew = new JSONArray();
1094  labelObject.remove(rdf.getPrefixItem("skos:exactMatch"));
1095  for (Object element : exactMatchArray) {
1096  JSONObject obj = (JSONObject) element;
1097  String value = (String) obj.get("value");
1098  JSONObject tmpObject = new JSONObject();
1099  tmpObject.put("uri", value);
1100  if (value.contains("//" + ConfigProperties.getPropertyParam("host"))) {
1101  equalConcepts.add(value);
1102  }
1103  // get retcat info
1104  boolean match = false;
1105  for (RetcatItem item : retcatlist) {
1106  if (value.contains(item.getPrefix())) {
1107  match = true;
1108  tmpObject.put("type", item.getType());
1109  }
1110  }
1111  if (!match) {
1112  tmpObject.put("type", "wayback");
1113  }
1114  arrayNew.add(tmpObject);
1115  }
1116  if (fields == null || fields.contains("exactMatch")) {
1117  labelObject.put(rdf.getPrefixItem("exactMatch"), arrayNew);
1118  }
1119  }
1120  // change skos:relatedMatch
1121  JSONArray relatedMatchArray = (JSONArray) labelObject.get(rdf.getPrefixItem("skos:relatedMatch"));
1122  if (relatedMatchArray != null && !relatedMatchArray.isEmpty()) {
1123  JSONArray arrayNew = new JSONArray();
1124  labelObject.remove(rdf.getPrefixItem("skos:relatedMatch"));
1125  for (Object element : relatedMatchArray) {
1126  JSONObject obj = (JSONObject) element;
1127  String value = (String) obj.get("value");
1128  JSONObject tmpObject = new JSONObject();
1129  tmpObject.put("uri", value);
1130  // get retcat info
1131  boolean match = false;
1132  for (RetcatItem item : retcatlist) {
1133  if (value.contains(item.getPrefix())) {
1134  match = true;
1135  tmpObject.put("type", item.getType());
1136  }
1137  }
1138  if (!match) {
1139  tmpObject.put("type", "wayback");
1140  }
1141  arrayNew.add(tmpObject);
1142  }
1143  if (fields == null || fields.contains("relatedMatch")) {
1144  labelObject.put(rdf.getPrefixItem("relatedMatch"), arrayNew);
1145  }
1146  }
1147  // change skos:narrowMatch
1148  JSONArray narrowMatchArray = (JSONArray) labelObject.get(rdf.getPrefixItem("skos:narrowMatch"));
1149  if (narrowMatchArray != null && !narrowMatchArray.isEmpty()) {
1150  JSONArray arrayNew = new JSONArray();
1151  labelObject.remove(rdf.getPrefixItem("skos:narrowMatch"));
1152  for (Object element : narrowMatchArray) {
1153  JSONObject obj = (JSONObject) element;
1154  String value = (String) obj.get("value");
1155  JSONObject tmpObject = new JSONObject();
1156  tmpObject.put("uri", value);
1157  // get retcat info
1158  boolean match = false;
1159  for (RetcatItem item : retcatlist) {
1160  if (value.contains(item.getPrefix())) {
1161  match = true;
1162  tmpObject.put("type", item.getType());
1163  }
1164  }
1165  if (!match) {
1166  tmpObject.put("type", "wayback");
1167  }
1168  arrayNew.add(tmpObject);
1169  }
1170  if (fields == null || fields.contains("altLabel")) {
1171  labelObject.put(rdf.getPrefixItem("narrowMatch"), arrayNew);
1172  }
1173  }
1174  // change skos:broadMatch
1175  JSONArray broadMatchArray = (JSONArray) labelObject.get(rdf.getPrefixItem("skos:broadMatch"));
1176  if (broadMatchArray != null && !broadMatchArray.isEmpty()) {
1177  JSONArray arrayNew = new JSONArray();
1178  labelObject.remove(rdf.getPrefixItem("skos:broadMatch"));
1179  for (Object element : broadMatchArray) {
1180  JSONObject obj = (JSONObject) element;
1181  String value = (String) obj.get("value");
1182  JSONObject tmpObject = new JSONObject();
1183  tmpObject.put("uri", value);
1184  // get retcat info
1185  boolean match = false;
1186  for (RetcatItem item : retcatlist) {
1187  if (value.contains(item.getPrefix())) {
1188  match = true;
1189  tmpObject.put("type", item.getType());
1190  }
1191  }
1192  if (!match) {
1193  tmpObject.put("type", "wayback");
1194  }
1195  arrayNew.add(tmpObject);
1196  }
1197  if (fields == null || fields.contains("broadMatch")) {
1198  labelObject.put(rdf.getPrefixItem("broadMatch"), arrayNew);
1199  }
1200  }
1201  // change rdfs:seeAlso
1202  JSONArray seeAlsoArray = (JSONArray) labelObject.get(rdf.getPrefixItem("rdfs:seeAlso"));
1203  if (seeAlsoArray != null && !seeAlsoArray.isEmpty()) {
1204  JSONArray arrayNew = new JSONArray();
1205  labelObject.remove(rdf.getPrefixItem("rdfs:seeAlso"));
1206  for (Object element : seeAlsoArray) {
1207  JSONObject obj = (JSONObject) element;
1208  String value = (String) obj.get("value");
1209  JSONObject tmpObject = new JSONObject();
1210  tmpObject.put("uri", value);
1211  tmpObject.put("type", "wayback");
1212  arrayNew.add(tmpObject);
1213  }
1214  if (fields == null || fields.contains("seeAlso")) {
1215  labelObject.put(rdf.getPrefixItem("seeAlso"), arrayNew);
1216  }
1217  }
1218  // change dc:created
1219  JSONArray createdArray = (JSONArray) labelObject.get(rdf.getPrefixItem("dc:created"));
1220  if (createdArray != null && !createdArray.isEmpty()) {
1221  for (Object element : createdArray) {
1222  labelObject.remove(rdf.getPrefixItem("dc:created"));
1223  JSONObject obj = (JSONObject) element;
1224  String value = (String) obj.get("value");
1225  if (fields == null || fields.contains("created")) {
1226  labelObject.put(rdf.getPrefixItem("created"), value);
1227  labelObject.put("lastModified", value);
1228  }
1229  }
1230  }
1231  // change dc:modified
1232  JSONArray modifiedArray = (JSONArray) labelObject.get(rdf.getPrefixItem("dc:modified"));
1233  if (modifiedArray != null && !modifiedArray.isEmpty()) {
1234  labelObject.remove(rdf.getPrefixItem("dc:modified"));
1235  List<String> listModify = new ArrayList();
1236  for (Object element : modifiedArray) {
1237  JSONObject obj = (JSONObject) element;
1238  String value = (String) obj.get("value");
1239  listModify.add(value);
1240  }
1241  // set last modified
1242  Collections.sort(listModify);
1243  labelObject.remove("lastModified");
1244  labelObject.put("lastModified", listModify.get(listModify.size() - 1));
1245  }
1246  // set released, license and origin
1247  for (InheritFromVocab item : inheritFromVocab) {
1248  if (vocabID.equals(item.getId())) {
1249  if (item.getLicense() != null) {
1250  labelObject.put(rdf.getPrefixItem("license"), item.getLicense());
1251  }
1252  if (item.getReleased() != null) {
1253  labelObject.put(rdf.getPrefixItem("released"), item.getReleased());
1254  }
1255  }
1256  }
1257  // set revisions
1258  labelObject.remove(rdf.getPrefixItem("skos:changeNote"));
1259  if (revisionsBool != null) {
1260  if (revisionsBool.equals("true")) {
1261  RDF rdf2 = new RDF();
1262  String query = rdf2.getPREFIXSPARQL();
1263  query += "SELECT * WHERE { "
1264  + "ls_lab:" + id + " skos:changeNote ?rev. "
1265  + "?rev ls:action ?action. "
1266  + "?rev ls:objectType ?objectType. "
1267  + "?rev ls:valueBefore ?valueBefore. "
1268  + "?rev ls:valueAfter ?valueAfter. "
1269  + "?rev prov:startedAtTime ?date. "
1270  + "} ORDER BY DESC(?date)";
1271  List<BindingSet> result = RDF4J_20.SPARQLquery(ConfigProperties.getPropertyParam("repository"), ConfigProperties.getPropertyParam("ts_server"), query);
1272  List<String> rev = RDF4J_20.getValuesFromBindingSet_ORDEREDLIST(result, "rev");
1273  List<String> action = RDF4J_20.getValuesFromBindingSet_ORDEREDLIST(result, "action");
1274  List<String> objectType = RDF4J_20.getValuesFromBindingSet_ORDEREDLIST(result, "objectType");
1275  List<String> valueBefore = RDF4J_20.getValuesFromBindingSet_ORDEREDLIST(result, "valueBefore");
1276  List<String> valueAfter = RDF4J_20.getValuesFromBindingSet_ORDEREDLIST(result, "valueAfter");
1277  List<String> date = RDF4J_20.getValuesFromBindingSet_ORDEREDLIST(result, "date");
1278  JSONArray revisionsArray = new JSONArray();
1279  for (int i = 0; i < rev.size(); i++) {
1280  JSONObject tmpObject = new JSONObject();
1281  tmpObject.put("action", action.get(i));
1282  tmpObject.put("objectType", objectType.get(i));
1283  tmpObject.put("valueBefore", valueBefore.get(i).replace("^^<http://www.w3.org/2001/XMLSchema#string>", ""));
1284  tmpObject.put("valueAfter", valueAfter.get(i).replace("^^<http://www.w3.org/2001/XMLSchema#string>", ""));
1285  tmpObject.put("date", date.get(i));
1286  revisionsArray.add(tmpObject);
1287  }
1288  if (revisionsArray != null && !revisionsArray.isEmpty()) {
1289  labelObject.put("revisions", revisionsArray);
1290  }
1291  }
1292  }
1293  // set equal concepts
1294  if (equalConceptsBool != null) {
1295  // get bidirectional concepts
1296  RDF rdf2 = new RDF();
1297  String query = rdf2.getPREFIXSPARQL();
1298  query += "SELECT * WHERE { ?em skos:exactMatch ls_lab:" + id + ". } ";
1299  List<BindingSet> result = RDF4J_20.SPARQLquery(ConfigProperties.getPropertyParam("repository"), ConfigProperties.getPropertyParam("ts_server"), query);
1300  List<String> em = RDF4J_20.getValuesFromBindingSet_ORDEREDLIST(result, "em");
1301  for (String value : em) {
1302  equalConcepts.add(value);
1303  }
1304  // get concept json objects
1305  if (equalConcepts.size() > 0 && equalConceptsBool.equals("true")) {
1306  JSONArray equalArray = new JSONArray();
1307  for (String concept : equalConcepts) {
1308  String[] conceptSplit = concept.split("/");
1309  String url = ConfigProperties.getPropertyParam("api") + "/v1/labels/" + conceptSplit[conceptSplit.length - 1] + ".json?equalConcepts=false";
1310  URL obj = new URL(url);
1311  HttpURLConnection con = (HttpURLConnection) obj.openConnection();
1312  con.setRequestMethod("GET");
1313  con.setRequestProperty("Accept-Encoding", "json");
1314  BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream(), "UTF8"));
1315  String inputLine;
1316  StringBuilder response = new StringBuilder();
1317  while ((inputLine = in.readLine()) != null) {
1318  response.append(inputLine);
1319  }
1320  in.close();
1321  JSONObject simillarConcept = (JSONObject) new JSONParser().parse(response.toString());
1322  equalArray.add(simillarConcept);
1323  }
1324  labelObject.put("equalConcepts", equalArray);
1325  }
1326  }
1327  // set creator info
1328  if (creatorInfoBool != null) {
1329  if (creatorInfoBool.equals("true")) {
1330  String url = ConfigProperties.getPropertyParam("api") + "/v1/agents/" + labelObject.get("creator") + ".json";
1331  URL obj = new URL(url);
1332  HttpURLConnection con = (HttpURLConnection) obj.openConnection();
1333  con.setRequestMethod("GET");
1334  con.setRequestProperty("Accept-Encoding", "json");
1335  if (con.getResponseCode() == 200) {
1336  BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream(), "UTF8"));
1337  String inputLine;
1338  StringBuilder response = new StringBuilder();
1339  while ((inputLine = in.readLine()) != null) {
1340  response.append(inputLine);
1341  }
1342  in.close();
1343  JSONObject simillarConcept = (JSONObject) new JSONParser().parse(response.toString());
1344  labelObject.put("creatorInfo", simillarConcept);
1345  }
1346  }
1347  }
1348  // delete items
1349  labelObject.remove(rdf.getPrefixItem("rdf:type"));
1350  labelObject.remove(rdf.getPrefixItem("dc:identifier"));
1351  labelObject.remove(rdf.getPrefixItem("dct:creator"));
1352  labelObject.remove(rdf.getPrefixItem("dc:creator"));
1353  labelObject.remove(rdf.getPrefixItem("dct:contributor"));
1354  labelObject.remove(rdf.getPrefixItem("dc:contributor"));
1355  labelObject.remove(rdf.getPrefixItem("skos:inScheme"));
1356  labelObject.remove(rdf.getPrefixItem("ls:thumbnail"));
1357  labelObject.remove(rdf.getPrefixItem("skos:prefLabel"));
1358  labelObject.remove(rdf.getPrefixItem("skos:scopeNote"));
1359  labelObject.remove(rdf.getPrefixItem("skos:broader"));
1360  labelObject.remove(rdf.getPrefixItem("skos:narrower"));
1361  labelObject.remove(rdf.getPrefixItem("skos:related"));
1362  labelObject.remove(rdf.getPrefixItem("skos:broadMatch"));
1363  labelObject.remove(rdf.getPrefixItem("skos:narrowMatch"));
1364  labelObject.remove(rdf.getPrefixItem("skos:relatedMatch"));
1365  labelObject.remove(rdf.getPrefixItem("skos:closeMatch"));
1366  labelObject.remove(rdf.getPrefixItem("skos:exactMatch"));
1367  labelObject.remove(rdf.getPrefixItem("rdfs:seeAlso"));
1368  labelObject.remove(rdf.getPrefixItem("dc:created"));
1369  labelObject.remove(rdf.getPrefixItem("dct:license"));
1370  labelObject.remove(rdf.getPrefixItem("dc:modified"));
1371  labelObject.remove(rdf.getPrefixItem("ls:releasedAt"));
1372  // deposits
1373  labelObject.remove(rdf.getPrefixItem("ls:sameAs"));
1374  labelObject.remove(rdf.getPrefixItem("ls:hasStatusType"));
1375  labelObject.remove(rdf.getPrefixItem("ls:hasContext"));
1376  labelObject.remove(rdf.getPrefixItem("skos:altLabel"));
1377  labelObject.remove(rdf.getPrefixItem("skos:changeNote"));
1378  labelObject.remove(rdf.getPrefixItem("ls:hasReleaseType"));
1379  } catch (Exception e) {
1380  int errorLine = -1;
1381  for (StackTraceElement element : e.getStackTrace()) {
1382  errorLine = element.getLineNumber();
1383  if (element.getClassName().equals(Transformer.class.getName())) {
1384  break;
1385  }
1386  }
1387  throw new TransformRdfToApiJsonException(e.toString() + " in line " + String.valueOf(errorLine));
1388  }
1389  // return
1390  return labelObject;
1391  }

References RDF.getPREFIXSPARQL(), and ConfigProperties.getPropertyParam().

Referenced by LabelsResource.getLabel(), LabelsResource.getLabel_JSON(), LabelsResource.getLabels(), LabelsResource.postLabel(), and LabelsResource.updateLabel().

◆ label_POST()

static String label_POST ( String  json,
String  id,
String  creator 
) throws IOException, UniqueIdentifierException, ParseException
static
619  {
620  //init
621  RDF rdf = new RDF();
622  // parse json
623  JSONObject rdfObject = new JSONObject();
624  JSONObject labelObject = (JSONObject) new JSONParser().parse(json);
625  // change language
626  String language = (String) labelObject.get("language");
627  if (language != null) {
628  labelObject.remove("language");
629  JSONArray languageArrayNew = new JSONArray();
630  JSONObject languageObject = new JSONObject();
631  languageObject.put("type", "literal");
632  languageObject.put("value", language);
633  languageArrayNew.add(languageObject);
634  labelObject.put(rdf.getPrefixItem("dc:language"), languageArrayNew);
635  }
636  // change thumbnail
637  String thumbnail = (String) labelObject.get("thumbnail");
638  JSONArray prefLabelArray = new JSONArray();
639  if (thumbnail != null) {
640  labelObject.remove("thumbnail");
641  JSONObject tmpObject = new JSONObject();
642  tmpObject.put("type", "literal");
643  tmpObject.put("value", thumbnail);
644  tmpObject.put("lang", language);
645  JSONArray arrayNew = new JSONArray();
646  arrayNew.add(tmpObject);
647  labelObject.put(rdf.getPrefixItem("ls:thumbnail"), arrayNew);
648  // add thumbnail to preflabels
649  prefLabelArray.add(tmpObject);
650  }
651  // change prefLabel
652  JSONArray translationsArray = (JSONArray) labelObject.get("translations");
653  if (translationsArray != null && !translationsArray.isEmpty()) {
654  labelObject.remove("translations");
655  for (Object element : translationsArray) {
656  JSONObject thisObject = (JSONObject) element;
657  JSONObject tmpObject = new JSONObject();
658  tmpObject.put("type", "literal");
659  tmpObject.put("value", thisObject.get("value"));
660  tmpObject.put("lang", thisObject.get("lang"));
661  prefLabelArray.add(tmpObject);
662  }
663  labelObject.put(rdf.getPrefixItem("skos:prefLabel"), prefLabelArray);
664  }
665  // change description
666  String description = (String) labelObject.get("description");
667  if (description != null) {
668  labelObject.remove("description");
669  JSONObject tmpObject = new JSONObject();
670  tmpObject.put("type", "literal");
671  tmpObject.put("value", description);
672  tmpObject.put("lang", language);
673  JSONArray arrayNew = new JSONArray();
674  arrayNew.add(tmpObject);
675  labelObject.put(rdf.getPrefixItem("skos:scopeNote"), arrayNew);
676  }
677  // change related
678  JSONArray relatedArray = (JSONArray) labelObject.get("related");
679  List<String> relatedStringList = new ArrayList<String>();
680  if (relatedArray != null && !relatedArray.isEmpty()) {
681  for (Object element : relatedArray) {
682  if (element.equals("null")) {
683  relatedStringList.add("http://dummy.net");
684  } else {
685  relatedStringList.add((String) element);
686  }
687  }
688  labelObject.remove("related");
689  JSONArray arrayNew = new JSONArray();
690  for (String element : relatedStringList) {
691  JSONObject tmpObject = new JSONObject();
692  tmpObject.put("type", "uri");
693  tmpObject.put("value", rdf.getPrefixItem("ls_lab:" + element));
694  arrayNew.add(tmpObject);
695  // related symmetric
696  JSONObject tmpLabelObject = new JSONObject();
697  JSONArray arrayNew2 = new JSONArray();
698  JSONObject tmpObject2 = new JSONObject();
699  tmpObject2.put("type", "uri");
700  tmpObject2.put("value", rdf.getPrefixItem("ls_lab" + ":" + id));
701  arrayNew2.add(tmpObject2);
702  tmpLabelObject.put(rdf.getPrefixItem("skos:related"), arrayNew2);
703  rdfObject.put(rdf.getPrefixItem("ls_lab:" + element), tmpLabelObject);
704  }
705  labelObject.put(rdf.getPrefixItem("skos:related"), arrayNew);
706  }
707  // change broader
708  JSONArray broaderArray = (JSONArray) labelObject.get("broader");
709  List<String> broaderStringList = new ArrayList<String>();
710  if (broaderArray != null && !broaderArray.isEmpty()) {
711  for (Object element : broaderArray) {
712  if (element.equals("null")) {
713  broaderStringList.add("http://dummy.net");
714  } else {
715  broaderStringList.add((String) element);
716  }
717  }
718  labelObject.remove("broader");
719  JSONArray arrayNew = new JSONArray();
720  for (String element : broaderStringList) {
721  JSONObject tmpObject = new JSONObject();
722  tmpObject.put("type", "uri");
723  tmpObject.put("value", rdf.getPrefixItem("ls_lab:" + element));
724  arrayNew.add(tmpObject);
725  // narrower
726  JSONObject tmpLabelObject = new JSONObject();
727  JSONArray arrayNew2 = new JSONArray();
728  JSONObject tmpObject2 = new JSONObject();
729  tmpObject2.put("type", "uri");
730  tmpObject2.put("value", rdf.getPrefixItem("ls_lab" + ":" + id));
731  arrayNew2.add(tmpObject2);
732  tmpLabelObject.put(rdf.getPrefixItem("skos:narrower"), arrayNew2);
733  rdfObject.put(rdf.getPrefixItem("ls_lab:" + element), tmpLabelObject);
734  }
735  labelObject.put(rdf.getPrefixItem("skos:broader"), arrayNew);
736  }
737  // change narrower
738  JSONArray narrowerArray = (JSONArray) labelObject.get("narrower");
739  List<String> narrowerStringList = new ArrayList<String>();
740  if (narrowerArray != null && !narrowerArray.isEmpty()) {
741  for (Object element : narrowerArray) {
742  if (element.equals("null")) {
743  narrowerStringList.add("http://dummy.net");
744  } else {
745  narrowerStringList.add((String) element);
746  }
747  }
748  labelObject.remove("narrower");
749  JSONArray arrayNew = new JSONArray();
750  for (String element : narrowerStringList) {
751  JSONObject tmpObject = new JSONObject();
752  tmpObject.put("type", "uri");
753  tmpObject.put("value", rdf.getPrefixItem("ls_lab:" + element));
754  arrayNew.add(tmpObject);
755  // broader
756  JSONObject tmpLabelObject = new JSONObject();
757  JSONArray arrayNew2 = new JSONArray();
758  JSONObject tmpObject2 = new JSONObject();
759  tmpObject2.put("type", "uri");
760  tmpObject2.put("value", rdf.getPrefixItem("ls_lab" + ":" + id));
761  arrayNew2.add(tmpObject2);
762  tmpLabelObject.put(rdf.getPrefixItem("skos:broader"), arrayNew2);
763  rdfObject.put(rdf.getPrefixItem("ls_lab:" + element), tmpLabelObject);
764  }
765  labelObject.put(rdf.getPrefixItem("skos:narrower"), arrayNew);
766  }
767  // change closeMatch
768  JSONArray closeMatchArray = (JSONArray) labelObject.get("closeMatch");
769  List<String> closeMatchStringList = new ArrayList<String>();
770  if (closeMatchArray != null && !closeMatchArray.isEmpty()) {
771  for (Object element : closeMatchArray) {
772  JSONObject tmpjson = (JSONObject) element;
773  closeMatchStringList.add((String) tmpjson.get("uri"));
774  }
775  labelObject.remove("closeMatch");
776  JSONArray arrayNew = new JSONArray();
777  for (String element : closeMatchStringList) {
778  JSONObject tmpObject = new JSONObject();
779  tmpObject.put("type", "uri");
780  tmpObject.put("value", element);
781  arrayNew.add(tmpObject);
782  }
783  labelObject.put(rdf.getPrefixItem("skos:closeMatch"), arrayNew);
784  }
785  // change exactMatch
786  JSONArray exactMatchArray = (JSONArray) labelObject.get("exactMatch");
787  List<String> exactMatchStringList = new ArrayList<String>();
788  if (exactMatchArray != null && !exactMatchArray.isEmpty()) {
789  for (Object element : exactMatchArray) {
790  JSONObject tmpjson = (JSONObject) element;
791  exactMatchStringList.add((String) tmpjson.get("uri"));
792  }
793  labelObject.remove("exactMatch");
794  JSONArray arrayNew = new JSONArray();
795  for (String element : exactMatchStringList) {
796  JSONObject tmpObject = new JSONObject();
797  tmpObject.put("type", "uri");
798  tmpObject.put("value", element);
799  arrayNew.add(tmpObject);
800  }
801  labelObject.put(rdf.getPrefixItem("skos:exactMatch"), arrayNew);
802  }
803  // change relatedMatch
804  JSONArray relatedMatchArray = (JSONArray) labelObject.get("relatedMatch");
805  List<String> relatedMatchStringList = new ArrayList<String>();
806  if (relatedMatchArray != null && !relatedMatchArray.isEmpty()) {
807  for (Object element : relatedMatchArray) {
808  JSONObject tmpjson = (JSONObject) element;
809  relatedMatchStringList.add((String) tmpjson.get("uri"));
810  }
811  labelObject.remove("relatedMatch");
812  JSONArray arrayNew = new JSONArray();
813  for (String element : relatedMatchStringList) {
814  JSONObject tmpObject = new JSONObject();
815  tmpObject.put("type", "uri");
816  tmpObject.put("value", element);
817  arrayNew.add(tmpObject);
818  }
819  labelObject.put(rdf.getPrefixItem("skos:relatedMatch"), arrayNew);
820  }
821  // change narrowMatch
822  JSONArray narrowMatchArray = (JSONArray) labelObject.get("narrowMatch");
823  List<String> narrowMatchStringList = new ArrayList<String>();
824  if (narrowMatchArray != null && !narrowMatchArray.isEmpty()) {
825  for (Object element : narrowMatchArray) {
826  JSONObject tmpjson = (JSONObject) element;
827  narrowMatchStringList.add((String) tmpjson.get("uri"));
828  }
829  labelObject.remove("narrowMatch");
830  JSONArray arrayNew = new JSONArray();
831  for (String element : narrowMatchStringList) {
832  JSONObject tmpObject = new JSONObject();
833  tmpObject.put("type", "uri");
834  tmpObject.put("value", element);
835  arrayNew.add(tmpObject);
836  }
837  labelObject.put(rdf.getPrefixItem("skos:narrowMatch"), arrayNew);
838  }
839  // change broadMatch
840  JSONArray broadMatchArray = (JSONArray) labelObject.get("broadMatch");
841  List<String> broadMatchStringList = new ArrayList<String>();
842  if (broadMatchArray != null && !broadMatchArray.isEmpty()) {
843  for (Object element : broadMatchArray) {
844  JSONObject tmpjson = (JSONObject) element;
845  broadMatchStringList.add((String) tmpjson.get("uri"));
846  }
847  labelObject.remove("broadMatch");
848  JSONArray arrayNew = new JSONArray();
849  for (String element : broadMatchStringList) {
850  JSONObject tmpObject = new JSONObject();
851  tmpObject.put("type", "uri");
852  tmpObject.put("value", element);
853  arrayNew.add(tmpObject);
854  }
855  labelObject.put(rdf.getPrefixItem("skos:broadMatch"), arrayNew);
856  }
857  // change seeAlso
858  JSONArray seeAlsoArray = (JSONArray) labelObject.get("seeAlso");
859  List<String> seeAlsoStringList = new ArrayList<String>();
860  if (seeAlsoArray != null && !seeAlsoArray.isEmpty()) {
861  for (Object element : seeAlsoArray) {
862  JSONObject tmpjson = (JSONObject) element;
863  seeAlsoStringList.add((String) tmpjson.get("uri"));
864  }
865  labelObject.remove("seeAlso");
866  JSONArray arrayNew = new JSONArray();
867  for (String element : seeAlsoStringList) {
868  JSONObject tmpObject = new JSONObject();
869  tmpObject.put("type", "uri");
870  tmpObject.put("value", element);
871  arrayNew.add(tmpObject);
872  }
873  labelObject.put(rdf.getPrefixItem("rdfs:seeAlso"), arrayNew);
874  }
875  // delete items
876  labelObject.remove("id");
877  labelObject.remove("creator");
878  labelObject.remove("contributors");
879  labelObject.remove("vocabID");
880  labelObject.remove("translations");
881  labelObject.remove("thumbnail");
882  labelObject.remove("description");
883  labelObject.remove("created");
884  labelObject.remove("license");
885  labelObject.remove("origin");
886  labelObject.remove("modifications");
887  labelObject.remove("lastModified");
888  labelObject.remove("revisionIDs");
889  labelObject.remove("releaseType");
890  labelObject.remove("related");
891  labelObject.remove("broader");
892  labelObject.remove("narrower");
893  labelObject.remove("closeMatch");
894  labelObject.remove("exactMatch");
895  labelObject.remove("relatedMatch");
896  labelObject.remove("narrowMatch");
897  labelObject.remove("broadMatch");
898  labelObject.remove("seeAlso");
899  labelObject.remove("equalConcepts");
900  labelObject.remove("revisions");
901  labelObject.remove("released");
902  labelObject.remove("creatorInfo");
903  // add object
904  rdfObject.put(rdf.getPrefixItem("ls_lab" + ":" + id), labelObject);
905  return rdfObject.toJSONString();
906  }

Referenced by LabelsResource.postLabel(), and LabelsResource.updateLabel().

◆ revision_GET()

static JSONObject revision_GET ( String  json,
String  id 
) throws IOException, UniqueIdentifierException, ParseException, TransformRdfToApiJsonException
static
344  {
345  JSONObject revisionObject = null;
346  try {
347  //init
348  RDF rdf = new RDF();
349  // parse json
350  JSONObject jsonObject = (JSONObject) new JSONParser().parse(json);
351  jsonObject.put("revision", jsonObject.remove(rdf.getPrefixItem("ls_rev" + ":" + id)));
352  // get items
353  revisionObject = (JSONObject) jsonObject.get(rdf.getPrefixItem("revision"));
354  // change dc:identifier
355  JSONArray identifierArray = (JSONArray) revisionObject.get(rdf.getPrefixItem("dc:identifier"));
356  for (Object element : identifierArray) {
357  revisionObject.remove(rdf.getPrefixItem("dc:identifier"));
358  JSONObject obj = (JSONObject) element;
359  String value = (String) obj.get("value");
360  revisionObject.put("id", value);
361  }
362  // change ls:action
363  JSONArray actionArray = (JSONArray) revisionObject.get(rdf.getPrefixItem("ls:action"));
364  if (actionArray != null && !actionArray.isEmpty()) {
365  for (Object element : actionArray) {
366  revisionObject.remove(rdf.getPrefixItem("ls:action"));
367  JSONObject obj = (JSONObject) element;
368  String value = (String) obj.get("value");
369  revisionObject.put("action", value);
370  }
371  }
372  // change ls:objectType
373  JSONArray objectTypeArray = (JSONArray) revisionObject.get(rdf.getPrefixItem("ls:objectType"));
374  if (objectTypeArray != null && !objectTypeArray.isEmpty()) {
375  for (Object element : objectTypeArray) {
376  revisionObject.remove(rdf.getPrefixItem("ls:objectType"));
377  JSONObject obj = (JSONObject) element;
378  String value = (String) obj.get("value");
379  revisionObject.put("objectType", value);
380  }
381  }
382  // change ls:valueBefore
383  JSONArray valueBeforeArray = (JSONArray) revisionObject.get(rdf.getPrefixItem("ls:valueBefore"));
384  if (valueBeforeArray != null && !valueBeforeArray.isEmpty()) {
385  for (Object element : valueBeforeArray) {
386  revisionObject.remove(rdf.getPrefixItem("ls:valueBefore"));
387  JSONObject obj = (JSONObject) element;
388  String value = (String) obj.get("value");
389  revisionObject.put("valueBefore", value);
390  }
391  }
392  // change ls:valueAfter
393  JSONArray valueAfterArray = (JSONArray) revisionObject.get(rdf.getPrefixItem("ls:valueAfter"));
394  if (valueAfterArray != null && !valueAfterArray.isEmpty()) {
395  for (Object element : valueAfterArray) {
396  revisionObject.remove(rdf.getPrefixItem("ls:valueAfter"));
397  JSONObject obj = (JSONObject) element;
398  String value = (String) obj.get("value");
399  revisionObject.put("valueAfter", value);
400  }
401  }
402  // change prov:startedAtTime
403  JSONArray createdArray = (JSONArray) revisionObject.get(rdf.getPrefixItem("prov:startedAtTime"));
404  if (createdArray != null && !createdArray.isEmpty()) {
405  for (Object element : createdArray) {
406  revisionObject.remove(rdf.getPrefixItem("prov:startedAtTime"));
407  JSONObject obj = (JSONObject) element;
408  String value = (String) obj.get("value");
409  revisionObject.put("date", value);
410  }
411  }
412  // delete items
413  revisionObject.remove(rdf.getPrefixItem("rdf:type"));
414  revisionObject.remove(rdf.getPrefixItem("dc:identifier"));
415  revisionObject.remove(rdf.getPrefixItem("dct:creator"));
416  revisionObject.remove(rdf.getPrefixItem("dc:creator"));
417  revisionObject.remove(rdf.getPrefixItem("dc:description"));
418  revisionObject.remove(rdf.getPrefixItem("prov:startedAtTime"));
419  revisionObject.remove(rdf.getPrefixItem("ls:action"));
420  revisionObject.remove(rdf.getPrefixItem("ls:objectType"));
421  revisionObject.remove(rdf.getPrefixItem("ls:valueBefore"));
422  revisionObject.remove(rdf.getPrefixItem("ls:valueAfter"));
423  } catch (Exception e) {
424  int errorLine = -1;
425  for (StackTraceElement element : e.getStackTrace()) {
426  errorLine = element.getLineNumber();
427  if (element.getClassName().equals(Transformer.class.getName())) {
428  break;
429  }
430  }
431  throw new TransformRdfToApiJsonException(e.toString() + " in line " + String.valueOf(errorLine));
432  }
433  // return
434  return revisionObject;
435  }

Referenced by RevisionsResource.getRevision(), RevisionsResource.getRevision_JSON(), and RevisionsResource.getRevisions().

◆ vocabulary_GET()

static JSONObject vocabulary_GET ( String  json,
String  id,
String  fields,
String  statisticsBool,
String  creatorInfoBool 
) throws IOException, UniqueIdentifierException, ParseException, TransformRdfToApiJsonException
static
148  {
149  JSONObject vocabularyObject = null;
150  try {
151  //init
152  RDF rdf = new RDF();
153  // parse json
154  JSONObject jsonObject = (JSONObject) new JSONParser().parse(json);
155  jsonObject.put("vocab", jsonObject.remove(rdf.getPrefixItem("ls_voc" + ":" + id)));
156  // get items
157  vocabularyObject = (JSONObject) jsonObject.get(rdf.getPrefixItem("vocab"));
158  // change dc:identifier
159  JSONArray identifierArray = (JSONArray) vocabularyObject.get(rdf.getPrefixItem("dc:identifier"));
160  if (identifierArray != null && !identifierArray.isEmpty()) {
161  for (Object element : identifierArray) {
162  vocabularyObject.remove(rdf.getPrefixItem("dc:identifier"));
163  JSONObject obj = (JSONObject) element;
164  String value = (String) obj.get("value");
165  vocabularyObject.put("id", value);
166  }
167  }
168  // change dc:creator
169  JSONArray creatorArray = (JSONArray) vocabularyObject.get(rdf.getPrefixItem("dc:creator"));
170  if (creatorArray != null && !creatorArray.isEmpty()) {
171  for (Object element : creatorArray) {
172  vocabularyObject.remove(rdf.getPrefixItem("dc:creator"));
173  JSONObject obj = (JSONObject) element;
174  String value = (String) obj.get("value");
175  vocabularyObject.put("creator", value);
176  }
177  }
178  // change dc:title
179  JSONArray titleArray = (JSONArray) vocabularyObject.get(rdf.getPrefixItem("dc:title"));
180  String vocabLang = "";
181  if (titleArray != null && !titleArray.isEmpty()) {
182  for (Object element : titleArray) {
183  vocabularyObject.remove(rdf.getPrefixItem("dc:title"));
184  JSONObject obj = (JSONObject) element;
185  String value = (String) obj.get("value");
186  vocabLang = (String) obj.get("lang");
187  vocabularyObject.put("title", value);
188  }
189  }
190  // change dc:description
191  JSONArray descriptionArray = (JSONArray) vocabularyObject.get(rdf.getPrefixItem("dc:description"));
192  if (descriptionArray != null && !descriptionArray.isEmpty()) {
193  for (Object element : descriptionArray) {
194  vocabularyObject.remove(rdf.getPrefixItem("dc:description"));
195  JSONObject obj = (JSONObject) element;
196  String value = (String) obj.get("value");
197  vocabularyObject.put("description", value);
198  }
199  }
200  // change dc:language
201  JSONArray languageArray = (JSONArray) vocabularyObject.get(rdf.getPrefixItem("dc:language"));
202  if (languageArray != null && !languageArray.isEmpty()) {
203  for (Object element : languageArray) {
204  vocabularyObject.remove(rdf.getPrefixItem("dc:language"));
205  JSONObject obj = (JSONObject) element;
206  String value = (String) obj.get("value");
207  vocabularyObject.put("language", value);
208  }
209  } else {
210  vocabularyObject.put("language", vocabLang);
211  }
212  // change dc:created
213  JSONArray createdArray = (JSONArray) vocabularyObject.get(rdf.getPrefixItem("dc:created"));
214  if (createdArray != null && !createdArray.isEmpty()) {
215  for (Object element : createdArray) {
216  vocabularyObject.remove(rdf.getPrefixItem("dc:created"));
217  JSONObject obj = (JSONObject) element;
218  String value = (String) obj.get("value");
219  if (fields == null || fields.contains("created")) {
220  vocabularyObject.put("created", value);
221  vocabularyObject.put("lastModified", value);
222  }
223  }
224  }
225  // change dct:license
226  JSONArray licenseArray = (JSONArray) vocabularyObject.get(rdf.getPrefixItem("dct:license"));
227  if (licenseArray != null && !licenseArray.isEmpty()) {
228  for (Object element : licenseArray) {
229  vocabularyObject.remove(rdf.getPrefixItem("dct:license"));
230  JSONObject obj = (JSONObject) element;
231  String value = (String) obj.get("value");
232  if (fields == null || fields.contains("license")) {
233  vocabularyObject.put("license", value);
234  }
235  }
236  }
237  // change dc:modified
238  JSONArray modifiedArray = (JSONArray) vocabularyObject.get(rdf.getPrefixItem("dc:modified"));
239  if (modifiedArray != null && !modifiedArray.isEmpty()) {
240  vocabularyObject.remove(rdf.getPrefixItem("dc:modified"));
241  List<String> listModify = new ArrayList();
242  for (Object element : modifiedArray) {
243  JSONObject obj = (JSONObject) element;
244  String value = (String) obj.get("value");
245  listModify.add(value);
246  }
247  // set last modified
248  Collections.sort(listModify);
249  vocabularyObject.remove("lastModified");
250  vocabularyObject.put("lastModified", listModify.get(listModify.size() - 1));
251  }
252  // change ls:hasReleaseType
253  JSONArray releaseTypeArray = (JSONArray) vocabularyObject.get(rdf.getPrefixItem("ls:hasReleaseType"));
254  if (releaseTypeArray != null && !releaseTypeArray.isEmpty()) {
255  for (Object element : releaseTypeArray) {
256  vocabularyObject.remove(rdf.getPrefixItem("ls:hasReleaseType"));
257  JSONObject obj = (JSONObject) element;
258  String value = (String) obj.get("value");
259  if (value.contains("Draft")) {
260  value = "draft";
261  } else {
262  value = "public";
263  }
264  if (fields == null || fields.contains("releaseType")) {
265  vocabularyObject.put("releaseType", value);
266  }
267  }
268  }
269  // change ls:released
270  JSONArray releasedArray = (JSONArray) vocabularyObject.get(rdf.getPrefixItem("ls:released"));
271  if (releasedArray != null && !releasedArray.isEmpty()) {
272  for (Object element : releasedArray) {
273  vocabularyObject.remove(rdf.getPrefixItem("ls:released"));
274  JSONObject obj = (JSONObject) element;
275  String value = (String) obj.get("value");
276  if (fields == null || fields.contains("released")) {
277  vocabularyObject.put("released", value);
278  }
279  }
280  }
281  // delete items
282  vocabularyObject.remove(rdf.getPrefixItem("rdf:type"));
283  vocabularyObject.remove(rdf.getPrefixItem("dc:identifier"));
284  vocabularyObject.remove(rdf.getPrefixItem("dct:creator"));
285  vocabularyObject.remove(rdf.getPrefixItem("dc:creator"));
286  vocabularyObject.remove(rdf.getPrefixItem("dct:contributor"));
287  vocabularyObject.remove(rdf.getPrefixItem("dc:contributor"));
288  vocabularyObject.remove(rdf.getPrefixItem("dc:title"));
289  vocabularyObject.remove(rdf.getPrefixItem("dc:description"));
290  vocabularyObject.remove(rdf.getPrefixItem("dc:created"));
291  vocabularyObject.remove(rdf.getPrefixItem("dct:license"));
292  vocabularyObject.remove(rdf.getPrefixItem("dc:rights"));
293  vocabularyObject.remove(rdf.getPrefixItem("dc:modified"));
294  vocabularyObject.remove(rdf.getPrefixItem("ls:hasReleaseType"));
295  vocabularyObject.remove(rdf.getPrefixItem("ls:released"));
296  // deposits
297  vocabularyObject.remove(rdf.getPrefixItem("skos:changeNote"));
298  vocabularyObject.remove(rdf.getPrefixItem("skos:hasTopConcept"));
299  vocabularyObject.remove(rdf.getPrefixItem("dcat:theme"));
300  vocabularyObject.remove(rdf.getPrefixItem("ls:hasStatusType"));
301  vocabularyObject.remove(rdf.getPrefixItem("ls:sameAs"));
302  // statistics
303  if (statisticsBool != null) {
304  if (statisticsBool.equals("true")) {
305  JSONObject statistics = SQlite.getStatisticsForVocabuary(id);
306  vocabularyObject.put(rdf.getPrefixItem("statistics"), statistics);
307  }
308  }
309  // set creator info
310  if (creatorInfoBool != null) {
311  if (creatorInfoBool.equals("true")) {
312  String url = ConfigProperties.getPropertyParam("api") + "/v1/agents/" + vocabularyObject.get("creator") + ".json";
313  URL obj = new URL(url);
314  HttpURLConnection con = (HttpURLConnection) obj.openConnection();
315  con.setRequestMethod("GET");
316  con.setRequestProperty("Accept-Encoding", "json");
317  if (con.getResponseCode() == 200) {
318  BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream(), "UTF8"));
319  String inputLine;
320  StringBuilder response = new StringBuilder();
321  while ((inputLine = in.readLine()) != null) {
322  response.append(inputLine);
323  }
324  in.close();
325  JSONObject simillarConcept = (JSONObject) new JSONParser().parse(response.toString());
326  vocabularyObject.put("creatorInfo", simillarConcept);
327  }
328  }
329  }
330  } catch (Exception e) {
331  int errorLine = -1;
332  for (StackTraceElement element : e.getStackTrace()) {
333  errorLine = element.getLineNumber();
334  if (element.getClassName().equals(Transformer.class.getName())) {
335  break;
336  }
337  }
338  throw new TransformRdfToApiJsonException(e.toString() + " in line " + String.valueOf(errorLine));
339  }
340  // return
341  return vocabularyObject;
342  }

References ConfigProperties.getPropertyParam(), and SQlite.getStatisticsForVocabuary().

Referenced by VocabsResource.getVocabularies(), VocabsResource.getVocabulary(), VocabsResource.getVocabulary_JSON(), VocabsResource.postVocabulary(), and VocabsResource.updateVocabulary().

◆ vocabulary_POST()

static String vocabulary_POST ( String  json,
String  id 
) throws IOException, UniqueIdentifierException, ParseException
static
42  {
43  //init
44  RDF rdf = new RDF();
45  // parse json
46  JSONObject rdfObject = new JSONObject();
47  JSONObject vocabularyObject = (JSONObject) new JSONParser().parse(json);
48  // change language
49  String language = (String) vocabularyObject.get("language");
50  if (language != null) {
51  vocabularyObject.remove("language");
52  JSONArray languageArrayNew = new JSONArray();
53  JSONObject languageObject = new JSONObject();
54  languageObject.put("type", "literal");
55  languageObject.put("value", language);
56  languageArrayNew.add(languageObject);
57  vocabularyObject.put(rdf.getPrefixItem("dc:language"), languageArrayNew);
58  }
59  // change title
60  String title = (String) vocabularyObject.get("title");
61  if (title != null) {
62  vocabularyObject.remove("title");
63  JSONArray titleArrayNew = new JSONArray();
64  JSONObject titleObject = new JSONObject();
65  titleObject.put("type", "literal");
66  titleObject.put("value", title);
67  titleObject.put("lang", language);
68  titleArrayNew.add(titleObject);
69  vocabularyObject.put(rdf.getPrefixItem("dc:title"), titleArrayNew);
70  }
71  // change description
72  String description = (String) vocabularyObject.get("description");
73  if (description != null) {
74  vocabularyObject.remove("description");
75  JSONArray descriptionArrayNew = new JSONArray();
76  JSONObject descriptionObject = new JSONObject();
77  descriptionObject.put("type", "literal");
78  descriptionObject.put("value", description);
79  descriptionObject.put("lang", language);
80  descriptionArrayNew.add(descriptionObject);
81  vocabularyObject.put(rdf.getPrefixItem("dc:description"), descriptionArrayNew);
82  }
83  // change license
84  String license = (String) vocabularyObject.get("license");
85  if (license != null) {
86  vocabularyObject.remove("license");
87  JSONArray licenseArrayNew = new JSONArray();
88  JSONObject licenseObject = new JSONObject();
89  licenseObject.put("type", "uri");
90  licenseObject.put("value", license);
91  licenseArrayNew.add(licenseObject);
92  vocabularyObject.put(rdf.getPrefixItem("dct:license"), licenseArrayNew);
93  } else { // set public domain as default
94  JSONArray licenseArrayNew = new JSONArray();
95  JSONObject licenseObject = new JSONObject();
96  licenseObject.put("type", "uri");
97  licenseObject.put("value", "http://creativecommons.org/publicdomain/zero/1.0/legalcode");
98  licenseArrayNew.add(licenseObject);
99  vocabularyObject.put(rdf.getPrefixItem("dct:license"), licenseArrayNew);
100  }
101  // change releasetype
102  String releaseString = (String) vocabularyObject.get("releaseType");
103  if (releaseString != null && !releaseString.isEmpty()) {
104  vocabularyObject.remove("releaseType");
105  JSONArray releaseArrayNew = new JSONArray();
106  JSONObject releaseObject = new JSONObject();
107  releaseObject.put("type", "uri");
108  if (releaseString.equals("draft")) {
109  releaseObject.put("value", rdf.getPrefixItem("ls:Draft"));
110  } else {
111  releaseObject.put("value", rdf.getPrefixItem("ls:Public"));
112  }
113  releaseArrayNew.add(releaseObject);
114  vocabularyObject.put(rdf.getPrefixItem("ls:hasReleaseType"), releaseArrayNew);
115  }
116  Calendar calender = Calendar.getInstance();
117  Date date = calender.getTime();
118  DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
119  String dateiso = formatter.format(date);
120  if (releaseString != null && !releaseString.isEmpty()) {
121  if (releaseString.equals("public")) {
122  JSONArray releaseArrayNew = new JSONArray();
123  JSONObject releaseObject = new JSONObject();
124  releaseObject.put("type", "literal");
125  releaseObject.put("value", dateiso);
126  releaseArrayNew.add(releaseObject);
127  vocabularyObject.put(rdf.getPrefixItem("ls:released"), releaseArrayNew);
128  }
129  }
130  // delete items
131  vocabularyObject.remove("id");
132  vocabularyObject.remove("creator");
133  vocabularyObject.remove("contributors");
134  vocabularyObject.remove("title");
135  vocabularyObject.remove("description");
136  vocabularyObject.remove("created");
137  vocabularyObject.remove("license");
138  vocabularyObject.remove("origin");
139  vocabularyObject.remove("lastModified");
140  vocabularyObject.remove("releaseType");
141  vocabularyObject.remove("statistics");
142  vocabularyObject.remove("creatorInfo");
143  // add object
144  rdfObject.put(rdf.getPrefixItem("ls_voc" + ":" + id), vocabularyObject);
145  return rdfObject.toJSONString();
146  }

Referenced by VocabsResource.postVocabulary(), and VocabsResource.updateVocabulary().

◆ writeVocabularyStatisticsToDatabase()

static void writeVocabularyStatisticsToDatabase ( String  vocabulary) throws org.eclipse.rdf4j.repository.RepositoryException, org.eclipse.rdf4j.query.MalformedQueryException, org.eclipse.rdf4j.query.QueryEvaluationException, SparqlParseException, SparqlQueryException, IOException, ClassNotFoundException, SQliteException, StatisticsException
static
2070  {
2071  try {
2072  RDF rdf = new RDF();
2073  // query triplestore
2074  String query = "PREFIX ls: <http://labeling.link/docs/ls/core#> PREFIX skos: <http://www.w3.org/2004/02/skos/core#> PREFIX dc: <http://purl.org/dc/elements/1.1/> SELECT ?l ?p ?o WHERE { ?l skos:inScheme ?v . ?v dc:identifier ?id . ?l ?p ?o. FILTER (?id = \"" + vocabulary + "\") }";
2075  List<BindingSet> result = RDF4J_20.SPARQLquery(ConfigProperties.getPropertyParam("repository"), ConfigProperties.getPropertyParam("ts_server"), query);
2076  List<String> subjects = RDF4J_20.getValuesFromBindingSet_ORDEREDLIST(result, "l");
2077  List<String> predicates = RDF4J_20.getValuesFromBindingSet_ORDEREDLIST(result, "p");
2078  List<String> objects = RDF4J_20.getValuesFromBindingSet_ORDEREDLIST(result, "o");
2079  int internalLinks = 0;
2080  int externalLinks = 0;
2081  int waybackLinks = 0;
2082  for (String item : predicates) {
2083  if (item.equals(rdf.getPrefixItem("skos:broader")) || item.equals(rdf.getPrefixItem("skos:narrower")) || item.equals(rdf.getPrefixItem("skos:related"))) {
2084  internalLinks++;
2085  } else if (item.equals(rdf.getPrefixItem("skos:broadMatch"))
2086  || item.equals(rdf.getPrefixItem("skos:narrowMatch"))
2087  || item.equals(rdf.getPrefixItem("skos:relatedMatch"))
2088  || item.equals(rdf.getPrefixItem("skos:closeMatch"))
2089  || item.equals(rdf.getPrefixItem("skos:exactMatch"))) {
2090  externalLinks++;
2091  } else if (item.equals(rdf.getPrefixItem("rdfs:seeAlso"))) {
2092  waybackLinks++;
2093  }
2094  }
2095  int labelCount = 0;
2096  int descriptions = 0;
2097  int prefLabels = 0;
2098  List<String> listModify = new ArrayList();
2099  for (int i = 0; i < subjects.size(); i++) {
2100  if (objects.get(i).equals(rdf.getPrefixItem("ls:Label"))) {
2101  labelCount++;
2102  }
2103  if (predicates.get(i).equals(rdf.getPrefixItem("skos:scopeNote"))) {
2104  descriptions++;
2105  }
2106  if (predicates.get(i).equals(rdf.getPrefixItem("skos:prefLabel"))) {
2107  prefLabels++;
2108  }
2109  if (predicates.get(i).equals(rdf.getPrefixItem("dc:modified")) || predicates.get(i).equals(rdf.getPrefixItem("dc:created"))) {
2110  listModify.add(objects.get(i));
2111  }
2112  }
2113  int linkscount = externalLinks + internalLinks;
2114  int translations = 0;
2115  if (prefLabels - labelCount < 0) {
2116  translations = 0;
2117  } else {
2118  translations = prefLabels - labelCount;
2119  }
2120  String lastModifyAction = "";
2121  if (listModify.size() > 0) {
2122  Collections.sort(listModify);
2123  lastModifyAction = listModify.get(listModify.size() - 1);
2124  } else {
2125  lastModifyAction = "";
2126  }
2127  // delete entry in database
2128  SQlite.deleteStatisticsForVocabuary(vocabulary);
2129  // write results to database
2130  SQlite.insertStatisticsForVocabuary(vocabulary, lastModifyAction, waybackLinks, translations, descriptions, externalLinks, internalLinks, linkscount, labelCount);
2131  } catch (Exception e) {
2132  throw new StatisticsException("cannot insert statistics for vocabulary. " + e.toString());
2133  }
2134  }

References SQlite.deleteStatisticsForVocabuary(), ConfigProperties.getPropertyParam(), and SQlite.insertStatisticsForVocabuary().

Referenced by ImportcsvResource.csvUploadDirectResponse(), LabelsResource.deleteLabel(), LabelsResource.postLabel(), VocabsResource.postVocabulary(), and LabelsResource.updateLabel().

rdf
Definition: RDF.java:1
Exception