Module: NexusCli::CustomMetadataActions

Included in:
ProRemote
Defined in:
lib/nexus_cli/mixins/pro/custom_metadata_actions.rb

Overview

Author:

Instance Method Summary collapse

Instance Method Details

#clear_artifact_custom_info(coordinates) ⇒ Object

Clears all custom metadata from an artifact

Parameters:

  • The (String)

    GAVE string of the artifact



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/nexus_cli/mixins/pro/custom_metadata_actions.rb', line 47

def clear_artifact_custom_info(coordinates)
  get_artifact_custom_info(coordinates) # Check that artifact has custom metadata
  artifact = Artifact.new(coordinates)
  encoded_string = N3Metadata::create_base64_subject(artifact)
  response = nexus.post(nexus_url("service/local/index/custom_metadata/#{configuration['repository']}/#{encoded_string}"), :body => , :header => DEFAULT_CONTENT_TYPE_HEADER)
  case response.status
  when 201
    return true
  else
    raise UnexpectedStatusCodeException.new(response.status)
  end
end

#get_artifact_custom_info(coordinates) ⇒ Object

Gets the custom metadata for an artifact in a simplified XML format

Parameters:

  • coordinates (String)

    The GAVE string of the artifact



29
30
31
# File 'lib/nexus_cli/mixins/pro/custom_metadata_actions.rb', line 29

def get_artifact_custom_info(coordinates)
  N3Metadata::convert_result_to_simple_xml(get_artifact_custom_info_raw(coordinates))
end

#get_artifact_custom_info_raw(coordinates) ⇒ Object

Gets the custom metadata for an artifact

Parameters:

  • coordinates (String)

    The GAVE string of the artifact



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/nexus_cli/mixins/pro/custom_metadata_actions.rb', line 8

def get_artifact_custom_info_raw(coordinates)
  artifact = Artifact.new(coordinates)
  encoded_string = N3Metadata::create_base64_subject(artifact)
  response = nexus.get(nexus_url("service/local/index/custom_metadata/#{configuration['repository']}/#{encoded_string}"))
  case response.status
  when 200
    if N3Metadata::missing_custom_metadata?(response.content)
      raise N3NotFoundException
    else
      return response.content
    end
  when 404
    raise ArtifactNotFoundException
  else
    raise UnexpectedStatusCodeException.new(response.status)
  end
end

#search_artifacts_custom(*params) ⇒ Object

Searches for artifacts using custom metadata

Parameters:

  • *params (Array)

    The array of key:type:value strings



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/nexus_cli/mixins/pro/custom_metadata_actions.rb', line 63

def search_artifacts_custom(*params)
  nodesets = Array.new
  (*params).each do |param|
    response = nexus.get(nexus_url("service/local/search/m2/freeform"), :query => {:p => param[0], :t => param[1], :v => param[2]})
    case response.status
    when 200
      nodesets.push(REXML::Document.new(response.body).elements["/search-results/data"])
    when 400
      raise BadSearchRequestException
    when 404
      raise ArtifactNotFoundException
    else
      raise UnexpectedStatusCodeException.new(response.status)
    end
  end
  # Perform array intersection across all NodeSets for the final common set.
  result = nodesets.inject(nodesets.first) {|memo, nodeset| get_common_artifact_set(memo, nodeset)}
  formatter = REXML::Formatters::Pretty.new(4)
  formatter.compact = true
  return result.nil? ? "" : formatter.write(result, "")
end

#update_artifact_custom_info(coordinates, *params) ⇒ Object

Updates custom metadata for an artifact

Parameters:

  • coordinates (String)

    The GAVE string of the artifact

  • *params (Array)

    The array of key:value strings



37
38
39
40
41
42
# File 'lib/nexus_cli/mixins/pro/custom_metadata_actions.rb', line 37

def update_artifact_custom_info(coordinates, *params)
  target_n3 = (*params)
  nexus_n3 = (coordinates)

  (coordinates, nexus_n3, target_n3)
end