Example usage for com.liferay.portal.kernel.json JSONObject getLong

List of usage examples for com.liferay.portal.kernel.json JSONObject getLong

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.json JSONObject getLong.

Prototype

public long getLong(String key);

Source Link

Usage

From source file:com.beorn.paymentapi.model.ApiPaymentMethod.java

License:Open Source License

public static ApiPaymentMethod fromJSON(JSONObject jsonObject) {
    return new ApiPaymentMethod(jsonObject.getLong("paymentMethodId"), jsonObject.getString("key"),
            jsonObject.getString("name"));
}

From source file:com.beorn.paymentapi.model.ApiTransaction.java

License:Open Source License

public static ApiTransaction fromJSON(JSONObject jsonObject) {
    return new ApiTransaction(jsonObject.getLong("transactionId"), jsonObject.getLong("sellerId"),
            jsonObject.getDouble("amount"), jsonObject.getString("currencyCode"), jsonObject.getLong("status"));
}

From source file:com.evozon.evoportal.my_account.wrapper.UserExpandoWrapper.java

public Date getCurrentStatusChangeDate() {
    Date statusChangeDate = null;

    JSONObject currentStatus = getCurrentStatus();
    if (currentStatus != null) {
        long statusChangeDateInMillis = currentStatus.getLong("statusChangeDate");
        statusChangeDate = new Date(statusChangeDateInMillis);
    }// w  w w. j  ava2  s. c o m

    return statusChangeDate;
}

From source file:com.fb.action.FacebookConnectAction.java

License:Open Source License

protected User addUser(HttpSession session, long companyId, JSONObject jsonObject) throws Exception {

    long creatorUserId = 0;
    boolean autoPassword = true;
    String password1 = StringPool.BLANK;
    String password2 = StringPool.BLANK;
    boolean autoScreenName = true;
    String screenName = StringPool.BLANK;
    String emailAddress = jsonObject.getString("email");
    long facebookId = jsonObject.getLong("id");
    String openId = StringPool.BLANK;
    Locale locale = LocaleUtil.getDefault();
    String firstName = jsonObject.getString("first_name");
    String middleName = StringPool.BLANK;
    String lastName = jsonObject.getString("last_name");
    int prefixId = 0;
    int suffixId = 0;
    boolean male = Validator.equals(jsonObject.getString("gender"), "male");
    int birthdayMonth = Calendar.JANUARY;
    int birthdayDay = 1;
    int birthdayYear = 1970;
    String jobTitle = StringPool.BLANK;
    long[] groupIds = null;
    long[] organizationIds = null;
    long[] roleIds = null;
    long[] userGroupIds = null;
    boolean sendEmail = true;

    ServiceContext serviceContext = new ServiceContext();

    User user = UserLocalServiceUtil.addUser(creatorUserId, companyId, autoPassword, password1, password2,
            autoScreenName, screenName, emailAddress, facebookId, openId, locale, firstName, middleName,
            lastName, prefixId, suffixId, male, birthdayMonth, birthdayDay, birthdayYear, jobTitle, groupIds,
            organizationIds, roleIds, userGroupIds, sendEmail, serviceContext);

    user = UserLocalServiceUtil.updateLastLogin(user.getUserId(), user.getLoginIP());

    user = UserLocalServiceUtil.updatePasswordReset(user.getUserId(), false);

    user = UserLocalServiceUtil.updateEmailAddressVerified(user.getUserId(), true);

    session.setAttribute(FACEBOOK_USER_EMAIL_ADDRESS, emailAddress);

    return user;/*w ww  .j  a va 2  s  . com*/
}

From source file:com.fb.action.FacebookConnectAction.java

License:Open Source License

protected void setFacebookCredentials(HttpSession session, long companyId, String token) throws Exception {

    JSONObject jsonObject = FacebookConnectUtil.getGraphResources(companyId, "/me", token,
            "id,email,first_name,last_name,gender");

    if ((jsonObject == null) || (jsonObject.getJSONObject("error") != null)) {

        return;//from w w  w  . ja v a2s  . c  o  m
    }

    if (FacebookConnectUtil.isVerifiedAccountRequired(companyId) && !jsonObject.getBoolean("verified")) {

        return;
    }

    User user = null;

    long facebookId = jsonObject.getLong("id");

    if (facebookId > 0) {
        session.setAttribute(FACEBOOK_USER_ID, String.valueOf(facebookId));

        try {
            user = UserLocalServiceUtil.getUserByFacebookId(companyId, facebookId);
        } catch (NoSuchUserException nsue) {
        }
    }

    String emailAddress = jsonObject.getString("email");

    if ((user == null) && Validator.isNotNull(emailAddress)) {
        session.setAttribute(FACEBOOK_USER_EMAIL_ADDRESS, emailAddress);

        try {
            user = UserLocalServiceUtil.getUserByEmailAddress(companyId, emailAddress);
        } catch (NoSuchUserException nsue) {
        }
    }

    if (user != null) {
        user = updateUser(user, jsonObject);
    } else {
        user = addUser(session, companyId, jsonObject);
    }

    saveTokenExpando(user, token);
}

From source file:com.fb.action.FacebookConnectAction.java

License:Open Source License

protected User updateUser(User user, JSONObject jsonObject) throws Exception {

    long facebookId = jsonObject.getLong("id");
    String emailAddress = jsonObject.getString("email");
    String firstName = jsonObject.getString("first_name");
    String lastName = jsonObject.getString("last_name");
    boolean male = Validator.equals(jsonObject.getString("gender"), "male");

    if ((facebookId == user.getFacebookId()) && emailAddress.equals(user.getEmailAddress())
            && firstName.equals(user.getFirstName()) && lastName.equals(user.getLastName())
            && (male == user.isMale())) {

        return user;
    }//from w w w.j  a  va2  s  .  c o m

    Contact contact = user.getContact();

    Calendar birthdayCal = CalendarFactoryUtil.getCalendar();

    birthdayCal.setTime(contact.getBirthday());

    int birthdayMonth = birthdayCal.get(Calendar.MONTH);
    int birthdayDay = birthdayCal.get(Calendar.DAY_OF_MONTH);
    int birthdayYear = birthdayCal.get(Calendar.YEAR);

    long[] groupIds = null;
    long[] organizationIds = null;
    long[] roleIds = null;
    List<UserGroupRole> userGroupRoles = null;
    long[] userGroupIds = null;

    ServiceContext serviceContext = new ServiceContext();

    if (!emailAddress.equalsIgnoreCase(user.getEmailAddress())) {
        UserLocalServiceUtil.updateEmailAddress(user.getUserId(), StringPool.BLANK, emailAddress, emailAddress);
    }

    UserLocalServiceUtil.updateEmailAddressVerified(user.getUserId(), true);

    return UserLocalServiceUtil.updateUser(user.getUserId(), StringPool.BLANK, StringPool.BLANK,
            StringPool.BLANK, false, user.getReminderQueryQuestion(), user.getReminderQueryAnswer(),
            user.getScreenName(), emailAddress, facebookId, user.getOpenId(), user.getLanguageId(),
            user.getTimeZoneId(), user.getGreeting(), user.getComments(), firstName, user.getMiddleName(),
            lastName, contact.getPrefixId(), contact.getSuffixId(), male, birthdayMonth, birthdayDay,
            birthdayYear, contact.getSmsSn(), contact.getAimSn(), contact.getFacebookSn(), contact.getIcqSn(),
            contact.getJabberSn(), contact.getMsnSn(), contact.getMySpaceSn(), contact.getSkypeSn(),
            contact.getTwitterSn(), contact.getYmSn(), contact.getJobTitle(), groupIds, organizationIds,
            roleIds, userGroupRoles, userGroupIds, serviceContext);
}

From source file:com.liferay.adaptive.media.image.item.selector.internal.resolver.test.FileEntryAdaptiveMediaImageFileEntryItemSelectorReturnTypeResolverTest.java

License:Open Source License

@Test
public void testAddingFileEntryWithImageCreatesMedia() throws Exception {
    try (DestinationReplacer destinationReplacer = new DestinationReplacer(
            "liferay/adaptive_media_processor")) {

        ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group,
                TestPropsValues.getUserId());

        final FileEntry fileEntry = _addImageFileEntry(serviceContext);

        String value = _resolver.getValue(fileEntry, null);

        JSONObject jsonObject = JSONFactoryUtil.createJSONObject(value);

        String url = jsonObject.getString("url");
        long fileEntryId = jsonObject.getLong("fileEntryId");

        Assert.assertEquals(DLUtil.getPreviewURL(fileEntry, fileEntry.getFileVersion(), null, StringPool.BLANK,
                false, false), url);/*ww w . jav  a 2s .  co  m*/

        Assert.assertEquals(fileEntry.getFileEntryId(), fileEntryId);
    }
}

From source file:com.liferay.adaptive.media.image.item.selector.internal.resolver.test.FileEntryAMImageFileEntryItemSelectorReturnTypeResolverTest.java

License:Open Source License

@Test
public void testAddingFileEntryWithImageCreatesMedia() throws Exception {
    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group,
            TestPropsValues.getUserId());

    final FileEntry fileEntry = _addImageFileEntry(serviceContext);

    String value = _resolver.getValue(fileEntry, null);

    JSONObject jsonObject = JSONFactoryUtil.createJSONObject(value);

    String url = jsonObject.getString("url");
    long fileEntryId = jsonObject.getLong("fileEntryId");

    Assert.assertEquals(/*from ww w .j  av a  2s. co  m*/
            DLUtil.getPreviewURL(fileEntry, fileEntry.getFileVersion(), null, StringPool.BLANK, false, false),
            url);

    Assert.assertEquals(fileEntry.getFileEntryId(), fileEntryId);
}

From source file:com.liferay.adaptive.media.image.item.selector.internal.test.FileEntryAMImageFileEntryItemSelectorReturnTypeResolverTest.java

License:Open Source License

@Test
public void testAddingFileEntryWithImageCreatesMedia() throws Exception {
    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group,
            TestPropsValues.getUserId());

    final FileEntry fileEntry = _addImageFileEntry(serviceContext);

    String value = _itemSelectorReturnTypeResolver.getValue(fileEntry, null);

    JSONObject jsonObject = JSONFactoryUtil.createJSONObject(value);

    String url = jsonObject.getString("url");
    long fileEntryId = jsonObject.getLong("fileEntryId");

    Assert.assertEquals(//from   w w  w.  ja v  a 2  s  .c om
            DLUtil.getPreviewURL(fileEntry, fileEntry.getFileVersion(), null, StringPool.BLANK, false, false),
            url);

    Assert.assertEquals(fileEntry.getFileEntryId(), fileEntryId);
}

From source file:com.liferay.calendar.util.test.CalendarUtilTest.java

License:Open Source License

protected Set<Long> getCalendarBookingIds(JSONArray jsonArray) {
    Set<Long> calendarBookingIds = new HashSet<>();

    for (int i = 0; i < jsonArray.length(); i++) {
        JSONObject jsonObject = jsonArray.getJSONObject(i);

        calendarBookingIds.add(jsonObject.getLong("calendarBookingId"));
    }/*ww  w.j  av  a 2s  .c  o  m*/

    return calendarBookingIds;
}