nadment commented on code in PR #9533: URL: https://github.com/apache/hop/pull/9533#discussion_r4621068923
########## plugins/tech/microsoft365/src/main/java/org/apache/hop/vfs/sharepoint/SharePointFileObject.java: ########## @@ -0,0 +1,318 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.hop.vfs.sharepoint; + +import com.microsoft.graph.models.DriveItem; +import java.io.FilterOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; +import org.apache.commons.vfs2.FileNotFoundException; +import org.apache.commons.vfs2.FileObject; +import org.apache.commons.vfs2.FileSystemException; +import org.apache.commons.vfs2.FileType; +import org.apache.commons.vfs2.NameScope; +import org.apache.commons.vfs2.provider.AbstractFileName; +import org.apache.commons.vfs2.provider.AbstractFileObject; +import org.apache.commons.vfs2.provider.UriParser; +import org.apache.commons.vfs2.util.FileObjectUtils; +import org.jspecify.annotations.NullMarked; +import org.jspecify.annotations.Nullable; + +/** + * A site, a document library, or a file or folder of a document library, depending on the depth of + * its name. + */ +@NullMarked +public class SharePointFileObject extends AbstractFileObject<SharePointFileSystem> { + + /** The id of the site, only for a site. */ + private @Nullable String siteId; + + /** The id of the document library, for a library and everything below. */ + private @Nullable String driveId; + + /** The metadata of the file or folder, only below a document library. */ + private @Nullable DriveItem item; + + protected SharePointFileObject(AbstractFileName name, SharePointFileSystem fileSystem) { + super(name, fileSystem); + } + + private SharePointFileName name() { + return (SharePointFileName) getName(); + } + + @Override + protected void doAttach() throws Exception { + // Already filled in by the listing of the parent folder + if (item != null) { + return; + } + SharePointFileName name = name(); + SharePointFileSystem fileSystem = getAbstractFileSystem(); + int depth = name.getLevel(); + if (depth == SharePointFileName.SITE_DEPTH) { + siteId = fileSystem.findSiteId(name.getSiteName()); + } else if (depth >= SharePointFileName.DRIVE_DEPTH) { + driveId = fileSystem.findDriveId(name); + if (driveId != null && name.isItem()) { + item = fileSystem.findItem(driveId, name.getEncodedItemPath()); + } + } + } + + @Override + protected void doDetach() { + siteId = null; + driveId = null; + item = null; + } + + @Override + protected FileType doGetType() { + int depth = name().getLevel(); + if (depth < SharePointFileName.SITE_DEPTH) { + return FileType.FOLDER; + } + if (depth == SharePointFileName.SITE_DEPTH) { + return siteId == null ? FileType.IMAGINARY : FileType.FOLDER; + } + if (depth == SharePointFileName.DRIVE_DEPTH) { + return driveId == null ? FileType.IMAGINARY : FileType.FOLDER; + } + return typeOf(item); + } + + private static FileType typeOf(@Nullable DriveItem item) { + if (item == null) { + return FileType.IMAGINARY; + } + // A package, such as a OneNote notebook, is browsed like a folder + return item.getFolder() != null || item.getPackage() != null ? FileType.FOLDER : FileType.FILE; + } + + @Override + protected long doGetContentSize() { + return item == null || item.getSize() == null ? 0 : item.getSize(); + } + + @Override + protected long doGetLastModifiedTime() { + return item == null || item.getLastModifiedDateTime() == null + ? 0 + : item.getLastModifiedDateTime().toInstant().toEpochMilli(); + } + + @Override + protected String @Nullable [] doListChildren() throws Exception { + // A file, or a site, library or folder that does not exist + if (doGetType() != FileType.FOLDER) { + return null; + } + SharePointFileSystem fileSystem = getAbstractFileSystem(); + int depth = name().getLevel(); + List<String> names = new ArrayList<>(); + if (depth < SharePointFileName.SITE_DEPTH) { + names.addAll(fileSystem.listSites().keySet()); Review Comment: Addressed in dd80f3b6b7, by a change of path layout rather than the suggested one-liner. The root now has two fixed folders that mirror the SharePoint address, `m365:///sites` and `m365:///teams`, so opening `m365:///` no longer calls Graph and can't fail. The sites are listed under their folder; when Graph refuses to list them (`Sites.Selected`), the refusal is caught and logged, and the folder is empty, as the docs say. The full path of a granted site still works, e.g. `m365:///sites/Finance`. ########## plugins/tech/microsoft365/src/main/java/org/apache/hop/vfs/sharepoint/SharePointFileSystem.java: ########## @@ -0,0 +1,504 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.hop.vfs.sharepoint; + +import com.microsoft.graph.core.models.UploadResult; +import com.microsoft.graph.core.tasks.LargeFileUploadTask; +import com.microsoft.graph.drives.item.items.item.DriveItemItemRequestBuilder; +import com.microsoft.graph.drives.item.items.item.children.ChildrenRequestBuilder; +import com.microsoft.graph.drives.item.items.item.createuploadsession.CreateUploadSessionPostRequestBody; +import com.microsoft.graph.models.BaseCollectionPaginationCountResponse; +import com.microsoft.graph.models.DriveCollectionResponse; +import com.microsoft.graph.models.DriveItem; +import com.microsoft.graph.models.DriveItemCollectionResponse; +import com.microsoft.graph.models.DriveItemUploadableProperties; +import com.microsoft.graph.models.Folder; +import com.microsoft.graph.models.ItemReference; +import com.microsoft.graph.models.Site; +import com.microsoft.graph.models.SiteCollectionResponse; +import com.microsoft.graph.models.UploadSession; +import com.microsoft.graph.models.odataerrors.ODataError; +import com.microsoft.graph.serviceclient.GraphServiceClient; +import com.microsoft.graph.sites.item.drives.DrivesRequestBuilder; +import com.microsoft.kiota.ApiException; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; +import java.util.concurrent.ConcurrentHashMap; +import java.util.function.Consumer; +import java.util.function.Function; +import org.apache.commons.vfs2.Capability; +import org.apache.commons.vfs2.FileName; +import org.apache.commons.vfs2.FileObject; +import org.apache.commons.vfs2.FileSystemException; +import org.apache.commons.vfs2.FileSystemOptions; +import org.apache.commons.vfs2.provider.AbstractFileName; +import org.apache.commons.vfs2.provider.AbstractFileSystem; +import org.apache.hop.core.logging.LogChannel; +import org.jspecify.annotations.NullMarked; +import org.jspecify.annotations.Nullable; + +/** + * One named Microsoft 365 connection. The sites are the folders of the root, the document libraries + * (drives) of a site are the folders of that site. + */ +@NullMarked +public class SharePointFileSystem extends AbstractFileSystem { + + public static final List<Capability> CAPABILITIES = + List.of( + Capability.CREATE, + Capability.DELETE, + Capability.RENAME, + Capability.GET_TYPE, + Capability.GET_LAST_MODIFIED, + Capability.LIST_CHILDREN, + Capability.READ_CONTENT, + Capability.URI, + Capability.WRITE_CONTENT); + + /** Above this size the content is sent in slices through an upload session. */ + static final long SIMPLE_UPLOAD_LIMIT = 4L * 1024 * 1024; + + /** The id that addresses the root folder of a document library, and the root site of a tenant. */ + static final String ROOT_ITEM_ID = "root"; + + /** A site created by a Microsoft Teams team may live under /teams. */ + private static final List<String> MANAGED_PATHS = List.of("sites", "teams"); + + /** The only properties of a file or folder that are used, the others are not requested. */ + private static final String[] ITEM_PROPERTIES = { + "id", "name", "size", "lastModifiedDateTime", "file", "folder", "package" + }; + + private static final String CONFLICT_BEHAVIOR = "@microsoft.graph.conflictBehavior"; + private static final int HTTP_NOT_FOUND = 404; + private static final int HTTP_CONFLICT = 409; + + private final GraphServiceClient client; + + /** Site name to site id, whatever the case of the name, for the sites found so far. */ + private volatile Map<String, String> siteIds = newNameMap(); + + /** The SharePoint host of the tenant, null until it is needed. */ + private volatile @Nullable String hostname; + + /** True once the sites were listed, or Microsoft Graph refused to list them. */ + private volatile boolean sitesListed; + + /** Site id to (drive name to drive id, whatever the case of the name). */ + private final Map<String, Map<String, String>> driveIds = new ConcurrentHashMap<>(); + + public SharePointFileSystem( + FileName rootName, + GraphServiceClient client, + @Nullable String hostname, + @Nullable FileSystemOptions fileSystemOptions) { + super(rootName, null, fileSystemOptions); + this.client = client; + this.hostname = hostname == null || hostname.isBlank() ? null : hostname.trim(); + } + + @Override + protected void addCapabilities(Collection<Capability> capabilities) { + capabilities.addAll(CAPABILITIES); + } + + @Override + protected FileObject createFile(AbstractFileName name) { + return new SharePointFileObject(name, this); + } + + /** + * Lists the sites of the tenant and refreshes the cache. + * + * @return the site ids by site name + */ + Map<String, String> listSites() throws FileSystemException { + Map<String, String> sites = newNameMap(); + try { + addSites(sites, client.sites().get()); + } catch (ApiException e) { + throw new FileSystemException( + "Microsoft Graph refused to list the SharePoint sites: " + describe(e), e); + } + if (sites.isEmpty()) { + // Depending on the tenant the plain listing is empty and only the search returns the sites + try { + String url = client.getRequestAdapter().getBaseUrl() + "/sites?search=*"; + addSites(sites, client.sites().withUrl(url).get()); + } catch (ApiException e) { + LogChannel.GENERAL.logBasic( + "Microsoft Graph refused to search the SharePoint sites: " + describe(e)); + } + } + if (sites.isEmpty()) { + LogChannel.GENERAL.logBasic( + "Microsoft Graph returned no SharePoint site. Listing the sites needs the application" + + " permission Sites.Read.All with admin consent. With Sites.Selected the sites" + + " can not be listed, use the full path of a site the application was granted."); + } + siteIds = sites; + sitesListed = true; + driveIds.clear(); + return sites; + } + + /** + * @return the HTTP status, the error code and the message of Microsoft Graph + */ + static String describe(ApiException e) { + StringBuilder text = new StringBuilder("HTTP ").append(e.getResponseStatusCode()); + if (e instanceof ODataError error && error.getError() != null) { + text.append(' ').append(error.getError().getCode()); + text.append(": ").append(error.getError().getMessage()); + } else if (e.getMessage() != null) { + text.append(": ").append(e.getMessage()); + } + return text.toString(); + } + + private void addSites(Map<String, String> sites, @Nullable SiteCollectionResponse firstPage) { + forEachPaged( + firstPage, + SiteCollectionResponse::getValue, + nextLink -> client.sites().withUrl(nextLink).get(), + site -> addSite(sites, site)); + } + + /** Two sites can have the same name, only the first one is kept. */ + private static void addSite(Map<String, String> sites, Site site) { + String name = site.getName() != null ? site.getName() : site.getDisplayName(); + if (name == null || site.getId() == null) { + return; + } + String namesake = sites.putIfAbsent(name, site.getId()); Review Comment: Fixed in dd80f3b6b7 by removing the ambiguity instead of ordering it. The managed path is now part of the path: `m365:///sites/Finance/...` and `m365:///teams/Finance/...` are two different paths, so a path can't switch sites any more and there is no "which one wins" rule left. A site is read by its address in a single request and cached under `<managed path>/<name>`; a listing only adds entries to that cache, keyed the same way from the `webUrl` of each site, so it can't replace one site by a namesake. Side effects, in the docs: every path has one more level, and the root site of the tenant and subsites are not reachable. The path is what follows the host in the browser, which also leaves room for a `personal` folder (OneDrive) later. The issue description is updated with the new layout. ########## plugins/tech/microsoft365/src/main/java/org/apache/hop/vfs/sharepoint/metadatatype/SharePointConnection.java: ########## @@ -0,0 +1,224 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hop.vfs.sharepoint.metadatatype; + +import com.azure.core.credential.TokenCredential; +import com.azure.identity.ClientCertificateCredentialBuilder; +import com.azure.identity.ClientSecretCredentialBuilder; +import com.azure.identity.DefaultAzureCredentialBuilder; +import java.io.ByteArrayInputStream; +import java.nio.charset.StandardCharsets; +import lombok.Getter; +import lombok.Setter; +import org.apache.hop.core.exception.HopException; +import org.apache.hop.core.gui.plugin.GuiElementType; +import org.apache.hop.core.gui.plugin.GuiPlugin; +import org.apache.hop.core.gui.plugin.GuiWidgetElement; +import org.apache.hop.core.logging.ILogChannel; +import org.apache.hop.core.variables.IVariables; +import org.apache.hop.core.vfs.IVfsBrowseLocation; +import org.apache.hop.i18n.BaseMessages; +import org.apache.hop.metadata.api.HopMetadata; +import org.apache.hop.metadata.api.HopMetadataBase; +import org.apache.hop.metadata.api.HopMetadataCategory; +import org.apache.hop.metadata.api.HopMetadataProperty; +import org.apache.hop.metadata.api.HopMetadataPropertyType; +import org.apache.hop.metadata.api.IEnumHasCode; +import org.apache.hop.metadata.api.IEnumHasCodeAndDescription; +import org.apache.hop.metadata.api.IHopMetadata; +import org.jspecify.annotations.NullMarked; +import org.jspecify.annotations.Nullable; + +@Getter +@Setter +@NullMarked +@GuiPlugin(classLoaderGroup = "vfs-graph") +@HopMetadata( + key = "sharepoint-connection", + name = "i18n::SharePointConnection.Name", + description = "i18n::SharePointConnection.Description", + image = "sharepoint.svg", + category = HopMetadataCategory.FILE_STORAGE, + documentationUrl = "/metadata-types/sharepoint-connection.html", + hopMetadataPropertyType = HopMetadataPropertyType.VFS_SHAREPOINT_CONNECTION, + classLoaderGroup = "vfs-graph") +public class SharePointConnection extends HopMetadataBase + implements IHopMetadata, IVfsBrowseLocation { + private static final Class<?> PKG = SharePointConnection.class; + + public static final String WIDGET_AUTHENTICATION_TYPE = "sharepoint-authentication-type"; + public static final String WIDGET_CLIENT_ID = "sharepoint-client-id"; + public static final String WIDGET_CLIENT_SECRET = "sharepoint-client-secret"; + public static final String WIDGET_CERTIFICATE = "sharepoint-certificate"; + + public enum AuthenticationType implements IEnumHasCodeAndDescription { + + /** Managed Identity. */ + MANAGED_IDENTITY("SharePointAuthenticationType.ManagedIdentity"), + /** Client Secret authentication. */ + SECRET("SharePointAuthenticationType.Secret"), + /** Client Certificate authentication. */ + CERTIFICATE("SharePointAuthenticationType.Certificate"); + + /** The authentification type description. */ + @Getter private final String description; + + AuthenticationType(String description) { + this.description = BaseMessages.getString(PKG, description); + } + + @Override + public String getCode() { + return name(); + } + + /** + * Return the authentification type for a certain code + * + * @param code the code to look for + * @return the authentification type or MANAGED_IDENTITY if nothing matches. + */ + public static AuthenticationType lookupCode(String code) { + return IEnumHasCode.lookupCode(AuthenticationType.class, code, MANAGED_IDENTITY); + } + + /** + * Return the authentification type for a certain description + * + * @param description the description to look for + * @return the authentification type or MANAGED_IDENTITY if nothing matches. + */ + public static AuthenticationType lookupDescription(String description) { + return IEnumHasCodeAndDescription.lookupDescription( + AuthenticationType.class, description, MANAGED_IDENTITY); + } + } + + public SharePointConnection() { + // Default to client secret authentication + this.authenticationType = AuthenticationType.SECRET; + } + + @GuiWidgetElement( + id = "sharepoint-description", + order = "0100", + parentId = SharePointConnectionEditor.GUI_PLUGIN_ELEMENT_PARENT_ID, + type = GuiElementType.MULTI_LINE_TEXT, + multiLineTextHeight = 4, + variables = false, + label = "i18n::SharePointConnectionEditor.Description.Label") + @HopMetadataProperty + private @Nullable String description; + + @GuiWidgetElement( + id = WIDGET_AUTHENTICATION_TYPE, + order = "0200", + parentId = SharePointConnectionEditor.GUI_PLUGIN_ELEMENT_PARENT_ID, + type = GuiElementType.COMBO, + variables = false, + label = "i18n::SharePointConnectionEditor.AuthenticationType.Label") + @HopMetadataProperty(storeWithCode = true) + private AuthenticationType authenticationType; + + @GuiWidgetElement( + id = "sharepoint-tenant-id", + order = "0300", + parentId = SharePointConnectionEditor.GUI_PLUGIN_ELEMENT_PARENT_ID, + type = GuiElementType.TEXT, + label = "i18n::SharePointConnectionEditor.TenantId.Label", + toolTip = "i18n::SharePointConnectionEditor.TenantId.Tooltip") + @HopMetadataProperty + private @Nullable String tenantId; + + /** + * The SharePoint host of the tenant, such as contoso.sharepoint.com. Needed when the application + * can not read the root site of the tenant to find it. + */ + @GuiWidgetElement( + id = "sharepoint-hostname", + order = "0400", + parentId = SharePointConnectionEditor.GUI_PLUGIN_ELEMENT_PARENT_ID, + type = GuiElementType.TEXT, + label = "i18n::SharePointConnectionEditor.Hostname.Label", + toolTip = "i18n::SharePointConnectionEditor.Hostname.Tooltip") + @HopMetadataProperty + private @Nullable String hostname; + + @GuiWidgetElement( + id = WIDGET_CLIENT_ID, + order = "0500", + parentId = SharePointConnectionEditor.GUI_PLUGIN_ELEMENT_PARENT_ID, + type = GuiElementType.TEXT, + label = "i18n::SharePointConnectionEditor.ClientId.Label", + toolTip = "i18n::SharePointConnectionEditor.ClientId.Tooltip") + @HopMetadataProperty + private @Nullable String clientId; + + @GuiWidgetElement( + id = WIDGET_CLIENT_SECRET, + order = "0600", + parentId = SharePointConnectionEditor.GUI_PLUGIN_ELEMENT_PARENT_ID, + type = GuiElementType.TEXT, + password = true, + label = "i18n::SharePointConnectionEditor.ClientSecret.Label", + toolTip = "i18n::SharePointConnectionEditor.ClientSecret.Tooltip") + @HopMetadataProperty(password = true) + private @Nullable String clientSecret; + + /** Certificate with its private key in PEM format */ + @GuiWidgetElement( + id = WIDGET_CERTIFICATE, + order = "0700", + parentId = SharePointConnectionEditor.GUI_PLUGIN_ELEMENT_PARENT_ID, + type = GuiElementType.MULTI_LINE_TEXT, + multiLineTextHeight = 12, + label = "i18n::SharePointConnectionEditor.PEMCertificate.Label", + toolTip = "i18n::SharePointConnectionEditor.PEMCertificate.Tooltip") + @HopMetadataProperty(password = true) + private @Nullable String certificate; + + public TokenCredential credentials(ILogChannel log, IVariables variables) throws HopException { + + String resolvedTenantId = variables.resolve(getTenantId()); + + return switch (authenticationType) { + case SECRET -> { + log.logBasic("SharePoint authentication is using Client Secret Credentials"); + yield new ClientSecretCredentialBuilder() + .tenantId(resolvedTenantId) + .clientId(variables.resolve(getClientId())) + .clientSecret(variables.resolve(getClientSecret())) + .build(); + } + case CERTIFICATE -> { + log.logBasic("SharePoint authentication is using Client Certificate Credentials"); + String resolvedCertificate = variables.resolve(getCertificate()); + yield new ClientCertificateCredentialBuilder() + .tenantId(resolvedTenantId) + .clientId(variables.resolve(getClientId())) + .pemCertificate( + new ByteArrayInputStream(resolvedCertificate.getBytes(StandardCharsets.UTF_8))) + .build(); + } Review Comment: Fixed in dd80f3b6b7: an empty tenant ID, client ID, client secret or certificate now throws a `HopException` naming the missing option (`The option "PEM Certificate" of the SharePoint connection is empty`), for both Test and file access. Covered by `SharePointFileSystemTest`. ########## plugins/tech/microsoft365/src/main/java/org/apache/hop/vfs/sharepoint/metadatatype/SharePointConnectionEditor.java: ########## @@ -0,0 +1,234 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hop.vfs.sharepoint.metadatatype; + +import com.azure.core.credential.TokenCredential; +import com.azure.core.credential.TokenRequestContext; +import java.util.HashSet; +import java.util.Set; +import org.apache.hop.core.Const; +import org.apache.hop.core.exception.HopException; +import org.apache.hop.core.gui.plugin.GuiPlugin; +import org.apache.hop.core.logging.LogChannel; +import org.apache.hop.core.vfs.HopVfs; +import org.apache.hop.i18n.BaseMessages; +import org.apache.hop.ui.core.PropsUi; +import org.apache.hop.ui.core.dialog.ErrorDialog; +import org.apache.hop.ui.core.dialog.MessageBox; +import org.apache.hop.ui.core.gui.GuiCompositeWidgets; +import org.apache.hop.ui.core.gui.GuiCompositeWidgetsAdapter; +import org.apache.hop.ui.core.metadata.MetadataEditor; +import org.apache.hop.ui.core.metadata.MetadataManager; +import org.apache.hop.ui.core.widget.ComboVar; +import org.apache.hop.ui.core.widget.NamingSchemeTypes; +import org.apache.hop.ui.core.widget.TextVar; +import org.apache.hop.ui.hopgui.HopGui; +import org.apache.hop.ui.hopgui.vfs.explorer.VfsFileExplorerViews; +import org.apache.hop.vfs.sharepoint.metadatatype.SharePointConnection.AuthenticationType; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.jspecify.annotations.NullMarked; + +/** + * The name is the only widget created here, the other options are the fields of {@link + * SharePointConnection} annotated with {@code @GuiWidgetElement}. + */ +@NullMarked +@GuiPlugin( + description = "Editor for SharePoint connection metadata", + classLoaderGroup = "vfs-graph") +public class SharePointConnectionEditor extends MetadataEditor<SharePointConnection> { + + private static final Class<?> PKG = SharePointConnectionEditor.class; + + public static final String GUI_PLUGIN_ELEMENT_PARENT_ID = + "SharePointConnectionEditor-GuiWidgetsParent"; + + private TextVar wName; + private Composite wWidgetsComposite; + private GuiCompositeWidgets guiCompositeWidgets; + + public SharePointConnectionEditor( + HopGui hopGui, MetadataManager<SharePointConnection> manager, SharePointConnection metadata) { + super(hopGui, manager, metadata); + } + + @Override + public void createControl(Composite parent) { + int middle = PropsUi.getInstance().getMiddlePct(); + int margin = PropsUi.getMargin() + 2; + + Label wIcon = new Label(parent, SWT.RIGHT); + wIcon.setImage(getImage()); + FormData fdIcon = new FormData(); + fdIcon.top = new FormAttachment(0, 0); + fdIcon.right = new FormAttachment(100, 0); + wIcon.setLayoutData(fdIcon); + PropsUi.setLook(wIcon); + + Label wlName = new Label(parent, SWT.RIGHT); + PropsUi.setLook(wlName); + wlName.setText(BaseMessages.getString(PKG, "SharePointConnectionEditor.Name.Label")); + FormData fdlName = new FormData(); + fdlName.top = new FormAttachment(0, margin); + fdlName.left = new FormAttachment(0, 0); + fdlName.right = new FormAttachment(middle, -margin); + wlName.setLayoutData(fdlName); + wName = + new TextVar(hopGui.getVariables(), parent, SWT.SINGLE | SWT.LEFT | SWT.BORDER) + .asNameField(NamingSchemeTypes.HOP_METADATA); + PropsUi.setLook(wName); + FormData fdName = new FormData(); + fdName.top = new FormAttachment(wlName, 0, SWT.CENTER); + fdName.left = new FormAttachment(middle, 0); + fdName.right = new FormAttachment(wIcon, -margin); + wName.setLayoutData(fdName); + + wWidgetsComposite = new Composite(parent, SWT.NONE); + PropsUi.setLook(wWidgetsComposite); + wWidgetsComposite.setLayout(new FormLayout()); + FormData fdWidgetsComposite = new FormData(); + fdWidgetsComposite.top = new FormAttachment(wName, margin); + fdWidgetsComposite.left = new FormAttachment(0, 0); + fdWidgetsComposite.right = new FormAttachment(100, 0); + fdWidgetsComposite.bottom = new FormAttachment(100, 0); + wWidgetsComposite.setLayoutData(fdWidgetsComposite); + + guiCompositeWidgets = new GuiCompositeWidgets(manager.getVariables()); + guiCompositeWidgets.createCompositeWidgets( Review Comment: Done in dd80f3b6b7: every field has `groupType = GuiWidgetGroupType.TABS` with two groups, *Connection* (description, tenant ID, SharePoint host) and *Authentication* (type, client ID, secret, certificate), and the editor uses `GuiCompositeWidgets.addScrolledComposite`. ########## plugins/tech/microsoft365/pom.xml: ########## @@ -0,0 +1,270 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ Licensed to the Apache Software Foundation (ASF) under one or more + ~ contributor license agreements. See the NOTICE file distributed with + ~ this work for additional information regarding copyright ownership. + ~ The ASF licenses this file to You under the Apache License, Version 2.0 + ~ (the "License"); you may not use this file except in compliance with + ~ the License. You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License. + ~ + --> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.hop</groupId> + <artifactId>hop-plugins-tech</artifactId> + <version>2.21.0-SNAPSHOT</version> + </parent> + + <artifactId>hop-tech-microsoft365</artifactId> + <packaging>jar</packaging> + <name>Hop Plugins Technology Microsoft 365</name> + + <properties> + <azure-eventhubs.version>3.3.0</azure-eventhubs.version> Review Comment: Removed in dd80f3b6b7. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
