Example #1
0
def stagingManifest():

    if request.method == 'GET':
        return redirect("/tasks/createManifest", code=302)

    if request.method == 'POST':
        # objMeta initial model
        form_data = {
        'id' : request.form['objID'],
        'label' : request.form['objLabel'],
        'policy' : str(json.loads(request.form['lockDown'])['object']),
        'content_type' : "WSUDOR_"+str(json.loads(request.form['contentModel'])['object']).replace('info:fedora/CM:',''),
        'object_relationships' : [
            json.loads(request.form['isDiscoverable']),
            json.loads(request.form['lockDown']),
            json.loads(request.form['contentModel'])
        ],
        'datastreams' : []
        }

        # extract datastreams
        f = request.form
        counter = 1
        while True:
            temp_dictionary = {}
            flag = True
            for key in f.keys():
                # look for number and append each one that matches current number to a dictionary
                if key.endswith(str(counter)):
                    flag = False
                    # key_temp = re.sub('\_'+str(counter)+'$', '', key)
                    key_temp = key
                    temp_dictionary[key_temp] = f[key]
                    if key.startswith('isRepresentedBy'):
                        form_data['isRepresentedBy'] = temp_dictionary['dsID_'+str(counter)]
                        temp_dictionary.pop(key, None)

            if flag:
                break
            form_data['datastreams'].append(temp_dictionary)

            objMeta = ObjMeta(**form_data)
            session['objMetaManifestData'] = form_data
            objMeta.downloadFile(form_data)
            counter = counter + 1

        return render_template("stagingManifest.html", form_data=form_data)
Example #2
0
def createBag_create():	

	def abort(msg):
		# rollback changes?
		return msg


	# get username
	username = session['username']			
	print request.form
	form_results = request.form

	
	# make output dir
	try:
		print "Making directory..."
		# os.mkdir(form_results['outputLocation'])
	except:
		return abort("Directory already exists or could permissions restrict")


	# instantiate objMeta instance
	handle = ObjMeta(**{
			"id" : form_results['objID'],
			"label" : form_results['objLabel']			
		})

	# get content type
	content_rels = form_results['hasContentModel']
	# this is the price of WSUDOR_ContentTypes and Fedora CM:* content types...
	wct = "WSUDOR_"+json.loads(content_rels)['object'].split(":")[-1]
	print "WSUDOR Content Type:",wct
	handle.content_type = wct

	

	# debug
	print handle.toJSON()
	return handle.displayJSONWeb()
Example #3
0
def createObj_worker():

    form_data = request.form
    print form_data

    # instantiate object with quick variables
    known_values = {
        "id": form_data["pid"],
        "identifier": form_data["pid"].split(":")[-1],
        "label": form_data["label"],
        "content_type": "WSUDOR_%s" % (form_data["CM"]),
        "policy": "%s" % (form_data["policy"]),
    }

    # instantiate ObjMeta object
    om_handle = ObjMeta(**known_values)

    # show relationships
    om_handle.object_relationships = [
        {
            "predicate": "http://digital.library.wayne.edu/fedora/objects/wayne:WSUDOR-Fedora-Relations/datastreams/RELATIONS/content/hasSecurityPolicy",
            "object": "info:fedora/%s" % (form_data["policy"]),
        },
        {
            "predicate": "http://digital.library.wayne.edu/fedora/objects/wayne:WSUDOR-Fedora-Relations/datastreams/RELATIONS/content/hasSecurityPolicy",
            "object": "info:fedora/%s" % (form_data["policy"]),
        },
    ]

    # prepare new working dir & recall original
    working_dir = "/tmp/Ouroboros/" + str(uuid.uuid4())
    print "creating working dir at", working_dir
    # create if doesn't exist
    if not os.path.exists(working_dir):
        os.mkdir(working_dir)
    os.system("mkdir %s/datastreams" % (working_dir))

    # write objMeta
    print "writing:", om_handle.toJSON()
    om_handle.writeToFile("%s/objMeta.json" % (working_dir))

    if "bagify" in form_data:
        # bagify
        print "bagifying"
        bag = bagit.make_bag("%s" % (working_dir), {"Object PID": form_data["pid"]})

        # ingest
    if "ingest" in form_data:

        # purge if already exists
        if "purge" in form_data:
            try:
                print "purging object"
                fedora_handle.purge_object(form_data["pid"])
            except:
                print "object not found, skipping purge"

                # bagify
        if "bagify" not in form_data:
            print "bagifying"
            bag = bagit.make_bag("%s" % (working_dir), {"Object PID": form_data["pid"]})

            # open new handle
        bag_handle = WSUDOR_ContentTypes.WSUDOR_GenObject(payload=working_dir, object_type="bag")
        ingest_result = bag_handle.ingestBag()

        # render
        return render_template(
            "createBag_confirm.html", status="result for %s was %s" % (form_data["pid"], ingest_result)
        )

    else:
        return render_template("createBag_confirm.html", status=working_dir)
Example #4
0
def downloadManifest():
	if request.method == 'POST':
		form_data = session['objMetaManifestData']
		objMeta = ObjMeta(**form_data)
		return objMeta.downloadFile(form_data)
Example #5
0
def previewManifest():
	if request.method == 'POST':
		form_data = session['objMetaManifestData']
		objMeta = ObjMeta(**form_data)
		return objMeta.displayJSONWeb(form_data)
Example #6
0
def createContainer_worker():
	
	form_data = request.form
	print form_data

	unique_identifier = "LearningObject_%s" % str(uuid.uuid4())
	pid = "wayne:"+unique_identifier

	# instantiate object with quick variables
	known_values = {
		"id":pid,
		"identifier":unique_identifier,
		"label":form_data['label'],
		"description":form_data['description'],
		"creator":form_data['creator'],
		"date":form_data['date'],
		"content_type":"WSUDOR_LearningObject", 
		"policy":"info:fedora/wayne:WSUDORSecurity-permit-apia-unrestricted",
	}

	# instantiate ObjMeta object
	om_handle = ObjMeta(**known_values)

	# show relationships
	om_handle.object_relationships = [		
		{
			"predicate": "info:fedora/fedora-system:def/relations-external#isMemberOfCollection",
			"object": form_data['collection']
		},
		{
			"predicate": "http://digital.library.wayne.edu/fedora/objects/wayne:WSUDOR-Fedora-Relations/datastreams/RELATIONS/content/hasParent",
			"object": form_data['collection']
		},		
		{
			"predicate": "http://digital.library.wayne.edu/fedora/objects/wayne:WSUDOR-Fedora-Relations/datastreams/RELATIONS/content/isDiscoverable",
			"object": "info:fedora/True"
		},
		{
			"predicate": "info:fedora/fedora-system:def/relations-external#hasContentModel",
			"object": "info:fedora/CM:LearningObject"
		},
		{
			"predicate": "http://digital.library.wayne.edu/fedora/objects/wayne:WSUDOR-Fedora-Relations/datastreams/RELATIONS/content/preferredContentModel",
			"object": "info:fedora/CM:Container"
		},
		{
			"predicate": "http://digital.library.wayne.edu/fedora/objects/wayne:WSUDOR-Fedora-Relations/datastreams/RELATIONS/content/hasSecurityPolicy",
			"object": "info:fedora/wayne:WSUDORSecurity-permit-apia-unrestricted"
		}
	]

	# add optional associated objects
	if "associated_objects" in form_data:
		print "writing associated object relationships"
		associated_objects = [obj.strip() for obj in form_data['associated_objects'].split(',')]
		for obj in associated_objects:
			if obj != '':
				om_handle.object_relationships.append({
					"predicate":"http://digital.library.wayne.edu/fedora/objects/wayne:WSUDOR-Fedora-Relations/datastreams/RELATIONS/content/learningObjectFor",
					"object": "info:fedora/%s" % obj
				})

	# prepare new working dir & recall original
	working_dir = "/tmp/Ouroboros/"+str(uuid.uuid4())
	print "creating working dir at", working_dir
	# create if doesn't exist
	if not os.path.exists(working_dir):
		os.mkdir(working_dir)			
	os.system("mkdir %s/datastreams" % (working_dir))

	# write custom MODS
	
	# prepare subjects
	subjects = [subject.strip() for subject in form_data['subjects'].split(",")]
	subject_string = ''
	for subject in subjects:
		if subject != '':
			subject_string += '<mods:subject authority="lcsh"><mods:topic>%s</mods:topic></mods:subject>' % subject

	raw_MODS = '''<?xml version="1.0" encoding="utf-8"?>
<mods:mods xmlns:mods="http://www.loc.gov/mods/v3" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="3.4" xsi:schemaLocation="http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-4.xsd">
  <mods:titleInfo>
	<mods:title>%(label)s</mods:title>
  </mods:titleInfo>
  <mods:abstract>%(description)s</mods:abstract>
  %(subject_string)s
  <mods:name authority="local" type="person">
	<mods:namePart>%(creator)s</mods:namePart>
	<mods:role>
	  <mods:roleTerm authority="marcrelator" type="text">creator</mods:roleTerm>
	</mods:role>
  </mods:name>
  <mods:originInfo>
	<mods:dateIssued encoding="w3cdtf" keyDate="yes">%(date)s</mods:dateIssued>
  </mods:originInfo>
  <mods:identifier type="local">%(identifier)s</mods:identifier>
  <mods:extension>
	<PID>%(id)s</PID>
  </mods:extension>
  <mods:accessCondition type="useAndReproduction">%(rights)s</mods:accessCondition>
</mods:mods>
	''' % {
			'label':om_handle.label,
			'description':om_handle.description,
			'creator':om_handle.creator,
			'date':om_handle.date,
			'id':om_handle.id,
			'identifier':om_handle.identifier,
			'subject_string':subject_string,
			'rights':form_data['rights']
		}
	print raw_MODS
	with open('%s/MODS.xml' % working_dir,'w') as f:
		f.write(raw_MODS)

	# write objMeta
	print "writing:",om_handle.toJSON()
	om_handle.writeToFile('%s/objMeta.json' % (working_dir))

	# bagify
	print 'bagifying'	
	bag = WSUDOR_bagger.make_bag(working_dir, {
		'Object PID' : pid
	})

	# ingest
	# purge if already exists
	if 'purge' in form_data:
		try:
			print "purging object"
			fedora_handle.purge_object(form_data['pid'])
		except:
			print "object not found, skipping purge"

	# open new handle
	bag_handle = WSUDOR_ContentTypes.WSUDOR_Object(payload=working_dir, object_type='bag')
	ingest_result = bag_handle.ingestBag()

	# cleanup
	shutil.rmtree(working_dir)

	# render
	time.sleep(3)
	return redirect('tasks/learningObj/container/%s' % pid)
Example #7
0
def createDocument_worker(parent_PID):

	form_data = request.form
	print form_data

	# open parent handle
	obj = WSUDOR_ContentTypes.WSUDOR_Object(parent_PID)

	unique_identifier = "LearningObject_File_%s" % str(uuid.uuid4())
	pid = "wayne:"+unique_identifier

	# instantiate object with quick variables
	known_values = {
		"id":pid,
		"identifier":unique_identifier,
		"label":form_data['label'],
		"description":form_data['description'],
		"creator":form_data['creator'],
		"date":form_data['date'],
		"content_type":"WSUDOR_%s" % form_data['CM'], 
		"policy":"info:fedora/wayne:WSUDORSecurity-permit-apia-unrestricted"
	}
	print known_values

	# instantiate ObjMeta object
	om_handle = ObjMeta(**known_values)

	# show relationships
	om_handle.object_relationships = [
		{
			"predicate": "http://digital.library.wayne.edu/fedora/objects/wayne:WSUDOR-Fedora-Relations/datastreams/RELATIONS/content/hasParent",
			"object": "info:fedora/%s" % parent_PID
		},
		{
			"predicate": "info:fedora/fedora-system:def/relations-external#isConstituentOf",
			"object": "info:fedora/%s" % parent_PID
		},
		{
			"predicate": "http://digital.library.wayne.edu/fedora/objects/wayne:WSUDOR-Fedora-Relations/datastreams/RELATIONS/content/isDiscoverable",
			"object": "info:fedora/False"
		},		
		{
			"predicate": "http://digital.library.wayne.edu/fedora/objects/wayne:WSUDOR-Fedora-Relations/datastreams/RELATIONS/content/preferredContentModel",
			"object": "info:fedora/CM:%s" % form_data['CM']
		},
		{
			"predicate": "http://digital.library.wayne.edu/fedora/objects/wayne:WSUDOR-Fedora-Relations/datastreams/RELATIONS/content/hasSecurityPolicy",
			"object": "info:fedora/wayne:WSUDORSecurity-permit-apia-unrestricted"
		}
	]

	# prepare new working dir & recall original
	working_dir = "/tmp/Ouroboros/"+str(uuid.uuid4())
	print "creating working dir at", working_dir
	# create if doesn't exist
	if not os.path.exists(working_dir):
		os.mkdir(working_dir)			
	os.system("mkdir %s/datastreams" % (working_dir))

	# write custom MODS

	# prepare subjects
	subjects = [subject.strip() for subject in form_data['subjects'].split(",")]
	subject_string = ''
	for subject in subjects:
		if subject != '':
			subject_string += '<mods:subject authority="lcsh"><mods:topic>%s</mods:topic></mods:subject>' % subject

	raw_MODS = '''<?xml version="1.0" encoding="utf-8"?>
<mods:mods xmlns:mods="http://www.loc.gov/mods/v3" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="3.4" xsi:schemaLocation="http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-4.xsd">
  <mods:titleInfo>
	<mods:title>%(label)s</mods:title>
  </mods:titleInfo>
  <mods:abstract>%(description)s</mods:abstract>
  %(subject_string)s
  <mods:name authority="local" type="person">
	<mods:namePart>%(creator)s</mods:namePart>
	<mods:role>
	  <mods:roleTerm authority="marcrelator" type="text">creator</mods:roleTerm>
	</mods:role>
  </mods:name>
  <mods:originInfo>
	<mods:dateCreated>%(date)s</mods:dateCreated>
  </mods:originInfo>
  <mods:identifier type="local">%(identifier)s</mods:identifier>
  <mods:extension>
	<PID>%(id)s</PID>
  </mods:extension>
  <mods:accessCondition type="useAndReproduction">%(rights)s</mods:accessCondition>
</mods:mods>
	''' % {
			'label':om_handle.label,
			'description':om_handle.description,
			'creator':om_handle.creator,
			'date':om_handle.date,
			'id':om_handle.id,
			'identifier':om_handle.identifier,
			'subject_string':subject_string,
			'rights':form_data['rights']
		}
	print raw_MODS
	with open('%s/MODS.xml' % working_dir,'w') as f:
		f.write(raw_MODS)

	# write datastream
	# Identify datastreams folder
	datastreams_dir = working_dir + "/datastreams"
	target_filename = '%s/%s' % (datastreams_dir,form_data['filename'])

	# retrieve uploaded / pasted / content and write to disk
	if form_data['dataType'] == 'dsLocation':
		file_data = requests.get(form_data['dsLocation'])
		with open(target_filename) as f:
			f.write(file_data.content)

	elif form_data['dataType'] == 'upload':
		# writes to temp file in /tmp/Ouroboros
		if 'upload' in request.files and request.files['upload'].filename != '':
			print "Form provided file, uploading and reading file to variable"
			with open(target_filename,'w') as fhand:
				fhand.write(request.files['upload'].read())

	else:
		print "file could not be found"
		return False

	filename = form_data['filename']
	label = form_data['label']
	order = 1

	# get extension, ds_id
	mimetypes.init()
	ds_id, ext = filename.split(".")

	# create datastream dictionary
	ds_dict = {
		"filename": filename,
		"ds_id": ds_id,
		"mimetype": mimetypes.types_map[".%s" % ext],
		"label": label,
		"internal_relationships": {},
		'order': order
	}

	om_handle.datastreams.append(ds_dict)
	
	om_handle.isRepresentedBy = ds_id

	# write objMeta
	print "writing:",om_handle.toJSON()
	om_handle.writeToFile('%s/objMeta.json' % (working_dir))

	# bagify
	print 'bagifying'	
	bag = WSUDOR_bagger.make_bag(working_dir, {
		'Object PID' : pid
	})

	# ingest
	# purge if already exists
	if 'purge' in form_data:
		try:
			print "purging object"
			fedora_handle.purge_object(form_data['pid'])
		except:
			print "object not found, skipping purge"

	# open new handle
	bag_handle = WSUDOR_ContentTypes.WSUDOR_Object(payload=working_dir, object_type='bag')
	ingest_result = bag_handle.ingestBag()

	# cleanup
	# shutil.rmtree(working_dir)

	# render
	time.sleep(3)
	return redirect('tasks/learningObj/container/%s' % parent_PID)