Mentions légales du service

Skip to content
Snippets Groups Projects
Commit c6356bb7 authored by BOULLE Olivier's avatar BOULLE Olivier
Browse files

updated new documents index management

parent 1b2d93ff
No related branches found
No related tags found
No related merge requests found
......@@ -96,30 +96,18 @@ then
exit 1
fi
#get list of current documents in the container
doc_list=$(find "$container_path"/* -maxdepth 0 -type d -printf "%f\n")
#if none, new document of index 0
if [ -z "$doc_list" ]; then
doc_index=0
else
#else index equals to max index +1
max_index=$(echo "${doc_list[*]}" | sort -nr | head -n1)
doc_index=$((max_index+1))
fi
# add a new document in the xml file and get its new index
doc_index=$(add_document "$container_path")
stored_document_path="$container_path"/$doc_index
mkdir -p "$stored_document_path"
add_document "$container_path" $doc_index
#----Source Encoding----#
# get the fragment length from the container options
frag_length=$(get_container_param $container_path "frag_length")
#----Source Encoding----#
assembly_type=$(get_container_param $container_path "assembly_type")
source_encoding_script="$project_dir"/source_encoding/source_encoding.py
......
......@@ -71,21 +71,34 @@ set_container_param() {
add_document() {
#add a new document to the container
#$1 container path
#$2 document index
#save operation in logs
log_metadata_call "$1" add_document "$2"
log_metadata_call "$1" add_document
#define the new document index
index_list=$(xmlstarlet sel -t -v "/container_metadata/documents/document/@id" "$1"/$meta_file_name)
#if existing index list is none, new document has index 0
if [ -z "$index_list" ]; then
doc_index="0"
else
#max existing index +1
doc_index=$(($(echo "${index_list[*]}" | sort -nr | head -n1)+1))
fi
#add a document then add the attribute 'index' for all documents wo attribute (should only be the added one)
xmlstarlet edit -L -s "/container_metadata/documents" --type elem --name document \
--insert "/container_metadata/documents/document[not(@id)]" --type attr --name id --value "$2" \
--insert "/container_metadata/documents/document[not(@id)]" --type attr --name id --value $doc_index \
"$1"/$meta_file_name
#add the creation date
add_doc_param $1 $2 "creation_date" "$(date)"
add_doc_param $1 $doc_index "creation_date" "$(date)"
#----Update number of documents----#
number_doc=$(get_container_param "$1" "number_of_documents")
set_container_param "$1" "number_of_documents" $((number_doc+1))
#return the index of the new document
echo $doc_index
}
......@@ -150,4 +163,3 @@ get_all_doc_param() {
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment