有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java使用管理目录API将一个组织单元移动到另一个组织单元?

我需要将一个组织从一个转移到另一个。我的组织单位如下:

      Domain.com
          -> Grade 12
                 - Botany
                 - Mathematics
          -> Grade 11
                 - Zoology

我需要把《植物学》从12年级转到11年级。这是我的代码:

        List<String> oua = new ArrayList<String>();
        oua.add("Grade 12");
        oua.add("Botany");
        OrgUnit org = service.orgunits().get("my_customer", oua).execute();

        org.setParentOrgUnitPath("/Grade 11");
        OrgUnit org = service.orgunits().update("my_customer", oua, org).execute();

我一直在关注这个问题。但这对我没什么帮助。我可以更新“植物学”的名称。但我无法移动组织单位。我得到这个错误:

Exception in thread "main" com.google.api.client.googleapis.json.GoogleJsonResponseException: 404 Not Found
{
  "code" : 404,
  "errors" : [ {
    "domain" : "global",
    "message" : "Parent Org unit not found",
    "reason" : "notFound"
  } ],
  "message" : "Parent Org unit not found"
}

导致此错误的原因是什么?如何解决此问题

编辑1: 这是我的全部代码:

public class Gsuite {
    private static Logger logger = LoggerFactory.getLogger(Gsuite.class);


    private static final String APPLICATION_NAME = "Quickstart";
    private static final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
    private static final String TOKENS_DIRECTORY_PATH = "tokens";


    /**
     * Global instance of the scopes required by this quickstart.
     * If modifying these scopes, delete your previously saved tokens/ folder.
     */
    private static final List<String> SCOPES = Arrays.asList(DirectoryScopes.ADMIN_DIRECTORY_USER,DirectoryScopes.ADMIN_DIRECTORY_GROUP,
            DirectoryScopes.ADMIN_DIRECTORY_GROUP_MEMBER, DirectoryScopes.ADMIN_DIRECTORY_ORGUNIT, DirectoryScopes.ADMIN_DIRECTORY_USER_SECURITY);

    private static final String CREDENTIALS_FILE_PATH = "/credentials.json";


    /**
     * Creates an authorized Credential object.
     * @param HTTP_TRANSPORT The network HTTP Transport.
     * @return An authorized Credential object.
     * @throws IOException If the credentials.json file cannot be found.
     */
    protected static Credential getCredentials(final NetHttpTransport HTTP_TRANSPORT) throws IOException {
        // Load client secrets.
        InputStream in = Gsuite.class.getResourceAsStream(CREDENTIALS_FILE_PATH);
        if (in == null) {
            throw new FileNotFoundException("Resource not found: " + CREDENTIALS_FILE_PATH);
        }
        GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(in));

        // Build flow and trigger user authorization request.
        GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
                HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES)
                .setDataStoreFactory(new FileDataStoreFactory(new java.io.File(TOKENS_DIRECTORY_PATH)))
                .setAccessType("offline")
                .build();
        LocalServerReceiver receiver = new LocalServerReceiver.Builder().setPort(8888).build();
        return new AuthorizationCodeInstalledApp(flow, receiver).authorize("user");
    }
    public Directory directoryApiCall() throws GeneralSecurityException, IOException {
        final NetHttpTransport HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();
        Directory service = new Directory.Builder(HTTP_TRANSPORT, JSON_FACTORY, getCredentials(HTTP_TRANSPORT))
            .setApplicationName(APPLICATION_NAME)
            .build();
        return service;
    }

     public void updateOrgUnit() throws GeneralSecurityException, IOException {
            Gsuite api = new Gsuite();
            Directory service = api.directoryApiCall();

            List<String> oua = new ArrayList<String>();
            oua.add("Grade 12");
            oua.add("Botany");
            OrgUnit org = service.orgunits().get("my_customer", oua).execute();
            logger.debug("Parent Organizational unit path before moving : " + org.getParentOrgUnitPath());
            org.setParentOrgUnitPath("/Grade 11");
            logger.debug("Parent Organizational unit path after moving : " + org.getParentOrgUnitPath());

            service.orgunits().update("my_customer", oua, org).execute();

        }
     public static void main(String... args) throws GeneralSecurityException, IOException{

            Gsuite dapi = new Gsuite();
            dapi.updateOrgUnit();

   }
}   

共 (0) 个答案