use of org.apache.hop.metadata.api.IHopMetadata in project hop by apache.
the class HopGuiAuditDelegate method openMetadataObject.
private void openMetadataObject(String className, String name) throws HopException {
try {
IHopMetadataProvider metadataProvider = hopGui.getMetadataProvider();
MetadataPerspective perspective = MetadataPerspective.getInstance();
// Find the class...
List<Class<IHopMetadata>> metadataClasses = metadataProvider.getMetadataClasses();
for (Class<IHopMetadata> metadataClass : metadataClasses) {
if (metadataClass.getName().equals(className)) {
// Get the serializer and open it up
//
IHopMetadataSerializer<IHopMetadata> serializer = metadataProvider.getSerializer(metadataClass);
//
if (serializer.exists(name)) {
IHopMetadata metadata = serializer.load(name);
MetadataManager<IHopMetadata> metadataManager = new MetadataManager<>(HopGui.getInstance().getVariables(), metadataProvider, metadataClass);
MetadataEditor<IHopMetadata> editor = metadataManager.createEditor(metadata);
// We assume that all tab items are closed so we can just open up a new editor for the
// metadata
//
perspective.addEditor(editor);
}
}
}
} catch (Exception e) {
throw new HopException("Error opening metadata object '" + name + "' of class " + className, e);
}
}
use of org.apache.hop.metadata.api.IHopMetadata in project hop by apache.
the class JsonMetadataProvider method getSerializer.
@Override
public <T extends IHopMetadata> IHopMetadataSerializer<T> getSerializer(Class<T> managedClass) throws HopException {
if (managedClass == null) {
throw new HopException("You need to specify the class to serialize");
}
// Is this a metadata class?
//
HopMetadata hopMetadata = managedClass.getAnnotation(HopMetadata.class);
if (hopMetadata == null) {
throw new HopException("To serialize class " + managedClass.getClass().getName() + " it needs to have annotation " + HopMetadata.class.getName());
}
String classFolder = Const.NVL(hopMetadata.key(), hopMetadata.name());
String serializerBaseFolderName = baseFolder + (baseFolder.endsWith(Const.FILE_SEPARATOR) ? "" : Const.FILE_SEPARATOR) + classFolder;
// Check if the folder exists...
//
FileObject serializerBaseFolder = HopVfs.getFileObject(serializerBaseFolderName);
try {
if (!serializerBaseFolder.exists()) {
serializerBaseFolder.createFolder();
}
} catch (Exception e) {
throw new HopException("Error validating or creating folder '" + serializerBaseFolderName + "'to store JSON serialized objects in from class " + managedClass.getName());
}
return new JsonMetadataSerializer<>(this, serializerBaseFolderName, managedClass, variables, hopMetadata.name());
}
use of org.apache.hop.metadata.api.IHopMetadata in project hop by apache.
the class XmlMetadataUtil method serializeObjectToXml.
/**
* This method looks at the fields in the class of the provided object. It then sees which fields
* have annotation HopMetadataProperty and proceeds to serialize the values of those fields as
* XML.
*
* @param object The object to serialize to XML
* @return The XML representation of the given object.
* @throws HopException
*/
public static String serializeObjectToXml(Object object) throws HopException {
String xml = "";
// Pick up all the @HopMetadataProperty annotations
// Serialize them to XML
//
List<Field> fields = new ArrayList(ReflectionUtil.findAllFields(object.getClass()));
// Sort the fields by name to get stable XML as output
//
Collections.sort(fields, Comparator.comparing(Field::getName));
for (Field field : fields) {
//
if (Modifier.isTransient(field.getModifiers()) || Modifier.isVolatile(field.getModifiers())) {
continue;
}
HopMetadataProperty property = field.getAnnotation(HopMetadataProperty.class);
if (property != null) {
String groupKey = property.groupKey();
String tag = property.key();
if (StringUtils.isEmpty(tag)) {
tag = field.getName();
}
Class<?> fieldType = field.getType();
// Is this a boolean?
//
boolean isBoolean = Boolean.class.equals(fieldType) || boolean.class.equals(fieldType);
// A password?
//
boolean isPassword = property.password();
// Store enums with their code?
//
boolean storeWithCode = property.storeWithCode();
// Get the value of the field...
//
Object value = ReflectionUtil.getFieldValue(object, field.getName(), isBoolean);
if (value != null) {
//
if (property.storeWithName()) {
xml += XmlHandler.addTagValue(tag, ((IHopMetadata) value).getName());
} else {
xml += serializeObjectToXml(value, groupKey, tag, isPassword, storeWithCode);
}
}
}
}
return xml;
}
use of org.apache.hop.metadata.api.IHopMetadata in project hop by apache.
the class HopMetadataUtil method getHopMetadataKeys.
public static String[] getHopMetadataKeys(IHopMetadataProvider provider) {
List<String> keys = new ArrayList<>();
for (Class<IHopMetadata> metadataClass : provider.getMetadataClasses()) {
HopMetadata hopMetadata = getHopMetadataAnnotation(metadataClass);
keys.add(hopMetadata.key());
}
Collections.sort(keys);
return keys.toArray(new String[0]);
}
use of org.apache.hop.metadata.api.IHopMetadata in project hop by apache.
the class MetadataFileTypeHandler method findTabItemHandler.
private TabItemHandler findTabItemHandler() {
if (metadata == null) {
return null;
}
MetadataPerspective perspective = MetadataPerspective.getInstance();
for (TabItemHandler tabItemHandler : perspective.getItems()) {
CTabItem tabItem = tabItemHandler.getTabItem();
MetadataEditor editor = (MetadataEditor) tabItem.getData();
IHopMetadata other = editor.getMetadata();
if (other.equals(metadata)) {
return tabItemHandler;
}
}
return null;
}
Aggregations