Search in sources :

Example 21 with NotAuthorizedException

use of org.eclipse.vorto.repository.web.core.exceptions.NotAuthorizedException in project vorto by eclipse.

the class AbstractRepositoryController method addModelToZip.

protected void addModelToZip(ZipOutputStream zipOutputStream, ModelId modelId) throws Exception {
    try {
        FileContent modelFile = getModelRepository(modelId).getFileContent(modelId, Optional.empty()).get();
        ModelInfo modelResource = getModelRepository(modelId).getById(modelId);
        try {
            ZipEntry zipEntry = new ZipEntry(modelResource.getId().getPrettyFormat() + modelResource.getType().getExtension());
            zipOutputStream.putNextEntry(zipEntry);
            zipOutputStream.write(modelFile.getContent());
            zipOutputStream.closeEntry();
        } catch (Exception ex) {
        // entry possible exists already, so skipping TODO: ugly hack!!
        }
        for (ModelId reference : modelResource.getReferences()) {
            addModelToZip(zipOutputStream, reference);
        }
    } catch (NotAuthorizedException notAuthorized) {
        return;
    }
}
Also used : FileContent(org.eclipse.vorto.repository.core.FileContent) ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) ZipEntry(java.util.zip.ZipEntry) NotAuthorizedException(org.eclipse.vorto.repository.web.core.exceptions.NotAuthorizedException) GenerationException(org.eclipse.vorto.repository.plugin.generator.GenerationException) ModelNotFoundException(org.eclipse.vorto.repository.core.ModelNotFoundException) ModelAlreadyExistsException(org.eclipse.vorto.repository.core.ModelAlreadyExistsException) NotAuthorizedException(org.eclipse.vorto.repository.web.core.exceptions.NotAuthorizedException) IOException(java.io.IOException) ValidationException(org.eclipse.vorto.repository.core.impl.validation.ValidationException) NewNamespacesNotSupersetException(org.eclipse.vorto.repository.tenant.NewNamespacesNotSupersetException) ModelId(org.eclipse.vorto.model.ModelId)

Aggregations

NotAuthorizedException (org.eclipse.vorto.repository.web.core.exceptions.NotAuthorizedException)21 ModelIdHelper (org.eclipse.vorto.repository.core.impl.utils.ModelIdHelper)13 ModelId (org.eclipse.vorto.model.ModelId)8 IOException (java.io.IOException)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 Attachment (org.eclipse.vorto.repository.core.Attachment)5 ValidationException (org.eclipse.vorto.repository.core.impl.validation.ValidationException)5 ModelInfo (org.eclipse.vorto.repository.core.ModelInfo)4 Lists (com.google.common.collect.Lists)3 Collectors (java.util.stream.Collectors)3 ZipEntry (java.util.zip.ZipEntry)3 Node (javax.jcr.Node)3 IOUtils (org.apache.commons.io.IOUtils)3 FatalModelRepositoryException (org.eclipse.vorto.repository.core.FatalModelRepositoryException)3 FileContent (org.eclipse.vorto.repository.core.FileContent)3 ModelAlreadyExistsException (org.eclipse.vorto.repository.core.ModelAlreadyExistsException)3 Permission (org.eclipse.vorto.repository.core.PolicyEntry.Permission)3 ResponseEntity (org.springframework.http.ResponseEntity)3 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)3 Authentication (org.springframework.security.core.Authentication)3