diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/AddAttendeeRoleToPersonGenerator.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/AddAttendeeRoleToPersonGenerator.java index 69ad74227..59c3076b5 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/AddAttendeeRoleToPersonGenerator.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/AddAttendeeRoleToPersonGenerator.java @@ -22,27 +22,50 @@ String getRoleType() { @Override FieldOptions getRoleActivityFieldOptions(VitroRequest vreq) throws Exception { return new ConstantFieldOptions( - "", "Select type", - "http://purl.org/NET/c4dm/event.owl#Event", "Event", - "http://vivoweb.org/ontology/core#Competition", "Competition", - "http://purl.org/ontology/bibo/Conference", "Conference", - "http://vivoweb.org/ontology/core#Course", "Course", - "http://vivoweb.org/ontology/core#Exhibit", "Exhibit", - "http://purl.org/ontology/bibo/Hearing", "Hearing", - "http://purl.org/ontology/bibo/Interview", "Interview", - "http://vivoweb.org/ontology/core#Meeting", "Meeting", - "http://purl.org/ontology/bibo/Performance", "Performance", - "http://vivoweb.org/ontology/core#Presentation", "Presentation", - "http://vivoweb.org/ontology/core#InvitedTalk", "Invited Talk", - "http://purl.org/ontology/bibo/Workshop", "Workshop", - "http://vivoweb.org/ontology/core#EventSeries", "Event Series", - "http://vivoweb.org/ontology/core#ConferenceSeries", "Conference Series", - "http://vivoweb.org/ontology/core#SeminarSeries", "Seminar Series", - "http://vivoweb.org/ontology/core#WorkshopSeries", "Workshop Series" - ); - } + // return new ConstantFieldOptions( + // "", "Select type", + // "http://purl.org/NET/c4dm/event.owl#Event", "Event", + // "http://vivoweb.org/ontology/core#Competition", "Competition", + // "http://purl.org/ontology/bibo/Conference", "Conference", + // "http://vivoweb.org/ontology/core#Course", "Course", + // "http://vivoweb.org/ontology/core#Exhibit", "Exhibit", + // "http://purl.org/ontology/bibo/Hearing", "Hearing", + // "http://purl.org/ontology/bibo/Interview", "Interview", + // "http://vivoweb.org/ontology/core#Meeting", "Meeting", + // "http://purl.org/ontology/bibo/Performance", "Performance", + // "http://vivoweb.org/ontology/core#Presentation", "Presentation", + // "http://vivoweb.org/ontology/core#InvitedTalk", "Invited Talk", + // "http://purl.org/ontology/bibo/Workshop", "Workshop", + // "http://vivoweb.org/ontology/core#EventSeries", "Event Series", + // "http://vivoweb.org/ontology/core#ConferenceSeries", "Conference Series", + // "http://vivoweb.org/ontology/core#SeminarSeries", "Seminar Series", + // "http://vivoweb.org/ontology/core#WorkshopSeries", "Workshop Series" + // ); - @Override + // UQAM Replacing the above hard coding assignment by a dynamic assignment that takes into account the linguistic context + ConstantFieldOptions filedOptions = GeneratorUtil.buildConstantFieldOptions(vreq, DESCRIBE_QUERY); + return filedOptions; + } + /* + * UQAM get attributes for this specific subject + */ + private static String DESCRIBE_QUERY = " describe "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "; boolean isShowRoleLabelField() { return false; } @@ -65,3 +88,4 @@ public String getEndDatePrecision() { } */ } + diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/AddClinicalRoleToPersonGenerator.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/AddClinicalRoleToPersonGenerator.java index 1586860f8..648e735f7 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/AddClinicalRoleToPersonGenerator.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/AddClinicalRoleToPersonGenerator.java @@ -10,10 +10,10 @@ public class AddClinicalRoleToPersonGenerator extends AddRoleToPersonTwoStageGen private static String template = "addClinicalRoleToPerson.ftl"; - //Should this be overridden + //Should this be overridden @Override String getTemplate() { - return template; + return template; } @Override @@ -22,29 +22,38 @@ String getRoleType() { } /** Clinical role involves hard-coded options for the "right side" of the role or activity. */ - @Override - FieldOptions getRoleActivityFieldOptions(VitroRequest vreq) throws Exception { - return new ConstantFieldOptions( - "", "Select one", - "http://vivoweb.org/ontology/core#Project", "Project", - "http://purl.obolibrary.org/obo/ERO_0000005", "Service" - ); - } + @Override + FieldOptions getRoleActivityFieldOptions(VitroRequest vreq) throws Exception { + // return new ConstantFieldOptions( + // "", "Select one", + // "http://vivoweb.org/ontology/core#Project", "Project", + // "http://purl.obolibrary.org/obo/ERO_0000005", "Service" + // ); + //UQAM Replacing the above hard coding assigment by a dynamic assigment that takes into account the linguistic context + ConstantFieldOptions filedOptions = GeneratorUtil.buildConstantFieldOptions(vreq, DESCRIBE_QUERY); + return filedOptions; + } + /* + * UQAM get attributes for this specific subject + */ + private static String DESCRIBE_QUERY = " describe "+ + " "+ + ""; //isShowRoleLabelField remains true for this so doesn't need to be overwritten @Override boolean isShowRoleLabelField(){ - return true; + return true; } - /* - * Use the methods below to change the date/time precision in the - * custom form associated with this generator. When not used, the - * precision will be YEAR. The other precisons are MONTH, DAY, HOUR, - * MINUTE, TIME and NONE. - */ - /* + /* + * Use the methods below to change the date/time precision in the + * custom form associated with this generator. When not used, the + * precision will be YEAR. The other precisons are MONTH, DAY, HOUR, + * MINUTE, TIME and NONE. + */ + /* public String getStartDatePrecision() { String precision = VitroVocabulary.Precision.MONTH.uri(); return precision; @@ -54,6 +63,6 @@ public String getEndDatePrecision() { String precision = VitroVocabulary.Precision.DAY.uri(); return precision; } - */ + */ } diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/AddEditorRoleToPersonGenerator.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/AddEditorRoleToPersonGenerator.java index fcfc66a85..a5114e6b5 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/AddEditorRoleToPersonGenerator.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/AddEditorRoleToPersonGenerator.java @@ -5,6 +5,8 @@ import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.ChildVClassesOptions; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldOptions; +import edu.cornell.mannlib.vitro.webapp.i18n.I18n; +import edu.cornell.mannlib.vitro.webapp.i18n.I18nBundle; /** * Generates the edit configuration for adding a Role to a Person. @@ -46,8 +48,13 @@ String getRoleType() { @Override FieldOptions getRoleActivityFieldOptions(VitroRequest vreq) throws Exception { + // UQAM Managing linguistic context + I18nBundle i18n = I18n.bundle(vreq); + String i18nSelectType = i18n.text("select_type"); + String selectType = (i18nSelectType == null || i18nSelectType.isEmpty()) ? "Select type" : i18nSelectType ; + return new ChildVClassesOptions(OPTION_CLASS_URI) - .setDefaultOptionLabel("Select type"); + .setDefaultOptionLabel(selectType); } /** Do not show the role label field for the AddEditorRoleToPerson form */ diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/AddEditorshipToPersonGenerator.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/AddEditorshipToPersonGenerator.java index 41cea1395..85e014565 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/AddEditorshipToPersonGenerator.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/AddEditorshipToPersonGenerator.java @@ -108,7 +108,8 @@ protected EditConfigurationVTwo doAddNew(VitroRequest vreq, conf.addField( new FieldVTwo(). setName("documentType"). setValidators( list("nonempty") ). - setOptions( new ConstantFieldOptions("documentType", getDocumentTypeLiteralOptions() )) + // UQAM vreq for linguistic context + setOptions( new ConstantFieldOptions("documentType", getDocumentTypeLiteralOptions(vreq) )) ); conf.addField( new FieldVTwo(). @@ -203,21 +204,42 @@ private EditConfigurationVTwo doBadEditorshipNoPub(VitroRequest vreq) { return null; } - private List> getDocumentTypeLiteralOptions() { - List> literalOptions = new ArrayList>(); - literalOptions.add(list("http://purl.org/ontology/bibo/Book", "Book")); - literalOptions.add(list("http://purl.org/ontology/bibo/Chapter", "Chapter")); - literalOptions.add(list("http://purl.org/ontology/bibo/EditedBook", "Edited Book")); - literalOptions.add(list("http://purl.org/ontology/bibo/Film", "Film")); - literalOptions.add(list("http://purl.org/ontology/bibo/Magazine", "Magazine")); - literalOptions.add(list("http://vivoweb.org/ontology/core#Newsletter", "Newsletter")); - literalOptions.add(list("http://purl.org/ontology/bibo/Newspaper", "Newspaper")); - literalOptions.add(list("http://vivoweb.org/ontology/core#NewsRelease", "News Release")); - literalOptions.add(list("http://purl.org/ontology/bibo/Report", "Report")); - literalOptions.add(list("http://vivoweb.org/ontology/core#Video", "Video")); - literalOptions.add(list("http://purl.org/ontology/bibo/Webpage", "Webpage")); - literalOptions.add(list("http://purl.org/ontology/bibo/Website", "Website")); - return literalOptions; + private List> getDocumentTypeLiteralOptions(VitroRequest vreq) throws Exception { + //UQAM Replacing hard coding assigment by a dynamic assigment that takes into account the linguistic context + List> value = GeneratorUtil.builFieldOptionsList(vreq, DESCRIBE_QUERY); + return value; + +// List> literalOptions = new ArrayList>(); +// literalOptions.add(list("http://purl.org/ontology/bibo/Book", "Book")); +// literalOptions.add(list("http://purl.org/ontology/bibo/Chapter", "Chapter")); +// literalOptions.add(list("http://purl.org/ontology/bibo/EditedBook", "Edited Book")); +// literalOptions.add(list("http://purl.org/ontology/bibo/Film", "Film")); +// literalOptions.add(list("http://purl.org/ontology/bibo/Magazine", "Magazine")); +// literalOptions.add(list("http://vivoweb.org/ontology/core#Newsletter", "Newsletter")); +// literalOptions.add(list("http://purl.org/ontology/bibo/Newspaper", "Newspaper")); +// literalOptions.add(list("http://vivoweb.org/ontology/core#NewsRelease", "News Release")); +// literalOptions.add(list("http://purl.org/ontology/bibo/Report", "Report")); +// literalOptions.add(list("http://vivoweb.org/ontology/core#Video", "Video")); +// literalOptions.add(list("http://purl.org/ontology/bibo/Webpage", "Webpage")); +// literalOptions.add(list("http://purl.org/ontology/bibo/Website", "Website")); +// return literalOptions; } + /* + * UQAM get attributes for this specific subject + */ + private static String DESCRIBE_QUERY = " describe "+ + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " "; + } diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/AddHeadOfRoleToPersonGenerator.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/AddHeadOfRoleToPersonGenerator.java index 8afed1e42..ed4b8e5d6 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/AddHeadOfRoleToPersonGenerator.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/AddHeadOfRoleToPersonGenerator.java @@ -5,6 +5,8 @@ import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.ChildVClassesOptions; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldOptions; +import edu.cornell.mannlib.vitro.webapp.i18n.I18n; +import edu.cornell.mannlib.vitro.webapp.i18n.I18nBundle; public class AddHeadOfRoleToPersonGenerator extends AddRoleToPersonTwoStageGenerator { @@ -25,10 +27,14 @@ String getRoleType() { /** Head Of role involves hard-coded options for the "right side" of the role or activity */ @Override FieldOptions getRoleActivityFieldOptions(VitroRequest vreq) throws Exception { + // UQAM Taking into account the linguistic context + I18nBundle i18n = I18n.bundle(vreq); + String i18nSelectType = i18n.text("select_type"); + String selectType = (i18nSelectType == null || i18nSelectType.isEmpty()) ? "Select type" : i18nSelectType ; return new ChildVClassesOptions(OPTION_CLASS_URI) - .setDefaultOptionLabel("Select type"); + .setDefaultOptionLabel(selectType); } @Override diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/AddMemberRoleToPersonGenerator.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/AddMemberRoleToPersonGenerator.java index ba79af359..ad4195bc8 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/AddMemberRoleToPersonGenerator.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/AddMemberRoleToPersonGenerator.java @@ -2,9 +2,28 @@ package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators; +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; + +import org.apache.jena.query.Query; +import org.apache.jena.query.QueryExecution; +import org.apache.jena.query.QueryExecutionFactory; +import org.apache.jena.query.QueryFactory; +import org.apache.jena.query.QuerySolution; +import org.apache.jena.query.ResultSet; +import org.apache.jena.rdf.model.AnonId; +import org.apache.jena.rdf.model.Model; +import org.apache.jena.rdf.model.ModelFactory; + import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.ConstantFieldOptions; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldOptions; +import edu.cornell.mannlib.vitro.webapp.i18n.I18n; +import edu.cornell.mannlib.vitro.webapp.i18n.I18nBundle; +import edu.cornell.mannlib.vitro.webapp.i18n.selection.SelectedLocale; +import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService; +import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceUtils; public class AddMemberRoleToPersonGenerator extends AddRoleToPersonTwoStageGenerator { @@ -20,55 +39,99 @@ String getRoleType() { return "http://vivoweb.org/ontology/core#MemberRole"; } - @Override - FieldOptions getRoleActivityFieldOptions(VitroRequest vreq) throws Exception { - return new ConstantFieldOptions( - "","Select type", - "http://vivoweb.org/ontology/core#AcademicDepartment","Academic Department", - "http://vivoweb.org/ontology/core#Association","Association", - "http://vivoweb.org/ontology/core#Center","Center", - "http://vivoweb.org/ontology/core#ClinicalOrganization","Clinical Organization", - "http://vivoweb.org/ontology/core#College","College", - "http://vivoweb.org/ontology/core#Committee","Committee", - "http://vivoweb.org/ontology/core#Company","Company", - "http://vivoweb.org/ontology/core#Consortium","Consortium", - "http://vivoweb.org/ontology/core#CoreLaboratory","Core Laboratory", - "http://vivoweb.org/ontology/core#Department","Department", - "http://vivoweb.org/ontology/core#Division","Division", - "http://vivoweb.org/ontology/core#ExtensionUnit","Extension Unit", - "http://vivoweb.org/ontology/core#Foundation","Foundation", - "http://vivoweb.org/ontology/core#FundingOrganization","Funding Organization", - "http://vivoweb.org/ontology/core#GovernmentAgency","Government Agency", - "http://xmlns.com/foaf/0.1/Group","Group", - "http://vivoweb.org/ontology/core#Hospital","Hospital", - "http://vivoweb.org/ontology/core#Institute","Institute", - "http://vivoweb.org/ontology/core#Laboratory","Laboratory", - "http://vivoweb.org/ontology/core#Library","Library", - "http://purl.obolibrary.org/obo/OBI_0000835","Manufacturer", - "http://vivoweb.org/ontology/core#Museum","Museum", - "http://xmlns.com/foaf/0.1/Organization","Organization", - "http://vivoweb.org/ontology/core#PrivateCompany","Private Company", - "http://vivoweb.org/ontology/core#Program","Program", - "http://vivoweb.org/ontology/core#Publisher","Publisher", - "http://vivoweb.org/ontology/core#ResearchOrganization","Research Organization", - "http://vivoweb.org/ontology/core#School","School", - "http://vivoweb.org/ontology/core#Team","Team", - "http://vivoweb.org/ontology/core#ServiceProvidingLaboratory","Service Providing Lab", - "http://vivoweb.org/ontology/core#StudentOrganization","Student Organization", - "http://purl.obolibrary.org/obo/ERO_0000565","Technology Transfer Office", - "http://vivoweb.org/ontology/core#University","University"); - } + FieldOptions getRoleActivityFieldOptions(VitroRequest vreq) throws Exception { + + +/* + + return new ConstantFieldOptions( + "",selectType, + "http://vivoweb.org/ontology/core#AcademicDepartment","Academic Department", + "http://vivoweb.org/ontology/core#Association","Association", + "http://vivoweb.org/ontology/core#Center","Center", + "http://vivoweb.org/ontology/core#ClinicalOrganization","Clinical Organization", + "http://vivoweb.org/ontology/core#College","College", + "http://vivoweb.org/ontology/core#Committee","Committee", + "http://vivoweb.org/ontology/core#Company","Company", + "http://vivoweb.org/ontology/core#Consortium","Consortium", + "http://vivoweb.org/ontology/core#CoreLaboratory","Core Laboratory", + "http://vivoweb.org/ontology/core#Department","Department", + "http://vivoweb.org/ontology/core#Division","Division", + "http://vivoweb.org/ontology/core#ExtensionUnit","Extension Unit", + "http://vivoweb.org/ontology/core#Foundation","Foundation", + "http://vivoweb.org/ontology/core#FundingOrganization","Funding Organization", + "http://vivoweb.org/ontology/core#GovernmentAgency","Government Agency", + "http://xmlns.com/foaf/0.1/Group","Group", + "http://vivoweb.org/ontology/core#Hospital","Hospital", + "http://vivoweb.org/ontology/core#Institute","Institute", + "http://vivoweb.org/ontology/core#Laboratory","Laboratory", + "http://vivoweb.org/ontology/core#Library","Library", + "http://purl.obolibrary.org/obo/OBI_0000835","Manufacturer", + "http://vivoweb.org/ontology/core#Museum","Museum", + "http://xmlns.com/foaf/0.1/Organization","Organization", + "http://vivoweb.org/ontology/core#PrivateCompany","Private Company", + "http://vivoweb.org/ontology/core#Program","Program", + "http://vivoweb.org/ontology/core#Publisher","Publisher", + "http://vivoweb.org/ontology/core#ResearchOrganization","Research Organization", + "http://vivoweb.org/ontology/core#School","School", + "http://vivoweb.org/ontology/core#Team","Team", + "http://vivoweb.org/ontology/core#ServiceProvidingLaboratory","Service Providing Lab", + "http://vivoweb.org/ontology/core#StudentOrganization","Student Organization", + "http://purl.obolibrary.org/obo/ERO_0000565","Technology Transfer Office", + "http://vivoweb.org/ontology/core#University","University"); + */ + //UQAM Replacing the above hard coding assigment by a dynamic assigment that takes into account the linguistic context + ConstantFieldOptions filedOptions = GeneratorUtil.buildConstantFieldOptions(vreq, DESCRIBE_QUERY); + return filedOptions; + } + /* + * UQAM get attributes for this specific subject + */ + private static String DESCRIBE_QUERY = " describe "+ + " " + + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "; @Override boolean isShowRoleLabelField(){return true;} - /* - * Use the methods below to change the date/time precision in the - * custom form associated with this generator. When not used, the - * precision will be YEAR. The other precisons are MONTH, DAY, HOUR, - * MINUTE, TIME and NONE. - */ -/* + /* + * Use the methods below to change the date/time precision in the + * custom form associated with this generator. When not used, the + * precision will be YEAR. The other precisons are MONTH, DAY, HOUR, + * MINUTE, TIME and NONE. + */ + /* public String getStartDatePrecision() { String precision = VitroVocabulary.Precision.MONTH.uri(); return precision; @@ -78,5 +141,5 @@ public String getEndDatePrecision() { String precision = VitroVocabulary.Precision.DAY.uri(); return precision; } -*/ + */ } diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/AddOrganizerRoleToPersonGenerator.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/AddOrganizerRoleToPersonGenerator.java index 1dec78f50..5290897e4 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/AddOrganizerRoleToPersonGenerator.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/AddOrganizerRoleToPersonGenerator.java @@ -20,28 +20,50 @@ String getTemplate() { String getRoleType() { return "http://vivoweb.org/ontology/core#OrganizerRole"; } + // UQAM Added for buildConstantFieldOptions() call + private static String DESCRIBE_QUERY = " describe "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "; //Organizer role involves hard-coded options for the "right side" of the role or activity - @Override - FieldOptions getRoleActivityFieldOptions(VitroRequest vreq) throws Exception { - return new ConstantFieldOptions( - "","Select type", - "http://vivoweb.org/ontology/core#Competition", "Competition", - "http://purl.org/ontology/bibo/Conference", "Conference", - "http://vivoweb.org/ontology/core#Course", "Course", - "http://purl.org/NET/c4dm/event.owl#Event", "Event", - "http://vivoweb.org/ontology/core#Exhibit", "Exhibit", - "http://purl.org/ontology/bibo/Hearing", "Hearing", - "http://purl.org/ontology/bibo/Interview", "Interview", - "http://vivoweb.org/ontology/core#InvitedTalk", "Invited Talk", - "http://vivoweb.org/ontology/core#Meeting", "Meeting", - "http://purl.org/ontology/bibo/Performance", "Performance", - "http://vivoweb.org/ontology/core#Presentation", "Presentation", - "http://purl.org/ontology/bibo/Workshop", "Workshop", - "http://vivoweb.org/ontology/core#ConferenceSeries", "Conference Series", - "http://vivoweb.org/ontology/core#EventSeries", "Event Series", - "http://vivoweb.org/ontology/core#SeminarSeries", "Seminar Series", - "http://vivoweb.org/ontology/core#WorkshopSeries", "Workshop Series"); + FieldOptions getRoleActivityFieldOptions(VitroRequest vreq) throws Exception { + + // UQAM Replacing the above hard coding assignment by a dynamic assignment that takes into account the linguistic context + ConstantFieldOptions filedOptions = GeneratorUtil.buildConstantFieldOptions(vreq, DESCRIBE_QUERY); + return filedOptions; + + // return new ConstantFieldOptions( + // "","Select type", + // "http://vivoweb.org/ontology/core#Competition", "Competition", + // "http://purl.org/ontology/bibo/Conference", "Conference", + // "http://vivoweb.org/ontology/core#Course", "Course", + // "http://purl.org/NET/c4dm/event.owl#Event", "Event", + // "http://vivoweb.org/ontology/core#Exhibit", "Exhibit", + // "http://purl.org/ontology/bibo/Hearing", "Hearing", + // "http://purl.org/ontology/bibo/Interview", "Interview", + // "http://vivoweb.org/ontology/core#InvitedTalk", "Invited Talk", + // "http://vivoweb.org/ontology/core#Meeting", "Meeting", + // "http://purl.org/ontology/bibo/Performance", "Performance", + // "http://vivoweb.org/ontology/core#Presentation", "Presentation", + // "http://purl.org/ontology/bibo/Workshop", "Workshop", + // "http://vivoweb.org/ontology/core#ConferenceSeries", "Conference Series", + // "http://vivoweb.org/ontology/core#EventSeries", "Event Series", + // "http://vivoweb.org/ontology/core#SeminarSeries", "Seminar Series", + // "http://vivoweb.org/ontology/core#WorkshopSeries", "Workshop Series"); } @Override diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/AddOutreachProviderRoleToPersonGenerator.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/AddOutreachProviderRoleToPersonGenerator.java index 0a69623eb..4719d43a6 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/AddOutreachProviderRoleToPersonGenerator.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/AddOutreachProviderRoleToPersonGenerator.java @@ -20,73 +20,127 @@ String getTemplate() { String getRoleType() { return "http://vivoweb.org/ontology/core#OutreachProviderRole"; } + private static String DESCRIBE_QUERY = " describe "+ + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + "> getPublicationTypeLiteralOptions() { - List> literalOptions = new ArrayList>(); - literalOptions.add(list("http://vivoweb.org/ontology/core#Abstract", "Abstract")); - literalOptions.add(list("http://purl.org/ontology/bibo/AcademicArticle", "Academic Article")); - literalOptions.add(list("http://purl.org/ontology/bibo/Article", "Article")); - literalOptions.add(list("http://purl.org/ontology/bibo/AudioDocument", "Audio Document")); - literalOptions.add(list("http://vivoweb.org/ontology/core#BlogPosting", "Blog Posting")); - literalOptions.add(list("http://purl.org/ontology/bibo/Book", "Book")); - literalOptions.add(list("http://vivoweb.org/ontology/core#CaseStudy", "Case Study")); - literalOptions.add(list("http://vivoweb.org/ontology/core#Catalog", "Catalog")); - literalOptions.add(list("http://purl.org/ontology/bibo/Chapter", "Chapter")); - literalOptions.add(list("http://vivoweb.org/ontology/core#ConferencePaper", "Conference Paper")); - literalOptions.add(list("http://vivoweb.org/ontology/core#ConferencePoster", "Conference Poster")); - literalOptions.add(list("http://vivoweb.org/ontology/core#Database", "Database")); - literalOptions.add(list("http://vivoweb.org/ontology/core#Dataset", "Dataset")); - literalOptions.add(list("http://purl.org/ontology/bibo/EditedBook", "Edited Book")); - literalOptions.add(list("http://vivoweb.org/ontology/core#EditorialArticle", "Editorial Article")); - literalOptions.add(list("http://purl.org/ontology/bibo/Film", "Film")); - literalOptions.add(list("http://vivoweb.org/ontology/core#Newsletter", "Newsletter")); - literalOptions.add(list("http://vivoweb.org/ontology/core#NewsRelease", "News Release")); - literalOptions.add(list("http://purl.org/ontology/bibo/Patent", "Patent")); - literalOptions.add(list("http://purl.obolibrary.org/obo/OBI_0000272", "Protocol")); - literalOptions.add(list("http://purl.org/ontology/bibo/Report", "Report")); - literalOptions.add(list("http://vivoweb.org/ontology/core#ResearchProposal", "Research Proposal")); - literalOptions.add(list("http://vivoweb.org/ontology/core#Review", "Review")); - literalOptions.add(list("http://purl.obolibrary.org/obo/ERO_0000071 ", "Software")); - literalOptions.add(list("http://vivoweb.org/ontology/core#Speech", "Speech")); - literalOptions.add(list("http://purl.org/ontology/bibo/Thesis", "Thesis")); - literalOptions.add(list("http://vivoweb.org/ontology/core#Video", "Video")); - literalOptions.add(list("http://purl.org/ontology/bibo/Webpage", "Webpage")); - literalOptions.add(list("http://purl.org/ontology/bibo/Website", "Website")); - literalOptions.add(list("http://vivoweb.org/ontology/core#WorkingPaper", "Working Paper")); - return literalOptions; - } + private List> getPublicationTypeLiteralOptions(VitroRequest vreq) throws Exception { + //UQAM Replacing hard coding assigment by a dynamic assigment that takes into account the linguistic context + List> value = GeneratorUtil.builFieldOptionsList(vreq, DESCRIBE_QUERY); + return value; + //UQAM in replacement of this + // List> literalOptions = new ArrayList>(); + // literalOptions.add(list("http://vivoweb.org/ontology/core#Abstract", "Abstract")); + // literalOptions.add(list("http://purl.org/ontology/bibo/AcademicArticle", "Academic Article")); + // literalOptions.add(list("http://purl.org/ontology/bibo/Article", "Article")); + // literalOptions.add(list("http://purl.org/ontology/bibo/AudioDocument", "Audio Document")); + // literalOptions.add(list("http://vivoweb.org/ontology/core#BlogPosting", "Blog Posting")); + // literalOptions.add(list("http://purl.org/ontology/bibo/Book", "Book")); + // literalOptions.add(list("http://vivoweb.org/ontology/core#CaseStudy", "Case Study")); + // literalOptions.add(list("http://vivoweb.org/ontology/core#Catalog", "Catalog")); + // literalOptions.add(list("http://purl.org/ontology/bibo/Chapter", "Chapter")); + // literalOptions.add(list("http://vivoweb.org/ontology/core#ConferencePaper", "Conference Paper")); + // literalOptions.add(list("http://vivoweb.org/ontology/core#ConferencePoster", "Conference Poster")); + // literalOptions.add(list("http://vivoweb.org/ontology/core#Database", "Database")); + // literalOptions.add(list("http://vivoweb.org/ontology/core#Dataset", "Dataset")); + // literalOptions.add(list("http://purl.org/ontology/bibo/EditedBook", "Edited Book")); + // literalOptions.add(list("http://vivoweb.org/ontology/core#EditorialArticle", "Editorial Article")); + // literalOptions.add(list("http://purl.org/ontology/bibo/Film", "Film")); + // literalOptions.add(list("http://vivoweb.org/ontology/core#Newsletter", "Newsletter")); + // literalOptions.add(list("http://vivoweb.org/ontology/core#NewsRelease", "News Release")); + // literalOptions.add(list("http://purl.org/ontology/bibo/Patent", "Patent")); + // literalOptions.add(list("http://purl.obolibrary.org/obo/OBI_0000272", "Protocol")); + // literalOptions.add(list("http://purl.org/ontology/bibo/Report", "Report")); + // literalOptions.add(list("http://vivoweb.org/ontology/core#ResearchProposal", "Research Proposal")); + // literalOptions.add(list("http://vivoweb.org/ontology/core#Review", "Review")); + // literalOptions.add(list("http://purl.obolibrary.org/obo/ERO_0000071 ", "Software")); + // literalOptions.add(list("http://vivoweb.org/ontology/core#Speech", "Speech")); + // literalOptions.add(list("http://purl.org/ontology/bibo/Thesis", "Thesis")); + // literalOptions.add(list("http://vivoweb.org/ontology/core#Video", "Video")); + // literalOptions.add(list("http://purl.org/ontology/bibo/Webpage", "Webpage")); + // literalOptions.add(list("http://purl.org/ontology/bibo/Website", "Website")); + // literalOptions.add(list("http://vivoweb.org/ontology/core#WorkingPaper", "Working Paper")); + // return literalOptions; + } + + + /* + * UQAM get attributes for this specific subject + */ + private static String DESCRIBE_QUERY = " describe "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "; //Form specific data public void addFormSpecificData(EditConfigurationVTwo editConfiguration, VitroRequest vreq) { diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/AddResearcherRoleToPersonGenerator.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/AddResearcherRoleToPersonGenerator.java index ae3bd262a..09ceae29a 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/AddResearcherRoleToPersonGenerator.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/AddResearcherRoleToPersonGenerator.java @@ -23,14 +23,24 @@ public String getRoleType() { /** Researcher role involves hard-coded options for the "right side" of the role or activity. */ @Override FieldOptions getRoleActivityFieldOptions(VitroRequest vreq) throws Exception { - return new ConstantFieldOptions( - "", "Select one", - "http://vivoweb.org/ontology/core#Grant", "Grant", - "http://purl.obolibrary.org/obo/ERO_0000015", "Human Study", - "http://vivoweb.org/ontology/core#Project", "Project", - "http://purl.obolibrary.org/obo/ERO_0000014", "Research Project"); + //UQAM Replacing the above hard coding assigment by a dynamic assigment that takes into account the linguistic context + ConstantFieldOptions filedOptions = GeneratorUtil.buildConstantFieldOptions(vreq, DESCRIBE_QUERY); + return filedOptions; +// return new ConstantFieldOptions( +// "", "Select one", +// "http://vivoweb.org/ontology/core#Grant", "Grant", +// "http://purl.obolibrary.org/obo/ERO_0000015", "Human Study", +// "http://vivoweb.org/ontology/core#Project", "Project", +// "http://purl.obolibrary.org/obo/ERO_0000014", "Research Project"); } - + /* + * UQAM get attributes for this specific subject + */ + private static String DESCRIBE_QUERY = " describe "+ + " " + + " " + + " " + + " "; @Override boolean isShowRoleLabelField() { return true; } /* diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/AddReviewerRoleToPersonGenerator.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/AddReviewerRoleToPersonGenerator.java index b12452d76..e2b2e9706 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/AddReviewerRoleToPersonGenerator.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/AddReviewerRoleToPersonGenerator.java @@ -8,19 +8,19 @@ public class AddReviewerRoleToPersonGenerator extends AddRoleToPersonTwoStageGenerator { - private static String OBJECT_VCLASS_URI = "http://purl.org/ontology/bibo/Document"; + private static String OBJECT_VCLASS_URI = "http://purl.org/ontology/bibo/Document"; @Override String getTemplate() { return "addReviewerRoleToPerson.ftl"; } - //The default activityToRolePredicate and roleToActivityPredicates are + //The default activityToRolePredicate and roleToActivityPredicates are //correct for this subclass so they don't need to be overwritten -/* @Override + /* @Override public String getRoleToActivityPredicate(VitroRequest vreq) { return ""; } -*/ + */ //role type will always be set based on particular form @Override public String getRoleType() { @@ -28,97 +28,172 @@ public String getRoleType() { return "http://vivoweb.org/ontology/core#ReviewerRole"; } + // UQAM Added for buildConstantFieldOptions() call + private static String DESCRIBE_QUERY = " describe "+ + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + "" + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " "; /** Service Provider role involves hard-coded options for the * "right side" of the role or activity. */ @Override -FieldOptions getRoleActivityFieldOptions(VitroRequest vreq) throws Exception { - return new ConstantFieldOptions( - "","Select type", - "http://vivoweb.org/ontology/core#AcademicDepartment","Academic Department", - "http://vivoweb.org/ontology/core#Association","Association", - "http://vivoweb.org/ontology/core#Center","Center", - "http://vivoweb.org/ontology/core#ClinicalOrganization","Clinical Organization", - "http://vivoweb.org/ontology/core#College","College", - "http://vivoweb.org/ontology/core#Committee","Committee", - "http://vivoweb.org/ontology/core#Company","Company", - "http://vivoweb.org/ontology/core#Competition", "Competition", - "http://purl.org/ontology/bibo/Conference", "Conference", - "http://vivoweb.org/ontology/core#ConferenceSeries", "Conference Series", - "http://vivoweb.org/ontology/core#Consortium","Consortium", - "http://vivoweb.org/ontology/core#CoreLaboratory","Core Laboratory", - "http://vivoweb.org/ontology/core#Course", "Course", - "http://vivoweb.org/ontology/core#Department","Department", - "http://vivoweb.org/ontology/core#Division","Division", - "http://purl.org/NET/c4dm/event.owl#Event","Event", - "http://vivoweb.org/ontology/core#EventSeries", "Event Series", - "http://vivoweb.org/ontology/core#Exhibit", "Exhibit", - "http://vivoweb.org/ontology/core#ExtensionUnit","Extension Unit", - "http://vivoweb.org/ontology/core#Foundation","Foundation", - "http://vivoweb.org/ontology/core#FundingOrganization","Funding Organization", - "http://vivoweb.org/ontology/core#GovernmentAgency","Government Agency", - "http://xmlns.com/foaf/0.1/Group","Group", - "http://purl.org/ontology/bibo/Hearing", "Hearing", - "http://vivoweb.org/ontology/core#Hospital","Hospital", - "http://vivoweb.org/ontology/core#Institute","Institute", - "http://purl.org/ontology/bibo/Interview", "Interview", - "http://vivoweb.org/ontology/core#InvitedTalk", "Invited Talk", - "http://vivoweb.org/ontology/core#Laboratory","Laboratory", - "http://vivoweb.org/ontology/core#Library","Library", - "http://purl.obolibrary.org/obo/OBI_0000835","Manufacturer", - "http://vivoweb.org/ontology/core#Meeting", "Meeting", - "http://vivoweb.org/ontology/core#Museum","Museum", - "http://xmlns.com/foaf/0.1/Organization","Organization", - "http://purl.org/ontology/bibo/Performance", "Performance", - "http://vivoweb.org/ontology/core#Presentation", "Presentation", - "http://vivoweb.org/ontology/core#PrivateCompany","Private Company", - "http://vivoweb.org/ontology/core#Program","Program", - "http://vivoweb.org/ontology/core#Publisher","Publisher", - "http://vivoweb.org/ontology/core#ResearchOrganization","Research Organization", - "http://vivoweb.org/ontology/core#School","School", - "http://vivoweb.org/ontology/core#SeminarSeries", "Seminar Series", - "http://vivoweb.org/ontology/core#Team","Team", - "http://vivoweb.org/ontology/core#ServiceProvidingLaboratory","Service Providing Lab", - "http://vivoweb.org/ontology/core#StudentOrganization","Student Organization", - "http://purl.obolibrary.org/obo/ERO_0000565","Technology Transfer Office", - "http://vivoweb.org/ontology/core#University","University", - "http://purl.org/ontology/bibo/Workshop", "Workshop", - "http://vivoweb.org/ontology/core#WorkshopSeries", "Workshop Series"); -} + FieldOptions getRoleActivityFieldOptions(VitroRequest vreq) throws Exception { + + // UQAM Replacing the above hard coding assignment by a dynamic assignment that takes into account the linguistic context + ConstantFieldOptions filedOptions = GeneratorUtil.buildConstantFieldOptions(vreq, DESCRIBE_QUERY); + return filedOptions; + + + // return new ConstantFieldOptions( + // "","Select type", + // "http://vivoweb.org/ontology/core#AcademicDepartment","Academic Department", + // "http://vivoweb.org/ontology/core#Association","Association", + // "http://vivoweb.org/ontology/core#Center","Center", + // "http://vivoweb.org/ontology/core#ClinicalOrganization","Clinical Organization", + // "http://vivoweb.org/ontology/core#College","College", + // "http://vivoweb.org/ontology/core#Committee","Committee", + // "http://vivoweb.org/ontology/core#Company","Company", + // "http://vivoweb.org/ontology/core#Competition", "Competition", + // "http://purl.org/ontology/bibo/Conference", "Conference", + // "http://vivoweb.org/ontology/core#ConferenceSeries", "Conference Series", + // "http://vivoweb.org/ontology/core#Consortium","Consortium", + // "http://vivoweb.org/ontology/core#CoreLaboratory","Core Laboratory", + // "http://vivoweb.org/ontology/core#Course", "Course", + // "http://vivoweb.org/ontology/core#Department","Department", + // "http://vivoweb.org/ontology/core#Division","Division", + // "http://purl.org/NET/c4dm/event.owl#Event","Event", + // "http://vivoweb.org/ontology/core#EventSeries", "Event Series", + // "http://vivoweb.org/ontology/core#Exhibit", "Exhibit", + // "http://vivoweb.org/ontology/core#ExtensionUnit","Extension Unit", + // "http://vivoweb.org/ontology/core#Foundation","Foundation", + // "http://vivoweb.org/ontology/core#FundingOrganization","Funding Organization", + // "http://vivoweb.org/ontology/core#GovernmentAgency","Government Agency", + // "http://xmlns.com/foaf/0.1/Group","Group", + // "http://purl.org/ontology/bibo/Hearing", "Hearing", + // "http://vivoweb.org/ontology/core#Hospital","Hospital", + // "http://vivoweb.org/ontology/core#Institute","Institute", + // "http://purl.org/ontology/bibo/Interview", "Interview", + // "http://vivoweb.org/ontology/core#InvitedTalk", "Invited Talk", + // "http://vivoweb.org/ontology/core#Laboratory","Laboratory", + // "http://vivoweb.org/ontology/core#Library","Library", + // "http://purl.obolibrary.org/obo/OBI_0000835","Manufacturer", + // "http://vivoweb.org/ontology/core#Meeting", "Meeting", + // "http://vivoweb.org/ontology/core#Museum","Museum", + // "http://xmlns.com/foaf/0.1/Organization","Organization", + // "http://purl.org/ontology/bibo/Performance", "Performance", + // "http://vivoweb.org/ontology/core#Presentation", "Presentation", + // "http://vivoweb.org/ontology/core#PrivateCompany","Private Company", + // "http://vivoweb.org/ontology/core#Program","Program", + // "http://vivoweb.org/ontology/core#Publisher","Publisher", + // "http://vivoweb.org/ontology/core#ResearchOrganization","Research Organization", + // "http://vivoweb.org/ontology/core#School","School", + // "http://vivoweb.org/ontology/core#SeminarSeries", "Seminar Series", + // "http://vivoweb.org/ontology/core#Team","Team", + // "http://vivoweb.org/ontology/core#ServiceProvidingLaboratory","Service Providing Lab", + // "http://vivoweb.org/ontology/core#StudentOrganization","Student Organization", + // "http://purl.obolibrary.org/obo/ERO_0000565","Technology Transfer Office", + // "http://vivoweb.org/ontology/core#University","University", + // "http://purl.org/ontology/bibo/Workshop", "Workshop", + // "http://vivoweb.org/ontology/core#WorkshopSeries", "Workshop Series"); + } @Override boolean isShowRoleLabelField(){return true;} diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/GeneratorUtil.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/GeneratorUtil.java new file mode 100644 index 000000000..10f644556 --- /dev/null +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/GeneratorUtil.java @@ -0,0 +1,82 @@ +package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators; + +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; + +import org.apache.jena.query.Query; +import org.apache.jena.query.QueryExecution; +import org.apache.jena.query.QueryExecutionFactory; +import org.apache.jena.query.QueryFactory; +import org.apache.jena.query.QuerySolution; +import org.apache.jena.query.ResultSet; +import org.apache.jena.rdf.model.Model; + +import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.ConstantFieldOptions; +import edu.cornell.mannlib.vitro.webapp.i18n.I18n; +import edu.cornell.mannlib.vitro.webapp.i18n.I18nBundle; +import edu.cornell.mannlib.vitro.webapp.i18n.selection.SelectedLocale; +import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService; +import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceException; +import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceUtils; + +public class GeneratorUtil { + private static String GET_LABEL_QUERY = " " + + "PREFIX rdfs: \n" + + "SELECT DISTINCT ?uri ?label \n" + + "WHERE { \n" + + " ?uri ?label \n" + // + " FILTER (lang(?label) = 'LANGUAGE' ) " + + "} \n" + + " ORDER BY ?label \n" + ; + /* + * UQAM Help to generate the labels of scrollDowm list in proper language + */ + static public ConstantFieldOptions buildConstantFieldOptions(VitroRequest vreq, String DESCRIBE_QUERY) throws Exception { + + List> options = builFieldOptionsList(vreq, DESCRIBE_QUERY); + ConstantFieldOptions filedOptions = new ConstantFieldOptions("" , options); + return filedOptions; + } + /* + * UQAM Help to generate the labels of scrollDowm list in proper language + */ + static public List> builFieldOptionsList(VitroRequest vreq, String DESCRIBE_QUERY) throws Exception { + + I18nBundle i18n = I18n.bundle(vreq); + String i18nSelectType = i18n.text("select_type"); + String selectType = (i18nSelectType == null || i18nSelectType.isEmpty()) ? "Select type" : i18nSelectType ; + Locale lang = SelectedLocale.getCurrentLocale(vreq); + List> options = new ArrayList>(); + List pair = new ArrayList(2); + pair.add(""); + pair.add(selectType); + options.add(pair); + RDFService rdfService = vreq.getRDFService(); + + Model constructedModel = RDFServiceUtils.parseModel( + rdfService.sparqlDescribeQuery(DESCRIBE_QUERY, RDFService.ModelSerializationFormat.N3), + RDFService.ModelSerializationFormat.N3); + + Query query = QueryFactory.create(GET_LABEL_QUERY.replaceAll("LANGUAGE", lang.toString())) ; + QueryExecution qe = QueryExecutionFactory.create(query, constructedModel); + try { + ResultSet results = qe.execSelect(); + + while (results.hasNext()) { + QuerySolution soln = results.nextSolution(); + String uriId = soln.getResource("uri").getURI(); + String label = soln.getLiteral("label").getLexicalForm(); + pair = new ArrayList(2); + pair.add(uriId); + pair.add(label); + options.add(pair); + } + } finally { + qe.close(); + } + return options; + } +} diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/ManageWebpagesForIndividualGenerator.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/ManageWebpagesForIndividualGenerator.java index 1c43cfa1c..1cb8b3f6b 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/ManageWebpagesForIndividualGenerator.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/ManageWebpagesForIndividualGenerator.java @@ -3,6 +3,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.Locale; import java.util.Map; import javax.servlet.http.HttpSession; @@ -26,6 +27,7 @@ import edu.cornell.mannlib.vitro.webapp.dao.jena.QueryUtils; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationUtils; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo; +import edu.cornell.mannlib.vitro.webapp.i18n.selection.SelectedLocale; /** * This is an odd controller that is just drawing a page with links on it. @@ -161,7 +163,9 @@ public EditConfigurationVTwo getEditConfiguration(VitroRequest vreq, HttpSession + " OPTIONAL { ?link rdfs:label ?linkLabel } \n" + " OPTIONAL { ?link core:rank ?rank } \n" + " OPTIONAL { ?link vitro:mostSpecificType ?type } \n" - + " OPTIONAL { ?type rdfs:label ?typeLabel } \n" + + " OPTIONAL { ?type rdfs:label ?typeLabel . \n" + // UQAM Add linguistic control on label + + " FILTER (lang(?typeLabel) = 'LANGUAGE' ) } \n" + "} GROUP BY ?rank ?vcard ?link ?url ?typeLabel \n" + " ORDER BY ?rank"; @@ -175,8 +179,10 @@ private List> getWebpages(String subjectUri, VitroRequest vr Model constructedModel = ModelFactory.createDefaultModel(); rdfService.sparqlConstructQuery(constructStr, constructedModel); - - String queryStr = QueryUtils.subUriForQueryVar(this.getQuery(), "subject", subjectUri); + /* + * UQAM Adjust the getQuery signature for managing the linguistic context + */ + String queryStr = QueryUtils.subUriForQueryVar(this.getQuery(vreq), "subject", subjectUri); log.debug("Query string is: " + queryStr); QueryExecution qe = QueryExecutionFactory.create(queryStr, constructedModel); @@ -205,8 +211,12 @@ protected String getEditForm() { return AddEditWebpageFormGenerator.class.getName(); } - protected String getQuery() { - return WEBPAGE_QUERY; + protected String getQuery(VitroRequest vreq) { + /* + * UQAM Adjust the query to the liguistic context + */ + Locale lang = SelectedLocale.getCurrentLocale(vreq); + return WEBPAGE_QUERY.replaceAll("LANGUAGE", lang.toString()); } protected String getTemplate() { diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/utilities/Describe.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/utilities/Describe.java new file mode 100644 index 000000000..c2c03d5cc --- /dev/null +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/utilities/Describe.java @@ -0,0 +1,36 @@ +package edu.cornell.mannlib.vitro.webapp.utilities; + +import java.util.Iterator; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.jena.ontology.OntModel; +import org.apache.jena.rdf.model.ModelFactory; +import org.apache.jena.rdf.model.RDFNode; +import org.apache.jena.rdf.model.ResourceFactory; +import org.apache.jena.rdf.model.Statement; +import org.apache.jena.rdf.model.StmtIterator; +import org.apache.jena.vocabulary.RDFS; + + +public class Describe { + private static final Log log = LogFactory.getLog(Describe.class.getName()); + + public static void main(String[] args) { + OntModel model = ModelFactory.createOntologyModel(); + model.read("C:\\VIVO-Trad-ecosysteme\\vivo\\home\\rdf\\applicationMetadata\\firsttime\\classgroups_fr_CA.rdf") ; + model.read("C:\\VIVO-Trad-ecosysteme\\vivo\\home\\rdf\\applicationMetadata\\firsttime\\classgroups.rdf") ; + Describe.showVitroClassGroupequipmentLabels(model,"test"); + System.out.println("Done!"); + } + + private static void showVitroClassGroupequipmentLabels(OntModel model, String message) { + String uri = "http://vivoweb.org/ontology#vitroClassGroupequipment"; + List stmts = model.listStatements(ResourceFactory.createResource(uri), RDFS.label, (RDFNode)null).toList(); + for (Iterator iterator = stmts.iterator(); iterator.hasNext();) { + Statement statement = (Statement) iterator.next(); + log.debug("\t\t"+message + " " +statement); + } + } +} diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/visualization/capabilitymap/CapabilityMapRequestHandler.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/visualization/capabilitymap/CapabilityMapRequestHandler.java index 07a96f299..d18e204c8 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/visualization/capabilitymap/CapabilityMapRequestHandler.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/visualization/capabilitymap/CapabilityMapRequestHandler.java @@ -54,10 +54,16 @@ public ResponseValues generateVisualizationForShortURLRequests(Map organizationLabels = VisualizationCaches.organizationLabels.getNoWait(vitroRequest.getRDFService()); + RDFService rdfService = vitroRequest.getRDFService(); + rdfService.setVitroRequest(vitroRequest); + // VisualizationCaches.rebuildAll(rdfService); + // VisualizationCaches.conceptToLabel.build(rdfService); +// ConceptLabelMap conceptLabelMap = VisualizationCaches.conceptToLabel.getNoWait(rdfService); + // UQAM Refresh all memory models with appropriate liguistic labels + ConceptLabelMap conceptLabelMap = VisualizationCaches.conceptToLabel.get(rdfService, true, true); + ConceptPeopleMap conceptPeopleMap = VisualizationCaches.conceptToPeopleMap.getNoWait(rdfService); + OrganizationPeopleMap organizationPeopleMap = VisualizationCaches.organisationToPeopleMap.getNoWait(rdfService); + Map organizationLabels = VisualizationCaches.organizationLabels.getNoWait(rdfService); String data = vitroRequest.getParameter("data"); if (!StringUtils.isEmpty(data)) { diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/visualization/utilities/CachingRDFServiceExecutor.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/visualization/utilities/CachingRDFServiceExecutor.java index ddbc68aa7..b559a991e 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/visualization/utilities/CachingRDFServiceExecutor.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/visualization/utilities/CachingRDFServiceExecutor.java @@ -2,8 +2,10 @@ package edu.cornell.mannlib.vitro.webapp.visualization.utilities; +import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService; import edu.cornell.mannlib.vitro.webapp.utils.threads.VitroBackgroundThread; +import edu.cornell.mannlib.vitro.webapp.visualization.model.ConceptLabelMap; import java.util.Date; import java.util.HashMap; @@ -85,7 +87,69 @@ public synchronized T get(RDFService rdfService, boolean allowWaits) { if (backgroundTask != null && backgroundTask.isDone()) { completeBackgroundTask(); } + // If we have cached results + if (cachedResults != null) { + // If the background service exists, and the cache is considered invalid + + if (backgroundRDFService != null && resultBuilder.invalidateCache(System.currentTimeMillis() - lastCacheTime)) { + // In most cases, only wait for half a second + long waitFor = 500; + + if (backgroundTask == null) { + // Start the background task to refresh the cache + startBackgroundTask(backgroundRDFService); + // As we've just started the background task, allow a wait time of 1 second + waitFor = 1000; + } + + // See if we expect it to complete in time, and if so, wait for it + if (allowWaits && isExpectedToCompleteIn(waitFor)) { + completeBackgroundTask(waitFor); + } + + } + } else { + // No cached results, so fetch the results using any available RDF service + if (rdfService != null) { + startBackgroundTask(rdfService); + } else if (backgroundRDFService != null) { + startBackgroundTask(backgroundRDFService); + } else { + throw new RuntimeException("Can't execute without an RDF Service"); + } + + // As there are no cached results, wait for an answer regardless of the RDF service used + completeBackgroundTask(); + } + return cachedResults; + } + + public synchronized T get(RDFService rdfService, boolean allowWaits, boolean force) { + /* + * UQAM + * Force la regénération du résultat + */ + if (force) { + try { + String backLang = backgroundRDFService.getVitroRequest().getLocale().getLanguage(); + String srvLang = rdfService.getVitroRequest().getLocale().getLanguage(); + if (!backLang.equals(srvLang)) { + backgroundRDFService.setVitroRequest(rdfService.getVitroRequest()); + startBackgroundTask(rdfService); + completeBackgroundTask(); + } + } catch (Exception e) { + backgroundRDFService.setVitroRequest(rdfService.getVitroRequest()); + startBackgroundTask(rdfService); + completeBackgroundTask(); + } + return cachedResults; + } + // First, check if there are results from the previous background task, and update the cache + if (backgroundTask != null && backgroundTask.isDone()) { + completeBackgroundTask(); + } // If we have cached results if (cachedResults != null) { // If the background service exists, and the cache is considered invalid diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/visualization/utilities/VisualizationCaches.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/visualization/utilities/VisualizationCaches.java index 6206e126e..a1704ce1d 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/visualization/utilities/VisualizationCaches.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/visualization/utilities/VisualizationCaches.java @@ -9,6 +9,8 @@ import org.apache.jena.rdf.model.Model; import org.apache.jena.rdf.model.ModelFactory; import org.apache.jena.rdf.model.Resource; + +import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService; import edu.cornell.mannlib.vitro.webapp.rdfservice.ResultSetConsumer; import edu.cornell.mannlib.vitro.webapp.visualization.constants.QueryConstants; @@ -390,6 +392,13 @@ protected void processQuerySolution(QuerySolution qs) { new CachingRDFServiceExecutor.RDFServiceCallable() { @Override protected ConceptLabelMap callWithService(RDFService rdfService) throws Exception { + VitroRequest vreq = rdfService.getVitroRequest(); + String langCtx = "en-US"; + // UQAM Adjust to linguistic context + try { + langCtx = vreq.getLocale().getLanguage() + "-"+vreq.getLocale().getCountry(); + } catch (Exception e) { + } String query = QueryConstants.getSparqlPrefixQuery() + "SELECT ?concept ?label\n" + "WHERE\n" + @@ -398,13 +407,13 @@ protected ConceptLabelMap callWithService(RDFService rdfService) throws Exceptio " ?person core:hasResearchArea ?concept .\n" + " ?concept a skos:Concept .\n" + " ?concept rdfs:label ?label .\n" + + " FILTER (lang(?label) = '" + langCtx+"' ) \n" + "}\n"; // final Map map = new HashMap<>(); final ConceptLabelMap map = new ConceptLabelMap(); - + rdfService.sparqlSelectQuery(query, new ResultSetConsumer() { - @Override protected void processQuerySolution(QuerySolution qs) { String conceptURI = qs.getResource("concept").getURI().intern(); String label = qs.getLiteral("label").getString().intern();