view src/main/java/de/mpiwg/itgroup/ismi/utils/templates/DigitalizationTemplate.java @ 184:135b29621a32

Fix bug with digitalizations having no own value.
author Robert Casties <casties@mpiwg-berlin.mpg.de>
date Fri, 27 Jul 2018 14:23:46 +0200
parents 2e911857a759
children 310f512f66af
line wrap: on
line source

package de.mpiwg.itgroup.ismi.utils.templates;

import java.util.List;

import org.mpi.openmind.cache.WrapperService;
import org.mpi.openmind.repository.bo.Entity;

public class DigitalizationTemplate implements Comparable<DigitalizationTemplate>{
	
	private String codexOv;
	private String codexId;
	private Entity entity;
	private String pages;
	private List<Entity> titlesInCodex;
	
	private WrapperService om;
	private boolean initialized = false;
	
	private boolean hasCodex = false;
	
	public DigitalizationTemplate(Entity digi, WrapperService om){
		this.entity = digi;
		this.om = om;
	}
	
	public void init(){
		this.initialized = true;
		this.pages = om.getAttributeByName(entity.getId(), "num_files").getValue();
		
		List<Entity> list = om.getTargetsForSourceRelation(entity, "is_digitalization_of", "CODEX", 1);
		if(list.size() > 0){
			Entity codex = list.get(0);
			this.codexOv = codex.getOwnValue();
			this.codexId = codex.getId().toString();
			this.titlesInCodex = om.getSourcesForTargetRelation(codex, "is_part_of", "WITNESS", -1);
			this.hasCodex = true;
		}
	}

	public boolean isHasCodex(){
		return this.hasCodex;
	}
	
	public String getCodexId() {
		if(!initialized)
			this.init();
		return codexId;
	}

	public Entity getEntity() {
		return entity;
	}
	
	public String getCodexOv(){
		return this.codexOv;
	}

	public String getPages() {
		if(!initialized)
			this.init();
		return pages;
	}

	public List<Entity> getTitlesInCodex() {
		if(!initialized)
			this.init();
		return titlesInCodex;
	}
	
	public int compareTo(DigitalizationTemplate o) {
		boolean thisnull = (this.entity == null || this.entity.getOwnValue() == null);
		boolean thatnull = (o.entity == null || o.entity.getOwnValue() == null);
		if (thisnull && thatnull) {
			return 0;
		}
		if (thisnull) {
			return -1;
		}
		if (thatnull) {
			return 1;
		}
		return this.entity.getOwnValue().compareTo(o.getEntity().getOwnValue()); 
	}
}