Class: WurcsVerify

Inherits:
Object
  • Object
show all
Defined in:
lib/wurcsverify.rb

Constant Summary collapse

@@gtc_version =
"1.2.14"
@@v1215 =
"1.2.15"
@@v1216 =
"1.2.16"
@@v130 =
"1.3.0"
@@v131 =
"1.3.1"

Instance Method Summary collapse

Constructor Details

#initializeWurcsVerify

Initializes the WurcsVerify class.

Sets up custom class loaders for different versions of the WURCS Framework. Loads the WURCSValidator classes for each version.



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/wurcsverify.rb', line 24

def initialize
    @wfw_glytoucan_loader = self.create_custom_classloader("jar/wurcsframework-" + @@gtc_version + ".jar")
    @wfw_v131_loader = self.create_custom_classloader("jar/wurcsframework-" + @@v131 + ".jar")
    @wfw_v130_loader = self.create_custom_classloader("jar/wurcsframework-" + @@v130 + ".jar")
    @wfw_v1216_loader = self.create_custom_classloader("jar/wurcsframework-" + @@v1216 + ".jar")
    @wfw_v1215_loader = self.create_custom_classloader("jar/wurcsframework-" + @@v1215 + ".jar")
    @validator_glytoucan = java.lang.Class.forName("org.glycoinfo.WURCSFramework.util.validation.WURCSValidator",true,@wfw_glytoucan_loader)
    @validator_v131 = java.lang.Class.forName("org.glycoinfo.WURCSFramework.util.validation.WURCSValidator", true, @wfw_v131_loader)
    @validator_v130 = java.lang.Class.forName("org.glycoinfo.WURCSFramework.util.validation.WURCSValidator", true, @wfw_v130_loader)
    @validator_v1216 = java.lang.Class.forName("org.glycoinfo.WURCSFramework.util.validation.WURCSValidator", true, @wfw_v1216_loader)
    @validator_v1215 = java.lang.Class.forName("org.glycoinfo.WURCSFramework.util.validation.WURCSValidator", true, @wfw_v1215_loader)
end

Instance Method Details

#create_custom_classloader(jar_path) ⇒ URLClassLoader

Creates a custom class loader for a given JAR file.

Parameters:

  • jar_path (String)

    The path to the JAR file.

Returns:

  • (URLClassLoader)

    The custom class loader.



41
42
43
44
45
# File 'lib/wurcsverify.rb', line 41

def create_custom_classloader(jar_path)
  absolute_path = File.dirname(File.expand_path(__FILE__)) + "/" + jar_path
  url = URL.new("file:#{absolute_path}")
  URLClassLoader.newInstance([url].to_java(URL), java.lang.Thread.currentThread.getContextClassLoader)
end

#dovalidator(validator, version) ⇒ Hash

Performs validation and returns basic reports.

Parameters:

  • validator (Object)

    The validator instance.

  • version (String)

    The version of the WURCS Framework.

Returns:

  • (Hash)

    The validation report.



120
121
122
123
124
125
# File 'lib/wurcsverify.rb', line 120

def dovalidator(validator, version)
  return { 
    "VALIDATOR" => ["WURCSFramework-" + version],
    "Report" => validator.getReport().getResults() 
  }
end

#dovalidatorv3(validator, version) ⇒ Hash

Performs validation and returns detailed reports for v3 style.

Parameters:

  • validator (Object)

    The validator instance.

  • version (String)

    The version of the WURCS Framework.

Returns:

  • (Hash)

    The validation report.



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/wurcsverify.rb', line 95

def dovalidatorv3(validator, version)
  if validator.getReport().respond_to?(:isStandardized)
    flag = validator.getReport().isStandardized()
  else
    flag = "undef"
  end
  reports = { 
    "VALIDATOR" => ["WURCSFramework-" + version],
    "WARNING" => validator.getReport().hasWarning(),
    "FLAG" => flag,
    "ERROR" => validator.getReport().hasError(),
    "UNVERIFIABLE" => validator.getReport().hasUnverifiable() 
  }
  return { 
    "message" => reports,
    "StandardWURCS" => validator.getReport().standard_string(),
    "RESULTS" => validator.getReport().getResults() 
  }
end

#validatorVerify(w, style) ⇒ Hash

Verifies the WURCS string using different versions of the WURCS Framework.

Parameters:

  • w (String)

    The WURCS string to verify.

  • style (String)

    The verification style (“v3” or “wfw”).

Returns:

  • (Hash)

    The verification results.



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/wurcsverify.rb', line 52

def validatorVerify(w, style)
  v_glytoucan = @validator_glytoucan.new_instance
  v_glytoucan.start(w)

  v_131 = @validator_v131.new_instance
  v_131.start(w)

  v_130 = @validator_v130.new_instance
  v_130.start(w)

  v_1216 = @validator_v1216.new_instance
  v_1216.start(w)

  v_1215 = @validator_v1215.new_instance
  v_1215.start(w)

  if (style == "v3")
    ret = {
      @@gtc_version => self.dovalidatorv3(v_glytoucan, @@gtc_version),
      @@v131 => self.dovalidatorv3(v_131, @@v131),
      @@v130 => self.dovalidatorv3(v_130, @@v130),
      @@v1215 => self.dovalidatorv3(v_1215, @@v1215),
      @@v1216 => self.dovalidatorv3(v_1216, @@v1216)
    }
  elsif (style == "wfw")
    ret = {
      @@gtc_version => self.dovalidator(v_glytoucan, @@gtc_version),
      @@v131 => self.dovalidator(v_131, @@v131),
      @@v130 => self.dovalidator(v_130, @@v130),
      @@v1215 => self.dovalidator(v_1215, @@v1215),
      @@v1216 => self.dovalidator(v_1216, @@v1216)
    }
  else
    pp "strange second paramerters"
  end
  return ret
end