Ejemplo n.º 1
0
  private boolean sendNotification(
      HttpServletRequest request,
      HttpServletResponse response,
      Repository db,
      String login,
      String commit,
      String url,
      String authorName,
      String message)
      throws ServletException, URISyntaxException, IOException, JSONException, CoreException,
          Exception {
    UserEmailUtil util = UserEmailUtil.getUtil();
    if (!util.isEmailConfigured()) {
      return statusHandler.handleRequest(
          request,
          response,
          new ServerStatus(
              IStatus.ERROR,
              HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
              "Smpt server not configured",
              null));
    }
    IOrionCredentialsService userAdmin = UserServiceHelper.getDefault().getUserStore();
    User user = (User) userAdmin.getUser(UserConstants.KEY_LOGIN, login);
    try {
      if (reviewRequestEmail == null) {
        reviewRequestEmail = new EmailContent(EMAIL_REVIEW_REQUEST_FILE);
      }

      String emailAdress = user.getEmail();

      util.sendEmail(
          reviewRequestEmail.getTitle(),
          reviewRequestEmail
              .getContent()
              .replaceAll(EMAIL_COMMITER_NAME, authorName)
              .replaceAll(EMAIL_URL_LINK, url)
              .replaceAll(EMAIL_COMMIT_MESSAGE, message),
          emailAdress);

      JSONObject result = new JSONObject();
      result.put(GitConstants.KEY_RESULT, "Email sent");
      OrionServlet.writeJSONResponse(
          request, response, result, JsonURIUnqualificationStrategy.ALL_NO_GIT);
      return true;
    } catch (Exception e) {
      return statusHandler.handleRequest(
          request,
          response,
          new ServerStatus(
              IStatus.ERROR,
              HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
              "User doesn't exist",
              null));
    }
  };
Ejemplo n.º 2
0
 /**
  * Gets the list of the vnmrj users(operators) for the current unix user logged in
  *
  * @return the list of vnmrj users
  */
 protected Object[] getOperators() {
   String strUser = System.getProperty("user.name");
   User user = LoginService.getDefault().getUser(strUser);
   ArrayList<String> aListOperators = user.getOperators();
   if (aListOperators == null || aListOperators.isEmpty())
     aListOperators = new ArrayList<String>();
   Collections.sort(aListOperators);
   if (aListOperators.contains(strUser)) aListOperators.remove(strUser);
   aListOperators.add(0, strUser);
   return (aListOperators.toArray());
 }
Ejemplo n.º 3
0
 void placeOrder(final User user, String cmd, Company comp, int qty, int id) {
   int cmdID = commID++;
   connect(user.getName(), user.getPassword());
   try {
     out.println(cmdID + ";" + cmd + ":" + comp.name + ":" + Integer.toString(qty) + ":" + id);
     out.flush();
     Shares pen = (Shares) receiveReply(cmdID);
     user.getPendingShares().add(pen);
     user.dataChanged();
   } catch (Exception r) {
     r.printStackTrace();
   }
 }
Ejemplo n.º 4
0
  private Point createFeedPoint(final User user) throws NimbitsException {

    final EntityName name =
        CommonFactoryLocator.getInstance().createName(Const.TEXT_DATA_FEED, EntityType.point);

    final Entity entity =
        EntityModelFactory.createEntity(
            name,
            "",
            EntityType.feed,
            ProtectionLevel.onlyConnection,
            user.getKey(),
            user.getKey(),
            UUID.randomUUID().toString());
    // final Entity r = EntityServiceFactory.getInstance().addUpdateEntity(user, entity);

    Point point = PointModelFactory.createPointModel(entity);

    final Point result = (Point) EntityServiceFactory.getInstance().addUpdateEntity(point);

    postToFeed(
        user,
        "A new data point has been created for your data feed. Your data feed is just "
            + "a data point. Points are capable of storing numbers, text, json and xml data. Nimbits uses "
            + "a single data point to drive this feed.",
        FeedType.info);
    return result;
  }
Ejemplo n.º 5
0
 private boolean handleAddNew(String str) {
   String[] data = str.split(":", 3);
   int userId_;
   try {
     userId_ = Integer.parseInt(data[0]);
   } catch (NumberFormatException e) {
     out.println("ERROR:UNCORRECT");
     System.out.println("sent: " + "ERROR:UNCORRECT");
     return false;
   }
   String pass = data[1];
   if (KotoServer.users.containsKey(userId_)) {
     out.println("ERROR:User Already Exists");
     System.out.println("sent: " + "ERROR:User Already Exists");
     return false;
   }
   synchronized (KotoServer.users) {
     KotoServer.users.put(userId_, User.createUser(userId_, pass));
   }
   out.println("ADDED");
   System.out.println("new user: "******" added.");
   KotoServer.saveUsers();
   return true;
 }
  /**
   * Creates an organization, its classification, and its services, and saves it to the registry.
   */
  public String executePublish(String username, String password, String endpoint) {

    String id = null;
    RegistryService rs = null;
    BusinessLifeCycleManager blcm = null;
    BusinessQueryManager bqm = null;

    try {
      rs = connection.getRegistryService();
      blcm = rs.getBusinessLifeCycleManager();
      bqm = rs.getBusinessQueryManager();
      System.out.println("Got registry service, query " + "manager, and life cycle manager");

      // Get authorization from the registry
      PasswordAuthentication passwdAuth =
          new PasswordAuthentication(username, password.toCharArray());

      Set creds = new HashSet();
      creds.add(passwdAuth);
      connection.setCredentials(creds);
      System.out.println("Established security credentials");

      // Get hardcoded strings from a ResourceBundle
      ResourceBundle bundle = ResourceBundle.getBundle("com.sun.cb.CoffeeRegistry");

      // Create organization name and description
      Organization org = blcm.createOrganization(bundle.getString("org.name"));
      InternationalString s = blcm.createInternationalString(bundle.getString("org.description"));
      org.setDescription(s);

      // Create primary contact, set name
      User primaryContact = blcm.createUser();
      PersonName pName = blcm.createPersonName(bundle.getString("person.name"));
      primaryContact.setPersonName(pName);

      // Set primary contact phone number
      TelephoneNumber tNum = blcm.createTelephoneNumber();
      tNum.setNumber(bundle.getString("phone.number"));
      Collection phoneNums = new ArrayList();
      phoneNums.add(tNum);
      primaryContact.setTelephoneNumbers(phoneNums);

      // Set primary contact email address
      EmailAddress emailAddress = blcm.createEmailAddress(bundle.getString("email.address"));
      Collection emailAddresses = new ArrayList();
      emailAddresses.add(emailAddress);
      primaryContact.setEmailAddresses(emailAddresses);

      // Set primary contact for organization
      org.setPrimaryContact(primaryContact);

      // Set classification scheme to NAICS
      ClassificationScheme cScheme =
          bqm.findClassificationSchemeByName(null, bundle.getString("classification.scheme"));

      // Create and add classification
      Classification classification =
          (Classification)
              blcm.createClassification(
                  cScheme,
                  bundle.getString("classification.name"),
                  bundle.getString("classification.value"));
      Collection classifications = new ArrayList();
      classifications.add(classification);
      org.addClassifications(classifications);

      // Create services and service
      Collection services = new ArrayList();
      Service service = blcm.createService(bundle.getString("service.name"));
      InternationalString is =
          blcm.createInternationalString(bundle.getString("service.description"));
      service.setDescription(is);

      // Create service bindings
      Collection serviceBindings = new ArrayList();
      ServiceBinding binding = blcm.createServiceBinding();
      is = blcm.createInternationalString(bundle.getString("service.binding"));
      binding.setDescription(is);
      binding.setValidateURI(false);
      binding.setAccessURI(endpoint);
      serviceBindings.add(binding);

      // Add service bindings to service
      service.addServiceBindings(serviceBindings);

      // Add service to services, then add services to organization
      services.add(service);
      org.addServices(services);

      // Add organization and submit to registry
      // Retrieve key if successful
      Collection orgs = new ArrayList();
      orgs.add(org);
      BulkResponse response = blcm.saveOrganizations(orgs);
      Collection exceptions = response.getExceptions();
      if (exceptions == null) {
        System.out.println("Organization saved");

        Collection keys = response.getCollection();
        Iterator keyIter = keys.iterator();
        if (keyIter.hasNext()) {
          javax.xml.registry.infomodel.Key orgKey =
              (javax.xml.registry.infomodel.Key) keyIter.next();
          id = orgKey.getId();
          System.out.println("Organization key is " + id);
        }
      } else {
        Iterator excIter = exceptions.iterator();
        Exception exception = null;
        while (excIter.hasNext()) {
          exception = (Exception) excIter.next();
          System.err.println("Exception on save: " + exception.toString());
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
      if (connection != null) {
        try {
          connection.close();
        } catch (JAXRException je) {
          System.err.println("Connection close failed");
        }
      }
    }
    return id;
  }