Search in sources :

Example 1 with ModelReferentialIntegrityException

use of org.eclipse.vorto.repository.core.ModelReferentialIntegrityException in project vorto by eclipse.

the class JcrModelRepository method removeModel.

@Override
public void removeModel(ModelId modelId) {
    try {
        ModelInfo modelResource = this.getById(modelId);
        if (!modelResource.getReferencedBy().isEmpty()) {
            throw new ModelReferentialIntegrityException("Cannot remove model because it is referenced by other model(s)", modelResource.getReferencedBy());
        }
        ModelIdHelper modelIdHelper = new ModelIdHelper(modelId);
        Item item = session.getItem(modelIdHelper.getFullPath());
        item.remove();
        session.save();
    } catch (RepositoryException e) {
        throw new FatalModelRepositoryException("Problem occured removing the model", e);
    }
}
Also used : Item(javax.jcr.Item) ModelInfo(org.eclipse.vorto.repository.api.ModelInfo) ModelIdHelper(org.eclipse.vorto.repository.core.impl.utils.ModelIdHelper) FatalModelRepositoryException(org.eclipse.vorto.repository.core.FatalModelRepositoryException) FatalModelRepositoryException(org.eclipse.vorto.repository.core.FatalModelRepositoryException) RepositoryException(javax.jcr.RepositoryException) ModelReferentialIntegrityException(org.eclipse.vorto.repository.core.ModelReferentialIntegrityException)

Aggregations

Item (javax.jcr.Item)1 RepositoryException (javax.jcr.RepositoryException)1 ModelInfo (org.eclipse.vorto.repository.api.ModelInfo)1 FatalModelRepositoryException (org.eclipse.vorto.repository.core.FatalModelRepositoryException)1 ModelReferentialIntegrityException (org.eclipse.vorto.repository.core.ModelReferentialIntegrityException)1 ModelIdHelper (org.eclipse.vorto.repository.core.impl.utils.ModelIdHelper)1