Class: Packages::Maven::Metadata::CreateVersionsXmlService

Inherits:
BaseCreateXmlService show all
Defined in:
app/services/packages/maven/metadata/create_versions_xml_service.rb

Constant Summary collapse

XPATH_VERSIONING =
'//metadata/versioning'
XPATH_VERSIONS =
'//versions'
XPATH_VERSION =
'//version'
XPATH_LATEST =
'//latest'
XPATH_RELEASE =
'//release'
XPATH_LAST_UPDATED =
'//lastUpdated'
EMPTY_VERSIONS_PAYLOAD =
{
  changes_exist: true,
  empty_versions: true
}.freeze

Constants inherited from BaseCreateXmlService

BaseCreateXmlService::INDENT_SPACE

Instance Method Summary collapse

Methods inherited from BaseCreateXmlService

#initialize

Methods included from Gitlab::Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Constructor Details

This class inherits a constructor from Packages::Maven::Metadata::BaseCreateXmlService

Instance Method Details

#executeObject


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/services/packages/maven/metadata/create_versions_xml_service.rb', line 19

def execute
  return ServiceResponse.error(message: 'package not set') unless @package
  return ServiceResponse.error(message: 'metadata_content not set') unless @metadata_content
  return ServiceResponse.error(message: 'metadata_content is invalid') unless 
  return ServiceResponse.success(payload: EMPTY_VERSIONS_PAYLOAD) if versions_from_database.empty?

  changes_exist = false
  changes_exist = true if update_versions_list
  changes_exist = true if update_latest
  changes_exist = true if update_release
  update_last_updated_timestamp if changes_exist

  payload = { changes_exist: changes_exist, empty_versions: false }
  payload[:metadata_content] = xml_doc.to_xml(indent: INDENT_SPACE) if changes_exist

  ServiceResponse.success(payload: payload)
end