@GET
  @Path("/registerCoupons/{id}&{couponcode}&{allocated}&{used}/")
  @Produces(MediaType.APPLICATION_JSON)
  public JSONObject registerCoupons(
      @PathParam("id") String id,
      @PathParam("couponcode") String couponcode,
      @PathParam("allocated") String allocated,
      @PathParam("used") String used) {
    JSONObject res = new JSONObject();
    System.out.println("Inside registerCoupons ");

    Registration registration = new Registration();
    int response = registration.registerCoupons(id, couponcode, allocated, used);
    try {
      if (response == 0) {
        res.append("result", "200");
        res.append("response", "Successfully Registered");
      } else {
        res.append("result", "400");
        res.append("response", "Not Registered");
      }
    } catch (JSONException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    return res;
  }
  /**
   * ****************************************************************
   *
   * <p>REGISTRATION URL FOR VARIOUS USERS 1. Kandy Details 2. Rewards
   *
   * <p>****************************************************************
   */
  @GET
  @Path("/registerKandy/{id}&{username}&{password}&{key}&{provider}&{uid}/")
  @Produces(MediaType.APPLICATION_JSON)
  public JSONObject registerEndUser(
      @PathParam("id") String id,
      @PathParam("username") String username,
      @PathParam("password") String password,
      @PathParam("key") String key,
      @PathParam("provider") String provider,
      @PathParam("uid") String uid) {
    JSONObject res = new JSONObject();
    System.out.println("Inside registerKandy Helper");

    Registration registration = new Registration();
    int response = registration.registerKandy(id, username, password, key, provider, uid);
    try {
      if (response == 0) {
        res.append("result", "200");
        res.append("response", "Successfully Registered");
      } else {
        res.append("result", "400");
        res.append("response", "Not Registered");
      }
    } catch (JSONException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    return res;
  }
  /**
   * Creates a new registration in the server. If it exists, updates its information
   *
   * @param registration The registration to create
   * @return The created registration
   * @throws Exception
   */
  private Registration registerInternal(Registration registration) throws Exception {

    if (mIsRefreshNeeded) {
      String pNSHandle = mSharedPreferences.getString(STORAGE_PREFIX + PNS_HANDLE_KEY, "");

      if (isNullOrWhiteSpace(pNSHandle)) {
        pNSHandle = registration.getPNSHandle();
      }

      refreshRegistrationInformation(pNSHandle);
    }

    String registrationId = retrieveRegistrationId(registration.getName());
    if (isNullOrWhiteSpace(registrationId)) {
      registrationId = createRegistrationId();
    }

    registration.setRegistrationId(registrationId);

    try {
      return upsertRegistrationInternal(registration);
    } catch (RegistrationGoneException e) {
      // if we get an RegistrationGoneException (410) from service, we will recreate registration id
      // and will try to do upsert one more time.
    }

    registrationId = createRegistrationId();
    registration.setRegistrationId(registrationId);
    return upsertRegistrationInternal(registration);
  }
Example #4
0
  public void testFlushRoundTrip() throws Exception {

    Kryo kryo = new Kryo();

    String s1 = "12345";

    ByteArrayOutputStream os = new ByteArrayOutputStream();
    ObjectOutputStream objOutput = new ObjectOutputStream(os);
    Output output = new Output(objOutput);

    kryo.writeClass(output, s1.getClass());
    kryo.writeObject(output, s1);
    output.flush();
    //		objOutput.flush();  // this layer wasn't flushed prior to this bugfix, add it for a
    // workaround

    byte[] b = os.toByteArray();
    System.out.println("size: " + b.length);

    ByteArrayInputStream in = new ByteArrayInputStream(b);
    ObjectInputStream objIn = new ObjectInputStream(in);
    Input input = new Input(objIn);

    Registration r = kryo.readClass(input);
    String s2 = kryo.readObject(input, r.getType());

    assertEquals(s1, s2);
  }
  /**
   * Registers the client for native notifications with the specified tags
   *
   * @param pnsHandle PNS specific identifier
   * @param tags Tags to use in the registration
   * @return The created registration
   * @throws Exception
   */
  public Registration register(String pnsHandle, String... tags) throws Exception {
    if (isNullOrWhiteSpace(pnsHandle)) {
      throw new IllegalArgumentException("pnsHandle");
    }

    Registration registration =
        PnsSpecificRegistrationFactory.getInstance().createNativeRegistration(mNotificationHubPath);
    registration.setPNSHandle(pnsHandle);
    registration.setName(Registration.DEFAULT_REGISTRATION_NAME);
    registration.addTags(tags);

    return registerInternal(registration);
  }
Example #6
0
 /**
  * Registers required resources with the binder.
  *
  * @param binder Binder to register with.
  */
 public static void registerResources(Binder binder) {
   registerJs(binder, "dygraph-combined.js");
   registerJs(binder, "dygraph-extra.js");
   registerJs(binder, "grapher.js");
   registerJs(binder, "parser.js");
   Registration.registerHttpAsset(
       binder, "/graphview", GraphViewer.class, "graphview/graphview.html", "text/html", false);
 }
  /**
   * Updates a registration
   *
   * @param registration The registration to update
   * @return The updated registration
   * @throws Exception
   */
  private Registration upsertRegistrationInternal(Registration registration) throws Exception {
    Connection conn = new Connection(mConnectionString);

    String resource = registration.getURI();
    String content = registration.toXml();

    String response = conn.executeRequest(resource, content, XML_CONTENT_TYPE, "PUT");

    Registration result;
    if (PnsSpecificRegistrationFactory.getInstance().isTemplateRegistration(response)) {
      result =
          PnsSpecificRegistrationFactory.getInstance()
              .createTemplateRegistration(mNotificationHubPath);
    } else {
      result =
          PnsSpecificRegistrationFactory.getInstance()
              .createNativeRegistration(mNotificationHubPath);
    }

    result.loadXml(response, mNotificationHubPath);

    storeRegistrationId(result.getName(), result.getRegistrationId(), registration.getPNSHandle());

    return result;
  }
Example #8
0
 private static void registerJs(Binder binder, String assetName) {
   Registration.registerHttpAsset(
       binder,
       "/graphview/" + assetName,
       GraphViewer.class,
       "graphview/" + assetName,
       "application/javascript",
       true);
 }
  private static Registration parseRegistration(XmlPullParser parser) throws Exception {
    Registration registration = new Registration();
    Map<String, String> fields = null;
    boolean done = false;
    while (!done) {
      int eventType = parser.next();
      if (eventType == XmlPullParser.START_TAG) {
        // Any element that's in the jabber:iq:register namespace,
        // attempt to parse it if it's in the form <name>value</name>.
        if (parser.getNamespace().equals("jabber:iq:register")) {
          String name = parser.getName();
          String value = "";
          if (fields == null) {
            fields = new HashMap<String, String>();
          }

          if (parser.next() == XmlPullParser.TEXT) {
            value = parser.getText();
          }
          // Ignore instructions, but anything else should be added to the map.
          if (!name.equals("instructions")) {
            fields.put(name, value);
          } else {
            registration.setInstructions(value);
          }
        }
        // Otherwise, it must be a packet extension.
        else {
          registration.addExtension(
              PacketParserUtils.parsePacketExtension(
                  parser.getName(), parser.getNamespace(), parser));
        }
      } else if (eventType == XmlPullParser.END_TAG) {
        if (parser.getName().equals("query")) {
          done = true;
        }
      }
    }
    registration.setAttributes(fields);
    return registration;
  }
 @Path("devices/{deviceLibraryIdentifier}/registrations/{passTypeIdentifier}")
 @GET
 public Response getSerialNumbersOfPassesAssociatedWithDevice(
     @PathParam("deviceLibraryIdentifier") String deviceLibraryIdentifier,
     @PathParam("passTypeIdentifier") String passTypeIdentifier,
     @QueryParam("passesUpdatedSince") @DefaultValue("") String passesUpdatedSince) {
   DeviceDAO device = new DeviceDAO(deviceLibraryIdentifier);
   ListOfPasses passes = new ListOfPasses();
   passes.setLastUpdated(DateUtil.getTimeStamp());
   if (device.retrieve()) {
     for (Registration reg : device.getRegistrations()) {
       if (passTypeIdentifier.equals(reg.getPassTypeIdentifier())) {
         passes.addSerialNumber(reg.getSerialNumber());
       }
     }
   }
   if (passes.getSerialNumbers().size() > 0) {
     return Response.status(Response.Status.OK).entity(passes.toJson(Pass.PRETTY)).build();
   }
   return Response.status(Response.Status.NO_CONTENT).build();
 }
  /**
   * Adds a registration with this transport, or updates an existing one.
   *
   * @param jid JID of user to add registration to.
   * @param username Legacy username of registration.
   * @param password Legacy password of registration.
   * @param nickname Legacy nickname of registration.
   * @param noRosterItem True if the transport is not to show up in the user's roster.
   * @throws UserNotFoundException if registration or roster not found.
   * @throws IllegalAccessException if jid is not from this server.
   * @throws IllegalArgumentException if username is not valid for this transport type.
   */
  public void addNewRegistration(
      JID jid, String username, String password, String nickname, Boolean noRosterItem)
      throws UserNotFoundException, IllegalAccessException {
    Log.debug("Adding or updating registration for : " + jid.toString() + " / " + username);

    if (!XMPPServer.getInstance().isLocal(jid)) {
      throw new IllegalAccessException(
          "Domain of jid registering does not match domain of server.");
    }

    if (!parent.isUsernameValid(username)) {
      throw new IllegalArgumentException(
          "Username specified is not valid for this transport type.");
    }

    final Collection<Registration> registrations =
        RegistrationManager.getInstance().getRegistrations(jid, parent.transportType);
    boolean foundReg = false;
    boolean triggerRestart = false;
    for (final Registration registration : registrations) {
      if (!registration.getUsername().equals(username)) {
        Log.debug("Deleting existing registration before" + " creating a new one: " + registration);
        RegistrationManager.getInstance().deleteRegistration(registration);
      } else {
        Log.debug("Existing registration found that can be updated: " + registration);
        if ((registration.getPassword() != null && password == null)
            || (registration.getPassword() == null && password != null)
            || (registration.getPassword() != null
                && password != null
                && !registration.getPassword().equals(password))) {
          Log.debug("Updating password for existing registration: " + registration);
          registration.setPassword(password);
          triggerRestart = true;
        }
        if ((registration.getNickname() != null && nickname == null)
            || (registration.getNickname() == null && nickname != null)
            || (registration.getNickname() != null
                && nickname != null
                && !registration.getNickname().equals(nickname))) {
          Log.debug("Updating nickname for existing registration: " + registration);
          registration.setNickname(nickname);
          triggerRestart = true;
        }
        foundReg = true;
      }

      // if a change was made to the registration, restart it.
      if (triggerRestart) {
        try {
          Log.debug(
              "An existing registration was "
                  + "updated. Restarting the related session: "
                  + registration);
          final TransportSession relatedSession =
              parent.sessionManager.getSession(registration.getJID().getNode());
          parent.registrationLoggedOut(relatedSession);
        } catch (NotFoundException e) {
          // No worries, move on.
        }
      }
    }

    if (!foundReg) {
      RegistrationManager.getInstance()
          .createRegistration(jid, parent.transportType, username, password, nickname);
      triggerRestart = true;
    }

    if (triggerRestart) {
      Log.debug("Clean up any leftover roster items " + "from other transports for: " + jid);
      try {
        parent.cleanUpRoster(jid, !noRosterItem);
      } catch (UserNotFoundException ee) {
        throw new UserNotFoundException("Unable to find roster.");
      }
    }

    if (!noRosterItem) {
      try {
        Log.debug("Adding Transport roster item to the roster of: " + jid);
        parent.addOrUpdateRosterItem(jid, parent.getJID(), parent.getDescription(), "Transports");
      } catch (UserNotFoundException e) {
        throw new UserNotFoundException("User not registered with server.");
      }
    } else {
      Log.debug(
          "Not adding Transport roster item to the roster of: "
              + jid
              + " (as this was explicitly requested).");
    }
  }
  private void refreshRegistrationInformation(String pnsHandle) throws Exception {
    if (isNullOrWhiteSpace(pnsHandle)) {
      throw new IllegalArgumentException("pnsHandle");
    }

    // delete old registration information
    Editor editor = mSharedPreferences.edit();
    Set<String> keys = mSharedPreferences.getAll().keySet();
    for (String key : keys) {
      if (key.startsWith(STORAGE_PREFIX + REGISTRATION_NAME_STORAGE_KEY)) {
        editor.remove(key);
      }
    }

    editor.commit();

    // get existing registrations
    Connection conn = new Connection(mConnectionString);

    String filter =
        PnsSpecificRegistrationFactory.getInstance().getPNSHandleFieldName()
            + " eq '"
            + pnsHandle
            + "'";

    String resource =
        mNotificationHubPath + "/Registrations/?$filter=" + URLEncoder.encode(filter, "UTF-8");
    String content = null;
    String response = conn.executeRequest(resource, content, XML_CONTENT_TYPE, "GET");

    DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    builder.setEntityResolver(
        new EntityResolver() {
          @Override
          public InputSource resolveEntity(String publicId, String systemId)
              throws SAXException, IOException {
            return null;
          }
        });

    Document doc = builder.parse(new InputSource(new StringReader(response)));

    doc.getDocumentElement().normalize();
    Element root = doc.getDocumentElement();

    // for each registration, parse it
    NodeList entries = root.getElementsByTagName("entry");
    for (int i = 0; i < entries.getLength(); i++) {
      Registration registration;
      Element entry = (Element) entries.item(i);
      String xml = getXmlString(entry);
      if (PnsSpecificRegistrationFactory.getInstance().isTemplateRegistration(xml)) {
        registration =
            PnsSpecificRegistrationFactory.getInstance()
                .createTemplateRegistration(mNotificationHubPath);
      } else {
        registration =
            PnsSpecificRegistrationFactory.getInstance()
                .createNativeRegistration(mNotificationHubPath);
      }

      registration.loadXml(xml, mNotificationHubPath);

      storeRegistrationId(
          registration.getName(), registration.getRegistrationId(), registration.getPNSHandle());
    }

    mIsRefreshNeeded = false;
  }
Example #13
0
 public Registration<A> add(Registration<A> registration) {
   return registrations.put(registration.getAccessorName(), registration);
 }
Example #14
0
 public Registration<A> remove(Registration<A> registration) {
   return registrations.remove(registration.getAccessorName());
 }
 public String register() {
   System.out.println(registration.getName());
   return "success.xhtml";
 }
  /**
   * Handles a IQ-register 'get' request, which is to be interpreted as a request for a registration
   * form template. The template will be prefilled with data, if the requestee has a current
   * registration with the gateway.
   *
   * @param packet the IQ-register 'get' stanza.
   * @throws UnauthorizedException if the user is not allowed to make use of the gateway.
   */
  private void getRegistrationForm(IQ packet) throws UnauthorizedException {
    final JID from = packet.getFrom();
    final IQ result = IQ.createResultIQ(packet);

    // search for existing registrations
    String curUsername = null;
    String curPassword = null;
    String curNickname = null;
    Boolean registered = false;
    final Collection<Registration> registrations =
        RegistrationManager.getInstance().getRegistrations(from, parent.transportType);
    if (registrations.iterator().hasNext()) {
      Registration registration = registrations.iterator().next();
      curUsername = registration.getUsername();
      curPassword = registration.getPassword();
      curNickname = registration.getNickname();
      registered = true;
    }

    // Verify that the user is allowed to make use of the gateway.
    if (!registered && !parent.permissionManager.hasAccess(from)) {
      // User does not have permission to register with transport.
      // We want to allow them to change settings if they are already
      // registered.
      throw new UnauthorizedException(
          LocaleUtils.getLocalizedString("gateway.base.registrationdeniedbyacls", "kraken"));
    }

    // generate a template registration form.
    final Element response =
        DocumentHelper.createElement(QName.get("query", NameSpace.IQ_REGISTER));
    final DataForm form = new DataForm(DataForm.Type.form);
    form.addInstruction(parent.getTerminologyRegistration());

    final FormField usernameField = form.addField();
    usernameField.setLabel(parent.getTerminologyUsername());
    usernameField.setVariable("username");
    usernameField.setType(FormField.Type.text_single);
    if (curUsername != null) {
      usernameField.addValue(curUsername);
    }

    final FormField passwordField = form.addField();
    passwordField.setLabel(parent.getTerminologyPassword());
    passwordField.setVariable("password");
    passwordField.setType(FormField.Type.text_private);
    if (curPassword != null) {
      passwordField.addValue(curPassword);
    }

    final String nicknameTerm = parent.getTerminologyNickname();
    if (nicknameTerm != null) {
      FormField nicknameField = form.addField();
      nicknameField.setLabel(nicknameTerm);
      nicknameField.setVariable("nick");
      nicknameField.setType(FormField.Type.text_single);
      if (curNickname != null) {
        nicknameField.addValue(curNickname);
      }
    }

    response.add(form.getElement());
    response.addElement("instructions").addText(parent.getTerminologyRegistration());

    // prefill the template with existing data if a registration already
    // exists.
    if (registered) {
      response.addElement("registered");
      response.addElement("username").addText(curUsername);
      if (curPassword == null) {
        response.addElement("password");
      } else {
        response.addElement("password").addText(curPassword);
      }
      if (nicknameTerm != null) {
        if (curNickname == null) {
          response.addElement("nick");
        } else {
          response.addElement("nick").addText(curNickname);
        }
      }
    } else {
      response.addElement("username");
      response.addElement("password");
      if (nicknameTerm != null) {
        response.addElement("nick");
      }
    }

    // Add special indicator for rosterless gateway handling.
    response.addElement("x").addNamespace("", NameSpace.IQ_GATEWAY_REGISTER);

    result.setChildElement(response);

    parent.sendPacket(result);
  }
Example #17
0
 public void dissocRegistration(Registration r) {
   r.setPersonID(0);
   r.update();
 }
Example #18
0
 public void assocRegistration(Registration r) {
   r.setPersonID(personID);
   r.update();
 }
Example #19
0
 public Vector getRegistration() {
   Registration r = new Registration();
   r.setPersonID(personID);
   return r.selectList();
 }
Example #20
0
  /** {@inheritDoc} */
  @Override
  @Put
  public Representation put(Representation entity) {
    authenticate();
    Representation representation = null;
    Experiment newObj = null;
    JaxbObject<Experiment> jo = new JaxbObject<Experiment>();
    try {
      String text = entity.getText();
      newObj = (Experiment) XmlTools.unMarshal(jo, new Experiment(), text);
    } catch (SAXException ex) {
      ex.printStackTrace();
      throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, ex);
    } catch (IOException e) {
      e.printStackTrace();
      throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, e);
    }
    try {
      ExperimentService service = BeanFactory.getExperimentServiceBean();
      Experiment exp = (Experiment) testIfNull(service.findByID(newObj.getExperimentId()));
      exp.givesPermission(registration);

      // simple types
      String title = newObj.getTitle();
      String name = newObj.getName();
      String desc = newObj.getDescription();
      String alias = newObj.getAlias();
      String accession = newObj.getAccession();
      String status = newObj.getStatus();
      String centerName = newObj.getCenterName();
      String sequencerSpace = newObj.getSequenceSpace();
      String baseCaller = newObj.getBaseCaller();
      String qualityScorer = newObj.getQualityScorer();
      Integer qualityNumberLevels = newObj.getQualityNumberOfLevels();
      Integer qualityMultiplier = newObj.getQualityMultiplier();
      Long expectedNumberSpots = newObj.getExpectedNumberSpots();
      Long expectedNumberReads = newObj.getExpectedNumberReads();

      // foreign keys
      Study study = newObj.getStudy();
      Registration owner = newObj.getOwner();

      // sets
      Set<ExperimentAttribute> expAttributes = newObj.getExperimentAttributes();

      if (title != null) {
        exp.setTitle(title);
      }
      if (name != null) {
        exp.setName(name);
      }
      if (desc != null) {
        exp.setDescription(desc);
      }
      if (alias != null) {
        exp.setAlias(alias);
      }
      if (accession != null) {
        exp.setAccession(accession);
      }
      if (status != null) {
        exp.setStatus(status);
      }
      if (centerName != null) {
        exp.setCenterName(centerName);
      }
      if (sequencerSpace != null) {
        exp.setSequenceSpace(sequencerSpace);
      }
      if (baseCaller != null) {
        exp.setBaseCaller(baseCaller);
      }
      if (qualityScorer != null) {
        exp.setQualityScorer(qualityScorer);
      }
      if (qualityNumberLevels != null) {
        exp.setQualityNumberOfLevels(qualityNumberLevels);
      }
      if (qualityMultiplier != null) {
        exp.setQualityMultiplier(qualityMultiplier);
      }
      if (expectedNumberSpots != null) {
        exp.setExpectedNumberSpots(expectedNumberSpots);
      }
      if (expectedNumberReads != null) {
        exp.setExpectedNumberReads(expectedNumberReads);
      }

      if (study != null) {
        StudyService ss = BeanFactory.getStudyServiceBean();
        Study newStudy = ss.findByID(study.getStudyId());
        if (newStudy != null && newStudy.givesPermission(registration)) {
          exp.setStudy(newStudy);
        } else if (newStudy == null) {
          Log.info("Could not be found " + study);
        }
      }

      if (owner != null) {
        RegistrationService rs = BeanFactory.getRegistrationServiceBean();
        Registration newReg = rs.findByEmailAddress(owner.getEmailAddress());
        if (newReg != null) {
          exp.setOwner(newReg);
        } else {
          Log.info("Could not be found " + owner);
        }
      } else if (exp.getOwner() == null) {
        exp.setOwner(registration);
      }

      if (null != expAttributes) {
        exp.getExperimentAttributes().clear();
        for (ExperimentAttribute ea : expAttributes) {
          ea.setExperiment(exp);
          exp.getExperimentAttributes().add(ea);
        }
      }

      service.update(registration, exp);

      Hibernate3DtoCopier copier = new Hibernate3DtoCopier();
      Experiment detachedLane = copier.hibernate2dto(Experiment.class, exp);

      Document line = XmlTools.marshalToDocument(jo, detachedLane);
      representation = XmlTools.getRepresentation(line);
      getResponse().setEntity(representation);
      getResponse()
          .setLocationRef(
              getRequest().getRootRef() + "/experiments/" + detachedLane.getSwAccession());
      getResponse().setStatus(Status.SUCCESS_CREATED);
    } catch (SecurityException e) {
      getResponse().setStatus(Status.CLIENT_ERROR_FORBIDDEN, e.getMessage());
    } catch (Exception e) {
      e.printStackTrace();
      getResponse().setStatus(Status.SERVER_ERROR_INTERNAL, e.getMessage());
    }

    return representation;
  }
 public void addRegistration(Registration registration) {
   registration.setOffering(this);
   registrations.add(registration);
 }