Search in sources :

Example 11 with ReferenceFileItem

use of org.talend.core.model.properties.ReferenceFileItem in project tesb-studio-se by Talend.

the class RouteResourcesHelper method getRouteResourcesLocation.

public static String getRouteResourcesLocation(IRepositoryViewObject repositoryObject) {
    if (repositoryObject == null) {
        return null;
    }
    Item item = repositoryObject.getProperty().getItem();
    if (item.getReferenceResources().isEmpty()) {
        return null;
    }
    ReferenceFileItem refFileItem = (ReferenceFileItem) item.getReferenceResources().get(0);
    URI uri = refFileItem.getContent().eResource().getURI();
    try {
        return FileLocator.toFileURL(new URL(uri.toString())).getFile();
    } catch (IOException e) {
        ExceptionHandler.process(e);
    }
    return null;
}
Also used : ReferenceFileItem(org.talend.core.model.properties.ReferenceFileItem) Item(org.talend.core.model.properties.Item) ReferenceFileItem(org.talend.core.model.properties.ReferenceFileItem) IOException(java.io.IOException) URI(org.eclipse.emf.common.util.URI) URL(java.net.URL)

Example 12 with ReferenceFileItem

use of org.talend.core.model.properties.ReferenceFileItem in project tesb-studio-se by Talend.

the class OpenWSDLPage method createReferenceResources.

private void createReferenceResources(String fileExtension) {
    for (Object resource : item.getReferenceResources()) {
        if (resource instanceof ReferenceFileItem && fileExtension.equals(((ReferenceFileItem) resource).getExtension())) {
            return;
        }
    }
    ReferenceFileItem referenceFileItem = PropertiesFactory.eINSTANCE.createReferenceFileItem();
    referenceFileItem.setExtension(fileExtension);
    item.getReferenceResources().add(referenceFileItem);
}
Also used : ReferenceFileItem(org.talend.core.model.properties.ReferenceFileItem) RepositoryViewObject(org.talend.core.model.repository.RepositoryViewObject)

Example 13 with ReferenceFileItem

use of org.talend.core.model.properties.ReferenceFileItem in project tmdm-studio-se by Talend.

the class DataModelOperatorUpdatorTest method testUpdateConditionOperator.

@Test
public void testUpdateConditionOperator() {
    // $NON-NLS-1$
    String filename = "Product_0.1.xsd";
    // $NON-NLS-1$
    File file = new File("temp/" + filename);
    try {
        byte[] fbyteArray = IOUtils.toByteArray(new FileInputStream(file));
        WSDataModelItem wsdataModelItem = MdmpropertiesFactory.eINSTANCE.createWSDataModelItem();
        ReferenceFileItem xsdFileItem = PropertiesFactory.eINSTANCE.createReferenceFileItem();
        ByteArray byteArray = PropertiesFactory.eINSTANCE.createByteArray();
        // 
        byteArray = spy(byteArray);
        // 
        when(byteArray.getInnerContent()).thenReturn(fbyteArray);
        xsdFileItem.setContent(byteArray);
        xsdFileItem.setExtension("xsd");
        wsdataModelItem.getReferenceResources().add(xsdFileItem);
        WSDataModelE wsdataModelE = MdmserverobjectFactory.eINSTANCE.createWSDataModelE();
        wsdataModelE.setXsdSchema(null);
        wsdataModelItem.setWsDataModel(wsdataModelE);
        ItemState itemState = PropertiesFactory.eINSTANCE.createItemState();
        itemState.setPath("system");
        wsdataModelItem.setState(itemState);
        DataModelOperatorUpdator dataModelOperatorUpdator = Mockito.spy(new DataModelOperatorUpdator());
        Mockito.doNothing().when(dataModelOperatorUpdator).saveItem(Mockito.any(Item.class), Mockito.anyBoolean());
        boolean updated = dataModelOperatorUpdator.updateConditionOperator(wsdataModelItem);
        assertFalse(updated);
        itemState.setPath("");
        updated = dataModelOperatorUpdator.updateConditionOperator(wsdataModelItem);
        assertTrue(updated);
        String xsdSchema = wsdataModelItem.getWsDataModel().getXsdSchema();
        assertNotNull(xsdSchema);
        // $NON-NLS-1$
        assertFalse(xsdSchema.contains("Strict Contains"));
        // $NON-NLS-1$
        assertFalse(xsdSchema.contains("Contains Text Of"));
        // $NON-NLS-1$
        assertTrue(xsdSchema.contains("Contains"));
        Mockito.verify(dataModelOperatorUpdator).saveItem(Mockito.any(Item.class), Mockito.anyBoolean());
    } catch (Exception e) {
        LOG.error(e.getMessage(), e);
    }
}
Also used : ReferenceFileItem(org.talend.core.model.properties.ReferenceFileItem) WSDataModelE(org.talend.mdm.repository.model.mdmserverobject.WSDataModelE) FileInputStream(java.io.FileInputStream) ReferenceFileItem(org.talend.core.model.properties.ReferenceFileItem) Item(org.talend.core.model.properties.Item) WSDataModelItem(org.talend.mdm.repository.model.mdmproperties.WSDataModelItem) WSDataModelItem(org.talend.mdm.repository.model.mdmproperties.WSDataModelItem) ItemState(org.talend.core.model.properties.ItemState) ByteArray(org.talend.core.model.properties.ByteArray) File(java.io.File) Test(org.junit.Test)

Example 14 with ReferenceFileItem

use of org.talend.core.model.properties.ReferenceFileItem in project tmdm-studio-se by Talend.

the class ConsistencyService method getReferenceFile.

private IFile getReferenceFile(Item item, ERepositoryObjectType type) {
    item = RepositoryResourceUtil.assertItem(item);
    List refResources = item.getReferenceResources();
    if (refResources != null && !refResources.isEmpty()) {
        ReferenceFileItem fileItem = (ReferenceFileItem) refResources.get(0);
        ByteArray content = fileItem.getContent();
        if (content.eResource() != null) {
            URI uri = content.eResource().getURI();
            if (uri.isPlatformResource()) {
                IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
                IPath path = new Path(uri.toPlatformString(true));
                IFile file = root.getFile(path);
                return file;
            }
        } else {
            return RepositoryResourceUtil.findReferenceFile(type, item, fileItem.getExtension());
        }
    }
    return null;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) ReferenceFileItem(org.talend.core.model.properties.ReferenceFileItem) IFile(org.eclipse.core.resources.IFile) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IPath(org.eclipse.core.runtime.IPath) ByteArray(org.talend.core.model.properties.ByteArray) List(java.util.List) ArrayList(java.util.ArrayList) InternalEList(org.eclipse.emf.ecore.util.InternalEList) LinkedList(java.util.LinkedList) EList(org.eclipse.emf.common.util.EList) URI(org.eclipse.emf.common.util.URI)

Example 15 with ReferenceFileItem

use of org.talend.core.model.properties.ReferenceFileItem in project tmdm-studio-se by Talend.

the class AbstractDataModelUpdator method updateDatamodel.

public boolean updateDatamodel(Item item) {
    boolean modified = false;
    if (item != null && item instanceof WSDataModelItem && accept(item)) {
        WSDataModelItem modelItem = (WSDataModelItem) item;
        EList<ReferenceFileItem> resources = modelItem.getReferenceResources();
        for (ReferenceFileItem fileItem : resources) {
            if (fileItem.getExtension().equals("xsd")) {
                // $NON-NLS-1$
                ByteArray content = fileItem.getContent();
                String xsdSchema = doUpdate(content.getInnerContent());
                if (xsdSchema != null) {
                    try {
                        // $NON-NLS-1$
                        byte[] byteContent = xsdSchema.getBytes("utf-8");
                        content.setInnerContent(byteContent);
                        // $NON-NLS-1$
                        modelItem.getWsDataModel().setXsdSchema(new String(byteContent, "utf-8"));
                    } catch (UnsupportedEncodingException e) {
                        // $NON-NLS-1$
                        LOG.error("Failed to encode/decode string by 'utf-8' encoding.", e);
                    }
                    modified = true;
                }
                break;
            }
        }
        saveItem(item, modified);
    }
    return modified;
}
Also used : ReferenceFileItem(org.talend.core.model.properties.ReferenceFileItem) WSDataModelItem(org.talend.mdm.repository.model.mdmproperties.WSDataModelItem) ByteArray(org.talend.core.model.properties.ByteArray) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

ReferenceFileItem (org.talend.core.model.properties.ReferenceFileItem)17 ByteArray (org.talend.core.model.properties.ByteArray)10 InputStream (java.io.InputStream)5 WSDataModelItem (org.talend.mdm.repository.model.mdmproperties.WSDataModelItem)5 File (java.io.File)4 IOException (java.io.IOException)4 IPath (org.eclipse.core.runtime.IPath)4 URI (org.eclipse.emf.common.util.URI)4 Item (org.talend.core.model.properties.Item)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 FileInputStream (java.io.FileInputStream)3 URL (java.net.URL)3 IFile (org.eclipse.core.resources.IFile)3 Path (org.eclipse.core.runtime.Path)3 EList (org.eclipse.emf.common.util.EList)3 Test (org.junit.Test)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2