Commit de298607 by Nilu

Merged 'develop'.

parents b1a027e9 a049e0d3
package performa.batch;
import java.util.Set;
import oneit.appservices.batch.ORMBatch;
import oneit.logging.*;
import oneit.objstore.ObjectTransaction;
......@@ -8,9 +7,7 @@ import oneit.objstore.StorageException;
import oneit.objstore.rdbms.filters.LessThanFilter;
import oneit.utils.DateDiff;
import oneit.utils.parsers.FieldException;
import performa.intercom.utils.IntercomUtils;
import performa.orm.Job;
import performa.orm.Company;
import performa.orm.types.JobStatus;
......@@ -34,13 +31,6 @@ public class CloseJobBatch extends ORMBatch
LogMgr.log(CLOSE_JOB_BATCH, LogLevel.PROCESSING1, "Setting Job Status to Closed in job : ", job);
}
// Update closed job details to intercom
Set<Company> companies = Job.pipesJob(expiringJobs).toCreatedBy().toCompany().uniqueVals();
for (Company company : companies)
{
IntercomUtils.updateCompany(company);
}
}
}
\ No newline at end of file
......@@ -10,7 +10,6 @@ import oneit.objstore.StorageException;
import oneit.objstore.parser.BusinessObjectParser;
import oneit.objstore.rdbms.filters.EqualsFilter;
import oneit.objstore.utils.ObjstoreUtils;
import oneit.security.SecUser;
import oneit.servlets.forms.SubmissionDetails;
import oneit.servlets.forms.SuccessfulResult;
import oneit.servlets.process.ORMProcessState;
......@@ -19,8 +18,6 @@ import oneit.utils.BusinessException;
import oneit.utils.Debug;
import oneit.utils.filter.CollectionFilter;
import oneit.utils.filter.Filter;
import performa.intercom.utils.IntercomUtils;
import performa.orm.CompanyUser;
import performa.orm.Job;
import performa.orm.JobApplication;
import performa.orm.types.ApplicationStatus;
......@@ -58,18 +55,7 @@ public class BulkUpdateFP extends SaveFP
LogMgr.log(JobApplication.LOG, LogLevel.PROCESSING1,"In BulkUpdateFP Job Application Status successfully changed : ", application );
}
}
// restarting process as custom attributes needs to be updated to intercom
completeProcessRestartAndRestoreAttribs(process, request);
SecUser secUser = SecUser.getTXUser(process.getTransaction());
CompanyUser companyUser = secUser.getExtension(CompanyUser.REFERENCE_CompanyUser);
// Update company in intercom
if(companyUser.getCompany() != null)
{
IntercomUtils.updateCompany(companyUser.getCompany());
}
return super.processForm(process, submission, params);
}
}
......@@ -5,15 +5,12 @@ import javax.servlet.http.HttpServletRequest;
import oneit.logging.LogLevel;
import oneit.logging.LogMgr;
import oneit.objstore.StorageException;
import oneit.security.SecUser;
import oneit.servlets.forms.RedisplayResult;
import oneit.servlets.forms.SubmissionDetails;
import oneit.servlets.forms.SuccessfulResult;
import oneit.servlets.process.ORMProcessState;
import oneit.servlets.process.SaveFP;
import oneit.utils.BusinessException;
import performa.intercom.utils.IntercomUtils;
import performa.orm.CompanyUser;
import performa.orm.JobApplication;
public class ChangeApplicationStatusFP extends SaveFP
......@@ -36,18 +33,6 @@ public class ChangeApplicationStatusFP extends SaveFP
jobApplication.setApplicationStatus(jobApplication.getWorkFlow().getApplicationStatus());
LogMgr.log(JobApplication.LOG, LogLevel.PROCESSING1,"In ChangeApplicationStatusFP Job Application Status successfully changed : ", jobApplication );
// restarting process as custom attributes needs to be updated to intercom
completeProcessRestartAndRestoreAttribs(process, request);
SecUser secUser = SecUser.getTXUser(process.getTransaction());
CompanyUser companyUser = secUser.getExtension(CompanyUser.REFERENCE_CompanyUser);
// Update company in intercom
if(companyUser.getCompany() != null)
{
IntercomUtils.updateCompany(companyUser.getCompany());
}
return super.processForm(process, submission, params);
}
......
......@@ -6,12 +6,10 @@ import javax.servlet.http.HttpServletRequest;
import oneit.logging.*;
import oneit.objstore.*;
import oneit.objstore.parser.BusinessObjectParser;
import oneit.objstore.services.TransactionTask;
import oneit.servlets.forms.*;
import oneit.servlets.process.*;
import oneit.utils.*;
import oneit.utils.parsers.FieldException;
import performa.intercom.utils.IntercomUtils;
import performa.orm.*;
import performa.orm.types.ApplicationStatus;
import performa.utils.AnalysisEngine;
......@@ -24,7 +22,8 @@ public class CompleteApplicationFP extends SaveFP
{
HttpServletRequest request = submission.getRequest();
ObjectTransaction objTran = process.getTransaction();
JobApplication jobApplication = (JobApplication) process.getAttribute("JobApplication");
JobApplication jobApplication = process.getAttribute("JobApplication") != null ? (JobApplication) process.getAttribute("JobApplication") : (JobApplication)request.getAttribute("JobApplication");
jobApplication = jobApplication.getInTransaction(objTran);
if(jobApplication.getStatus() != ObjectStatus.NEW) //getInTransaction will return NULL for NEW object, resulting NPE
{
......@@ -41,16 +40,8 @@ public class CompleteApplicationFP extends SaveFP
{
updateJobApplication(objTran, jobApplication.getID().longID());
}
// restarting process as custom attributes needs to be updated to intercom
completeProcessRestartAndRestoreAttribs(process, request);
jobApplication = (JobApplication) process.getAttribute("JobApplication");
// Update company in intercom
if(jobApplication != null && jobApplication.getJob().getCreatedBy() != null)
{
IntercomUtils.updateCompany(jobApplication.getJob().getCreatedBy().getCompany());
}
process.setAttribute("JobApplication", jobApplication);
return super.processForm(process, submission, params);
}
......@@ -61,7 +52,8 @@ public class CompleteApplicationFP extends SaveFP
{
HttpServletRequest request = submission.getRequest();
ObjectTransaction objTran = ObjectTransaction.getTransaction();
JobApplication jobApplication = (JobApplication) process.getAttribute("JobApplication");
JobApplication jobApplication = process.getAttribute("JobApplication") != null ? (JobApplication) process.getAttribute("JobApplication") : (JobApplication)request.getAttribute("JobApplication");
jobApplication = jobApplication.getInTransaction(objTran);
if(!jobApplication.cultureCompleted())
{
......@@ -94,6 +86,7 @@ public class CompleteApplicationFP extends SaveFP
{
jobApplication.setApplicationStatus(ApplicationStatus.UNSUITABLE);
}
LogMgr.log(JobApplication.LOG, LogLevel.PROCESSING2, "Job Application Completed", jobApplication);
}
}
\ No newline at end of file
package performa.form;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import javax.servlet.http.HttpServletRequest;
import oneit.logging.*;
import oneit.objstore.ObjectTransaction;
import oneit.objstore.StorageException;
import oneit.security.SecUser;
import oneit.servlets.forms.*;
import oneit.servlets.process.*;
import oneit.utils.*;
import performa.orm.*;
import performa.utils.Utils;
public class ConfirmDetailsFP extends SaveFP
{
private static final LoggingArea LOG = LoggingArea.createLoggingArea("ConfirmDetailsFP");
@Override
public SuccessfulResult processForm(ORMProcessState process, SubmissionDetails submission, Map params) throws BusinessException, StorageException
{
HttpServletRequest request = submission.getRequest();
ObjectTransaction objTran = process.getTransaction();
Job job = (Job) request.getAttribute("Job");
String email = job.getEmail();
Debug.assertion(email != null, "Email not avaialble");
email = email.toLowerCase();
LogMgr.log(LOG, LogLevel.PROCESSING1, "Started to send varification email.", job , email);
SecUser secUser = SecUser.searchNAME(objTran, email);
if(secUser == null)
{
secUser = SecUser.createSecUser(objTran);
secUser.setUserName(email);
secUser.setEmail(email);
secUser.setAttribute("md5:" + SecUser.FIELD_Password, CompanyUser.DEFAULT_PASSWORD);
secUser.addRole(Utils.getRole(Utils.ROLE_APPLICANT, objTran));
}
Candidate candidate = secUser.getExtensionOrCreate(Candidate.REFERENCE_Candidate);
LogMgr.log(LOG, LogLevel.PROCESSING1, "New user created :: ", secUser);
Set<String> attribsToRestore = new HashSet<>();
attribsToRestore.add("Job");
attribsToRestore.add("NewCandidate");
request.setAttribute("attribNamesToRestore", attribsToRestore);
process.setAttribute("NewCandidate",candidate);
return super.processForm(process, submission, params);
}
}
\ No newline at end of file
......@@ -91,23 +91,6 @@ public class MakePaymentFP extends SaveFP
// StripeUtils.updatePlan(company);
}
// restarting process as custom attributes needs to be updated to intercom
// Set<String> attribsToRestore = new HashSet<>();
// attribsToRestore.add("Job");
// attribsToRestore.add("Company");
//
// completeProcessRestartAndRestoreAttribs(process, attribsToRestore);
//
// secUser = SecUser.getTXUser(process.getTransaction());
// companyUser = secUser.getExtension(CompanyUser.REFERENCE_CompanyUser);
//
// // Update company in intercom
// if(companyUser.getCompany() != null)
// {
// IntercomUtils.updateCompany(companyUser.getCompany());
// }
return super.processForm(process, submission, p);
}
}
\ No newline at end of file
......@@ -3,19 +3,23 @@ package performa.form;
import com.stripe.model.Subscription;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import oneit.business.content.Article;
import oneit.logging.LogLevel;
import oneit.logging.LogMgr;
import oneit.net.LoopbackHTTP;
import oneit.objstore.StorageException;
import oneit.objstore.parser.BusinessObjectParser;
import oneit.servlets.forms.SubmissionDetails;
import oneit.servlets.forms.SuccessfulResult;
import oneit.servlets.process.ORMProcessState;
import oneit.servlets.process.ProcessRedirectResult;
import oneit.servlets.process.SaveFP;
import oneit.utils.BusinessException;
import oneit.utils.CollectionUtils;
import oneit.utils.MultiException;
import performa.orm.HiringTeam;
import performa.utils.StripeUtils;
import performa.utils.WebUtils;
public class SaveCompanyFP extends SaveFP
......@@ -27,6 +31,10 @@ public class SaveCompanyFP extends SaveFP
HiringTeam hiringTeam = (HiringTeam) process.getAttribute("HiringTeam");
Boolean isPayment = (Boolean) request.getAttribute("IsPayment");
Subscription subscription = StripeUtils.retrieveSubscription(hiringTeam.getStripeSubscription());
Boolean isHTLogoPresent = process.getAttribute("IsHTLogoPresent") != null ? (Boolean) process.getAttribute("IsHTLogoPresent") : Boolean.FALSE;
Article article = WebUtils.getArticleByShortCut(process.getTransaction(), WebUtils.MY_COMPANY);
String nextPage = LoopbackHTTP.getRemoteAccessURL(request)
+ article.getLink(request, CollectionUtils.mapEntry("cms.rm", hiringTeam.getHiringTeamLogo() != null ? "Page" : "HiringTeam").toMap(), "/");
if(CollectionUtils.equals(hiringTeam.getIsLogoDeleted(), Boolean.TRUE))
{
......@@ -62,8 +70,17 @@ public class SaveCompanyFP extends SaveFP
}
}
// // Update company in intercom
// IntercomUtils.updateCompany(company);
//Set attribute IsHTLogoPresent false when HT logo is not uploaded or deleted
if(hiringTeam.getHiringTeamLogo() == null && !isHTLogoPresent)
{
process.setAttribute("IsHTLogoPresent", Boolean.FALSE);
return new ProcessRedirectResult(nextPage, new String[]{});
}
process.setAttribute("nextPage", nextPage);
process.setAttribute("HiringTeam", hiringTeam);
return super.processForm(process, submission, params);
}
......
......@@ -8,7 +8,6 @@ import oneit.logging.LogLevel;
import oneit.logging.LogMgr;
import oneit.objstore.StorageException;
import oneit.objstore.parser.BusinessObjectParser;
import oneit.security.SecUser;
import oneit.servlets.forms.SubmissionDetails;
import oneit.servlets.forms.SuccessfulResult;
import oneit.servlets.process.ORMProcessState;
......@@ -17,7 +16,6 @@ import oneit.utils.BusinessException;
import oneit.utils.DateDiff;
import oneit.utils.MultiException;
import oneit.utils.math.NullArith;
import performa.intercom.utils.IntercomUtils;
import performa.orm.*;
import performa.orm.types.*;
import performa.utils.StripeUtils;
......@@ -90,18 +88,6 @@ public class SaveJobFP extends SaveFP
job.setAssessmentType(occupation.getAssessmentType());
}
// restarting process as custom attributes needs to be updated to intercom
completeProcessRestartAndRestoreAttribs(process, request);
SecUser secUser = SecUser.getTXUser(process.getTransaction());
CompanyUser companyUser = secUser.getExtension(CompanyUser.REFERENCE_CompanyUser);
// Update company in intercom
if(companyUser.getCompany() != null)
{
IntercomUtils.updateCompany(companyUser.getCompany());
}
return super.processForm(process, submission, params);
}
......
......@@ -19,8 +19,6 @@ import oneit.utils.CollectionUtils;
import oneit.utils.InitialisationException;
import oneit.utils.MultiException;
import oneit.utils.StringUtils;
import performa.intercom.resources.User;
import performa.intercom.utils.IntercomUtils;
import performa.orm.CompanyUser;
import performa.utils.Utils;
......@@ -82,19 +80,7 @@ public class SaveUserDetailsFP extends SaveFP
Utils.sendEmailChangedMail(companyUser, request, emailer, SaveUserDetailsFP.class.getName());
}
}
User intercomUser = (User)request.getSession().getAttribute("IntercomUser");
if(intercomUser == null)
{
performa.intercom.resources.Company intercomCompany = IntercomUtils.findOrCreateCompany(companyUser.getCompany());
IntercomUtils.createIntercomUser(secUser, "Hiring Team", intercomCompany, companyUser.getPhone());
}
else
{
IntercomUtils.updateIntercomUser(secUser, companyUser.getPhone());
}
}
return super.processForm(process, submission, params);
......
......@@ -17,7 +17,6 @@ import oneit.servlets.forms.*;
import oneit.servlets.process.*;
import oneit.servlets.security.SessionSecUserDecorator;
import oneit.utils.*;
import performa.intercom.utils.IntercomUtils;
import performa.orm.*;
import performa.orm.types.RoleType;
import performa.utils.StripeUtils;
......@@ -165,12 +164,6 @@ public class SendCompanyUserInvitesFP extends SaveFP
}
}
// Create company and the first user of it in intercom
performa.intercom.resources.Company intercomCompany = IntercomUtils.findOrCreateCompany(company);
IntercomUtils.createIntercomUser(secUser, "Hiring Team", intercomCompany, companyUser.getPhone());
return super.processForm(process, submission, params);
}
......@@ -201,14 +194,14 @@ public class SendCompanyUserInvitesFP extends SaveFP
Map defaultParams = CollectionUtils.mapEntry("link", link)
.mapEntry("create_job_link", jobCreateLink)
.toMap();
ObjectTransform transform = Utils.createCompoundTransform(defaultParams, companyUser.getUser(), companyUser.getCompany());
ObjectTransform transform = Utils.createCompoundTransform(defaultParams, companyUser.getUser(), companyUser.getCompany(),companyUser.getDefaultHiringTeam());
Utils.sendMail(ownerAccountCreatedEmailer, transform, new String[]{companyUser.getEmailAddressFromUser()}, null, companyUser);
}
else
{
Map defaultParams = CollectionUtils.mapEntry("link", link).toMap();
ObjectTransform transform = Utils.createCompoundTransform(defaultParams, companyUser.getCompany(), companyUser.getUser());
ObjectTransform transform = Utils.createCompoundTransform(defaultParams, companyUser.getCompany(), companyUser.getUser(), companyUser.getDefaultHiringTeam());
Utils.sendMail(emailer, transform, new String[]{companyUser.getEmailAddressFromUser()}, null, companyUser);
}
......
......@@ -173,7 +173,7 @@ public class SendUserInvitationFP extends SaveFP
+ "?id=" + companyUser.getID()
+ "&key=" + companyUser.getVerificationKey();
Map defaultParams = CollectionUtils.mapEntry("link", link).toMap();
ObjectTransform transform = Utils.createCompoundTransform(defaultParams, companyUser.getCompany(), SecUser.getTXUser(objTran));
ObjectTransform transform = Utils.createCompoundTransform(defaultParams, companyUser.getCompany(),companyUser.getDefaultHiringTeam(), SecUser.getTXUser(objTran));
Utils.sendMail(invitationEmailer, transform, new String[]{companyUser.getEmailAddressFromUser()}, null, companyUser);
......
......@@ -49,7 +49,26 @@ public class SendVerificationMailFP extends SaveFP
}
else
{
BusinessObjectParser.assertFieldCondition(!Utils.emailExists(process.getTransaction(), job.getEmail()), job, Job.FIELD_Email, "emailExists", exceptions, true, request);
JobApplication jobApplication = (JobApplication)request.getAttribute("JobApplication");
Candidate candidate = (Candidate) request.getAttribute("Candidate");
SecUser secUser = candidate.getUser();
BusinessObjectParser.assertFieldCondition(secUser.getEmail() != null , job, Job.FIELD_Email, "mandatory", exceptions, true, request);
BusinessObjectParser.assertFieldCondition(StringUtils.isEmailAddress(secUser.getEmail()), job, Job.FIELD_Email, "invalid", exceptions, true, request);
BusinessObjectParser.assertFieldCondition(secUser.getFirstName() != null, secUser, SecUser.FIELD_FirstName, "mandatory", exceptions, true, request);
BusinessObjectParser.assertFieldCondition(secUser.getLastName() != null, secUser, SecUser.FIELD_LastName, "mandatory", exceptions, true, request);
BusinessObjectParser.assertFieldCondition(candidate.isTrue(candidate.getPrivacyPolicyAgreed()), candidate, Candidate.FIELD_PrivacyPolicyAgreed, "agreePrivacy", exceptions, true, request);
BusinessObjectParser.assertFieldCondition(candidate.isTrue(candidate.getConditionsAgreed()), candidate, Candidate.FIELD_ConditionsAgreed, "agreeTerms", exceptions, true, request);
// BusinessObjectParser.assertFieldCondition(secUser.checkPassword(job.getPassword()), job, Job.FIELD_Password, "invalid", exceptions, true, request);
if(job.getRequireCV())
{
BusinessObjectParser.assertFieldCondition(jobApplication.getCV() != null , jobApplication, JobApplication.FIELD_CV, "uploadCV", exceptions, true, request);
BusinessObjectParser.assertFieldCondition(jobApplication.getCoverLetter() != null , jobApplication, JobApplication.FIELD_CoverLetter, "uploadCover", exceptions, true, request);
}
}
super.validate(process, submission, exceptions, params);
......@@ -62,6 +81,7 @@ public class SendVerificationMailFP extends SaveFP
HttpServletRequest request = submission.getRequest();
ObjectTransaction objTran = process.getTransaction();
Job job = (Job) request.getAttribute("Job");
Candidate candidate = (Candidate) request.getAttribute("Candidate");
Company company = (Company) request.getAttribute("Company");
if(company != null)
......@@ -113,40 +133,6 @@ public class SendVerificationMailFP extends SaveFP
}
else
{
String email = job.getEmail();
Debug.assertion(email != null, "Email not avaialble");
email = email.toLowerCase();
LogMgr.log(LOG, LogLevel.PROCESSING1, "Started to send varification email.", job , email);
SecUser secUser = SecUser.searchNAME(objTran, email);
if(secUser!=null)
{
Candidate tmpCandidate = secUser.getExtension(Candidate.REFERENCE_Candidate);
Debug.assertion((tmpCandidate == null || !tmpCandidate.getIsAccountVerified()), "user available", email, secUser);
}
LogMgr.log(LOG, LogLevel.PROCESSING1, "Inside SendVerificationMailFP for send account verification mail for ", email);
if(secUser==null)
{
secUser = SecUser.createSecUser(objTran);
secUser.setUserName(email);
secUser.setEmail(email);
secUser.setAttribute("md5:" + SecUser.FIELD_Password, CompanyUser.DEFAULT_PASSWORD);
secUser.addRole(Utils.getRole(Utils.ROLE_APPLICANT, objTran));
}
Candidate candidate = secUser.getExtensionOrCreate(Candidate.REFERENCE_Candidate);
LogMgr.log(LOG, LogLevel.PROCESSING1, "New user created :: ", secUser);
sendVerificationMail(candidate, job, request);
request.setAttribute("nextPage", request.getAttribute("nextPage") + "&JobID=" + job.getID());
......
......@@ -5,6 +5,7 @@ import javax.servlet.http.HttpServletRequest;
import oneit.objstore.ObjectTransaction;
import oneit.objstore.StorageException;
import oneit.objstore.parser.BusinessObjectParser;
import oneit.objstore.rdbms.filters.EqualsFilter;
import oneit.servlets.forms.SubmissionDetails;
import oneit.servlets.forms.SuccessfulResult;
import oneit.servlets.process.ORMProcessState;
......@@ -13,6 +14,7 @@ import oneit.servlets.process.SaveFP;
import oneit.utils.BusinessException;
import oneit.utils.Debug;
import oneit.utils.MultiException;
import performa.orm.AssessmentCriteriaAnswer;
import performa.orm.JobApplication;
......@@ -32,24 +34,20 @@ public class ValidateApplicationFP extends SaveFP
super.validate(process, submission, exceptions, params);
HttpServletRequest request = submission.getRequest();
ObjectTransaction objTran = ObjectTransaction.getTransaction();
JobApplication jobApplication = (JobApplication) process.getAttribute("JobApplication");
ObjectTransaction objTran = process.getTransaction();
JobApplication jobApplication = process.getAttribute("JobApplication") != null ? (JobApplication) process.getAttribute("JobApplication") : (JobApplication)request.getAttribute("JobApplication");
boolean fromRequirements = request.getAttribute("fromRequirements") != null ? (boolean) request.getAttribute("fromRequirements"): false;
boolean fromCoverLetter = request.getAttribute("fromCoverLetter") != null ? (boolean) request.getAttribute("fromCoverLetter"): false;
Debug.assertion(jobApplication != null, "No jobApplication found . Call from " + getClass().getName());
jobApplication = jobApplication.getInTransaction(objTran);
if(jobApplication.isIncludeAssessmentCriteria() && fromRequirements)
{
JobApplication application = jobApplication.getInTransaction(objTran);
// JobApplication application = jobApplication.getInTransaction(objTran);
AssessmentCriteriaAnswer[] application = AssessmentCriteriaAnswer.SearchByAll().andJobApplication(new EqualsFilter<>(jobApplication)).search(objTran);
BusinessObjectParser.assertFieldCondition(jobApplication.getJob().getAssessmentCriteriasCount() == application.getAssessmentCriteriaAnswersCount(), jobApplication, JobApplication.FIELD_ObjectID, "completeAssessment", exceptions, true, request);
BusinessObjectParser.assertFieldCondition(jobApplication.getJob().getAssessmentCriteriasCount() == application.length, jobApplication, JobApplication.FIELD_ObjectID, "completeAssessment", exceptions, true, request);
}
if(fromCoverLetter)
{
BusinessObjectParser.assertFieldCondition(jobApplication.getCV() != null , jobApplication, JobApplication.FIELD_CV, "uploadCV", exceptions, true, request);
BusinessObjectParser.assertFieldCondition(jobApplication.getCoverLetter() != null , jobApplication, JobApplication.FIELD_CoverLetter, "uploadCover", exceptions, true, request);
}
}
}
\ No newline at end of file
......@@ -15,7 +15,6 @@ import oneit.servlets.forms.*;
import oneit.servlets.process.*;
import oneit.servlets.security.SessionSecUserDecorator;
import oneit.utils.*;
import performa.intercom.utils.IntercomUtils;
import performa.orm.*;
import performa.utils.Utils;
import performa.utils.WebUtils;
......@@ -29,22 +28,23 @@ public class VerifyIdentityFP extends SaveFP
@Override
protected Map validate(SubmissionDetails submission, MultiException exceptions)
{
HttpServletRequest request = submission.getRequest();
Job job = (Job) request.getAttribute("Job");
Candidate candidate = (Candidate) request.getAttribute("Candidate");
SecUser secUser = candidate.getUser();
Boolean isVerify = CollectionUtils.equals(request.getAttribute("isVerify"), Boolean.TRUE);
HttpServletRequest request = submission.getRequest();
JobApplication jobApplication = (JobApplication)request.getAttribute("JobApplication");
Candidate candidate = (Candidate) request.getAttribute("Candidate");
SecUser secUser = candidate.getUser();
Boolean isVerify = CollectionUtils.equals(request.getAttribute("isVerify"), Boolean.TRUE);
boolean fromCoverLetter = request.getAttribute("fromCoverLetter") != null ? (boolean) request.getAttribute("fromCoverLetter"): false;
Job job = (Job) request.getAttribute("Job");
BusinessObjectParser.assertFieldCondition(secUser.getEmail() != null , job, Job.FIELD_Email, "mandatory", exceptions, true, request);
BusinessObjectParser.assertFieldCondition(StringUtils.isEmailAddress(secUser.getEmail()), job, Job.FIELD_Email, "invalid", exceptions, true, request);
BusinessObjectParser.assertFieldCondition(secUser.getFirstName() != null, secUser, SecUser.FIELD_FirstName, "mandatory", exceptions, true, request);
BusinessObjectParser.assertFieldCondition(secUser.getLastName() != null, secUser, SecUser.FIELD_LastName, "mandatory", exceptions, true, request);
if(isVerify)
{
BusinessObjectParser.assertFieldCondition(candidate.isTrue(candidate.getPrivacyPolicyAgreed()), candidate, Candidate.FIELD_PrivacyPolicyAgreed, "agreePrivacy", exceptions, true, request);
BusinessObjectParser.assertFieldCondition(candidate.isTrue(candidate.getConditionsAgreed()), candidate, Candidate.FIELD_ConditionsAgreed, "agreeTerms", exceptions, true, request);
BusinessObjectParser.assertFieldCondition(secUser.checkPassword(job.getPassword()) , job, Job.FIELD_Password, "invalid", exceptions, true, request);
}
if(fromCoverLetter && job.getRequireCV())
{
BusinessObjectParser.assertFieldCondition(jobApplication.getCV() != null , jobApplication, JobApplication.FIELD_CV, "uploadCV", exceptions, true, request);
BusinessObjectParser.assertFieldCondition(jobApplication.getCoverLetter() != null , jobApplication, JobApplication.FIELD_CoverLetter, "uploadCover", exceptions, true, request);
}
return super.validate(submission, exceptions);
......@@ -58,40 +58,29 @@ public class VerifyIdentityFP extends SaveFP
Boolean isVerify = CollectionUtils.equals(request.getAttribute("isVerify"), Boolean.TRUE);
Job job = (Job) request.getAttribute("Job");
JobApplication jobApplication = (JobApplication) request.getAttribute("JobApplication");
String nextPage = (String) request.getAttribute("nextPage");
Candidate candidate = (Candidate) request.getAttribute("Candidate");
if(isVerify)
{
SecUser secUser = candidate.getUser();
SecUser secUser = candidate.getUser();
LogMgr.log(LOG, LogLevel.PROCESSING1, "Verifing User", job, secUser);
LogMgr.log(LOG, LogLevel.PROCESSING1, "Verifing User ", job, secUser);
// if(CollectionUtils.equals(job.getPassword(), job.getConfirmPassword()))
// {
// secUser.setAttribute("md5:" + SecUser.FIELD_Password, job.getPassword());
candidate.setIsAccountVerified(Boolean.TRUE);
candidate.setIsAccountVerified(Boolean.TRUE);
sendMail(candidate, job, request);
// Create a applicant user in intercom
IntercomUtils.createIntercomUser(secUser, "Applicant", null, candidate.getPhone());
sendMail(candidate, job, request);
request.getSession().setAttribute (SecUser.SEC_USER_ID, secUser);
request.getSession().setAttribute (SessionSecUserDecorator.REFRESH_SECURITY, Boolean.TRUE);
// request.setAttribute("nextPage", nextPage + "&JobID=" + job.getObjectID());
request.getSession().setAttribute (SecUser.SEC_USER_ID, secUser);
request.getSession().setAttribute (SessionSecUserDecorator.REFRESH_SECURITY, Boolean.TRUE);
LogMgr.log(LOG, LogLevel.PROCESSING1, "Password resetted", job, secUser);
// }
LogMgr.log(LOG, LogLevel.PROCESSING1, "Verified User ", job, secUser);
}
// storing candidate location in application for distance calculation to be accurate even if user edits
// location in the next application
jobApplication.setGoogleAddressText(candidate.getGoogleAddressText());
process.completeAndRestart();
return new ProcessRedirectResult(nextPage + "&JobID=" + job.getObjectID(), new String[0]);
return super.processForm(process, submission, params);
}
......
package performa.intercom.resources;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.collect.Maps;
import java.util.Map;
@SuppressWarnings("UnusedDeclaration")
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class Admin extends TypedData implements Replier {
private static final Map<String, String> SENTINEL = Maps.newHashMap();
public static final String TYPE_NOBODY = "nobody_admin";
// don't make public for now
static AdminCollection list(Map<String, String> params)
throws AuthorizationException, ClientException, ServerException, InvalidException, RateLimitException {
return DataResource.list(params, "admins", AdminCollection.class);
}
public static AdminCollection list()
throws AuthorizationException, ClientException, ServerException, InvalidException, RateLimitException {
return DataResource.list(SENTINEL, "admins", AdminCollection.class);
}
@SuppressWarnings("FieldCanBeLocal")
@JsonProperty("type")
private final String type = "admin";
@JsonProperty("id")
private String id;
@JsonProperty("name")
private String name;
@JsonProperty("email")
private String email;
@JsonProperty("created_at")
private long createdAt;
@JsonProperty("updated_at")
private long updatedAt;
@JsonProperty("open")
private long open;
@JsonProperty("closed")
private long closed;
public Admin() {
}
@JsonIgnore
public String getReplyType() {
return getType() + "_reply";
}
public String getType() {
return type;
}
@JsonIgnore
public boolean isNobody() {
return TYPE_NOBODY.equalsIgnoreCase(getType());
}
@JsonIgnore
public boolean isSomebody() {
return (!isNobody()) && (getId() != null);
}
public String getId() {
return id;
}
public Admin setId(String id) {
this.id = id;
return this;
}
public String getName() {
return name;
}
public String getEmail() {
return email;
}
public long getCreatedAt() {
return createdAt;
}
public long getUpdatedAt() {
return updatedAt;
}
public long getOpen() {
return open;
}
public long getClosed() {
return closed;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Admin admin = (Admin) o;
if (closed != admin.closed) return false;
if (createdAt != admin.createdAt) return false;
if (open != admin.open) return false;
if (updatedAt != admin.updatedAt) return false;
if (email != null ? !email.equals(admin.email) : admin.email != null) return false;
if (id != null ? !id.equals(admin.id) : admin.id != null) return false;
if (name != null ? !name.equals(admin.name) : admin.name != null) return false;
//noinspection RedundantIfStatement
if (!type.equals(admin.type)) return false;
return true;
}
@Override
public int hashCode() {
int result = type.hashCode();
result = 31 * result + (id != null ? id.hashCode() : 0);
result = 31 * result + (name != null ? name.hashCode() : 0);
result = 31 * result + (email != null ? email.hashCode() : 0);
result = 31 * result + (int) (createdAt ^ (createdAt >>> 32));
result = 31 * result + (int) (updatedAt ^ (updatedAt >>> 32));
result = 31 * result + (int) (open ^ (open >>> 32));
result = 31 * result + (int) (closed ^ (closed >>> 32));
return result;
}
@Override
public String toString() {
return "Admin{" +
"id='" + id + '\'' +
", name='" + name + '\'' +
", email='" + email + '\'' +
", createdAt=" + createdAt +
", updatedAt=" + updatedAt +
"} " + super.toString();
}
}
package performa.intercom.resources;
import performa.intercom.resources.Admin;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.Iterator;
import java.util.List;
@SuppressWarnings("UnusedDeclaration")
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class AdminCollection extends TypedDataCollection<Admin> implements Iterator<Admin> {
protected TypedDataCollectionIterator<Admin> iterator;
public AdminCollection() {
type = "company.list";
iterator = new TypedDataCollectionIterator<Admin>(this);
}
@Override
public AdminCollection nextPage() {
return fetchNextPage(AdminCollection.class);
}
@SuppressWarnings("EmptyMethod")
@JsonProperty("admins")
@Override
public List<Admin> getPage() {
return super.getPage();
}
public boolean hasNext() {
return iterator.hasNext();
}
public Admin next() {
return iterator.next();
}
public void remove() {
iterator.remove();
}
}
package performa.intercom.resources;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.annotations.VisibleForTesting;
@SuppressWarnings("UnusedDeclaration")
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class AdminMessage extends TypedData {
@JsonProperty("type")
private final String type = "admin_message";
@JsonProperty("id")
private String id;
@JsonProperty("message_type")
private String messageType;
@JsonProperty("subject")
private String subject=""; // Set default to blank string so null pointer exception won't thrown if messageType = inapp and subject not set
@JsonProperty("body")
private String body;
@JsonProperty("template")
private String template="plain"; // Set default to plain so null pointer exception won't thrown if messageType = inapp and template not set
@JsonProperty("created_at")
private long createdAt;
@JsonProperty("from")
private Admin admin;
@JsonProperty("to")
private User user;
public AdminMessage() {
}
public String getType() {
return type;
}
public String getId() {
return id;
}
@SuppressWarnings("UnusedReturnValue")
@VisibleForTesting
AdminMessage setId(String id) {
this.id = id;
return this;
}
public String getMessageType() {
return messageType;
}
public AdminMessage setMessageType(String messageType) {
this.messageType = messageType;
return this;
}
public String getSubject() {
return subject;
}
public AdminMessage setSubject(String subject) {
this.subject = subject;
return this;
}
public String getBody() {
return body;
}
public AdminMessage setBody(String body) {
this.body = body;
return this;
}
public String getTemplate() {
return template;
}
public AdminMessage setTemplate(String template) {
this.template = template;
return this;
}
public long getCreatedAt() {
return createdAt;
}
@SuppressWarnings("UnusedReturnValue")
public AdminMessage setCreatedAt(long createdAt) {
this.createdAt = createdAt;
return this;
}
public Admin getAdmin() {
return admin;
}
public AdminMessage setAdmin(Admin admin) {
this.admin = admin;
return this;
}
public User getUser() {
return user;
}
public AdminMessage setUser(User user) {
this.user = user;
return this;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
AdminMessage message = (AdminMessage) o;
if (createdAt != message.createdAt) return false;
if (admin != null ? !admin.equals(message.admin) : message.admin != null) return false;
if (body != null ? !body.equals(message.body) : message.body != null) return false;
if (id != null ? !id.equals(message.id) : message.id != null) return false;
if (messageType != null ? !messageType.equals(message.messageType) : message.messageType != null) return false;
if (subject != null ? !subject.equals(message.subject) : message.subject != null) return false;
if (template != null ? !template.equals(message.template) : message.template != null) return false;
if (!type.equals(message.type)) return false;
//noinspection RedundantIfStatement
if (user != null ? !user.equals(message.user) : message.user != null) return false;
return true;
}
@Override
public int hashCode() {
int result = type.hashCode();
result = 31 * result + (id != null ? id.hashCode() : 0);
result = 31 * result + (messageType != null ? messageType.hashCode() : 0);
result = 31 * result + (subject != null ? subject.hashCode() : 0);
result = 31 * result + (body != null ? body.hashCode() : 0);
result = 31 * result + (template != null ? template.hashCode() : 0);
result = 31 * result + (int) (createdAt ^ (createdAt >>> 32));
result = 31 * result + (admin != null ? admin.hashCode() : 0);
result = 31 * result + (user != null ? user.hashCode() : 0);
return result;
}
@Override
public String toString() {
return "AdminMessage{" +
"id='" + id + '\'' +
", messageType='" + messageType + '\'' +
", subject='" + subject + '\'' +
", body='" + body + '\'' +
", template='" + template + '\'' +
", createdAt=" + createdAt +
", admin=" + admin +
", user=" + user +
"} " + super.toString();
}
}
package performa.intercom.resources;
import performa.intercom.resources.Admin;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
@SuppressWarnings("UnusedDeclaration")
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_EMPTY)
class AdminMessageResponse extends TypedData {
@JsonProperty("id")
private String id;
@JsonProperty("message_type")
private String messageType;
@JsonProperty("subject")
private String subject;
@JsonProperty("body")
private String body;
@JsonProperty("template")
private String template;
@JsonProperty("created_at")
private long createdAt;
@JsonProperty("updated_at")
private long updatedAt;
@JsonProperty("owner")
private Admin admin;
@JsonProperty("to")
private User user;
public AdminMessageResponse() {
}
public String getType() {
return "admin_message";
}
public String getId() {
return id;
}
public AdminMessageResponse setId(String id) {
this.id = id;
return this;
}
public String getMessageType() {
return messageType;
}
public AdminMessageResponse setMessageType(String messageType) {
this.messageType = messageType;
return this;
}
public String getSubject() {
return subject;
}
public AdminMessageResponse setSubject(String subject) {
this.subject = subject;
return this;
}
public String getBody() {
return body;
}
public AdminMessageResponse setBody(String body) {
this.body = body;
return this;
}
public String getTemplate() {
return template;
}
public AdminMessageResponse setTemplate(String template) {
this.template = template;
return this;
}
public long getCreatedAt() {
return createdAt;
}
public AdminMessageResponse setCreatedAt(long createdAt) {
this.createdAt = createdAt;
return this;
}
public long getUpdatedAt() {
return updatedAt;
}
public AdminMessageResponse setUpdatedAt(long updatedAt) {
this.updatedAt = updatedAt;
return this;
}
public Admin getAdmin() {
return admin;
}
public AdminMessageResponse setAdmin(Admin admin) {
this.admin = admin;
return this;
}
public User getUser() {
return user;
}
public AdminMessageResponse setUser(User user) {
this.user = user;
return this;
}
}
package performa.intercom.resources;
import performa.intercom.resources.Admin;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
@SuppressWarnings("UnusedDeclaration")
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class AdminReply extends Reply<Admin> {
@SuppressWarnings("UnusedDeclaration")
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_EMPTY)
static class AdminStringReply {
private AdminReply reply;
public AdminStringReply(AdminReply reply) {
this.reply = reply;
}
@JsonProperty("type")
public String getType() {
return reply.getType();
}
@JsonProperty("message_type")
public String getMessageType() {
return reply.getMessageType();
}
@JsonProperty("body")
public String getBody() {
return reply.getBody();
}
@JsonProperty("admin_id")
public String getAdminID() {
return reply.getFrom().getId();
}
@JsonProperty("assignee_id")
public String getAssigneeID() {
return reply.getAssigneeID();
}
@JsonProperty("attachment_urls")
private String[] getAttachmentUrls() {
return reply.getAttachmentUrls();
}
}
@JsonProperty("assignee_id")
private String assigneeID;
public AdminReply(Admin admin) {
this.from = admin;
}
public Reply<Admin> setMessageType(String messageType) {
return setMessageReplyType(messageType);
}
public String getAssigneeID() {
return assigneeID;
}
public Reply<Admin> setAssigneeID(String assigneeID) {
this.assigneeID = assigneeID;
this.setMessageType(Conversation.MESSAGE_TYPE_ASSIGNMENT);
return this;
}
@Override
public String toString() {
return "AdminReply{} " + super.toString();
}
}
package performa.intercom.resources;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
@SuppressWarnings("UnusedDeclaration")
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class Author extends TypedData {
@JsonProperty("type")
private String type;
@JsonProperty("id")
private String id;
@JsonProperty("name")
private String name;
@JsonProperty("email")
private String email;
@JsonProperty("user_id")
private String userId;
public Author() {
}
public String getType() {
return type;
}
@JsonIgnore
public boolean isUser() {
return "user".equalsIgnoreCase(getType());
}
@JsonIgnore
public boolean isAdmin() {
return "admin".equalsIgnoreCase(getType());
}
public String getId() {
return id;
}
public Author setId(String id) {
this.id = id;
return this;
}
public String getName() {
return name;
}
public Author setName(String name) {
this.name = name;
return this;
}
public String getEmail() {
return email;
}
public Author setEmail(String email) {
this.email = email;
return this;
}
public String getUserId() {
return userId;
}
public Author setUserId(String userId) {
this.userId = userId;
return this;
}
@Override
public int hashCode() {
int result = id != null ? id.hashCode() : 0;
result = 31 * result + (name != null ? name.hashCode() : 0);
result = 31 * result + (email != null ? email.hashCode() : 0);
result = 31 * result + (userId != null ? userId.hashCode() : 0);
return result;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Author author = (Author) o;
if (email != null ? !email.equals(author.email) : author.email != null) return false;
if (id != null ? !id.equals(author.id) : author.id != null) return false;
if (name != null ? !name.equals(author.name) : author.name != null) return false;
//noinspection RedundantIfStatement
if (userId != null ? !userId.equals(author.userId) : author.userId != null) return false;
return true;
}
@Override
public String toString() {
return "Author{" +
"id='" + id + '\'' +
", name='" + name + '\'' +
", email='" + email + '\'' +
", userId='" + userId + '\'' +
"} " + super.toString();
}
}
package performa.intercom.resources;
public class AuthorizationException extends IntercomException {
private static final long serialVersionUID = 2917082281352001861L;
public AuthorizationException(String message) {
super(message);
}
public AuthorizationException(String message, Throwable cause) {
super(message, cause);
}
public AuthorizationException(ErrorCollection errorCollection) {
super(errorCollection);
}
public AuthorizationException(ErrorCollection errorCollection, Throwable cause) {
super(errorCollection, cause);
}
}
package performa.intercom.resources;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.net.URI;
@SuppressWarnings("UnusedDeclaration")
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_DEFAULT)
public class Avatar extends TypedData {
@JsonProperty("type")
private final String type = "avatar";
@JsonProperty("image_url")
private URI imageURL;
Avatar() {
}
public String getType() {
return type;
}
public URI getImageURL() {
return imageURL;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Avatar avatar = (Avatar) o;
if (imageURL != null ? !imageURL.equals(avatar.imageURL) : avatar.imageURL != null) return false;
//noinspection RedundantIfStatement
if (!type.equals(avatar.type)) return false;
return true;
}
@Override
public int hashCode() {
int result = type.hashCode();
result = 31 * result + (imageURL != null ? imageURL.hashCode() : 0);
return result;
}
@Override
public String toString() {
return "Avatar{" +
"type='" + type + '\'' +
", imageURL=" + imageURL +
"} " + super.toString();
}
}
package performa.intercom.resources;
public class ClientException extends IntercomException {
private static final long serialVersionUID = -2111295679006526646L;
public ClientException(String message) {
super(message);
}
public ClientException(String message, Throwable cause) {
super(message, cause);
}
public ClientException(ErrorCollection errorCollection) {
super(errorCollection);
}
public ClientException(ErrorCollection errorCollection, Throwable cause) {
super(errorCollection, cause);
}
}
package performa.intercom.resources;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.Iterator;
import java.util.List;
@SuppressWarnings("UnusedDeclaration")
@JsonIgnoreProperties(ignoreUnknown = true)
public class CompanyCollection extends TypedDataCollection<Company> implements Iterator<Company> {
protected TypedDataCollectionIterator<Company> iterator;
@JsonProperty("total_count")
private long totalCount;
public CompanyCollection() {
type = "company.list";
iterator = new TypedDataCollectionIterator<Company>(this);
}
public CompanyCollection(List<Company> companies) {
this();
this.page = companies;
}
@SuppressWarnings("EmptyMethod")
@JsonProperty("companies")
@Override
public List<Company> getPage() {
return super.getPage();
}
public long getTotalCount() {
return totalCount;
}
@Override
public CompanyCollection nextPage() {
return fetchNextPage(CompanyCollection.class);
}
public boolean hasNext() {
return iterator.hasNext();
}
public Company next() {
return iterator.next();
}
public void remove() {
iterator.remove();
}
@Override
public String toString() {
return "CompanyCollection{" +
", totalCount=" + totalCount +
"} " + super.toString();
}
void addCompany(Company company) {
page.add(company);
}
}
package performa.intercom.resources;
import com.google.common.base.Objects;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import java.util.List;
class CompanyUpdateBuilder {
/**
* Provide restrictions on the company data that can be sent via a user update
*/
static List<CompanyWithStringPlan> buildUserUpdateCompanies(CompanyCollection add, CompanyCollection remove) {
final List<CompanyWithStringPlan> updatableCompanies = Lists.newArrayList();
if (add != null) {
final List<Company> companies = add.getPage();
for (Company company : companies) {
if (!isCompanyInList(company, remove)) {
updatableCompanies.add(prepareUpdatableCompany(company));
}
}
}
if (remove != null) {
final List<Company> companies = remove.getPage();
for (Company company : companies) {
updatableCompanies.add(prepareUpdatableCompany(company).setRemove(Boolean.TRUE));
}
}
return updatableCompanies;
}
private static boolean isCompanyInList(final Company company, CompanyCollection companyCollection) {
if (companyCollection == null) {
return false;
}
return Iterables.any(companyCollection.getPage(), new Predicate<Company>() {
@Override
public boolean apply(Company e) {
return Objects.equal(company.getCompanyID(), e.getCompanyID())
|| Objects.equal(company.getId(), e.getId());
}
});
}
private static CompanyWithStringPlan prepareUpdatableCompany(Company company) {
final CompanyWithStringPlan updatableCompany = new CompanyWithStringPlan();
updatableCompany.setId(company.getId());
updatableCompany.setCompanyID(company.getCompanyID());
updatableCompany.setName(company.getName());
updatableCompany.setSessionCount(company.getSessionCount());
updatableCompany.setMonthlySpend(company.getMonthlySpend());
updatableCompany.setRemoteCreatedAt(company.getRemoteCreatedAt());
if (company.getCustomAttributes() != null) {
updatableCompany.getCustomAttributes().putAll(company.getCustomAttributes());
}
if (company.getPlan() != null) {
updatableCompany.setPlan(company.getPlan().getName());
}
return updatableCompany;
}
}
package performa.intercom.resources;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.collect.Maps;
import java.util.Map;
@SuppressWarnings("UnusedDeclaration")
@JsonInclude(JsonInclude.Include.NON_DEFAULT)
@JsonIgnoreProperties(ignoreUnknown = true)
class CompanyWithStringPlan extends TypedData {
@JsonProperty("id")
private String id;
@JsonProperty("name")
private String name;
@JsonProperty("company_id")
private String companyID;
@JsonProperty("session_count")
private int sessionCount;
@JsonProperty("monthly_spend")
private float monthlySpend;
@JsonProperty("remote_created_at")
private long remoteCreatedAt;
@JsonProperty("plan")
private String plan;
@JsonIgnoreProperties(ignoreUnknown = false)
@JsonProperty("custom_attributes")
private Map<String, CustomAttribute> customAttributes = Maps.newHashMap();
@JsonProperty("remove")
@JsonInclude(JsonInclude.Include.NON_NULL)
private Boolean remove;
public CompanyWithStringPlan() {
}
public String getType() {
return "company";
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCompanyID() {
return companyID;
}
public void setCompanyID(String companyID) {
this.companyID = companyID;
}
public Integer getSessionCount() {
return sessionCount;
}
public void setSessionCount(Integer sessionCount) {
this.sessionCount = sessionCount;
}
public float getMonthlySpend() {
return monthlySpend;
}
public void setMonthlySpend(float monthlySpend) {
this.monthlySpend = monthlySpend;
}
public long getRemoteCreatedAt() {
return remoteCreatedAt;
}
public void setRemoteCreatedAt(long remoteCreatedAt) {
this.remoteCreatedAt = remoteCreatedAt;
}
public String getPlan() {
return plan;
}
public void setPlan(String plan) {
this.plan = plan;
}
public Map<String, CustomAttribute> getCustomAttributes() {
return customAttributes;
}
public void setCustomAttributes(Map<String, CustomAttribute> customAttributes) {
this.customAttributes = customAttributes;
}
public Boolean getRemove() {
return remove;
}
public CompanyWithStringPlan setRemove(Boolean remove) {
this.remove = remove;
return this;
}
}
package performa.intercom.resources;
import com.google.common.collect.Lists;
class Conditions {
/**
* Ensures that an object reference passed as a parameter to the calling
* method is not null. Variant of Guava's Preconditions that returns an
* InvalidException containing an ErrorCollection
*
* @param reference an object reference
* @param errorMessage the exception message to use if the check fails
* @return the non-null reference that was validated
* @throws InvalidException if {@code reference} is null
*/
public static <T> T checkNotNull(T reference, String errorMessage) {
if (reference == null) {
throw new InvalidException(
new ErrorCollection(
Lists.newArrayList(
new Error("invalid", "item method must be supplied"))));
}
return reference;
}
}
package performa.intercom.resources;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.Iterator;
import java.util.List;
@SuppressWarnings("UnusedDeclaration")
@JsonIgnoreProperties(ignoreUnknown = true)
public class ContactCollection extends TypedDataCollection<Contact> implements Iterator<Contact> {
protected TypedDataCollectionIterator<Contact> iterator;
public ContactCollection() {
iterator = new TypedDataCollectionIterator<Contact>(this);
}
public ContactCollection(List<Contact> contacts) {
this();
this.page = contacts;
}
@SuppressWarnings("EmptyMethod")
@JsonProperty("contacts")
@Override
public List<Contact> getPage() {
return super.getPage();
}
@Override
public ContactCollection nextPage() {
return fetchNextPage(ContactCollection.class);
}
public boolean hasNext() {
return iterator.hasNext();
}
public Contact next() {
return iterator.next();
}
public void remove() {
iterator.remove();
}
}
package performa.intercom.resources;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
@SuppressWarnings("UnusedDeclaration")
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class ContactMessage extends TypedMessage<Contact, ContactMessage> {
public ContactMessage() {
}
@Override
public String toString() {
return "ContactMessage{} " + super.toString();
}
}
package performa.intercom.resources;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.Iterator;
import java.util.List;
@SuppressWarnings("UnusedDeclaration")
@JsonIgnoreProperties(ignoreUnknown = true)
public class ConversationCollection extends TypedDataCollection<Conversation> implements Iterator<Conversation> {
protected TypedDataCollectionIterator<Conversation> iterator;
public ConversationCollection() {
type = "conversation.list";
iterator = new TypedDataCollectionIterator<Conversation>(this);
}
@SuppressWarnings("EmptyMethod")
@JsonProperty("conversations")
public List<Conversation> getPage() {
return super.getPage();
}
@Override
public ConversationCollection nextPage() {
return fetchNextPage(ConversationCollection.class);
}
public boolean hasNext() {
return iterator.hasNext();
}
public Conversation next() {
return iterator.next();
}
public void remove() {
iterator.remove();
}
}
package performa.intercom.resources;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
@SuppressWarnings("UnusedDeclaration")
@JsonIgnoreProperties(ignoreUnknown = true)
public class ConversationMessage extends TypedData {
@SuppressWarnings("FieldCanBeLocal")
@JsonProperty("type")
private final String type = "conversation_message";
@JsonProperty
private String subject;
@JsonProperty
private String body;
@JsonProperty
private Author author;
public ConversationMessage() {
}
public String getType() {
return type;
}
public String getSubject() {
return subject;
}
public String getBody() {
return body;
}
public Author getAuthor() {
return author;
}
@Override
public int hashCode() {
int result = subject != null ? subject.hashCode() : 0;
result = 31 * result + (body != null ? body.hashCode() : 0);
result = 31 * result + (author != null ? author.hashCode() : 0);
return result;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ConversationMessage that = (ConversationMessage) o;
if (author != null ? !author.equals(that.author) : that.author != null) return false;
if (body != null ? !body.equals(that.body) : that.body != null) return false;
//noinspection RedundantIfStatement
if (subject != null ? !subject.equals(that.subject) : that.subject != null) return false;
return true;
}
@Override
public String toString() {
return "ConversationMessage{" +
"type='" + type + '\'' +
", subject='" + subject + '\'' +
", body='" + body + '\'' +
", author=" + author +
"} " + super.toString();
}
}
package performa.intercom.resources;
import performa.intercom.resources.Admin;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
@SuppressWarnings("UnusedDeclaration")
@JsonIgnoreProperties(ignoreUnknown = true)
public class ConversationPart extends TypedData {
@JsonProperty("type")
private final String type = "conversation_part";
@JsonProperty
private String id;
@JsonProperty("part_type")
private String partType;
@JsonProperty
private String body;
@JsonProperty
private Author author;
@JsonProperty("assigned_to")
private Admin assignedTo;
@JsonProperty("created_at")
private long createdAt;
@JsonProperty("updated_at")
private long updatedAt;
@JsonProperty("notified_at")
private long NotifiedAt;
public ConversationPart() {
}
public String getType() {
return type;
}
public String getId() {
return id;
}
public String getPartType() {
return partType;
}
public String getBody() {
return body;
}
public Author getAuthor() {
return author;
}
public Admin getAssignedTo() {
return assignedTo;
}
public long getCreatedAt() {
return createdAt;
}
public long getUpdatedAt() {
return updatedAt;
}
public long getNotifiedAt() {
return NotifiedAt;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ConversationPart that = (ConversationPart) o;
if (NotifiedAt != that.NotifiedAt) return false;
if (createdAt != that.createdAt) return false;
if (updatedAt != that.updatedAt) return false;
if (assignedTo != null ? !assignedTo.equals(that.assignedTo) : that.assignedTo != null) return false;
if (author != null ? !author.equals(that.author) : that.author != null) return false;
if (body != null ? !body.equals(that.body) : that.body != null) return false;
if (id != null ? !id.equals(that.id) : that.id != null) return false;
if (partType != null ? !partType.equals(that.partType) : that.partType != null) return false;
//noinspection RedundantIfStatement
if (!type.equals(that.type)) return false;
return true;
}
@Override
public int hashCode() {
int result = type.hashCode();
result = 31 * result + (id != null ? id.hashCode() : 0);
result = 31 * result + (partType != null ? partType.hashCode() : 0);
result = 31 * result + (body != null ? body.hashCode() : 0);
result = 31 * result + (author != null ? author.hashCode() : 0);
result = 31 * result + (assignedTo != null ? assignedTo.hashCode() : 0);
result = 31 * result + (int) (createdAt ^ (createdAt >>> 32));
result = 31 * result + (int) (updatedAt ^ (updatedAt >>> 32));
result = 31 * result + (int) (NotifiedAt ^ (NotifiedAt >>> 32));
return result;
}
@Override
public String toString() {
return "ConversationPart{" +
"type='" + type + '\'' +
", id='" + id + '\'' +
", partType='" + partType + '\'' +
", body='" + body + '\'' +
", author=" + author +
", assignedTo=" + assignedTo +
", createdAt=" + createdAt +
", updatedAt=" + updatedAt +
", NotifiedAt=" + NotifiedAt +
"} " + super.toString();
}
}
package performa.intercom.resources;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.List;
@SuppressWarnings("UnusedDeclaration")
@JsonIgnoreProperties(ignoreUnknown = true)
public class ConversationPartCollection extends TypedDataCollection<ConversationPart> {
public ConversationPartCollection() {
type = "conversation_part.list";
}
@SuppressWarnings("EmptyMethod")
@JsonProperty("conversation_parts")
public List<ConversationPart> getPage() {
return super.getPage();
}
@Override
public ConversationPartCollection nextPage() {
return new ConversationPartCollection();
}
}
package performa.intercom.resources;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.TreeNode;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import com.fasterxml.jackson.databind.node.ObjectNode;
import java.io.IOException;
import java.util.Map;
class CountItemDeserializer extends StdDeserializer<Counts.CountItem> {
private static final long serialVersionUID = 8226175715446656115L;
public CountItemDeserializer() {
super(Counts.CountItem.class);
}
@Override
public Counts.CountItem deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
final TreeNode treeNode = jp.getCodec().readTree(jp);
final Map.Entry<String, JsonNode> next = ((ObjectNode) treeNode).fields().next();
return new Counts.CountItem(next.getKey(), next.getValue().asLong());
}
}
package performa.intercom.resources;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import java.io.IOException;
class CountItemSerializer extends StdSerializer<Counts.CountItem> {
public CountItemSerializer() {
super(Counts.CountItem.class);
}
@Override
public void serialize(Counts.CountItem value, JsonGenerator jgen, SerializerProvider provider)
throws IOException {
jgen.writeStartObject();
jgen.writeNumberField(value.getName(), value.getValue());
jgen.writeEndObject();
}
}
package performa.intercom.resources;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.collect.Maps;
import java.net.URI;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@SuppressWarnings("UnusedDeclaration")
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class Counts {
static Counts countQuery(Map<String, String> query) {
final URI build = UriBuilder.newBuilder()
.path("counts")
.query(query)
.build();
final HttpClient resource = new HttpClient(build);
return resource.get(Counts.class);
}
public static Counts.Totals appTotals() throws InvalidException, AuthorizationException {
final HttpClient resource = new HttpClient(UriBuilder.newBuilder().path("counts").build());
return resource.get(Totals.class);
}
// public static Long userCount() throws InvalidException, AuthorizationException{
// final HashMap<String, String> params = Maps.newHashMap();
// params.put("type", "user");
// return countQuery(params).getUser().getUser();
// }
public static List<CountItem> userTags() throws InvalidException, AuthorizationException {
final HashMap<String, String> params = Maps.newHashMap();
params.put("type", "user");
params.put("count", "tag");
return countQuery(params).getUser().getTags();
}
public static List<CountItem> userSegments() throws InvalidException, AuthorizationException {
final HashMap<String, String> params = Maps.newHashMap();
params.put("type", "user");
params.put("count", "segment");
return countQuery(params).getUser().getSegments();
}
public static Counts.Conversation conversationTotals() throws InvalidException, AuthorizationException {
final HashMap<String, String> params = Maps.newHashMap();
params.put("type", "conversation");
return countQuery(params).getConversation();
}
public static Counts.Conversation conversationAdmins() throws InvalidException, AuthorizationException {
final HashMap<String, String> params = Maps.newHashMap();
params.put("type", "conversation");
params.put("count", "admin");
return countQuery(params).getConversation();
}
// public static Long companyCount() throws InvalidException, AuthorizationException{
// final HashMap<String, String> params = Maps.newHashMap();
// params.put("type", "company");
// return countQuery(params).getCompany().getCompanies();
// }
public static List<CountItem> companySegments() throws InvalidException, AuthorizationException {
final HashMap<String, String> params = Maps.newHashMap();
params.put("type", "company");
params.put("count", "segment");
return countQuery(params).getCompany().getSegments();
}
public static List<CountItem> companyTags() throws InvalidException, AuthorizationException {
final HashMap<String, String> params = Maps.newHashMap();
params.put("type", "company");
params.put("count", "tag");
return countQuery(params).getCompany().getTags();
}
public static List<CountItem> companyUsers() throws InvalidException, AuthorizationException {
final HashMap<String, String> params = Maps.newHashMap();
params.put("type", "company");
params.put("count", "user");
return countQuery(params).getCompany().getUsers();
}
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public static class Totals {
@JsonProperty("company")
private CountItem company;
@JsonProperty("segment")
private CountItem segment;
@JsonProperty("tag")
private CountItem tag;
@JsonProperty("user")
private CountItem user;
public CountItem getCompany() {
return company;
}
public CountItem getSegment() {
return segment;
}
public CountItem getTag() {
return tag;
}
public CountItem getUser() {
return user;
}
@Override
public String toString() {
return "Totals{" +
"company=" + company +
", segment=" + segment +
", tag=" + tag +
", user=" + user +
'}';
}
}
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public static class CountItem {
private String name;
private long value;
public CountItem(String name, long value) {
this.name = name;
this.value = value;
}
public String getName() {
return name;
}
public long getValue() {
return value;
}
@Override
public String toString() {
return "CountItem{" +
"name='" + name + '\'' +
", value=" + value +
'}';
}
}
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public static class Conversation {
@JsonProperty("admin")
List<Admin> admins;
@JsonProperty("assigned")
private long assigned;
@JsonProperty("closed")
private long closed;
@JsonProperty("open")
private long open;
@JsonProperty("unassigned")
private long unassigned;
Conversation() {
}
public List<Admin> getAdmins() {
return admins;
}
public long getAssigned() {
return assigned;
}
public long getClosed() {
return closed;
}
public long getOpen() {
return open;
}
public long getUnassigned() {
return unassigned;
}
@Override
public String toString() {
return "Conversation{" +
"assigned=" + assigned +
", closed=" + closed +
", open=" + open +
", unassigned=" + unassigned +
", admins=" + admins +
'}';
}
}
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public static class User {
@JsonProperty("user")
private long user;
@JsonProperty("tag")
private List<CountItem> tags;
@JsonProperty("segment")
private List<CountItem> segments;
User() {
}
public long getUser() {
return user;
}
public List<CountItem> getTags() {
return tags;
}
public List<CountItem> getSegments() {
return segments;
}
@Override
public String toString() {
return "User{" +
"user=" + user +
", tags=" + tags +
", segments=" + segments +
'}';
}
}
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public static class Company {
@JsonProperty("company")
private long companies;
@JsonProperty("tag")
private List<CountItem> tags;
@JsonProperty("user")
private List<CountItem> users;
@JsonProperty("segment")
private List<CountItem> segments;
Company() {
}
public long getCompanies() {
return companies;
}
public List<CountItem> getTags() {
return tags;
}
public List<CountItem> getUsers() {
return users;
}
public List<CountItem> getSegments() {
return segments;
}
@Override
public String toString() {
return "Company{" +
"companies=" + companies +
", tags=" + tags +
", users=" + users +
", segments=" + segments +
'}';
}
}
@JsonProperty("type")
private String type = "count";
@JsonProperty("company")
private Counts.Company company;
@JsonProperty("user")
private Counts.User user;
@JsonProperty("conversation")
private Counts.Conversation conversation;
public String getType() {
return type;
}
public Company getCompany() {
return company;
}
public User getUser() {
return user;
}
public Conversation getConversation() {
return conversation;
}
@Override
public String toString() {
return "Counts{" +
"type='" + type + '\'' +
", company=" + company +
", user=" + user +
", conversation=" + conversation +
'}';
}
}
package performa.intercom.resources;
import com.google.common.collect.Lists;
import java.io.Serializable;
import java.util.ArrayList;
@SuppressWarnings("UnusedDeclaration")
public class CustomAttribute<T> {
@SuppressWarnings("unchecked")
private static final ArrayList<? extends Class<? extends Serializable>> CLASSES = Lists.newArrayList(String.class, Long.class, Float.class, Double.class, Boolean.class, Integer.class);
public static StringAttribute newStringAttribute(String name, String value) {
return new StringAttribute(name, value);
}
public static BooleanAttribute newBooleanAttribute(String name, boolean value) {
return new BooleanAttribute(name, value);
}
public static DoubleAttribute newDoubleAttribute(String name, double value) {
return new DoubleAttribute(name, value);
}
public static LongAttribute newLongAttribute(String name, long value) {
return new LongAttribute(name, value);
}
public static IntegerAttribute newIntegerAttribute(String name, int value) {
return new IntegerAttribute(name, value);
}
public static FloatAttribute newFloatAttribute(String name, float value) {
return new FloatAttribute(name, value);
}
public static class StringAttribute extends CustomAttribute<String> {
private StringAttribute(String name, String value) {
super(name, value, String.class);
}
private StringAttribute(String name, String value, Class<String> clazz) {
super(name, value, clazz);
}
}
public static class BooleanAttribute extends CustomAttribute<Boolean> {
private BooleanAttribute(String name, boolean value) {
super(name, value, Boolean.class);
}
private BooleanAttribute(String name, boolean value, Class<Boolean> clazz) {
super(name, value, clazz);
}
}
public static class DoubleAttribute extends CustomAttribute<Double> {
private DoubleAttribute(String name, double value, Class<Double> clazz) {
super(name, value, clazz);
}
private DoubleAttribute(String name, double value) {
super(name, value, Double.class);
}
}
public static class FloatAttribute extends CustomAttribute<Float> {
private FloatAttribute(String name, float value, Class<Float> clazz) {
super(name, value, clazz);
}
private FloatAttribute(String name, float value) {
super(name, value, Float.class);
}
}
public static class IntegerAttribute extends CustomAttribute<Integer> {
private IntegerAttribute(String name, int value) {
super(name, value, Integer.class);
}
private IntegerAttribute(String name, int value, Class<Integer> clazz) {
super(name, value, clazz);
}
}
public static class LongAttribute extends CustomAttribute<Long> {
public LongAttribute(String name, long value, Class<Long> clazz) {
super(name, value, clazz);
}
public LongAttribute(String name, long value) {
super(name, value, Long.class);
}
}
private String name;
private T value;
private Class<T> clazz;
public CustomAttribute(String name, T value, Class<T> clazz) {
//noinspection SuspiciousMethodCalls
if (!CLASSES.contains(clazz)) {
throw new InvalidException(String.format("cannot accept class type [%s] for custom attribute", clazz.getName()));
}
this.name = name;
this.value = value;
this.clazz = clazz;
}
public Class<T> getValueClass() {
return clazz;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public T getValue() {
return value;
}
public void setValue(T value) {
this.value = value;
}
public <C> C as(Class<C> c) {
//noinspection unchecked
return (C) getValue();
}
public long longValue() {
return as(Long.class);
}
public String textValue() {
return as(String.class);
}
public boolean booleanValue() {
return as(Boolean.class);
}
public float floatValue() {
return as(Float.class);
}
public double doubleValue() {
return as(Double.class);
}
public int integerValue() {
return as(Integer.class);
}
@Override
public int hashCode() {
int result = name != null ? name.hashCode() : 0;
result = 31 * result + (value != null ? value.hashCode() : 0);
result = 31 * result + (clazz != null ? clazz.hashCode() : 0);
return result;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
CustomAttribute that = (CustomAttribute) o;
if (clazz != null ? !clazz.equals(that.clazz) : that.clazz != null) return false;
if (name != null ? !name.equals(that.name) : that.name != null) return false;
//noinspection RedundantIfStatement
if (value != null ? !value.equals(that.value) : that.value != null) return false;
return true;
}
@Override
public String toString() {
return "CustomAttribute{" +
"name='" + name + '\'' +
", value=" + value +
", clazz=" + clazz +
'}';
}
}
package performa.intercom.resources;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import com.fasterxml.jackson.databind.node.JsonNodeType;
import com.fasterxml.jackson.databind.node.NumericNode;
import com.fasterxml.jackson.databind.node.ValueNode;
import java.io.IOException;
class CustomAttributeDeserializer extends StdDeserializer<CustomAttribute> {
private static final long serialVersionUID = 5069924730975394938L;
public CustomAttributeDeserializer() {
super(CustomAttribute.class);
}
@Override
public CustomAttribute deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
CustomAttribute cda = null;
final String currentName = jp.getParsingContext().getCurrentName();
final ObjectMapper mapper = (ObjectMapper) jp.getCodec();
final ValueNode vNode = mapper.readTree(jp);
if (vNode.asToken().isScalarValue()) {
if (vNode.getNodeType() == JsonNodeType.BOOLEAN) {
cda = new CustomAttribute<Boolean>(currentName, vNode.asBoolean(), Boolean.class);
} else if (vNode.getNodeType() == JsonNodeType.STRING) {
cda = new CustomAttribute<String>(currentName, vNode.asText(), String.class);
} else if (vNode.getNodeType() == JsonNodeType.NUMBER) {
final NumericNode nNode = (NumericNode) vNode;
if (currentName.endsWith("_at")) {
cda = new CustomAttribute<Long>(currentName, vNode.longValue(), Long.class);
} else if (nNode.isInt()) {
cda = new CustomAttribute<Integer>(currentName, vNode.intValue(), Integer.class);
} else if (nNode.isFloat()) {
cda = new CustomAttribute<Float>(currentName, vNode.floatValue(), Float.class);
} else if (nNode.isDouble()) {
cda = new CustomAttribute<Double>(currentName, vNode.doubleValue(), Double.class);
} else if (nNode.isLong()) {
cda = new CustomAttribute<Long>(currentName, vNode.longValue(), Long.class);
} else {
cda = new CustomAttribute<String>(currentName, vNode.asText(), String.class);
}
} else {
cda = new CustomAttribute<String>(currentName, vNode.asText(), String.class);
}
}
return cda;
}
}
package performa.intercom.resources;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import java.io.IOException;
class CustomAttributeSerializer extends StdSerializer<CustomAttribute> {
public CustomAttributeSerializer() {
super(CustomAttribute.class);
}
@Override
public void serialize(CustomAttribute value, JsonGenerator jgen, SerializerProvider provider)
throws IOException {
// the field name has already been written
jgen.writeObject(value.getValue());
}
}
package performa.intercom.resources;
import com.google.common.base.Strings;
import com.google.common.collect.Maps;
import java.net.URI;
import java.util.List;
import java.util.Map;
abstract class DataResource {
@SuppressWarnings("SameParameterValue")
public static <T> T find(String id, String collectionPath, Class<T> c) {
final HttpClient resource = new HttpClient(UriBuilder.newBuilder().path(collectionPath).path(id).build());
return resource.get(c);
}
public static <T> T find(Map<String, String> params, String collectionPath, Class<T> c) {
final HttpClient resource = new HttpClient(UriBuilder.newBuilder().path(collectionPath).query(params).build());
return resource.get(c);
}
public static <T, R> R create(T entity, String collectionPath, Class<R> response) {
final HttpClient resource = new HttpClient(UriBuilder.newBuilder().path(collectionPath).build());
return resource.post(response, entity);
}
public static <T, R> R create(T entity, List<String> paths, Class<R> response) {
final HttpClient resource = new HttpClient(UriBuilder.newBuilder().path(paths).build());
return resource.post(response, entity);
}
public static <T, R> R update(T entity, String collectionPath, Class<R> response) {
final HttpClient resource = new HttpClient(UriBuilder.newBuilder().path(collectionPath).build());
return resource.post(response, entity);
}
public static <T, R> R post(T entity, URI path, Class<R> response) {
final HttpClient resource = new HttpClient(path);
return resource.post(response, entity);
}
public static <T, R> R updatePut(T entity, URI collectionPath, Class<R> response) {
final HttpClient resource = new HttpClient(collectionPath);
return resource.put(response, entity);
}
@SuppressWarnings("SameParameterValue")
public static <T, R> R update(T entity, String collectionPath, String id, Class<R> response) {
final HttpClient resource = new HttpClient(UriBuilder.newBuilder().path(collectionPath).path(id).build());
return resource.post(response, entity);
}
public static <T> T delete(String id, String collectionPath, Class<T> c) {
final HttpClient resource = new HttpClient(UriBuilder.newBuilder().path(collectionPath).path(id).build());
return resource.delete(c);
}
public static <C> C list(Map<String, String> params, String collectionPath, Class<C> c) {
final HttpClient resource = new HttpClient(UriBuilder.newBuilder().path(collectionPath).query(params).build());
return resource.get(c);
}
public static <C> C scroll(String scrollParam, String collectionPath, Class<C> c) {
Map<String, String> params = Maps.newHashMap();
if (!Strings.isNullOrEmpty(scrollParam)) {
params.put("scroll_param", scrollParam);
}
final HttpClient resource = new HttpClient(UriBuilder.newBuilder().path(collectionPath + "/scroll").query(params).build());
return resource.get(c);
}
}
package performa.intercom.resources;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
@SuppressWarnings("UnusedDeclaration")
@JsonIgnoreProperties(ignoreUnknown = true)
public class Error extends TypedData {
@SuppressWarnings("FieldCanBeLocal")
@JsonProperty("type")
private final String type = "error";
@JsonProperty("code")
private String code;
@JsonProperty("message")
private String message;
public Error() {
}
public Error(String code, String message) {
this.code = code;
this.message = message;
}
public String getType() {
return type;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
@Override
public int hashCode() {
int result = code != null ? code.hashCode() : 0;
result = 31 * result + (message != null ? message.hashCode() : 0);
return result;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Error error = (Error) o;
if (code != null ? !code.equals(error.code) : error.code != null) return false;
//noinspection RedundantIfStatement
if (message != null ? !message.equals(error.message) : error.message != null) return false;
return true;
}
@Override
public String toString() {
return getType() + "{" +
"code='" + code + '\'' +
", message='" + message + '\'' +
"} " + super.toString();
}
}
package performa.intercom.resources;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.Preconditions;
import java.util.List;
@SuppressWarnings("UnusedDeclaration")
@JsonIgnoreProperties(ignoreUnknown = true)
public final class ErrorCollection {
@JsonProperty("errors")
private List<Error> errors;
// for jackson
ErrorCollection() {
}
public ErrorCollection(List<Error> errors) {
Preconditions.checkNotNull(errors, "cannot create an error collection with a null error list");
Preconditions.checkArgument(errors.size() > 0, "cannot create an error collection with an empty error list");
this.errors = errors;
}
public List<Error> getErrors() {
return errors;
}
public String getType() {
return "error.list";
}
}
package performa.intercom.resources;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@SuppressWarnings("UnusedDeclaration")
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_DEFAULT)
public class Event extends TypedData {
private static final List<String> BULK_METHODS = Lists.newArrayList("post");
private static final ArrayList<String> BULK_PATHS = Lists.newArrayListWithExpectedSize(2);
static {
BULK_PATHS.add("bulk");
BULK_PATHS.add("events");
}
public static void create(Event event) throws InvalidException, AuthorizationException {
validateCreateEvent(event);
if (event.getCreatedAt() == 0L) {
event.setCreatedAt(System.currentTimeMillis() / 1000);
}
DataResource.create(event, "events", Void.class);
}
public static Job submit(List<JobItem<Event>> items)
throws AuthorizationException, ClientException, ServerException, InvalidException, RateLimitException {
return submit(items, null);
}
public static Job submit(List<JobItem<Event>> items, Job job)
throws AuthorizationException, ClientException, ServerException, InvalidException, RateLimitException {
return Job.submit(validateJobItems(items), job, BULK_PATHS);
}
public static JobItemCollection<Event> listJobErrorFeed(String jobID)
throws AuthorizationException, ClientException, ServerException, InvalidException, RateLimitException {
return Job.listJobErrorFeed(jobID, Event.class);
}
@VisibleForTesting
static List<JobItem<Event>> validateJobItems(List<JobItem<Event>> items) {
final JobSupport jobSupport = new JobSupport();
for (JobItem<Event> item : items) {
jobSupport.validateJobItem(item, BULK_METHODS);
validateCreateEvent(item.getData());
}
return items;
}
private static final ErrorCollection INVALID_NAME = new ErrorCollection(
Lists.newArrayList(
new Error("invalid", "an event must supply an event name")));
private static final ErrorCollection INVALID_USER = new ErrorCollection(
Lists.newArrayList(
new Error("invalid", "an event must supply either an email or a user id")));
@VisibleForTesting
static void validateCreateEvent(Event event) {
if (Strings.isNullOrEmpty(event.getEventName())) {
throw new InvalidException(INVALID_NAME);
}
if (Strings.isNullOrEmpty(event.getUserID())
&& Strings.isNullOrEmpty(event.getEmail())) {
throw new InvalidException(INVALID_USER);
}
}
@SuppressWarnings("FieldCanBeLocal")
@JsonProperty("type")
private final String type = "event";
@JsonProperty("event_name")
private String eventName;
@JsonProperty("created_at")
private long createdAt;
@JsonProperty("email")
private String email;
@JsonProperty("user_id")
private String userID;
@JsonProperty("metadata")
private Map<String, Object> metadata = Maps.newHashMap();
public Event() {
}
public String getType() {
return type;
}
public String getEventName() {
return eventName;
}
public Event setEventName(String eventName) {
this.eventName = eventName;
return this;
}
public long getCreatedAt() {
return createdAt;
}
@SuppressWarnings("UnusedReturnValue")
public Event setCreatedAt(long createdAt) {
this.createdAt = createdAt;
return this;
}
public String getEmail() {
return email;
}
public Event setEmail(String email) {
this.email = email;
return this;
}
public String getUserID() {
return userID;
}
public Event setUserID(String userID) {
this.userID = userID;
return this;
}
public Event putMetadata(String name, String value) {
metadata.put(name, value);
return this;
}
public Event putMetadata(String name, boolean value) {
metadata.put(name, value);
return this;
}
public Event putMetadata(String name, int value) {
metadata.put(name, value);
return this;
}
public Event putMetadata(String name, double value) {
metadata.put(name, value);
return this;
}
public Event putMetadata(String name, long value) {
metadata.put(name, value);
return this;
}
public Event putMetadata(String name, float value) {
metadata.put(name, value);
return this;
}
public Map<String, Object> getMetadata() {
return metadata;
}
public Event setMetadata(Map<String, Object> metadata) {
this.metadata = metadata;
return this;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Event event = (Event) o;
if (createdAt != event.createdAt) return false;
if (email != null ? !email.equals(event.email) : event.email != null) return false;
if (eventName != null ? !eventName.equals(event.eventName) : event.eventName != null) return false;
if (metadata != null ? !metadata.equals(event.metadata) : event.metadata != null) return false;
if (!type.equals(event.type)) return false;
//noinspection RedundantIfStatement
if (userID != null ? !userID.equals(event.userID) : event.userID != null) return false;
return true;
}
@Override
public int hashCode() {
int result = type.hashCode();
result = 31 * result + (eventName != null ? eventName.hashCode() : 0);
result = 31 * result + (int) (createdAt ^ (createdAt >>> 32));
result = 31 * result + (email != null ? email.hashCode() : 0);
result = 31 * result + (userID != null ? userID.hashCode() : 0);
result = 31 * result + (metadata != null ? metadata.hashCode() : 0);
return result;
}
@Override
public String toString() {
return "Event{" +
"type='" + type + '\'' +
", eventName='" + eventName + '\'' +
", createdAt=" + createdAt +
", email='" + email + '\'' +
", userID='" + userID + '\'' +
", metadata=" + metadata +
"} " + super.toString();
}
}
package performa.intercom.resources;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URI;
public interface HttpConnectorSupplier {
HttpURLConnection connect(URI uri) throws IOException;
HttpConnectorSupplier defaultSupplier = new HttpConnectorSupplier() {
public HttpURLConnection connect(URI uri) throws IOException {
return (HttpURLConnection) uri.toURL().openConnection();
}
};
}
package performa.intercom.resources;
import org.slf4j.LoggerFactory;
import java.io.Closeable;
import java.net.HttpURLConnection;
class IOUtils {
private static final org.slf4j.Logger logger = LoggerFactory.getLogger("intercom-java");
/**
* Close a HttpURLConnection, ignores checked Exceptions and nulls,
* but rethrows RuntimeExceptions.
*
* @param connection the connection to disconnect
*/
public static void disconnectQuietly(HttpURLConnection connection) {
if (connection != null) {
try {
connection.disconnect();
} catch (RuntimeException rethrow) {
throw rethrow;
} catch (Exception e) {
logger.warn(e.getMessage());
}
}
}
/**
* Close a stream, ignores checked Exceptions and nulls,
* but rethrows RuntimeExceptions.
*
* @param stream the object to close
*/
public static void closeQuietly(Closeable stream) {
if (stream != null) {
try {
stream.close();
} catch (RuntimeException rethrow) {
throw rethrow;
} catch (Exception e) {
logger.warn(e.getMessage());
}
}
}
}
package performa.intercom.resources;
import java.net.URI;
public class Intercom {
private static final URI API_BASE_URI = URI.create("https://api.intercom.io/");
private static volatile URI apiBaseURI = API_BASE_URI;
private static volatile AuthKeyType authKeyType = AuthKeyType.API_KEY;
enum AuthKeyType {
API_KEY,
TOKEN
}
private static final String VERSION = "2.2.7";
public static final String USER_AGENT = "intercom-java/" + Intercom.VERSION;
private static volatile String apiKey;
private static volatile String token;
private static volatile String appID;
private static volatile int connectionTimeout = 3 * 1000;
private static volatile int requestTimeout = 60 * 1000;
private static volatile boolean requestUsingCaches = false;
private static volatile HttpConnectorSupplier httpConnectorSupplier = HttpConnectorSupplier.defaultSupplier;
public static long currentTimestamp() {
return System.currentTimeMillis()/1000;
}
public static int getConnectionTimeout() {
return connectionTimeout;
}
@SuppressWarnings("UnusedDeclaration")
public static void setConnectionTimeout(int connectionTimeout) {
Intercom.connectionTimeout = connectionTimeout;
}
public static int getRequestTimeout() {
return requestTimeout;
}
@SuppressWarnings("UnusedDeclaration")
public static void setRequestTimeout(int requestTimeout) {
Intercom.requestTimeout = requestTimeout;
}
public static boolean isRequestUsingCaches() {
return requestUsingCaches;
}
public static void setRequestUsingCaches(boolean requestUsingCaches) {
Intercom.requestUsingCaches = requestUsingCaches;
}
public static HttpConnectorSupplier getHttpConnectorSupplier() {
return httpConnectorSupplier;
}
public static void setHttpConnectorSupplier(HttpConnectorSupplier supplier) {
Intercom.httpConnectorSupplier = supplier;
}
public static String getAppID() {
return appID;
}
public static void setAppID(String appID) {
Intercom.appID = appID;
}
public static void setToken(String token) {
authKeyType = AuthKeyType.TOKEN;
Intercom.token = token;
}
public static String getApiKey() {
return Intercom.apiKey;
}
public static void setApiKey(String apiKey) {
authKeyType = AuthKeyType.API_KEY;
Intercom.apiKey = apiKey;
}
public static URI getApiBaseURI() {
return Intercom.apiBaseURI;
}
public static void setApiBaseURI(URI apiBaseURI) {
Intercom.apiBaseURI = apiBaseURI;
}
static AuthKeyType getAuthKeyType() {
return authKeyType;
}
public static String getToken() {
return token;
}
}
package performa.intercom.resources;
public class IntercomException extends RuntimeException {
private static final long serialVersionUID = -2723350106062183796L;
private ErrorCollection errorCollection;
@SuppressWarnings("WeakerAccess")
public IntercomException(String message) {
super(message);
}
public IntercomException(String message, Throwable cause) {
super(message, cause);
}
public IntercomException(ErrorCollection errorCollection) {
this(getMessage(errorCollection));
this.errorCollection = errorCollection;
}
public static String getMessage(ErrorCollection errorCollection) {
String message = "Could not read error message from server";
if(errorCollection!=null
&& errorCollection.getErrors() != null
&& errorCollection.getErrors().size() > 0
&& errorCollection.getErrors().get(0) != null
&& errorCollection.getErrors().get(0).getMessage() != null){
message = errorCollection.getErrors().get(0).getMessage();
}
return message;
}
@SuppressWarnings("WeakerAccess")
public IntercomException(ErrorCollection errorCollection, Throwable cause) {
this(getMessage(errorCollection), cause);
this.errorCollection = errorCollection;
}
public ErrorCollection getErrorCollection() {
return errorCollection;
}
public Error getFirstError() {
return errorCollection.getErrors().get(0);
}
}
package performa.intercom.resources;
public class InvalidException extends IntercomException {
private static final long serialVersionUID = -2111295679006526646L;
public InvalidException(String message) {
super(message);
}
public InvalidException(String message, Throwable cause) {
super(message, cause);
}
public InvalidException(ErrorCollection errorCollection) {
super(errorCollection);
}
public InvalidException(ErrorCollection errorCollection, Throwable cause) {
super(errorCollection, cause);
}
}
package performa.intercom.resources;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JavaType;
import com.google.common.collect.Maps;
import java.net.URI;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@SuppressWarnings("UnusedDeclaration")
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_DEFAULT)
public class Job extends TypedData {
private static final HashMap<String, String> SENTINEL = Maps.newHashMap();
public static Job find(String id)
throws AuthorizationException, ClientException, ServerException, InvalidException, RateLimitException {
return find(id, SENTINEL);
}
public static Job find(String id, Map<String, String> params)
throws AuthorizationException, ClientException, ServerException, InvalidException, RateLimitException {
return new HttpClient(
UriBuilder.newBuilder().path("jobs").path(id).query(params).build()
).get(Job.class);
}
public static Job update(Job job)
throws AuthorizationException, ClientException, ServerException, InvalidException, RateLimitException {
return DataResource.post(
job,
UriBuilder.newBuilder().path("jobs").path(job.getID()).build(),
Job.class);
}
static <T extends TypedData> Job submit(List<JobItem<T>> items, List<String> bulkPaths)
throws AuthorizationException, ClientException, ServerException, InvalidException, RateLimitException {
return submit(items, null, bulkPaths);
}
static <T extends TypedData> Job submit(List<JobItem<T>> items, Job job, List<String> bulkPaths)
throws AuthorizationException, ClientException, ServerException, InvalidException, RateLimitException {
return DataResource.create(new JobItemRequest<T>(items, job), bulkPaths, Job.class);
}
static <T extends TypedData> JobItemCollection<T> listJobErrorFeed(String jobID, Class<T> c)
throws AuthorizationException, ClientException, ServerException, InvalidException, RateLimitException {
final URI feedURI = UriBuilder.newBuilder()
.path("jobs")
.path(jobID)
.path("error")
.build();
final HttpClient resource = new HttpClient(feedURI);
final TypeReference<JobItemCollection<T>> typeReference =
new TypeReference<JobItemCollection<T>>() {
};
final JavaType type = MapperSupport
.objectMapper()
.getTypeFactory()
.constructParametricType(JobItemCollection.class, c);
return resource.get(type);
}
@JsonProperty("type")
private final String type = "job";
@JsonProperty("id")
private String id;
@JsonProperty("app_id")
private String appID;
@JsonProperty("created_at")
private long createdAt;
@JsonProperty("updated_at")
private long updatedAt;
@JsonProperty("completed_at")
private long completedAt;
@JsonProperty("closing_at")
private long closingAt;
@JsonProperty("name")
private String name;
@JsonProperty("state")
private String state;
@JsonProperty("tasks")
private List<JobTask> tasks;
@JsonProperty("links")
private Map<String, URI> links;
public Job() {
}
public String getType() {
return type;
}
public String getID() {
return id;
}
public Job setID(String id) {
this.id = id;
return this;
}
public long getCreatedAt() {
return createdAt;
}
public long getUpdatedAt() {
return updatedAt;
}
public long getCompletedAt() {
return completedAt;
}
public String getName() {
return name;
}
public Job setName(String name) {
this.name = name;
return this;
}
public String getState() {
return state;
}
public String getAppID() {
return appID;
}
public Map<String, URI> getLinks() {
return links;
}
public long getClosingAt() {
return closingAt;
}
public Job setClosingAt(long closingAt) {
this.closingAt = closingAt;
return this;
}
public List<JobTask> getTasks() {
return tasks;
}
@Override
public String toString() {
return "Job{" +
"type='" + type + '\'' +
", id='" + id + '\'' +
", appID='" + appID + '\'' +
", createdAt=" + createdAt +
", updatedAt=" + updatedAt +
", completedAt=" + completedAt +
", name='" + name + '\'' +
", state='" + state + '\'' +
", links=" + links +
"} " + super.toString();
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Job job = (Job) o;
if (createdAt != job.createdAt) return false;
if (updatedAt != job.updatedAt) return false;
if (completedAt != job.completedAt) return false;
//noinspection ConstantConditions
if (type != null ? !type.equals(job.type) : job.type != null) return false;
if (id != null ? !id.equals(job.id) : job.id != null) return false;
if (appID != null ? !appID.equals(job.appID) : job.appID != null) return false;
if (name != null ? !name.equals(job.name) : job.name != null) return false;
//noinspection SimplifiableIfStatement
if (state != null ? !state.equals(job.state) : job.state != null) return false;
return !(links != null ? !links.equals(job.links) : job.links != null);
}
@Override
public int hashCode() {
@SuppressWarnings("ConstantConditions") int result = type != null ? type.hashCode() : 0;
result = 31 * result + (id != null ? id.hashCode() : 0);
result = 31 * result + (appID != null ? appID.hashCode() : 0);
result = 31 * result + (int) (createdAt ^ (createdAt >>> 32));
result = 31 * result + (int) (updatedAt ^ (updatedAt >>> 32));
result = 31 * result + (int) (completedAt ^ (completedAt >>> 32));
result = 31 * result + (name != null ? name.hashCode() : 0);
result = 31 * result + (state != null ? state.hashCode() : 0);
result = 31 * result + (links != null ? links.hashCode() : 0);
return result;
}
}
package performa.intercom.resources;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
@SuppressWarnings("UnusedDeclaration")
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_DEFAULT)
public class JobItem<T extends TypedData> extends TypedData {
@JsonProperty("type")
private final String type = "job_item";
@JsonProperty("id")
private String id;
@JsonProperty("updated_at")
private long updatedAt;
@JsonProperty("method")
private String method;
@JsonProperty("data_type")
private String dataType;
@JsonProperty("error")
private Error error;
@JsonProperty("data")
private T data;
public JobItem() {
}
public JobItem(String method, T data) {
this(method, data, null);
}
JobItem(String method, T data, String dataType) {
Conditions.checkNotNull(method, "item method must be supplied");
Conditions.checkNotNull(data, "item data must be supplied");
this.method = method;
this.data = data;
this.dataType = dataType;
if (dataType == null) {
this.dataType = data.getType();
}
Conditions.checkNotNull(data, "item dataType must be supplied");
}
public String getType() {
return type;
}
public String getID() {
return id;
}
public long getUpdatedAt() {
return updatedAt;
}
public String getMethod() {
return method;
}
public JobItem<T> setMethod(String method) {
this.method = method;
return this;
}
public Error getError() {
return error;
}
public T getData() {
return data;
}
public JobItem<T> setData(T data) {
this.data = data;
return this;
}
public String getDataType() {
return dataType;
}
@Override
public String toString() {
return "JobItem{" +
"type='" + type + '\'' +
", id='" + id + '\'' +
", updatedAt=" + updatedAt +
", method='" + method + '\'' +
", dataType='" + dataType + '\'' +
", error=" + error +
", data=" + data +
"} " + super.toString();
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
JobItem<?> jobItem = (JobItem<?>) o;
if (updatedAt != jobItem.updatedAt) return false;
//noinspection ConstantConditions
if (type != null ? !type.equals(jobItem.type) : jobItem.type != null) return false;
if (id != null ? !id.equals(jobItem.id) : jobItem.id != null) return false;
if (method != null ? !method.equals(jobItem.method) : jobItem.method != null) return false;
if (dataType != null ? !dataType.equals(jobItem.dataType) : jobItem.dataType != null) return false;
//noinspection SimplifiableIfStatement
if (error != null ? !error.equals(jobItem.error) : jobItem.error != null) return false;
return !(data != null ? !data.equals(jobItem.data) : jobItem.data != null);
}
@Override
public int hashCode() {
@SuppressWarnings("ConstantConditions") int result = type != null ? type.hashCode() : 0;
result = 31 * result + (id != null ? id.hashCode() : 0);
result = 31 * result + (int) (updatedAt ^ (updatedAt >>> 32));
result = 31 * result + (method != null ? method.hashCode() : 0);
result = 31 * result + (dataType != null ? dataType.hashCode() : 0);
result = 31 * result + (error != null ? error.hashCode() : 0);
result = 31 * result + (data != null ? data.hashCode() : 0);
return result;
}
}
package performa.intercom.resources;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.Iterator;
import java.util.List;
@SuppressWarnings("UnusedDeclaration")
@JsonIgnoreProperties(ignoreUnknown = true)
public class JobItemCollection<T extends TypedData>
extends TypedDataCollection<JobItem<T>>
implements Iterator<JobItem<T>> {
protected TypedDataCollectionIterator<JobItem<T>> iterator;
public JobItemCollection() {
iterator = new TypedDataCollectionIterator<JobItem<T>>(this);
}
public JobItemCollection(List<JobItem<T>> items) {
this();
this.page = items;
}
@SuppressWarnings("EmptyMethod")
@JsonProperty("items")
@Override
public List<JobItem<T>> getPage() {
return super.getPage();
}
@Override
public JobItemCollection<T> nextPage() {
return fetchNextPage(JobItemCollection.class);
}
public boolean hasNext() {
return iterator.hasNext();
}
public JobItem<T> next() {
return iterator.next();
}
public void remove() {
iterator.remove();
}
}
package performa.intercom.resources;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.List;
@SuppressWarnings("UnusedDeclaration")
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_EMPTY)
class JobItemRequest<T extends TypedData> extends TypedData {
@JsonProperty("items")
private List<JobItem<T>> items;
@JsonProperty("job")
@JsonInclude(JsonInclude.Include.NON_NULL)
private Job job;
public JobItemRequest(List<JobItem<T>> items, Job job) {
this.items = items;
this.job = job;
}
public List<JobItem<T>> getItems() {
return items;
}
public Job getJob() {
return job;
}
@Override
String getType() {
return "job_item.list";
}
}
package performa.intercom.resources;
import com.google.common.base.Joiner;
import com.google.common.collect.Lists;
import java.util.List;
class JobSupport {
public void validateJobItem(JobItem item, List<String> methods) {
if (!methods.contains(item.getMethod())) {
final String message = String.format(
"job method [%s] not allowed, must be one of "
+ Joiner.on(", ").join(methods), item.getMethod()
);
throw new InvalidException(
new ErrorCollection(
Lists.newArrayList(
new Error("invalid", message))));
}
}
}
package performa.intercom.resources;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
@SuppressWarnings("UnusedDeclaration")
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_DEFAULT)
public class JobTask extends TypedData {
@JsonProperty("type")
private final String type = "job_task";
@JsonProperty("id")
private String id;
@JsonProperty("completed_at")
private Long completedAt;
@JsonProperty("created_at")
private long createdAt;
@JsonProperty("item_count")
private long itemCount;
@Override
public String getType() {
return type;
}
public String getID() {
return id;
}
public Long getCompletedAt() {
return completedAt;
}
public long getCreatedAt() {
return createdAt;
}
public long getItemCount() {
return itemCount;
}
}
package performa.intercom.resources;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
@SuppressWarnings("UnusedDeclaration")
@JsonIgnoreProperties(ignoreUnknown = true)
public class LocationData extends TypedData {
@JsonProperty("type")
private final String type = "location_data";
@JsonProperty("city_name")
private String city_Name;
@JsonProperty("continent_code")
private String continentCode;
@JsonProperty("country_code")
private String countryCode;
@JsonProperty("country_name")
private String countryName;
@JsonProperty("latitude")
private float latitude;
@JsonProperty("longitude")
private float longitude;
@JsonProperty("postal_code")
private String postalCode;
@JsonProperty("region_name")
private String regionName;
@JsonProperty("timezone")
private String timezone;
public LocationData() {
}
public String getType() {
return type;
}
public String getCity_Name() {
return city_Name;
}
public String getContinentCode() {
return continentCode;
}
public String getCountryCode() {
return countryCode;
}
public String getCountryName() {
return countryName;
}
public float getLatitude() {
return latitude;
}
public float getLongitude() {
return longitude;
}
public String getPostalCode() {
return postalCode;
}
public String getRegionName() {
return regionName;
}
public String getTimezone() {
return timezone;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
LocationData that = (LocationData) o;
if (Float.compare(that.latitude, latitude) != 0) return false;
if (Float.compare(that.longitude, longitude) != 0) return false;
if (city_Name != null ? !city_Name.equals(that.city_Name) : that.city_Name != null) return false;
if (continentCode != null ? !continentCode.equals(that.continentCode) : that.continentCode != null)
return false;
if (countryCode != null ? !countryCode.equals(that.countryCode) : that.countryCode != null) return false;
if (countryName != null ? !countryName.equals(that.countryName) : that.countryName != null) return false;
if (postalCode != null ? !postalCode.equals(that.postalCode) : that.postalCode != null) return false;
if (regionName != null ? !regionName.equals(that.regionName) : that.regionName != null) return false;
if (timezone != null ? !timezone.equals(that.timezone) : that.timezone != null) return false;
//noinspection RedundantIfStatement
if (!type.equals(that.type)) return false;
return true;
}
@Override
public int hashCode() {
int result = type.hashCode();
result = 31 * result + (city_Name != null ? city_Name.hashCode() : 0);
result = 31 * result + (continentCode != null ? continentCode.hashCode() : 0);
result = 31 * result + (countryCode != null ? countryCode.hashCode() : 0);
result = 31 * result + (countryName != null ? countryName.hashCode() : 0);
result = 31 * result + (latitude != +0.0f ? Float.floatToIntBits(latitude) : 0);
result = 31 * result + (longitude != +0.0f ? Float.floatToIntBits(longitude) : 0);
result = 31 * result + (postalCode != null ? postalCode.hashCode() : 0);
result = 31 * result + (regionName != null ? regionName.hashCode() : 0);
result = 31 * result + (timezone != null ? timezone.hashCode() : 0);
return result;
}
@Override
public String toString() {
return "LocationData{" +
"type='" + type + '\'' +
", city_Name='" + city_Name + '\'' +
", continentCode='" + continentCode + '\'' +
", countryCode='" + countryCode + '\'' +
", countryName='" + countryName + '\'' +
", latitude=" + latitude +
", longitude=" + longitude +
", postalCode='" + postalCode + '\'' +
", regionName='" + regionName + '\'' +
", timezone='" + timezone + '\'' +
"} " + super.toString();
}
}
package performa.intercom.resources;
import com.fasterxml.jackson.core.Version;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.module.SimpleModule;
public class MapperSupport {
public static ObjectMapper objectMapper() {
return Holder.INSTANCE;
}
private static class Holder {
private static final ObjectMapper INSTANCE = new Holder().configure(new ObjectMapper());
private ObjectMapper configure(ObjectMapper om) {
return om.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, true)
.configure(SerializationFeature.INDENT_OUTPUT, true)
.configure(SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS, false)
.configure(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS, false)
.registerModule(customAttributeModule());
}
private SimpleModule customAttributeModule() {
final SimpleModule customAttributeModule = new SimpleModule(
"IntercomClientModule",
new Version(1, 0, 0, null, "", "")
);
customAttributeModule.addDeserializer(CustomAttribute.class, new CustomAttributeDeserializer());
customAttributeModule.addSerializer(CustomAttribute.class, new CustomAttributeSerializer());
customAttributeModule.addDeserializer(Subscription.Topic.class, new TopicDeserializer());
customAttributeModule.addSerializer(Subscription.Topic.class, new TopicSerializer());
customAttributeModule.addSerializer(Counts.CountItem.class, new CountItemSerializer());
customAttributeModule.addDeserializer(Counts.CountItem.class, new CountItemDeserializer());
return customAttributeModule;
}
}
}
package performa.intercom.resources;
public class NotFoundException extends IntercomException {
private static final long serialVersionUID = 2917082281352001861L;
public NotFoundException(String message) {
super(message);
}
public NotFoundException(String message, Throwable cause) {
super(message, cause);
}
public NotFoundException(ErrorCollection errorCollection) {
super(errorCollection);
}
public NotFoundException(ErrorCollection errorCollection, Throwable cause) {
super(errorCollection, cause);
}
}
package performa.intercom.resources;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.collect.Maps;
import java.util.HashMap;
import java.util.Map;
@SuppressWarnings("UnusedDeclaration")
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class Note extends TypedData {
private static final HashMap<String, String> SENTINEL = Maps.newHashMap();
public static Note find(String id) throws InvalidException, AuthorizationException {
return DataResource.find(id, "notes", Note.class);
}
public static Note create(Note note) throws InvalidException, AuthorizationException {
return DataResource.create(note, "notes", Note.class);
}
public static NoteCollection list(Map<String, String> params) throws InvalidException, AuthorizationException {
if ((!params.containsKey("email")) && (!params.containsKey("id")) && (!params.containsKey("user_id")) && (!params.containsKey("intercom_user_id"))) {
throw new InvalidException("a notes query must include an email, user_id or intercom_user_id parameter");
}
return DataResource.list(params, "notes", NoteCollection.class);
}
@JsonProperty("type")
private final String type = "note";
@JsonProperty("id")
private String id;
@JsonProperty("body")
private String body;
@JsonProperty("created_at")
private long createdAt;
@JsonProperty("user")
private User user;
@JsonProperty("author")
private Author author;
public Note() {
}
public String getType() {
return type;
}
public String getId() {
return id;
}
public String getBody() {
return body;
}
public Note setBody(String body) {
this.body = body;
return this;
}
public long getCreatedAt() {
return createdAt;
}
public User getUser() {
return user;
}
public Note setUser(User user) {
this.user = user;
return this;
}
public Author getAuthor() {
return author;
}
public Note setAuthor(Author author) {
this.author = author;
return this;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Note note = (Note) o;
if (createdAt != note.createdAt) return false;
if (author != null ? !author.equals(note.author) : note.author != null) return false;
if (body != null ? !body.equals(note.body) : note.body != null) return false;
if (id != null ? !id.equals(note.id) : note.id != null) return false;
if (!type.equals(note.type)) return false;
//noinspection RedundantIfStatement
if (user != null ? !user.equals(note.user) : note.user != null) return false;
return true;
}
@Override
public int hashCode() {
int result = type.hashCode();
result = 31 * result + (id != null ? id.hashCode() : 0);
result = 31 * result + (body != null ? body.hashCode() : 0);
result = 31 * result + (int) (createdAt ^ (createdAt >>> 32));
result = 31 * result + (user != null ? user.hashCode() : 0);
result = 31 * result + (author != null ? author.hashCode() : 0);
return result;
}
@Override
public String toString() {
return "Note{" +
"id='" + id + '\'' +
", body='" + body + '\'' +
", createdAt=" + createdAt +
", user=" + user +
", author=" + author +
"} " + super.toString();
}
}
package performa.intercom.resources;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.Iterator;
import java.util.List;
@SuppressWarnings("UnusedDeclaration")
@JsonIgnoreProperties(ignoreUnknown = true)
public class NoteCollection extends TypedDataCollection<Note> implements Iterator<Note> {
protected TypedDataCollectionIterator<Note> iterator;
public NoteCollection() {
iterator = new TypedDataCollectionIterator<Note>(this);
}
@Override
public NoteCollection nextPage() {
return fetchNextPage(NoteCollection.class);
}
@SuppressWarnings("EmptyMethod")
@JsonProperty("notes")
@Override
public List<Note> getPage() {
return super.getPage();
}
public boolean hasNext() {
return iterator.hasNext();
}
public Note next() {
return iterator.next();
}
public void remove() {
iterator.remove();
}
}
package performa.intercom.resources;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.collect.Maps;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.util.Map;
@SuppressWarnings("UnusedDeclaration")
@JsonIgnoreProperties({"intercom"})
public class Notification extends TypedData {
public static Notification readJSON(String json) throws InvalidException {
try {
return MapperSupport.objectMapper().readValue(json, Notification.class);
} catch (IOException e) {
throw new InvalidException("could not parse json string [" + e.getMessage() + "]", e);
}
}
public static Notification readJSON(InputStream json) throws InvalidException {
try {
return MapperSupport.objectMapper().readValue(json, Notification.class);
} catch (IOException e) {
throw new InvalidException("could not parse json stream [" + e.getMessage() + "]", e);
}
}
@JsonProperty("type")
private final String type = "notification_event";
@JsonProperty("id")
private String id;
@JsonProperty("topic")
private String topic;
@JsonProperty("app_id")
private String appID;
@JsonProperty("data")
private NotificationData data;
@JsonProperty("delivery_status")
private String deliveryStatus;
@JsonProperty("delivery_attempts")
private int deliveryAttempts;
@JsonProperty("delivered_at")
private long deliveredAt;
@JsonProperty("first_sent_at")
private long firstSentAt;
@JsonProperty("created_at")
private long createdAt;
@JsonProperty
private Map<String, URI> links = Maps.newHashMap();
@JsonProperty("self")
private URI self;
public Notification() {
}
public String getType() {
return type;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getTopic() {
return topic;
}
public void setTopic(String topic) {
this.topic = topic;
}
public String getAppID() {
return appID;
}
public void setAppID(String appID) {
this.appID = appID;
}
public NotificationData getData() {
return data;
}
public void setData(NotificationData data) {
this.data = data;
}
public String getDeliveryStatus() {
return deliveryStatus;
}
public void setDeliveryStatus(String deliveryStatus) {
this.deliveryStatus = deliveryStatus;
}
public int getDeliveryAttempts() {
return deliveryAttempts;
}
public void setDeliveryAttempts(int deliveryAttempts) {
this.deliveryAttempts = deliveryAttempts;
}
public long getDeliveredAt() {
return deliveredAt;
}
public void setDeliveredAt(long deliveredAt) {
this.deliveredAt = deliveredAt;
}
public long getFirstSentAt() {
return firstSentAt;
}
public void setFirstSentAt(long firstSentAt) {
this.firstSentAt = firstSentAt;
}
public long getCreatedAt() {
return createdAt;
}
public Map<String, URI> getLinks() {
return links;
}
public void setLinks(Map<String, URI> links) {
this.links = links;
}
public URI getSelf() {
return self;
}
public void setSelf(URI self) {
this.self = self;
}
@Override
public int hashCode() {
int result = id != null ? id.hashCode() : 0;
result = 31 * result + (topic != null ? topic.hashCode() : 0);
result = 31 * result + (appID != null ? appID.hashCode() : 0);
result = 31 * result + (data != null ? data.hashCode() : 0);
result = 31 * result + (deliveryStatus != null ? deliveryStatus.hashCode() : 0);
result = 31 * result + deliveryAttempts;
result = 31 * result + (int) (deliveredAt ^ (deliveredAt >>> 32));
result = 31 * result + (int) (firstSentAt ^ (firstSentAt >>> 32));
result = 31 * result + (int) (createdAt ^ (createdAt >>> 32));
result = 31 * result + (links != null ? links.hashCode() : 0);
result = 31 * result + (self != null ? self.hashCode() : 0);
return result;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Notification that = (Notification) o;
if (createdAt != that.createdAt) return false;
if (deliveredAt != that.deliveredAt) return false;
if (deliveryAttempts != that.deliveryAttempts) return false;
if (firstSentAt != that.firstSentAt) return false;
if (appID != null ? !appID.equals(that.appID) : that.appID != null) return false;
if (data != null ? !data.equals(that.data) : that.data != null) return false;
if (deliveryStatus != null ? !deliveryStatus.equals(that.deliveryStatus) : that.deliveryStatus != null)
return false;
if (id != null ? !id.equals(that.id) : that.id != null) return false;
if (links != null ? !links.equals(that.links) : that.links != null) return false;
if (self != null ? !self.equals(that.self) : that.self != null) return false;
//noinspection RedundantIfStatement
if (topic != null ? !topic.equals(that.topic) : that.topic != null) return false;
return true;
}
@Override
public String toString() {
return "Notification{" +
"type='" + type + '\'' +
", id='" + id + '\'' +
", topic='" + topic + '\'' +
", appID='" + appID + '\'' +
", data=" + data +
", deliveryStatus='" + deliveryStatus + '\'' +
", deliveryAttempts=" + deliveryAttempts +
", deliveredAt=" + deliveredAt +
", firstSentAt=" + firstSentAt +
", createdAt=" + createdAt +
", links=" + links +
", self=" + self +
"} " + super.toString();
}
}
package performa.intercom.resources;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.Iterator;
import java.util.List;
@SuppressWarnings("UnusedDeclaration")
@JsonIgnoreProperties(ignoreUnknown = true)
public class NotificationCollection extends TypedDataCollection<Notification> implements Iterator<Notification> {
protected TypedDataCollectionIterator<Notification> iterator;
public NotificationCollection() {
type = "notification.list";
iterator = new TypedDataCollectionIterator<Notification>(this);
}
@Override
public NotificationCollection nextPage() {
return fetchNextPage(NotificationCollection.class);
}
@SuppressWarnings("EmptyMethod")
@JsonProperty("notifications")
@Override
public List<Notification> getPage() {
return super.getPage();
}
public boolean hasNext() {
return iterator.hasNext();
}
public Notification next() {
return iterator.next();
}
public void remove() {
iterator.remove();
}
}
package performa.intercom.resources;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.Map;
@SuppressWarnings("UnusedDeclaration")
@JsonIgnoreProperties(ignoreUnknown = true)
public class NotificationData extends TypedData {
@JsonProperty("type")
protected String type;
@JsonProperty
private Map item;
public NotificationData() {
type = "notification_event_data";
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public Map getItem() {
return item;
}
public void setItem(Map item) {
this.item = item;
}
@Override
public int hashCode() {
return item != null ? item.hashCode() : 0;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
NotificationData that = (NotificationData) o;
//noinspection RedundantIfStatement
if (item != null ? !item.equals(that.item) : that.item != null) return false;
return true;
}
@Override
public String toString() {
return "NotificationData{" +
"type='" + type + '\'' +
", item=" + item +
"} " + super.toString();
}
}
package performa.intercom.resources;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
@SuppressWarnings("UnusedDeclaration")
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_DEFAULT)
public class NotificationError extends Notification {
@JsonProperty("http_request")
private RequestResponseCapture capture;
public RequestResponseCapture getCapture() {
return capture;
}
public void setCapture(RequestResponseCapture capture) {
this.capture = capture;
}
@Override
public String toString() {
return "NotificationError{" +
"capture=" + capture +
"} " + super.toString();
}
}
package performa.intercom.resources;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.Iterator;
import java.util.List;
@SuppressWarnings("UnusedDeclaration")
@JsonIgnoreProperties(ignoreUnknown = true)
public class NotificationErrorCollection extends TypedDataCollection<NotificationError> implements Iterator<NotificationError> {
protected TypedDataCollectionIterator<NotificationError> iterator;
public NotificationErrorCollection() {
type = "notification.list";
iterator = new TypedDataCollectionIterator<NotificationError>(this);
}
@SuppressWarnings("EmptyMethod")
@JsonProperty("notifications")
@Override
public List<NotificationError> getPage() {
return super.getPage();
}
@Override
public NotificationErrorCollection nextPage() {
return fetchNextPage(NotificationErrorCollection.class);
}
public boolean hasNext() {
return iterator.hasNext();
}
public NotificationError next() {
return iterator.next();
}
public void remove() {
iterator.remove();
}
}
package performa.intercom.resources;
public class RateLimitException extends IntercomException {
private static final long serialVersionUID = -6100754169056165622L;
private int rateLimit;
private int remainingRequests;
private long resetTime;
public RateLimitException(String message) {
super(message);
}
public RateLimitException(String message, Throwable cause) {
super(message, cause);
}
public RateLimitException(ErrorCollection errorCollection) {
super(errorCollection);
}
public RateLimitException(ErrorCollection errorCollection, int rateLimit,
int remainingRequests, long resetTime) {
super(errorCollection);
this.rateLimit = rateLimit;
this.remainingRequests = remainingRequests;
this.resetTime = resetTime;
}
public RateLimitException(ErrorCollection errorCollection, Throwable cause) {
super(errorCollection, cause);
}
public int getRateLimit() {
return rateLimit;
}
public void setRateLimit(int rateLimit) {
this.rateLimit = rateLimit;
}
public int getRemainingRequests() {
return remainingRequests;
}
public void setRemainingRequests(int remainingRequests) {
this.remainingRequests = remainingRequests;
}
public long getResetTime() {
return resetTime;
}
public void setResetTime(long resetTime) {
this.resetTime = resetTime;
}
}
package performa.intercom.resources;
interface Replier {
String getReplyType();
}
package performa.intercom.resources;
import com.fasterxml.jackson.annotation.JsonProperty;
class Reply<T extends Replier> extends TypedData {
@JsonProperty("message_type")
private String messageType = "comment";
@JsonProperty("body")
private String body;
@JsonProperty("attachment_urls")
private String[] attachmentUrls;
@JsonProperty("from")
T from;
Reply() {
}
@JsonProperty("type")
String getType() {
return from.getReplyType();
}
String getBody() {
return body;
}
public Reply<T> setBody(String body) {
this.body = body;
return this;
}
public String[] getAttachmentUrls() {
return attachmentUrls;
}
public Reply<T> setAttachmentUrls(String[] attachmentUrls) {
this.attachmentUrls = attachmentUrls;
return this;
}
T getFrom() {
return from;
}
@SuppressWarnings("UnusedDeclaration")
public Reply<T> setFrom(T from) {
this.from = from;
return this;
}
String getMessageType() {
return messageType;
}
Reply<T> setMessageReplyType(String messageType) {
this.messageType = messageType;
return this;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Reply reply = (Reply) o;
if (body != null ? !body.equals(reply.body) : reply.body != null) return false;
if (from != null ? !from.equals(reply.from) : reply.from != null) return false;
//noinspection RedundantIfStatement
if (!messageType.equals(reply.messageType)) return false;
return true;
}
@Override
public int hashCode() {
int result = messageType.hashCode();
result = 31 * result + (body != null ? body.hashCode() : 0);
result = 31 * result + (from != null ? from.hashCode() : 0);
return result;
}
@Override
public String toString() {
return "Reply{" +
"messageType='" + messageType + '\'' +
", body='" + body + '\'' +
", from=" + from +
"} " + super.toString();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment