Search in sources :

Example 1 with CPDependency

use of org.olat.ims.cp.objects.CPDependency in project OpenOLAT by OpenOLAT.

the class CPCore method referencesCount.

/**
 * Checks how many item-elements link to the given resource element.
 *
 * @param resource
 * @return
 */
protected int referencesCount(CPResource resource) {
    int linkCount = 0;
    Vector<CPItem> items = new Vector<CPItem>();
    for (Iterator<CPOrganization> it = rootNode.getOrganizations().getOrganizationIterator(); it.hasNext(); ) {
        CPOrganization org = it.next();
        items.addAll(org.getAllItems());
    }
    for (CPItem item : items) {
        if (item.getIdentifierRef().equals(resource.getIdentifier()))
            linkCount++;
    }
    Vector<CPDependency> dependencies = rootNode.getResources().getAllDependencies();
    for (CPDependency dependency : dependencies) {
        if (dependency.getIdentifierRef().equals(resource.getIdentifier()))
            linkCount++;
    }
    return linkCount;
}
Also used : Vector(java.util.Vector) CPItem(org.olat.ims.cp.objects.CPItem) CPOrganization(org.olat.ims.cp.objects.CPOrganization) CPDependency(org.olat.ims.cp.objects.CPDependency)

Example 2 with CPDependency

use of org.olat.ims.cp.objects.CPDependency in project OpenOLAT by OpenOLAT.

the class CPCore method addElement.

// *** CP manipulation ***
/**
 * adds an element as a child to the element with id parentId if the element
 * with parentId is not found, it returns false
 *
 * if adding was successful, it returns true
 */
public boolean addElement(DefaultElement newElement, String parentId, int position) {
    DefaultElement parentElement = rootNode.getElementByIdentifier(parentId);
    if (parentElement == null) {
        throw new OLATRuntimeException(CPOrganizations.class, "Parent-element with identifier:\"" + parentId + "\" not found!", new Exception());
    }
    if (parentElement instanceof CPItem) {
        // parent is a <item>
        if (newElement instanceof CPItem) {
            // only CPItems can be added to CPItems
            CPItem item = (CPItem) parentElement;
            item.addItemAt((CPItem) newElement, position);
            return true;
        } else {
            throw new OLATRuntimeException(CPOrganizations.class, "you can only add <item>  elements to an <item>-element", new Exception());
        }
    } else if (parentElement instanceof CPOrganization) {
        // parent is a <organization>
        if (newElement instanceof CPItem) {
            // add a new item to organization element
            CPOrganization org = (CPOrganization) parentElement;
            org.addItemAt((CPItem) newElement, position);
            return true;
        } else {
            throw new OLATRuntimeException(CPOrganizations.class, "you can only add <item>  elements to an <organization>-element", new Exception());
        }
    } else if (parentElement instanceof CPResource) {
        // parent is a <resource>
        CPResource resource = (CPResource) parentElement;
        if (newElement instanceof CPFile) {
            resource.addFile((CPFile) newElement);
        } else if (newElement instanceof CPDependency) {
            resource.addDependency((CPDependency) newElement);
        } else {
            throw new OLATRuntimeException(CPOrganizations.class, "you can only add <dependency> or <file> elements to a Resource", new Exception());
        }
        return true;
    } else if (parentElement instanceof CPResources) {
        // parent is <resources> !!see the "s" at the end ;)
        if (newElement instanceof CPResource) {
            CPResources resources = (CPResources) parentElement;
            resources.addResource((CPResource) newElement);
            return true;
        } else {
            throw new OLATRuntimeException(CPOrganizations.class, "you can only add <resource>elements to the <resources> element", new Exception());
        }
    }
    return false;
}
Also used : CPOrganizations(org.olat.ims.cp.objects.CPOrganizations) CPFile(org.olat.ims.cp.objects.CPFile) DefaultElement(org.dom4j.tree.DefaultElement) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) CPResources(org.olat.ims.cp.objects.CPResources) CPResource(org.olat.ims.cp.objects.CPResource) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) CPItem(org.olat.ims.cp.objects.CPItem) CPOrganization(org.olat.ims.cp.objects.CPOrganization) CPDependency(org.olat.ims.cp.objects.CPDependency)

Example 3 with CPDependency

use of org.olat.ims.cp.objects.CPDependency in project openolat by klemens.

the class CPCore method referencesCount.

/**
 * Checks how many item-elements link to the given resource element.
 *
 * @param resource
 * @return
 */
protected int referencesCount(CPResource resource) {
    int linkCount = 0;
    Vector<CPItem> items = new Vector<CPItem>();
    for (Iterator<CPOrganization> it = rootNode.getOrganizations().getOrganizationIterator(); it.hasNext(); ) {
        CPOrganization org = it.next();
        items.addAll(org.getAllItems());
    }
    for (CPItem item : items) {
        if (item.getIdentifierRef().equals(resource.getIdentifier()))
            linkCount++;
    }
    Vector<CPDependency> dependencies = rootNode.getResources().getAllDependencies();
    for (CPDependency dependency : dependencies) {
        if (dependency.getIdentifierRef().equals(resource.getIdentifier()))
            linkCount++;
    }
    return linkCount;
}
Also used : Vector(java.util.Vector) CPItem(org.olat.ims.cp.objects.CPItem) CPOrganization(org.olat.ims.cp.objects.CPOrganization) CPDependency(org.olat.ims.cp.objects.CPDependency)

Example 4 with CPDependency

use of org.olat.ims.cp.objects.CPDependency in project OpenOLAT by OpenOLAT.

the class CPCore method findReferencesToResource.

/**
 * Searches for <item>-elements or <dependency>-elements which references to
 * the resource with id "resourceIdentifier"
 *
 * if an element is found, search is aborted and the found element is returned
 *
 * @param resourceIdentifier
 * @return the found element or null
 */
public DefaultElement findReferencesToResource(String resourceIdentifier) {
    // search for <item identifierref="resourceIdentifier" >
    for (Iterator<CPOrganization> it = rootNode.getOrganizations().getOrganizationIterator(); it.hasNext(); ) {
        CPOrganization org = it.next();
        for (Iterator<CPItem> itO = org.getItems().iterator(); itO.hasNext(); ) {
            CPItem item = itO.next();
            CPItem found = _findReferencesToRes(item, resourceIdentifier);
            if (found != null)
                return found;
        }
    }
    // search for <dependency identifierref="resourceIdentifier" >
    for (Iterator<CPResource> itRes = rootNode.getResources().getResourceIterator(); itRes.hasNext(); ) {
        CPResource res = itRes.next();
        for (Iterator<CPDependency> itDep = res.getDependencyIterator(); itDep.hasNext(); ) {
            CPDependency dep = itDep.next();
            if (dep.getIdentifierRef().equals(resourceIdentifier))
                return dep;
        }
    }
    return null;
}
Also used : CPResource(org.olat.ims.cp.objects.CPResource) CPOrganization(org.olat.ims.cp.objects.CPOrganization) CPItem(org.olat.ims.cp.objects.CPItem) CPDependency(org.olat.ims.cp.objects.CPDependency)

Example 5 with CPDependency

use of org.olat.ims.cp.objects.CPDependency in project openolat by klemens.

the class CPCore method addElement.

// *** CP manipulation ***
/**
 * adds an element as a child to the element with id parentId if the element
 * with parentId is not found, it returns false
 *
 * if adding was successful, it returns true
 */
public boolean addElement(DefaultElement newElement, String parentId, int position) {
    DefaultElement parentElement = rootNode.getElementByIdentifier(parentId);
    if (parentElement == null) {
        throw new OLATRuntimeException(CPOrganizations.class, "Parent-element with identifier:\"" + parentId + "\" not found!", new Exception());
    }
    if (parentElement instanceof CPItem) {
        // parent is a <item>
        if (newElement instanceof CPItem) {
            // only CPItems can be added to CPItems
            CPItem item = (CPItem) parentElement;
            item.addItemAt((CPItem) newElement, position);
            return true;
        } else {
            throw new OLATRuntimeException(CPOrganizations.class, "you can only add <item>  elements to an <item>-element", new Exception());
        }
    } else if (parentElement instanceof CPOrganization) {
        // parent is a <organization>
        if (newElement instanceof CPItem) {
            // add a new item to organization element
            CPOrganization org = (CPOrganization) parentElement;
            org.addItemAt((CPItem) newElement, position);
            return true;
        } else {
            throw new OLATRuntimeException(CPOrganizations.class, "you can only add <item>  elements to an <organization>-element", new Exception());
        }
    } else if (parentElement instanceof CPResource) {
        // parent is a <resource>
        CPResource resource = (CPResource) parentElement;
        if (newElement instanceof CPFile) {
            resource.addFile((CPFile) newElement);
        } else if (newElement instanceof CPDependency) {
            resource.addDependency((CPDependency) newElement);
        } else {
            throw new OLATRuntimeException(CPOrganizations.class, "you can only add <dependency> or <file> elements to a Resource", new Exception());
        }
        return true;
    } else if (parentElement instanceof CPResources) {
        // parent is <resources> !!see the "s" at the end ;)
        if (newElement instanceof CPResource) {
            CPResources resources = (CPResources) parentElement;
            resources.addResource((CPResource) newElement);
            return true;
        } else {
            throw new OLATRuntimeException(CPOrganizations.class, "you can only add <resource>elements to the <resources> element", new Exception());
        }
    }
    return false;
}
Also used : CPOrganizations(org.olat.ims.cp.objects.CPOrganizations) CPFile(org.olat.ims.cp.objects.CPFile) DefaultElement(org.dom4j.tree.DefaultElement) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) CPResources(org.olat.ims.cp.objects.CPResources) CPResource(org.olat.ims.cp.objects.CPResource) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) CPItem(org.olat.ims.cp.objects.CPItem) CPOrganization(org.olat.ims.cp.objects.CPOrganization) CPDependency(org.olat.ims.cp.objects.CPDependency)

Aggregations

CPDependency (org.olat.ims.cp.objects.CPDependency)6 CPItem (org.olat.ims.cp.objects.CPItem)6 CPOrganization (org.olat.ims.cp.objects.CPOrganization)6 CPResource (org.olat.ims.cp.objects.CPResource)4 Vector (java.util.Vector)2 DefaultElement (org.dom4j.tree.DefaultElement)2 OLATRuntimeException (org.olat.core.logging.OLATRuntimeException)2 CPFile (org.olat.ims.cp.objects.CPFile)2 CPOrganizations (org.olat.ims.cp.objects.CPOrganizations)2 CPResources (org.olat.ims.cp.objects.CPResources)2