Search in sources :

Example 1 with TaxonomyLevelImpl

use of org.olat.modules.taxonomy.model.TaxonomyLevelImpl in project OpenOLAT by OpenOLAT.

the class TaxonomyLevelDAO method createTaxonomyLevel.

public TaxonomyLevel createTaxonomyLevel(String identifier, String displayName, String description, String externalId, TaxonomyLevelManagedFlag[] flags, TaxonomyLevel parent, TaxonomyLevelType type, Taxonomy taxonomy) {
    TaxonomyLevelImpl level = new TaxonomyLevelImpl();
    level.setCreationDate(new Date());
    level.setLastModified(level.getCreationDate());
    level.setEnabled(true);
    if (StringHelper.containsNonWhitespace(identifier)) {
        level.setIdentifier(identifier);
    } else {
        level.setIdentifier(UUID.randomUUID().toString());
    }
    level.setManagedFlagsString(TaxonomyLevelManagedFlag.toString(flags));
    level.setDisplayName(displayName);
    level.setDescription(description);
    level.setExternalId(externalId);
    level.setTaxonomy(taxonomy);
    level.setType(type);
    dbInstance.getCurrentEntityManager().persist(level);
    String storage = createLevelStorage(taxonomy, level);
    level.setDirectoryPath(storage);
    String identifiersPath = getMaterializedPathIdentifiers(parent, level);
    String keysPath = getMaterializedPathKeys(parent, level);
    level.setParent(parent);
    level.setMaterializedPathKeys(keysPath);
    level.setMaterializedPathIdentifiers(identifiersPath);
    level = dbInstance.getCurrentEntityManager().merge(level);
    level.getTaxonomy();
    return level;
}
Also used : TaxonomyLevelImpl(org.olat.modules.taxonomy.model.TaxonomyLevelImpl) Date(java.util.Date)

Example 2 with TaxonomyLevelImpl

use of org.olat.modules.taxonomy.model.TaxonomyLevelImpl in project openolat by klemens.

the class TaxonomyLevelDAO method updateTaxonomyLevel.

public TaxonomyLevel updateTaxonomyLevel(TaxonomyLevel level) {
    TaxonomyLevel parentLevel = getParent(level);
    String path = level.getMaterializedPathIdentifiers();
    String newPath = getMaterializedPathIdentifiers(parentLevel, level);
    boolean updatePath = !newPath.equals(path);
    if (updatePath) {
        ((TaxonomyLevelImpl) level).setMaterializedPathIdentifiers(newPath);
    }
    ((TaxonomyLevelImpl) level).setLastModified(new Date());
    TaxonomyLevel mergedLevel = dbInstance.getCurrentEntityManager().merge(level);
    if (updatePath) {
        List<TaxonomyLevel> descendants = getDescendants(mergedLevel, mergedLevel.getTaxonomy());
        for (TaxonomyLevel descendant : descendants) {
            String descendantPath = descendant.getMaterializedPathIdentifiers();
            if (descendantPath.indexOf(path) == 0) {
                String end = descendantPath.substring(path.length(), descendantPath.length());
                String updatedPath = newPath + end;
                ((TaxonomyLevelImpl) descendant).setMaterializedPathIdentifiers(updatedPath);
            }
            dbInstance.getCurrentEntityManager().merge(descendant);
        }
    }
    return mergedLevel;
}
Also used : TaxonomyLevelImpl(org.olat.modules.taxonomy.model.TaxonomyLevelImpl) TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) Date(java.util.Date)

Example 3 with TaxonomyLevelImpl

use of org.olat.modules.taxonomy.model.TaxonomyLevelImpl in project OpenOLAT by OpenOLAT.

the class TaxonomyLevelDAO method updateTaxonomyLevel.

public TaxonomyLevel updateTaxonomyLevel(TaxonomyLevel level) {
    TaxonomyLevel parentLevel = getParent(level);
    String path = level.getMaterializedPathIdentifiers();
    String newPath = getMaterializedPathIdentifiers(parentLevel, level);
    boolean updatePath = !newPath.equals(path);
    if (updatePath) {
        ((TaxonomyLevelImpl) level).setMaterializedPathIdentifiers(newPath);
    }
    ((TaxonomyLevelImpl) level).setLastModified(new Date());
    TaxonomyLevel mergedLevel = dbInstance.getCurrentEntityManager().merge(level);
    if (updatePath) {
        List<TaxonomyLevel> descendants = getDescendants(mergedLevel, mergedLevel.getTaxonomy());
        for (TaxonomyLevel descendant : descendants) {
            String descendantPath = descendant.getMaterializedPathIdentifiers();
            if (descendantPath.indexOf(path) == 0) {
                String end = descendantPath.substring(path.length(), descendantPath.length());
                String updatedPath = newPath + end;
                ((TaxonomyLevelImpl) descendant).setMaterializedPathIdentifiers(updatedPath);
            }
            dbInstance.getCurrentEntityManager().merge(descendant);
        }
    }
    return mergedLevel;
}
Also used : TaxonomyLevelImpl(org.olat.modules.taxonomy.model.TaxonomyLevelImpl) TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) Date(java.util.Date)

Example 4 with TaxonomyLevelImpl

use of org.olat.modules.taxonomy.model.TaxonomyLevelImpl in project OpenOLAT by OpenOLAT.

the class TaxonomyLevelDAO method moveTaxonomyLevel.

/**
 * Move use a lock on the taxonomy to prevent concurrent changes. Therefore
 * the method will commit the changes as soon as possible.
 *
 * @param level The level to move
 * @param newParentLevel The new parent level, if null the level move as a root
 * @return The updated level
 */
public TaxonomyLevel moveTaxonomyLevel(TaxonomyLevel level, TaxonomyLevel newParentLevel) {
    @SuppressWarnings("unused") Taxonomy lockedTaxonomy = loadForUpdate(level.getTaxonomy());
    TaxonomyLevel parentLevel = getParent(level);
    if (parentLevel == null && newParentLevel == null) {
        // already root
        return level;
    } else if (parentLevel != null && parentLevel.equals(newParentLevel)) {
        // same parent
        return level;
    }
    String keysPath = level.getMaterializedPathKeys();
    String identifiersPath = level.getMaterializedPathIdentifiers();
    List<TaxonomyLevel> descendants = getDescendants(level, level.getTaxonomy());
    TaxonomyLevelImpl levelImpl = (TaxonomyLevelImpl) level;
    levelImpl.setParent(newParentLevel);
    levelImpl.setLastModified(new Date());
    String newKeysPath = getMaterializedPathKeys(newParentLevel, levelImpl);
    String newIdentifiersPath = getMaterializedPathIdentifiers(newParentLevel, levelImpl);
    levelImpl.setMaterializedPathKeys(newKeysPath);
    levelImpl.setMaterializedPathIdentifiers(newIdentifiersPath);
    levelImpl = dbInstance.getCurrentEntityManager().merge(levelImpl);
    for (TaxonomyLevel descendant : descendants) {
        String descendantKeysPath = descendant.getMaterializedPathKeys();
        String descendantIdentifiersPath = descendant.getMaterializedPathIdentifiers();
        if (descendantIdentifiersPath.indexOf(identifiersPath) == 0) {
            String end = descendantIdentifiersPath.substring(identifiersPath.length(), descendantIdentifiersPath.length());
            String updatedPath = newIdentifiersPath + end;
            ((TaxonomyLevelImpl) descendant).setMaterializedPathIdentifiers(updatedPath);
        }
        if (descendantKeysPath.indexOf(keysPath) == 0) {
            String end = descendantKeysPath.substring(keysPath.length(), descendantKeysPath.length());
            String updatedPath = newKeysPath + end;
            ((TaxonomyLevelImpl) descendant).setMaterializedPathKeys(updatedPath);
        }
        dbInstance.getCurrentEntityManager().merge(descendant);
    }
    dbInstance.commit();
    return levelImpl;
}
Also used : Taxonomy(org.olat.modules.taxonomy.Taxonomy) TaxonomyLevelImpl(org.olat.modules.taxonomy.model.TaxonomyLevelImpl) TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) Date(java.util.Date)

Example 5 with TaxonomyLevelImpl

use of org.olat.modules.taxonomy.model.TaxonomyLevelImpl in project openolat by klemens.

the class TaxonomyLevelDAO method moveTaxonomyLevel.

/**
 * Move use a lock on the taxonomy to prevent concurrent changes. Therefore
 * the method will commit the changes as soon as possible.
 *
 * @param level The level to move
 * @param newParentLevel The new parent level, if null the level move as a root
 * @return The updated level
 */
public TaxonomyLevel moveTaxonomyLevel(TaxonomyLevel level, TaxonomyLevel newParentLevel) {
    @SuppressWarnings("unused") Taxonomy lockedTaxonomy = loadForUpdate(level.getTaxonomy());
    TaxonomyLevel parentLevel = getParent(level);
    if (parentLevel == null && newParentLevel == null) {
        // already root
        return level;
    } else if (parentLevel != null && parentLevel.equals(newParentLevel)) {
        // same parent
        return level;
    }
    String keysPath = level.getMaterializedPathKeys();
    String identifiersPath = level.getMaterializedPathIdentifiers();
    List<TaxonomyLevel> descendants = getDescendants(level, level.getTaxonomy());
    TaxonomyLevelImpl levelImpl = (TaxonomyLevelImpl) level;
    levelImpl.setParent(newParentLevel);
    levelImpl.setLastModified(new Date());
    String newKeysPath = getMaterializedPathKeys(newParentLevel, levelImpl);
    String newIdentifiersPath = getMaterializedPathIdentifiers(newParentLevel, levelImpl);
    levelImpl.setMaterializedPathKeys(newKeysPath);
    levelImpl.setMaterializedPathIdentifiers(newIdentifiersPath);
    levelImpl = dbInstance.getCurrentEntityManager().merge(levelImpl);
    for (TaxonomyLevel descendant : descendants) {
        String descendantKeysPath = descendant.getMaterializedPathKeys();
        String descendantIdentifiersPath = descendant.getMaterializedPathIdentifiers();
        if (descendantIdentifiersPath.indexOf(identifiersPath) == 0) {
            String end = descendantIdentifiersPath.substring(identifiersPath.length(), descendantIdentifiersPath.length());
            String updatedPath = newIdentifiersPath + end;
            ((TaxonomyLevelImpl) descendant).setMaterializedPathIdentifiers(updatedPath);
        }
        if (descendantKeysPath.indexOf(keysPath) == 0) {
            String end = descendantKeysPath.substring(keysPath.length(), descendantKeysPath.length());
            String updatedPath = newKeysPath + end;
            ((TaxonomyLevelImpl) descendant).setMaterializedPathKeys(updatedPath);
        }
        dbInstance.getCurrentEntityManager().merge(descendant);
    }
    dbInstance.commit();
    return levelImpl;
}
Also used : Taxonomy(org.olat.modules.taxonomy.Taxonomy) TaxonomyLevelImpl(org.olat.modules.taxonomy.model.TaxonomyLevelImpl) TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) Date(java.util.Date)

Aggregations

Date (java.util.Date)6 TaxonomyLevelImpl (org.olat.modules.taxonomy.model.TaxonomyLevelImpl)6 TaxonomyLevel (org.olat.modules.taxonomy.TaxonomyLevel)4 Taxonomy (org.olat.modules.taxonomy.Taxonomy)2