Search in sources :

Example 6 with RegistryMatcher

use of org.simpleframework.xml.transform.RegistryMatcher in project randomizedtesting by randomizedtesting.

the class TestXmlStringsRoundtrip method check.

private void check(char[] chars) throws Exception {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    RegistryMatcher rm = new RegistryMatcher();
    rm.bind(String.class, XmlStringTransformerAccess.getInstance());
    Persister persister = new Persister(rm);
    persister.write(new Model(new String(chars)), baos);
    DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
    try {
        docBuilder.parse(new ByteArrayInputStream(baos.toByteArray()));
    } catch (SAXParseException e) {
        System.out.println("Input: " + Arrays.toString(chars));
        System.out.println("XML: " + new String(baos.toByteArray(), StandardCharsets.UTF_8));
        throw e;
    }
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ByteArrayInputStream(java.io.ByteArrayInputStream) SAXParseException(org.xml.sax.SAXParseException) RegistryMatcher(org.simpleframework.xml.transform.RegistryMatcher) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Persister(org.simpleframework.xml.core.Persister)

Example 7 with RegistryMatcher

use of org.simpleframework.xml.transform.RegistryMatcher 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 8 with RegistryMatcher

use of org.simpleframework.xml.transform.RegistryMatcher 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)

Example 9 with RegistryMatcher

use of org.simpleframework.xml.transform.RegistryMatcher in project openmeetings by apache.

the class BackupImport method importRecordings.

/*
	 * ##################### Import Recordings
	 */
private void importRecordings(File f) throws Exception {
    log.info("Meeting members import complete, starting recordings server import");
    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);
    registry.bind(Recording.Status.class, RecordingStatusConverter.class);
    List<Recording> list = readList(ser, f, "flvRecordings.xml", "flvrecordings", Recording.class);
    for (Recording r : list) {
        Long recId = r.getId();
        r.setId(null);
        if (r.getRoomId() != null) {
            r.setRoomId(roomMap.get(r.getRoomId()));
        }
        if (r.getOwnerId() != null) {
            r.setOwnerId(userMap.get(r.getOwnerId()));
        }
        if (r.getMetaData() != null) {
            for (RecordingMetaData meta : r.getMetaData()) {
                meta.setId(null);
                meta.setRecording(r);
            }
        }
        if (!Strings.isEmpty(r.getHash()) && r.getHash().startsWith(RECORDING_FILE_NAME)) {
            String name = getFileName(r.getHash());
            r.setHash(UUID.randomUUID().toString());
            fileMap.put(String.format(FILE_NAME_FMT, name, EXTENSION_JPG), String.format(FILE_NAME_FMT, r.getHash(), EXTENSION_PNG));
            fileMap.put(String.format("%s.%s.%s", name, EXTENSION_FLV, EXTENSION_MP4), String.format(FILE_NAME_FMT, r.getHash(), EXTENSION_MP4));
        }
        if (Strings.isEmpty(r.getHash())) {
            r.setHash(UUID.randomUUID().toString());
        }
        r = recordingDao.update(r);
        fileItemMap.put(recId, r.getId());
    }
}
Also used : RecordingMetaData(org.apache.openmeetings.db.entity.record.RecordingMetaData) 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) Recording(org.apache.openmeetings.db.entity.record.Recording) Serializer(org.simpleframework.xml.Serializer)

Aggregations

Persister (org.simpleframework.xml.core.Persister)9 RegistryMatcher (org.simpleframework.xml.transform.RegistryMatcher)9 Strategy (org.simpleframework.xml.strategy.Strategy)7 Serializer (org.simpleframework.xml.Serializer)6 Registry (org.simpleframework.xml.convert.Registry)6 RegistryStrategy (org.simpleframework.xml.convert.RegistryStrategy)6 IOException (java.io.IOException)3 UserConverter (org.apache.openmeetings.backup.converter.UserConverter)3 File (java.io.File)2 BaseFileItem (org.apache.openmeetings.db.entity.file.BaseFileItem)2 FileItem (org.apache.openmeetings.db.entity.file.FileItem)2 Subscribe (com.google.common.eventbus.Subscribe)1 Provides (dagger.Provides)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ArrayList (java.util.ArrayList)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 RoomConverter (org.apache.openmeetings.backup.converter.RoomConverter)1 Whiteboard (org.apache.openmeetings.db.dto.room.Whiteboard)1