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);
}
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);
}
}
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());
}
}
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;
}
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);
}
}
Aggregations