Search in sources :

Example 1 with RegistryMatcher

use of org.simpleframework.xml.transform.RegistryMatcher in project osm-contributor by jawg.

the class CommonSyncModule method getPersister.

@Provides
Persister getPersister() {
    RegistryMatcher matchers = new RegistryMatcher();
    matchers.bind(org.joda.time.DateTime.class, JodaTimeDateTimeTransform.class);
    Strategy strategy = new AnnotationStrategy();
    return new Persister(strategy, matchers);
}
Also used : AnnotationStrategy(org.simpleframework.xml.convert.AnnotationStrategy) AnnotationStrategy(org.simpleframework.xml.convert.AnnotationStrategy) Strategy(org.simpleframework.xml.strategy.Strategy) RegistryMatcher(org.simpleframework.xml.transform.RegistryMatcher) Persister(org.simpleframework.xml.core.Persister) Provides(dagger.Provides)

Example 2 with RegistryMatcher

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

the class BackupImport method importConfigs.

/*
	 * ##################### Import Configs
	 */
private void importConfigs(File f) throws Exception {
    Registry registry = new Registry();
    Strategy strategy = new RegistryStrategy(registry);
    RegistryMatcher matcher = new RegistryMatcher();
    Serializer serializer = new Persister(strategy, matcher);
    matcher.bind(Long.class, LongTransform.class);
    registry.bind(Date.class, DateConverter.class);
    registry.bind(User.class, new UserConverter(userDao, userMap));
    List<Configuration> list = readList(serializer, f, "configs.xml", "configs", Configuration.class);
    for (Configuration c : list) {
        if (c.getKey() == null || c.isDeleted()) {
            continue;
        }
        String newKey = outdatedConfigKeys.get(c.getKey());
        if (newKey != null) {
            c.setKey(newKey);
        }
        Configuration.Type type = configTypes.get(c.getKey());
        if (type != null) {
            c.setType(type);
            if (Configuration.Type.bool == type) {
                c.setValue(String.valueOf("1".equals(c.getValue()) || "yes".equals(c.getValue()) || "true".equals(c.getValue())));
            }
        }
        Configuration cfg = cfgDao.forceGet(c.getKey());
        if (cfg != null && !cfg.isDeleted()) {
            log.warn("Non deleted configuration with same key is found! old value: {}, new value: {}", cfg.getValue(), c.getValue());
        }
        c.setId(cfg == null ? null : cfg.getId());
        if (c.getUser() != null && c.getUser().getId() == null) {
            c.setUser(null);
        }
        if (CONFIG_CRYPT.equals(c.getKey())) {
            try {
                Class<?> clazz = Class.forName(c.getValue());
                clazz.getDeclaredConstructor().newInstance();
            } catch (Exception e) {
                log.warn("Not existing Crypt class found {}, replacing with SCryptImplementation", c.getValue());
                c.setValue(SCryptImplementation.class.getCanonicalName());
            }
        }
        cfgDao.update(c, null);
    }
}
Also used : UserConverter(org.apache.openmeetings.backup.converter.UserConverter) Configuration(org.apache.openmeetings.db.entity.basic.Configuration) RegistryMatcher(org.simpleframework.xml.transform.RegistryMatcher) Registry(org.simpleframework.xml.convert.Registry) IOException(java.io.IOException) RegistryStrategy(org.simpleframework.xml.convert.RegistryStrategy) RegistryStrategy(org.simpleframework.xml.convert.RegistryStrategy) Strategy(org.simpleframework.xml.strategy.Strategy) Persister(org.simpleframework.xml.core.Persister) Serializer(org.simpleframework.xml.Serializer)

Example 3 with RegistryMatcher

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

the class BackupImport method importRooms.

/*
	 * ##################### Import Rooms
	 */
private void importRooms(File f) throws Exception {
    log.info("Users import complete, starting room 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(User.class, new UserConverter(userDao, userMap));
    registry.bind(Room.Type.class, RoomTypeConverter.class);
    registry.bind(Date.class, DateConverter.class);
    List<Room> list = readList(ser, f, "rooms.xml", "rooms", Room.class);
    for (Room r : list) {
        Long roomId = r.getId();
        // We need to reset ids as openJPA reject to store them otherwise
        r.setId(null);
        if (r.getModerators() != null) {
            for (Iterator<RoomModerator> i = r.getModerators().iterator(); i.hasNext(); ) {
                RoomModerator rm = i.next();
                if (rm.getUser().getId() == null) {
                    i.remove();
                }
            }
        }
        r = roomDao.update(r, null);
        roomMap.put(roomId, r.getId());
    }
}
Also used : UserConverter(org.apache.openmeetings.backup.converter.UserConverter) RegistryStrategy(org.simpleframework.xml.convert.RegistryStrategy) RoomModerator(org.apache.openmeetings.db.entity.room.RoomModerator) 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) Room(org.apache.openmeetings.db.entity.room.Room) Serializer(org.simpleframework.xml.Serializer)

Example 4 with RegistryMatcher

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

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

the class AntXmlReport method onSuiteResult.

/**
 * Emit information about all of suite's tests.
 */
@Subscribe
public void onSuiteResult(AggregatedSuiteResultEvent e) {
    // Calculate summaries.
    summaryListener.suiteSummary(e);
    Description suiteDescription = e.getDescription();
    String displayName = suiteDescription.getDisplayName();
    if (displayName.trim().isEmpty()) {
        junit4.log("Could not emit XML report for suite (null description).", Project.MSG_WARN);
        return;
    }
    if (!suiteCounts.containsKey(displayName)) {
        suiteCounts.put(displayName, 1);
    } else {
        int newCount = suiteCounts.get(displayName) + 1;
        suiteCounts.put(displayName, newCount);
        if (!ignoreDuplicateSuites && newCount == 2) {
            junit4.log("Duplicate suite name used with XML reports: " + displayName + ". This may confuse tools that process XML reports. " + "Set 'ignoreDuplicateSuites' to true to skip this message.", Project.MSG_WARN);
        }
        displayName = displayName + "-" + newCount;
    }
    try {
        File reportFile = new File(dir, "TEST-" + displayName + ".xml");
        RegistryMatcher rm = new RegistryMatcher();
        rm.bind(String.class, new XmlStringTransformer());
        Persister persister = new Persister(rm);
        persister.write(buildModel(e), reportFile);
    } catch (Exception x) {
        junit4.log("Could not serialize report for suite " + displayName + ": " + x.toString(), x, Project.MSG_WARN);
    }
}
Also used : Description(org.junit.runner.Description) RegistryMatcher(org.simpleframework.xml.transform.RegistryMatcher) Persister(org.simpleframework.xml.core.Persister) File(java.io.File) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException) Subscribe(com.google.common.eventbus.Subscribe)

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