Search in sources :

Example 16 with Strategy

use of org.simpleframework.xml.strategy.Strategy in project openmeetings by apache.

the class BackupImport method importFiles.

/*
	 * ##################### Import File-Explorer Items
	 */
private List<FileItem> importFiles(File f) throws Exception {
    log.info("Private message import complete, starting file explorer item import");
    List<FileItem> result = new ArrayList<>();
    Registry registry = new Registry();
    Strategy strategy = new RegistryStrategy(registry);
    RegistryMatcher matcher = new RegistryMatcher();
    Serializer ser = new Persister(strategy, matcher);
    matcher.bind(Long.class, LongTransform.class);
    matcher.bind(Integer.class, IntegerTransform.class);
    registry.bind(Date.class, DateConverter.class);
    List<FileItem> list = readList(ser, f, "fileExplorerItems.xml", "fileExplorerItems", FileItem.class);
    for (FileItem file : list) {
        Long fId = file.getId();
        // We need to reset this as openJPA reject to store them otherwise
        file.setId(null);
        Long roomId = file.getRoomId();
        file.setRoomId(roomMap.containsKey(roomId) ? roomMap.get(roomId) : null);
        if (file.getOwnerId() != null) {
            file.setOwnerId(userMap.get(file.getOwnerId()));
        }
        if (file.getParentId() != null && file.getParentId().longValue() <= 0L) {
            file.setParentId(null);
        }
        if (Strings.isEmpty(file.getHash())) {
            file.setHash(UUID.randomUUID().toString());
        }
        file = fileItemDao.update(file);
        result.add(file);
        fileItemMap.put(fId, file.getId());
    }
    return result;
}
Also used : FileItem(org.apache.openmeetings.db.entity.file.FileItem) BaseFileItem(org.apache.openmeetings.db.entity.file.BaseFileItem) ArrayList(java.util.ArrayList) RegistryStrategy(org.simpleframework.xml.convert.RegistryStrategy) RegistryStrategy(org.simpleframework.xml.convert.RegistryStrategy) Strategy(org.simpleframework.xml.strategy.Strategy) RegistryMatcher(org.simpleframework.xml.transform.RegistryMatcher) Registry(org.simpleframework.xml.convert.Registry) Persister(org.simpleframework.xml.core.Persister) Serializer(org.simpleframework.xml.Serializer)

Example 17 with Strategy

use of org.simpleframework.xml.strategy.Strategy in project syncany by syncany.

the class ConfigTO method save.

public void save(File file) throws ConfigException {
    try {
        Registry registry = new Registry();
        Strategy strategy = new RegistryStrategy(registry);
        registry.bind(SaltedSecretKey.class, new SaltedSecretKeyConverter());
        registry.bind(String.class, new EncryptedTransferSettingsConverter(transferSettings.getClass()));
        new Persister(strategy).write(this, file);
    } catch (Exception e) {
        throw new ConfigException("Cannot write config to file " + file, e);
    }
}
Also used : SaltedSecretKeyConverter(org.syncany.crypto.SaltedSecretKeyConverter) RegistryStrategy(org.simpleframework.xml.convert.RegistryStrategy) Strategy(org.simpleframework.xml.strategy.Strategy) RegistryStrategy(org.simpleframework.xml.convert.RegistryStrategy) ConfigException(org.syncany.config.ConfigException) Registry(org.simpleframework.xml.convert.Registry) Persister(org.simpleframework.xml.core.Persister) EncryptedTransferSettingsConverter(org.syncany.plugins.transfer.EncryptedTransferSettingsConverter) ConfigException(org.syncany.config.ConfigException)

Example 18 with Strategy

use of org.simpleframework.xml.strategy.Strategy in project syncany by syncany.

the class ConfigTO method load.

public static ConfigTO load(File file) throws ConfigException {
    try {
        Registry registry = new Registry();
        Strategy strategy = new RegistryStrategy(registry);
        registry.bind(SaltedSecretKey.class, new SaltedSecretKeyConverter());
        registry.bind(String.class, new EncryptedTransferSettingsConverter());
        return new Persister(strategy).read(ConfigTO.class, file);
    } catch (ClassNotFoundException ex) {
        // Ugly hack to catch common case of non-existing plugin
        String message = ex.getMessage();
        if (!message.startsWith("org.syncany.plugins.")) {
            // Apparently there are other ClassNotFoundExceptions possible.
            throw new ConfigException("Config file does not exist or is invalid: " + file, ex);
        }
        message = message.replaceFirst("org.syncany.plugins.", "");
        message = message.replaceAll("\\..*", "");
        throw new ConfigException("Is the " + message + " plugin installed?");
    } catch (Exception ex) {
        throw new ConfigException("Config file does not exist or is invalid: " + file, ex);
    }
}
Also used : SaltedSecretKeyConverter(org.syncany.crypto.SaltedSecretKeyConverter) RegistryStrategy(org.simpleframework.xml.convert.RegistryStrategy) Strategy(org.simpleframework.xml.strategy.Strategy) RegistryStrategy(org.simpleframework.xml.convert.RegistryStrategy) ConfigException(org.syncany.config.ConfigException) Registry(org.simpleframework.xml.convert.Registry) Persister(org.simpleframework.xml.core.Persister) EncryptedTransferSettingsConverter(org.syncany.plugins.transfer.EncryptedTransferSettingsConverter) ConfigException(org.syncany.config.ConfigException)

Example 19 with Strategy

use of org.simpleframework.xml.strategy.Strategy in project openmeetings by apache.

the class BackupImport method performImport.

public void performImport(InputStream is) throws Exception {
    userMap.clear();
    groupMap.clear();
    calendarMap.clear();
    appointmentMap.clear();
    roomMap.clear();
    messageFolderMap.clear();
    userContactMap.clear();
    fileMap.clear();
    messageFolderMap.put(INBOX_FOLDER_ID, INBOX_FOLDER_ID);
    messageFolderMap.put(SENT_FOLDER_ID, SENT_FOLDER_ID);
    messageFolderMap.put(TRASH_FOLDER_ID, TRASH_FOLDER_ID);
    File f = unzip(is);
    Registry registry = new Registry();
    Strategy strategy = new RegistryStrategy(registry);
    RegistryMatcher matcher = new RegistryMatcher();
    Serializer simpleSerializer = new Persister(strategy, matcher);
    matcher.bind(Long.class, LongTransform.class);
    registry.bind(Date.class, DateConverter.class);
    BackupVersion ver = getVersion(simpleSerializer, f);
    importConfigs(f);
    importGroups(f, simpleSerializer);
    Long defaultLdapId = importLdap(f, simpleSerializer);
    importOauth(f, simpleSerializer);
    importUsers(f, defaultLdapId);
    importRooms(f);
    importRoomGroups(f);
    importChat(f);
    importCalendars(f);
    importAppointments(f);
    importMeetingMembers(f);
    importRecordings(f);
    importPrivateMsgFolders(f, simpleSerializer);
    importContacts(f);
    importPrivateMsgs(f);
    List<FileItem> files = importFiles(f);
    importPolls(f);
    importRoomFiles(f);
    log.info("Room files import complete, starting copy of files and folders");
    /*
		 * ##################### Import real files and folders
		 */
    importFolders(f);
    if (ver.compareTo(BackupVersion.get("4.0.0")) < 0) {
        for (BaseFileItem bfi : files) {
            if (bfi.isDeleted()) {
                continue;
            }
            if (BaseFileItem.Type.Presentation == bfi.getType()) {
                convertOldPresentation((FileItem) bfi);
                fileItemDao._update(bfi);
            }
            if (BaseFileItem.Type.WmlFile == bfi.getType()) {
                try {
                    Whiteboard wb = WbConverter.convert((FileItem) bfi);
                    wb.save(bfi.getFile().toPath());
                } catch (Exception e) {
                    log.error("Unexpected error while converting WB", e);
                }
            }
        }
    }
    log.info("File explorer item import complete, clearing temp files");
    FileUtils.deleteDirectory(f);
}
Also used : RegistryMatcher(org.simpleframework.xml.transform.RegistryMatcher) Registry(org.simpleframework.xml.convert.Registry) IOException(java.io.IOException) BaseFileItem(org.apache.openmeetings.db.entity.file.BaseFileItem) FileItem(org.apache.openmeetings.db.entity.file.FileItem) BaseFileItem(org.apache.openmeetings.db.entity.file.BaseFileItem) RegistryStrategy(org.simpleframework.xml.convert.RegistryStrategy) RegistryStrategy(org.simpleframework.xml.convert.RegistryStrategy) Strategy(org.simpleframework.xml.strategy.Strategy) Persister(org.simpleframework.xml.core.Persister) StoredFile(org.apache.openmeetings.util.StoredFile) File(java.io.File) RoomFile(org.apache.openmeetings.db.entity.room.RoomFile) Whiteboard(org.apache.openmeetings.db.dto.room.Whiteboard) Serializer(org.simpleframework.xml.Serializer)

Example 20 with Strategy

use of org.simpleframework.xml.strategy.Strategy in project openmeetings by apache.

the class BackupImport method importPolls.

/*
	 * ##################### Import Room Polls
	 */
private void importPolls(File f) throws Exception {
    log.info("File explorer item import complete, starting room poll import");
    Registry registry = new Registry();
    Strategy strategy = new RegistryStrategy(registry);
    RegistryMatcher matcher = new RegistryMatcher();
    Serializer serializer = new Persister(strategy, matcher);
    matcher.bind(Integer.class, IntegerTransform.class);
    registry.bind(User.class, new UserConverter(userDao, userMap));
    registry.bind(Room.class, new RoomConverter(roomDao, roomMap));
    registry.bind(RoomPoll.Type.class, PollTypeConverter.class);
    registry.bind(Date.class, DateConverter.class);
    List<RoomPoll> list = readList(serializer, f, "roompolls.xml", "roompolls", RoomPoll.class);
    for (RoomPoll rp : list) {
        rp.setId(null);
        if (rp.getRoom() == null || rp.getRoom().getId() == null) {
            // room was deleted
            continue;
        }
        if (rp.getCreator() == null || rp.getCreator().getId() == null) {
            rp.setCreator(null);
        }
        for (RoomPollAnswer rpa : rp.getAnswers()) {
            if (rpa.getVotedUser() == null || rpa.getVotedUser().getId() == null) {
                rpa.setVotedUser(null);
            }
        }
        pollDao.update(rp);
    }
}
Also used : UserConverter(org.apache.openmeetings.backup.converter.UserConverter) RoomConverter(org.apache.openmeetings.backup.converter.RoomConverter) RoomPollAnswer(org.apache.openmeetings.db.entity.room.RoomPollAnswer) RegistryStrategy(org.simpleframework.xml.convert.RegistryStrategy) RegistryStrategy(org.simpleframework.xml.convert.RegistryStrategy) Strategy(org.simpleframework.xml.strategy.Strategy) RegistryMatcher(org.simpleframework.xml.transform.RegistryMatcher) Registry(org.simpleframework.xml.convert.Registry) Persister(org.simpleframework.xml.core.Persister) RoomPoll(org.apache.openmeetings.db.entity.room.RoomPoll) Serializer(org.simpleframework.xml.Serializer)

Aggregations

Persister (org.simpleframework.xml.core.Persister)34 Strategy (org.simpleframework.xml.strategy.Strategy)34 Registry (org.simpleframework.xml.convert.Registry)33 RegistryStrategy (org.simpleframework.xml.convert.RegistryStrategy)33 Serializer (org.simpleframework.xml.Serializer)31 UserConverter (org.apache.openmeetings.backup.converter.UserConverter)9 RegistryMatcher (org.simpleframework.xml.transform.RegistryMatcher)7 RoomConverter (org.apache.openmeetings.backup.converter.RoomConverter)5 Room (org.apache.openmeetings.db.entity.room.Room)4 FileItem (org.apache.openmeetings.db.entity.file.FileItem)3 IOException (java.io.IOException)2 GroupConverter (org.apache.openmeetings.backup.converter.GroupConverter)2 ChatMessage (org.apache.openmeetings.db.entity.basic.ChatMessage)2 Appointment (org.apache.openmeetings.db.entity.calendar.Appointment)2 OmCalendar (org.apache.openmeetings.db.entity.calendar.OmCalendar)2 BaseFileItem (org.apache.openmeetings.db.entity.file.BaseFileItem)2 Recording (org.apache.openmeetings.db.entity.record.Recording)2 RoomFile (org.apache.openmeetings.db.entity.room.RoomFile)2 RoomPoll (org.apache.openmeetings.db.entity.room.RoomPoll)2 PrivateMessage (org.apache.openmeetings.db.entity.user.PrivateMessage)2