hmrc_ir_mark_calculator 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 05ea7f0cdf02514c42fe9ba0f8a41522cdc5d51c16966a5aca08859a5c68810f
4
+ data.tar.gz: 3006f438daec9513327793cc557c99b61b6d213a79c2cf38c537c3a980ad60bf
5
+ SHA512:
6
+ metadata.gz: 786f1375f000b7c1fc62c589ab2f70c5ad0d7ab1bb129f845a3f8a3106aa0f83bfa74e384f22074c6865d2a7b9ac5bee4980939f3bad39e26af51ba1e5a08a8b
7
+ data.tar.gz: e3763990cb5c901c41025a4f2b265144d37cf5e231d60f1268650ce6e2e50cc0c321e681c7713542224629efc1a5f0782b30197888a7c3928f300ef36013c79b
data/README.md ADDED
@@ -0,0 +1,51 @@
1
+ # Building the project
2
+
3
+ ### Step 1
4
+
5
+ Compile the Java code into Java class files by running the following in the root of the project directory
6
+
7
+ `javac -cp 'lib/dependencies/*' java-src/*.java`
8
+
9
+ ### Step 2
10
+
11
+ Create the build/ directory
12
+
13
+ `mkdir -p build/uk/gov/hmrc/mark`
14
+
15
+ ### Step 3
16
+
17
+ Move the class files into the build directory
18
+ `mv java-src/*.class build/uk/gov/hmrc/mark`
19
+
20
+ ### Step 4
21
+
22
+ Bundle the files into a .jar file
23
+ `cd build/ && jar cfv markcalc.jar uk/gov/hmrc/mark && cd -`
24
+
25
+ ### Step 5
26
+
27
+ Move the new .jar file into the lib/ directory
28
+ `mv build/markcalc.jar lib/dependencies/`
29
+
30
+ ### Step 6
31
+
32
+ Delete the build directory
33
+ `rm -rf build/`
34
+
35
+ ### Step 7
36
+
37
+ Update and add new tests to cover changes
38
+
39
+ ### Step 8
40
+
41
+ Run specs `rake test`
42
+
43
+ ### Step 9
44
+
45
+ Bump the version of the gem in the `.gemspec` file
46
+
47
+ #### Note: All commands must be run in the root of the project
48
+
49
+ ## Dependencies
50
+
51
+ You will need Java 17.0.1 or later installed.
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'logger'
4
+
5
+ # Logging for the calculator
6
+ # Provides an escape hatch to set a custom logger
7
+ # otherwise the default ruby logger will be used
8
+ #
9
+ module IrMarkLogger
10
+ attr_writer :logger
11
+
12
+ def logger
13
+ @logger ||= Logger.new($stdout).tap do |log|
14
+ log.progname = name
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'open3'
4
+ require 'hmrc_ir_mark_calculator/logger'
5
+
6
+ # A Java wrapper that creates an IRmark from an HMRC submission file
7
+ # It accepts the path to the file, which should contain the same contents
8
+ # being sent to HMRC, inlcuding the GovTalkMessage, and body
9
+ #
10
+ # It needs the absolute path to the Full CT600 File that has been prepared
11
+ # for submission. Providing a relative path may not work as expected.
12
+ class HmrcIrMarkCalculator
13
+ attr_reader :file_path
14
+
15
+ extend IrMarkLogger
16
+
17
+ def initialize(file_path)
18
+ @file_path = file_path
19
+ end
20
+
21
+ def run
22
+ self.class.logger.info("Using #{cmd} to generate IRmark for file #{file_path}")
23
+
24
+ create_mark
25
+ rescue StandardError => e
26
+ handle_error(e.message)
27
+ end
28
+
29
+ private
30
+
31
+ def create_mark
32
+ Open3.popen3(cmd) do |_stdin, stdout, stderr, _wait_thr|
33
+ original_result = stdout.read
34
+
35
+ original_result =~ /{(.*)}/
36
+ result = ::Regexp.last_match(1)
37
+
38
+ return handle_success(result) unless result.nil?
39
+
40
+ error = stderr&.read
41
+ return handle_error(error, original_result)
42
+ end
43
+ end
44
+
45
+ def handle_error(error, original_result = '')
46
+ self.class.logger.error(
47
+ "There was an error generating the IRmark for file #{file_path}. #{error} #{original_result}"
48
+ )
49
+ { error: error, success: false }
50
+ end
51
+
52
+ def handle_success(result)
53
+ self.class.logger.info("Output of the IRmark for file #{file_path} is #{result}")
54
+
55
+ { result: result, success: true }
56
+ end
57
+
58
+ def cmd
59
+ "#{change_directory} && #{set_env!} && #{ir_mark}"
60
+ end
61
+
62
+ def set_env!
63
+ "export CLASSPATH='dependencies/jce-jdk13-114.jar:dependencies/xmlsec-1.4.1.jar:"\
64
+ "dependencies/xalan_enhanced.jar:dependencies/commons-logging-1.1.1.jar:dependencies/markcalc.jar'"
65
+ end
66
+
67
+ def ir_mark
68
+ "java uk.gov.hmrc.mark.IRMarkCalculator #{file_path}"
69
+ end
70
+
71
+ def change_directory
72
+ "cd #{dir}"
73
+ end
74
+
75
+ def dir
76
+ __dir__
77
+ end
78
+ end
metadata ADDED
@@ -0,0 +1,49 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hmrc_ir_mark_calculator
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Midorya Izuku
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-03-06 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: IRmark calculator for HMRC Corporate Tax Submissions
14
+ email: midorya@izuku.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - README.md
20
+ - lib/dependencies/commons-logging-1.1.1.jar
21
+ - lib/dependencies/jce-jdk13-114.jar
22
+ - lib/dependencies/markcalc.jar
23
+ - lib/dependencies/xalan_enhanced.jar
24
+ - lib/dependencies/xmlsec-1.4.1.jar
25
+ - lib/hmrc_ir_mark_calculator.rb
26
+ - lib/hmrc_ir_mark_calculator/logger.rb
27
+ homepage: https://midoryaizuku.com
28
+ licenses: []
29
+ metadata: {}
30
+ post_install_message:
31
+ rdoc_options: []
32
+ require_paths:
33
+ - lib
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ required_rubygems_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ requirements: []
45
+ rubygems_version: 3.4.19
46
+ signing_key:
47
+ specification_version: 4
48
+ summary: IRmark calculator for HMRC Corporate Tax Submissions
49
+ test_files: []