public static Collection<DataFormat> getBasicDataFormats() { ArrayList<DataFormat> cFormats = new ArrayList<>(2); ArrayList<String> cExt = new ArrayList<>(1); cExt.add("xml"); DataFormat df = new DataFormat(1, new java.util.Date(), "", "XML", null, "application/xml", cExt, XmlHandler.class.getName(), true, null); cFormats.add(df); cExt = new ArrayList<>(1); cExt.add("json"); df = new DataFormat(1, new java.util.Date(), "", "JSON", null, "application/json", cExt, JsonpHandler.class.getName(), true, null); cFormats.add(df); df = new DataFormat(1, new java.util.Date(), "", "MAP", null, null, null, MapHandler.class.getName(), true, null); cFormats.add(df); return cFormats; }
@Override public void write(ObjectDataOutput out, DataFormat xFormat) throws IOException { super.writeEntity(out, xFormat); out.writeUTF(xFormat.getName()); out.writeUTF(xFormat.getDescription()); out.writeUTF(xFormat.getType()); out.writeObject(xFormat.getExtensions()); out.writeUTF(xFormat.getHandlerClass()); out.writeBoolean(xFormat.isEnabled()); out.writeObject(xFormat.getProperties()); }
@Override public Object process(Entry<String, DataFormat> entry) { logger.debug("process.enter; entry: {}", entry); if (entry.getValue() != null) { DataFormat format = entry.getValue(); if (format.getVersion() == getVersion()) { entry.setValue(null); auditEntity(AuditType.delete, format); return format; } else { // throw ex ? logger.warn("process; outdated data format version: {}; entry version: {}; process terminated", getVersion(), entry.getValue().getVersion()); } } return null; }
ContentHandler getHandler(String dataFormat) { logger.trace("getHandler.enter; got dataFormat: {}", dataFormat); ContentHandler ch = handlers.get(dataFormat); if (ch == null) { DataFormat df = getDataFormat(dataFormat); if (df != null) { dataFormat = df.getName(); ch = handlers.get(dataFormat); if (ch == null) { ch = instantiateClass(df.getHandlerClass()); } } if (ch != null) { ch.init(df.getProperties()); handlers.putIfAbsent(dataFormat, ch); } } logger.trace("getHandler.exit; returning handler {} for dataFormat: {}", ch, dataFormat); return ch; }
private List<Path> getPathFiles(Path root) throws IOException { DataFormat df = xdmRepo.getDataFormat(dataFormat); final List<String> exts; if (df != null) { exts = new ArrayList<>(df.getExtensions().size()); for (String ext: df.getExtensions()) { exts.add("." + ext); } } else { exts = new ArrayList<>(1); exts.add("." + dataFormat.toLowerCase()); } List<Path> files = new ArrayList<>(); processPathFiles(root, root, exts, files); return files; }
public void setDataFormats(Collection<DataFormat> cFormats) { if (cFormats != null) { xdmFormats = new HashMap<>(cFormats.size()); for (DataFormat df: cFormats) { xdmFormats.put(df.getName(), df); } } }
@ManagedAttribute(description="Returns Data Format description") public String getDescription() { return getEntity().getDescription(); }
@ManagedAttribute(description="Returns Handler class for this Data Format") public String getHandlerClass() { return getEntity().getHandlerClass(); }
@ManagedAttribute(description="Returns Data Store properties") public CompositeData getProperties() { DataFormat format = getEntity(); return JMXUtils.propsToComposite(entityName, "properties", format.getProperties()); }
@Override public String getDocumentContentType(long docKey) throws BagriException { Document doc = getDocument(docKey); if (doc != null) { return doc.getContentType(); } String def = repo.getSchema().getProperty(pn_schema_format_default); DataFormat df = repo.getDataFormat(def); if (df == null) { return mt_xml; } return df.getType(); }
@ManagedAttribute(description="Returns Data Format extensions") public String[] getExtensions() { DataFormat format = getEntity(); List<String> result = new ArrayList<>(format.getExtensions()); Collections.sort(result); return result.toArray(new String[result.size()]); }
@SuppressWarnings("unchecked") @Override protected Map<String, DataFormat> loadEntities() { Collection<DataFormat> formats = (Collection<DataFormat>) cfg.getEntities(DataFormat.class); Map<String, DataFormat> result = new HashMap<String, DataFormat>(formats.size()); for (DataFormat format: formats) { result.put(format.getName(), format); } return result; }
@Override public Object process(Entry<String, DataFormat> entry) { logger.debug("process.enter; entry: {}", entry); if (entry.getValue() == null) { String name = entry.getKey(); DataFormat format = new DataFormat(getVersion(), new Date(), getAdmin(), name, description, type, extensions, handler, true, properties); entry.setValue(format); auditEntity(AuditType.create, format); return format; } return null; }
public DataFormat getDataFormat(String dataFormat) { // TODO: make it as fast as possible as it is called from many other places! //logger.info("getDataFormat; format: {}", dataFormat); Map<String, DataFormat> formats = xdmFormats; if (formats == null) { HazelcastInstance dataInstance = findSystemInstance(); if (dataInstance != null) { formats = dataInstance.getMap(CN_SYS_FORMATS); } } if (formats != null) { // find by name DataFormat df = formats.get(dataFormat); if (df != null) { return df; } else { // find by extension for (DataFormat df2: formats.values()) { if (df2.getExtensions().contains(dataFormat)) { return df2; } } } // still not found -> get schema default format dataFormat = this.xdmSchema.getProperty(pn_schema_format_default); return formats.get(dataFormat); } return null; }
@ManagedOperation(description="Removes an existing Extension Library") @ManagedOperationParameters({@ManagedOperationParameter(name = "name", description = "Data Format name to delete")}) public boolean deleteDataFormat(String name) { logger.trace("deleteDataFormat.enter; name: {}", name); DataFormat format = entityCache.get(name); if (format != null) { Object result = entityCache.executeOnKey(name, new DataFormatRemover(format.getVersion(), getCurrentUser())); format = (DataFormat) result; } logger.trace("deleteDataFormat.exit; dataFormat deleted: {}", format); return format != null; }
@Override public DataFormat read(ObjectDataInput in) throws IOException { Object[] entity = super.readEntity(in); return new DataFormat( (int) entity[0], (Date) entity[1], (String) entity[2], in.readUTF(), in.readUTF(), in.readUTF(), (Collection<String>) in.readObject(), in.readUTF(), in.readBoolean(), (Properties) in.readObject()); }