Ejemplo n.º 1
0
  @Override
  protected void doGet(final HttpServletRequest req, final HttpServletResponse resp)
      throws IOException {

    try {
      AppIdentityCredential credential = new AppIdentityCredential(Arrays.asList(STORAGE_SCOPE));

      // Set up and execute Google Cloud Storage request.
      String bucketName = req.getRequestURI();
      if (bucketName.equals("/")) {
        resp.sendError(
            HTTP_NOT_FOUND, "No bucket specified - append /bucket-name to the URL and retry.");
        return;
      }
      // Remove any trailing slashes, if found.
      // [START snippet]
      String cleanBucketName = bucketName.replaceAll("/$", "");
      String uri = GCS_URI + cleanBucketName;
      HttpRequestFactory requestFactory = HTTP_TRANSPORT.createRequestFactory(credential);
      GenericUrl url = new GenericUrl(uri);
      HttpRequest request = requestFactory.buildGetRequest(url);
      HttpResponse response = request.execute();
      String content = response.parseAsString();
      // [END snippet]

      // Display the output XML.
      resp.setContentType("text/xml");
      BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(resp.getOutputStream()));
      String formattedContent = content.replaceAll("(<ListBucketResult)", XSL + "$1");
      writer.append(formattedContent);
      writer.flush();
      resp.setStatus(HTTP_OK);
    } catch (Throwable e) {
      resp.sendError(HTTP_NOT_FOUND, e.getMessage());
    }
  }
  public List<BeanUsuarioDirectorio> BuscarUsuario() {

    String resultado = null;
    List<BeanUsuarioDirectorio> empleadosNuevos = new ArrayList<BeanUsuarioDirectorio>();
    BeanUsuarioDirectorio empleadoNuevo = null;

    try {

      List<String> SCOPES = Arrays.asList("email");

      String emailAddressDev =
          "*****@*****.**";

      JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
      NetHttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
      GoogleCredential credential;

      credential =
          new GoogleCredential.Builder()
              .setTransport(httpTransport)
              .setJsonFactory(JSON_FACTORY)
              .setServiceAccountId(emailAddressDev)
              .setServiceAccountPrivateKey(key)
              .setServiceAccountScopes(SCOPES)
              .setServiceAccountUser("*****@*****.**")
              .build();

      if (listaRegistrosCyge != null) {

        for (BeanCyge registroCyge : listaRegistrosCyge) {
          if ((registroCyge.getEmail() != null)
              && (!registroCyge.getEmail().isEmpty())
              && !registroCyge.getEmail().trim().isEmpty()) {
            /*PRUEBA OFFLINE*/

            try {
              String URI =
                  "https://bbva-gapis.appspot.com/gprofile/users/" + registroCyge.getEmail();
              HttpRequestFactory requestFactory = httpTransport.createRequestFactory(credential);
              GenericUrl url = new GenericUrl(URI);
              HttpRequest request = requestFactory.buildGetRequest(url);
              HttpResponse response = request.execute();
              String content = response.parseAsString();

              resultado = content;
              /*END PRUEBA OFFLINE*/

              // resultado =
              // "{\"code\":\"OK\",\"message\":\"successful\",\"data\":{\"userDefinedFields\":[{\"key\":\"uid\",\"value\":\"MB58756\"},{\"key\":\"descOUPadre\",\"value\":\"SISTEMAS Y OPERACIONES\"},{\"key\":\"codCorporativo\",\"value\":\"00003719381\"},{\"key\":\"descEmpresaExterno\",\"value\":\" \"},{\"key\":\"codCargo\",\"value\":\"IHJ\"},{\"key\":\"descEmpresa\",\"value\":\"BBVA BANCOMER SERVICIO ADMINIS\"},{\"key\":\"codCSB\",\"value\":\"9016\"},{\"key\":\"descOUBase\",\"value\":\"CANALES ATENDIDOS\"},{\"key\":\"descOUNivel10\",\"value\":\"CANALES ATENDIDOS\"},{\"key\":\"descCentroCoste\",\"value\":\"D Y D CANALES\"},{\"key\":\"uidJefe\",\"value\":\"M901737\"},{\"key\":\"codEstado\",\"value\":\"DF\"},{\"key\":\"codOUNivel10\",\"value\":\"00012899\"},{\"key\":\"codOUPadre\",\"value\":\"00005833\"},{\"key\":\"descpais\",\"value\":\"MÉXICO\"},{\"key\":\"c\",\"value\":\"MEX\"},{\"key\":\"telephoneNumber\",\"value\":\" \"},{\"key\":\"rangoGlobal\",\"value\":\" \"},{\"key\":\"codPostalCentroTrabajo\",\"value\":\"03339\"},{\"key\":\"codBancoOficinaPers\",\"value\":\"01853307\"},{\"key\":\"descCentroTrabajo\",\"value\":\"CENTRO BANCOMER D.F. (CON COME\"},{\"key\":\"descEstado\",\"value\":\"DISTRITO FEDERAL\"},{\"key\":\"mobile\",\"value\":\" \"},{\"key\":\"descLargaPlanta\",\"value\":\"N-6 C-A C-E M-7 E-24\"},{\"key\":\"esEmpleado\",\"value\":\"E\"},{\"key\":\"title\",\"value\":\"LIDER DE PROYECTO DYD A\"},{\"key\":\"o\",\"value\":\"0185\"},{\"key\":\"codCentroCoste\",\"value\":\"0000\"},{\"key\":\"posicion\",\"value\":\"00238344\"},{\"key\":\"pager\",\"value\":\" \"},{\"key\":\"apellido2\",\"value\":\"RAMIREZ\"},{\"key\":\"codCentroTrabajo\",\"value\":\"25001\"},{\"key\":\"descOUNivel2\",\"value\":\"MEXICO\"},{\"key\":\"descOUNivel1\",\"value\":\"MEXICO\"},{\"key\":\"mail\",\"value\":\"[email protected]\"},{\"key\":\"codOficina\",\"value\":\"01853307\"},{\"key\":\"codOUNivel1\",\"value\":\"00000141\"},{\"key\":\"codOUNivel2\",\"value\":\"00000141\"},{\"key\":\"apellido1\",\"value\":\"ROSAS\"},{\"key\":\"codOUNivel3\",\"value\":\"00005833\"},{\"key\":\"descCodPostalCentroTrabajo\",\"value\":\"DF\"},{\"key\":\"descOUNivel9\",\"value\":\"CANALES ATENDIDOS\"},{\"key\":\"descOUNivel8\",\"value\":\"CANALES ATENDIDOS\"},{\"key\":\"descOUNivel7\",\"value\":\"CANALES ATENDIDOS\"},{\"key\":\"descOUNivel6\",\"value\":\"CANALES ATENDIDOS\"},{\"key\":\"descOUNivel5\",\"value\":\"CANALES ATENDIDOS\"},{\"key\":\"descOUNivel4\",\"value\":\"TECNOLOGIA MULTICANAL\"},{\"key\":\"descOUNivel3\",\"value\":\"SISTEMAS Y OPERACIONES\"},{\"key\":\"descBancoOficinaPers\",\"value\":\"3307\"},{\"key\":\"corporateNumber\",\"value\":\" \"},{\"key\":\"codOUNivel5\",\"value\":\"00012899\"},{\"key\":\"codOUNivel4\",\"value\":\"00010142\"},{\"key\":\"codOUNivel7\",\"value\":\"00012899\"},{\"key\":\"codOUNivel6\",\"value\":\"00012899\"},{\"key\":\"codOUNivel9\",\"value\":\"00012899\"},{\"key\":\"codOUNivel8\",\"value\":\"00012899\"}],\"id\":\"102286709937216158038\",\"addresses\":[{\"country\":\"MÉXICO\",\"countryCode\":\"ES\",\"formatted\":\"DISTRITO FEDERAL\\n03339\\nMÉXICO\",\"locality\":\"DF\",\"poBox\":\"03339\",\"postalCode\":\"03339\",\"streetAddress\":\"N-6 C-A C-E M-7 E-24\",\"type\":\"work\"}],\"updateTime\":1449889391185,\"customSchemas\":{\"ldapUserData\":{\"uid\":\"MB58756\",\"descOUPadre\":\"SISTEMAS Y OPERACIONES\",\"codCorporativo\":\"00003719381\",\"descEmpresaExterno\":\" \",\"codCargo\":\"IHJ\",\"descEmpresa\":\"BBVA BANCOMER SERVICIO ADMINIS\",\"codCSB\":\"9016\",\"descOUBase\":\"CANALES ATENDIDOS\",\"descOUNivel10\":\"CANALES ATENDIDOS\",\"descCentroCoste\":\"D Y D CANALES\",\"uidJefe\":\"M901737\",\"codEstado\":\"DF\",\"codOUNivel10\":\"00012899\",\"codOUPadre\":\"00005833\",\"descpais\":\"MÉXICO\",\"codPais\":\"MEX\",\"telephoneNumber\":\" \",\"rangoGlobal\":\" \",\"codPostalCentroTrabajo\":\"03339\",\"codBancoOficinaPers\":\"01853307\",\"descCentroTrabajo\":\"CENTRO BANCOMER D.F. (CON COME\",\"descEstado\":\"DISTRITO FEDERAL\",\"mobile\":\" \",\"descLargaPlanta\":\"N-6 C-A C-E M-7 E-24\",\"esEmpleado\":\"E\",\"title\":\"LIDER DE PROYECTO DYD A\",\"organization\":\"0185\",\"codCentroCoste\":\"0000\",\"posicion\":\"00238344\",\"pager\":\" \",\"apellido2\":\"RAMIREZ\",\"codCentroTrabajo\":\"25001\",\"descOUNivel2\":\"MEXICO\",\"descOUNivel1\":\"MEXICO\",\"mail\":\"[email protected]\",\"codOficina\":\"01853307\",\"codOUNivel1\":\"00000141\",\"codOUNivel2\":\"00000141\",\"apellido1\":\"ROSAS\",\"codOUNivel3\":\"00005833\",\"descCodPostalCentroTrabajo\":\"DF\",\"descOUNivel9\":\"CANALES ATENDIDOS\",\"descOUNivel8\":\"CANALES ATENDIDOS\",\"descOUNivel7\":\"CANALES ATENDIDOS\",\"descOUNivel6\":\"CANALES ATENDIDOS\",\"descOUNivel5\":\"CANALES ATENDIDOS\",\"descOUNivel4\":\"TECNOLOGIA MULTICANAL\",\"descOUNivel3\":\"SISTEMAS Y OPERACIONES\",\"descBancoOficinaPers\":\"3307\",\"corporateNumber\":\" \",\"codOUNivel5\":\"00012899\",\"codOUNivel4\":\"00010142\",\"codOUNivel7\":\"00012899\",\"codOUNivel6\":\"00012899\",\"codOUNivel9\":\"00012899\",\"codOUNivel8\":\"00012899\"}},\"emails\":[{\"address\":\"[email protected]\",\"primary\":true}],\"etag\":\"\\\"KuAr0EK1uUI7oJNfO_dWOREN2ro/dbE6bs1euQMov6wc4Dmi3rfnjUc\\\"\",\"externalIds\":[{\"customType\":\"Employee ID\",\"type\":\"custom\",\"value\":\"MB58756\"}],\"kind\":\"admin#directory#user\",\"name\":{\"familyName\":\"ROSAS RAMIREZ\",\"fullName\":\"PEDRO ROSAS RAMIREZ\",\"givenName\":\"PEDRO\"},\"nonEditableAliases\":[\"[email protected]\"],\"organizations\":[{\"customType\":\"Work\",\"department\":\"CANALES ATENDIDOS\",\"location\":\"018533073307\",\"name\":\"BBVA BANCOMER SERVICIO ADMINIS\",\"primary\":true,\"title\":\"LIDER DE PROYECTO DYD A\"}],\"primaryEmail\":\"[email protected]\",\"suspended\":false,\"status\":\"ACTIVE\",\"ouResponsible\":{\"id\":\"00012899\",\"name\":\"CANALES ATENDIDOS\",\"responsibleEmployeeId\":\"M62139\",\"updateDate\":1450243038394}}}";
              ParsearJson parser = new ParsearJson();

              empleadoNuevo = parser.ConvertirAUsuario(resultado);

              System.out.println(resultado);

              empleadosNuevos.add(empleadoNuevo);

            } catch (Exception e) {
              e.printStackTrace();
            }
          }
        }
      } else {
        for (String strEmailUsuario : listaEmailsUsuarios) {

          /*PRUEBA OFFLINE*/

          String URI = "https://bbva-gapis.appspot.com/gprofile/users/" + strEmailUsuario;
          HttpRequestFactory requestFactory = httpTransport.createRequestFactory(credential);
          GenericUrl url = new GenericUrl(URI);
          HttpRequest request = requestFactory.buildGetRequest(url);
          HttpResponse response = request.execute();
          String content = response.parseAsString();

          resultado = content;
          /*END PRUEBA OFFLINE*/

          // resultado =
          // "{\"code\":\"OK\",\"message\":\"successful\",\"data\":{\"userDefinedFields\":[{\"key\":\"uid\",\"value\":\"MB58756\"},{\"key\":\"descOUPadre\",\"value\":\"SISTEMAS Y OPERACIONES\"},{\"key\":\"codCorporativo\",\"value\":\"00003719381\"},{\"key\":\"descEmpresaExterno\",\"value\":\" \"},{\"key\":\"codCargo\",\"value\":\"IHJ\"},{\"key\":\"descEmpresa\",\"value\":\"BBVA BANCOMER SERVICIO ADMINIS\"},{\"key\":\"codCSB\",\"value\":\"9016\"},{\"key\":\"descOUBase\",\"value\":\"CANALES ATENDIDOS\"},{\"key\":\"descOUNivel10\",\"value\":\"CANALES ATENDIDOS\"},{\"key\":\"descCentroCoste\",\"value\":\"D Y D CANALES\"},{\"key\":\"uidJefe\",\"value\":\"M901737\"},{\"key\":\"codEstado\",\"value\":\"DF\"},{\"key\":\"codOUNivel10\",\"value\":\"00012899\"},{\"key\":\"codOUPadre\",\"value\":\"00005833\"},{\"key\":\"descpais\",\"value\":\"MÉXICO\"},{\"key\":\"c\",\"value\":\"MEX\"},{\"key\":\"telephoneNumber\",\"value\":\" \"},{\"key\":\"rangoGlobal\",\"value\":\" \"},{\"key\":\"codPostalCentroTrabajo\",\"value\":\"03339\"},{\"key\":\"codBancoOficinaPers\",\"value\":\"01853307\"},{\"key\":\"descCentroTrabajo\",\"value\":\"CENTRO BANCOMER D.F. (CON COME\"},{\"key\":\"descEstado\",\"value\":\"DISTRITO FEDERAL\"},{\"key\":\"mobile\",\"value\":\" \"},{\"key\":\"descLargaPlanta\",\"value\":\"N-6 C-A C-E M-7 E-24\"},{\"key\":\"esEmpleado\",\"value\":\"E\"},{\"key\":\"title\",\"value\":\"LIDER DE PROYECTO DYD A\"},{\"key\":\"o\",\"value\":\"0185\"},{\"key\":\"codCentroCoste\",\"value\":\"0000\"},{\"key\":\"posicion\",\"value\":\"00238344\"},{\"key\":\"pager\",\"value\":\" \"},{\"key\":\"apellido2\",\"value\":\"RAMIREZ\"},{\"key\":\"codCentroTrabajo\",\"value\":\"25001\"},{\"key\":\"descOUNivel2\",\"value\":\"MEXICO\"},{\"key\":\"descOUNivel1\",\"value\":\"MEXICO\"},{\"key\":\"mail\",\"value\":\"[email protected]\"},{\"key\":\"codOficina\",\"value\":\"01853307\"},{\"key\":\"codOUNivel1\",\"value\":\"00000141\"},{\"key\":\"codOUNivel2\",\"value\":\"00000141\"},{\"key\":\"apellido1\",\"value\":\"ROSAS\"},{\"key\":\"codOUNivel3\",\"value\":\"00005833\"},{\"key\":\"descCodPostalCentroTrabajo\",\"value\":\"DF\"},{\"key\":\"descOUNivel9\",\"value\":\"CANALES ATENDIDOS\"},{\"key\":\"descOUNivel8\",\"value\":\"CANALES ATENDIDOS\"},{\"key\":\"descOUNivel7\",\"value\":\"CANALES ATENDIDOS\"},{\"key\":\"descOUNivel6\",\"value\":\"CANALES ATENDIDOS\"},{\"key\":\"descOUNivel5\",\"value\":\"CANALES ATENDIDOS\"},{\"key\":\"descOUNivel4\",\"value\":\"TECNOLOGIA MULTICANAL\"},{\"key\":\"descOUNivel3\",\"value\":\"SISTEMAS Y OPERACIONES\"},{\"key\":\"descBancoOficinaPers\",\"value\":\"3307\"},{\"key\":\"corporateNumber\",\"value\":\" \"},{\"key\":\"codOUNivel5\",\"value\":\"00012899\"},{\"key\":\"codOUNivel4\",\"value\":\"00010142\"},{\"key\":\"codOUNivel7\",\"value\":\"00012899\"},{\"key\":\"codOUNivel6\",\"value\":\"00012899\"},{\"key\":\"codOUNivel9\",\"value\":\"00012899\"},{\"key\":\"codOUNivel8\",\"value\":\"00012899\"}],\"id\":\"102286709937216158038\",\"addresses\":[{\"country\":\"MÉXICO\",\"countryCode\":\"ES\",\"formatted\":\"DISTRITO FEDERAL\\n03339\\nMÉXICO\",\"locality\":\"DF\",\"poBox\":\"03339\",\"postalCode\":\"03339\",\"streetAddress\":\"N-6 C-A C-E M-7 E-24\",\"type\":\"work\"}],\"updateTime\":1449889391185,\"customSchemas\":{\"ldapUserData\":{\"uid\":\"MB58756\",\"descOUPadre\":\"SISTEMAS Y OPERACIONES\",\"codCorporativo\":\"00003719381\",\"descEmpresaExterno\":\" \",\"codCargo\":\"IHJ\",\"descEmpresa\":\"BBVA BANCOMER SERVICIO ADMINIS\",\"codCSB\":\"9016\",\"descOUBase\":\"CANALES ATENDIDOS\",\"descOUNivel10\":\"CANALES ATENDIDOS\",\"descCentroCoste\":\"D Y D CANALES\",\"uidJefe\":\"M901737\",\"codEstado\":\"DF\",\"codOUNivel10\":\"00012899\",\"codOUPadre\":\"00005833\",\"descpais\":\"MÉXICO\",\"codPais\":\"MEX\",\"telephoneNumber\":\" \",\"rangoGlobal\":\" \",\"codPostalCentroTrabajo\":\"03339\",\"codBancoOficinaPers\":\"01853307\",\"descCentroTrabajo\":\"CENTRO BANCOMER D.F. (CON COME\",\"descEstado\":\"DISTRITO FEDERAL\",\"mobile\":\" \",\"descLargaPlanta\":\"N-6 C-A C-E M-7 E-24\",\"esEmpleado\":\"E\",\"title\":\"LIDER DE PROYECTO DYD A\",\"organization\":\"0185\",\"codCentroCoste\":\"0000\",\"posicion\":\"00238344\",\"pager\":\" \",\"apellido2\":\"RAMIREZ\",\"codCentroTrabajo\":\"25001\",\"descOUNivel2\":\"MEXICO\",\"descOUNivel1\":\"MEXICO\",\"mail\":\"[email protected]\",\"codOficina\":\"01853307\",\"codOUNivel1\":\"00000141\",\"codOUNivel2\":\"00000141\",\"apellido1\":\"ROSAS\",\"codOUNivel3\":\"00005833\",\"descCodPostalCentroTrabajo\":\"DF\",\"descOUNivel9\":\"CANALES ATENDIDOS\",\"descOUNivel8\":\"CANALES ATENDIDOS\",\"descOUNivel7\":\"CANALES ATENDIDOS\",\"descOUNivel6\":\"CANALES ATENDIDOS\",\"descOUNivel5\":\"CANALES ATENDIDOS\",\"descOUNivel4\":\"TECNOLOGIA MULTICANAL\",\"descOUNivel3\":\"SISTEMAS Y OPERACIONES\",\"descBancoOficinaPers\":\"3307\",\"corporateNumber\":\" \",\"codOUNivel5\":\"00012899\",\"codOUNivel4\":\"00010142\",\"codOUNivel7\":\"00012899\",\"codOUNivel6\":\"00012899\",\"codOUNivel9\":\"00012899\",\"codOUNivel8\":\"00012899\"}},\"emails\":[{\"address\":\"[email protected]\",\"primary\":true}],\"etag\":\"\\\"KuAr0EK1uUI7oJNfO_dWOREN2ro/dbE6bs1euQMov6wc4Dmi3rfnjUc\\\"\",\"externalIds\":[{\"customType\":\"Employee ID\",\"type\":\"custom\",\"value\":\"MB58756\"}],\"kind\":\"admin#directory#user\",\"name\":{\"familyName\":\"ROSAS RAMIREZ\",\"fullName\":\"PEDRO ROSAS RAMIREZ\",\"givenName\":\"PEDRO\"},\"nonEditableAliases\":[\"[email protected]\"],\"organizations\":[{\"customType\":\"Work\",\"department\":\"CANALES ATENDIDOS\",\"location\":\"018533073307\",\"name\":\"BBVA BANCOMER SERVICIO ADMINIS\",\"primary\":true,\"title\":\"LIDER DE PROYECTO DYD A\"}],\"primaryEmail\":\"[email protected]\",\"suspended\":false,\"status\":\"ACTIVE\",\"ouResponsible\":{\"id\":\"00012899\",\"name\":\"CANALES ATENDIDOS\",\"responsibleEmployeeId\":\"M62139\",\"updateDate\":1450243038394}}}";
          ParsearJson parser = new ParsearJson();

          empleadoNuevo = parser.ConvertirAUsuario(resultado);

          System.out.println(resultado);

          empleadosNuevos.add(empleadoNuevo);
        }
      }

    } catch (IOException e) {

      e.printStackTrace();

    } catch (Exception e) {
      e.printStackTrace();
    }

    return empleadosNuevos;
  }