Search in sources :

Example 16 with MetaFile

use of com.axelor.meta.db.MetaFile in project axelor-open-suite by axelor.

the class ObjectDataExportController method export.

public void export(ActionRequest request, ActionResponse response) throws AxelorException {
    ObjectDataConfigExport objDataConfigExport = request.getContext().asType(ObjectDataConfigExport.class);
    Long objectDataconfigId = objDataConfigExport.getObjectDataConfig().getId();
    ObjectDataConfig objectDataConfig = Beans.get(ObjectDataConfigRepository.class).find(objectDataconfigId);
    MetaFile dataFile = Beans.get(ObjectDataExportService.class).export(objectDataConfig, objDataConfigExport);
    if (dataFile != null) {
        response.setView(ActionView.define(I18n.get("Data")).add("html", "ws/rest/com.axelor.meta.db.MetaFile/" + dataFile.getId() + "/content/download?v=" + dataFile.getVersion()).param("download", "true").map());
    }
    response.setCanClose(true);
}
Also used : ObjectDataConfigExport(com.axelor.apps.base.db.ObjectDataConfigExport) ObjectDataExportService(com.axelor.apps.base.service.ObjectDataExportService) MetaFile(com.axelor.meta.db.MetaFile) ObjectDataConfigRepository(com.axelor.apps.base.db.repo.ObjectDataConfigRepository) ObjectDataConfig(com.axelor.apps.base.db.ObjectDataConfig)

Example 17 with MetaFile

use of com.axelor.meta.db.MetaFile in project axelor-open-suite by axelor.

the class PermissionAssistantService method importPermissions.

public String importPermissions(PermissionAssistant permissionAssistant) {
    try {
        ResourceBundle bundle = I18n.getBundle(new Locale(permissionAssistant.getLanguage()));
        MetaFile metaFile = permissionAssistant.getMetaFile();
        File csvFile = MetaFiles.getPath(metaFile).toFile();
        try (CSVReader csvReader = new CSVReader(new InputStreamReader(new FileInputStream(csvFile), StandardCharsets.UTF_8), ';')) {
            String[] groupRow = csvReader.readNext();
            if (groupRow == null || groupRow.length < 11) {
                errorLog = I18n.get(IMessage.BAD_FILE);
            }
            String[] headerRow = csvReader.readNext();
            if (headerRow == null) {
                errorLog = I18n.get(IMessage.NO_HEADER);
            }
            if (!checkHeaderRow(Arrays.asList(headerRow), bundle)) {
                errorLog = I18n.get(IMessage.BAD_HEADER) + " " + Arrays.asList(headerRow);
            }
            if (!errorLog.equals("")) {
                return errorLog;
            }
            if (permissionAssistant.getTypeSelect() == PermissionAssistantRepository.TYPE_GROUPS) {
                Map<String, Group> groupMap = checkBadGroups(groupRow);
                processGroupCSV(csvReader, groupRow, groupMap, permissionAssistant.getMetaField(), permissionAssistant.getFieldPermission());
                saveGroups(groupMap);
            } else if (permissionAssistant.getTypeSelect() == PermissionAssistantRepository.TYPE_ROLES) {
                Map<String, Role> roleMap = checkBadRoles(groupRow);
                processRoleCSV(csvReader, groupRow, roleMap, permissionAssistant.getMetaField(), permissionAssistant.getFieldPermission());
                saveRoles(roleMap);
            }
        }
    } catch (Exception e) {
        LOG.error(e.getLocalizedMessage());
        TraceBackService.trace(e);
        errorLog += "\n" + String.format(I18n.get(IMessage.ERR_IMPORT_WITH_MSG), e.getMessage());
    }
    return errorLog;
}
Also used : Locale(java.util.Locale) Group(com.axelor.auth.db.Group) InputStreamReader(java.io.InputStreamReader) CSVReader(com.opencsv.CSVReader) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) ResourceBundle(java.util.ResourceBundle) MetaFile(com.axelor.meta.db.MetaFile) File(java.io.File) MetaFile(com.axelor.meta.db.MetaFile) Map(java.util.Map) HashMap(java.util.HashMap)

Example 18 with MetaFile

use of com.axelor.meta.db.MetaFile in project axelor-open-suite by axelor.

the class ImportApp method importApp.

public Object importApp(Object bean, Map<String, Object> values) {
    assert bean instanceof App;
    App app = (App) bean;
    final Path path = (Path) values.get("__path__");
    String fileName = (String) values.get("imagePath");
    if (!Strings.isNullOrEmpty(fileName)) {
        try {
            final File image = path.resolve("img" + File.separator + fileName).toFile();
            if (image.exists()) {
                final MetaFile metaFile = metaFiles.upload(image);
                app.setImage(metaFile);
            }
        } catch (Exception e) {
            LOG.warn("Can't load image {} for app {}", fileName, app.getName());
        }
    }
    if (app.getLanguageSelect() == null) {
        String language = AppSettings.get().get("application.locale");
        app.setLanguageSelect(language);
    }
    return app;
}
Also used : App(com.axelor.apps.base.db.App) Path(java.nio.file.Path) MetaFile(com.axelor.meta.db.MetaFile) MetaFile(com.axelor.meta.db.MetaFile) File(java.io.File)

Example 19 with MetaFile

use of com.axelor.meta.db.MetaFile in project axelor-open-suite by axelor.

the class AccessTemplateServiceImpl method createMetaFile.

public MetaFile createMetaFile(XSSFWorkbook workBook) throws IOException {
    Path path = MetaFiles.createTempFile("AccessConfigTemplate", ".xlsx");
    File file = path.toFile();
    FileOutputStream fout = new FileOutputStream(file);
    workBook.write(fout);
    fout.close();
    return metaFiles.upload(file);
}
Also used : Path(java.nio.file.Path) FileOutputStream(java.io.FileOutputStream) File(java.io.File) MetaFile(com.axelor.meta.db.MetaFile)

Example 20 with MetaFile

use of com.axelor.meta.db.MetaFile in project axelor-open-suite by axelor.

the class BpmDeploymentServiceImpl method deploy.

@Override
@Transactional
public void deploy(WkfModel wkfModel, Map<String, Map<String, String>> migrationMap) {
    if (wkfModel.getDiagramXml() == null) {
        return;
    }
    this.wkfModel = wkfModel;
    this.migrationMap = migrationMap;
    ProcessEngine engine = Beans.get(ProcessEngineService.class).getEngine();
    String key = wkfModel.getId() + ".bpmn";
    BpmnModelInstance bpmInstance = Bpmn.readModelFromStream(new ByteArrayInputStream(wkfModel.getDiagramXml().getBytes()));
    DeploymentBuilder deploymentBuilder = engine.getRepositoryService().createDeployment().addModelInstance(key, bpmInstance).source(key);
    Set<MetaFile> dmnFiles = wkfModel.getDmnFileSet();
    if (dmnFiles != null) {
        addDmn(deploymentBuilder, dmnFiles);
    }
    Map<String, String> processMap = deployProcess(engine, deploymentBuilder, bpmInstance);
    List<MetaAttrs> metaAttrsList = Beans.get(WkfNodeService.class).extractNodes(wkfModel, bpmInstance, processMap);
    Beans.get(WkfModelRepository.class).save(wkfModel);
    metaAttrsService.saveMetaAttrs(metaAttrsList, wkfModel.getId());
}
Also used : ProcessEngineService(com.axelor.apps.bpm.service.init.ProcessEngineService) BpmnModelInstance(org.camunda.bpm.model.bpmn.BpmnModelInstance) MetaAttrs(com.axelor.meta.db.MetaAttrs) ByteArrayInputStream(java.io.ByteArrayInputStream) WkfModelRepository(com.axelor.apps.bpm.db.repo.WkfModelRepository) MetaFile(com.axelor.meta.db.MetaFile) DeploymentBuilder(org.camunda.bpm.engine.repository.DeploymentBuilder) ProcessEngine(org.camunda.bpm.engine.ProcessEngine) Transactional(com.google.inject.persist.Transactional)

Aggregations

MetaFile (com.axelor.meta.db.MetaFile)87 File (java.io.File)50 FileInputStream (java.io.FileInputStream)25 IOException (java.io.IOException)24 AxelorException (com.axelor.exception.AxelorException)21 MetaFiles (com.axelor.meta.MetaFiles)18 Transactional (com.google.inject.persist.Transactional)17 ArrayList (java.util.ArrayList)13 Path (java.nio.file.Path)12 InputStream (java.io.InputStream)10 ZipFile (java.util.zip.ZipFile)9 FileOutputStream (java.io.FileOutputStream)8 MetaFileRepository (com.axelor.meta.db.repo.MetaFileRepository)7 ImportHistory (com.axelor.apps.base.db.ImportHistory)6 DMSFile (com.axelor.dms.db.DMSFile)6 HashMap (java.util.HashMap)6 ZipEntry (java.util.zip.ZipEntry)6 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ZipInputStream (java.util.zip.ZipInputStream)4 App (com.axelor.apps.base.db.App)3