Search in sources :

Example 1 with SyncContact

use of com.axelor.apps.base.db.SyncContact in project axelor-open-suite by axelor.

the class SyncContactService method getKeyAndClientId.

@POST
@Path("/key/{id}")
public SyncContactResponse getKeyAndClientId(@PathParam("id") Long id) {
    SyncContact syncContact = syncContactRepo.find(id);
    if (syncContact == null) {
        return null;
    }
    SyncContactResponse response = new SyncContactResponse();
    response.setClientid(syncContact.getCid());
    response.setKey(syncContact.getGoogleApiKey());
    response.setAuthFailed(I18n.get(SYNC_CONTACT_AUTH_FAILED));
    response.setImportSuccessful(I18n.get(SYNC_CONTACT_IMPORT_SUCCESSFUL));
    response.setNoImport(I18n.get(SYNC_CONTACT_NO_IMPORT));
    return response;
}
Also used : SyncContact(com.axelor.apps.base.db.SyncContact) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 2 with SyncContact

use of com.axelor.apps.base.db.SyncContact in project axelor-open-suite by axelor.

the class SyncContactService method updateSyncContact.

@Transactional(rollbackOn = { AxelorException.class, Exception.class })
public void updateSyncContact(Long id, SyncContactHistoric syncContactHistoric) {
    SyncContact syncContact;
    syncContact = syncContactRepo.find(id);
    syncContactHistoric.setUser(userService.getUser());
    Set<Partner> partnerSet = new HashSet<>();
    for (Partner partner : syncContactHistoric.getPartnerSet()) {
        Partner find = partnerRepo.find(partner.getId());
        if (find != null) {
            partnerSet.add(find);
        }
    }
    syncContactHistoric.clearPartnerSet();
    syncContactHistoric.setPartnerSet(partnerSet);
    syncContact.addSyncContactHistoricListItem(syncContactHistoric);
    syncContactRepo.save(syncContact);
}
Also used : SyncContact(com.axelor.apps.base.db.SyncContact) Partner(com.axelor.apps.base.db.Partner) HashSet(java.util.HashSet) Transactional(com.google.inject.persist.Transactional)

Example 3 with SyncContact

use of com.axelor.apps.base.db.SyncContact in project axelor-open-suite by axelor.

the class SyncContactService method importAllContact.

public void importAllContact(Long id, List<Person> people) {
    int i = 0;
    SyncContact syncContact = syncContactRepo.find(id);
    if (syncContact == null) {
        return;
    }
    SyncContactHistoric syncContactHistoric = new SyncContactHistoric();
    for (Person googlePerson : people) {
        Partner partner = importContact(googlePerson, syncContact.getUpdateContactField());
        if (partner != null) {
            syncContactHistoric.addPartnerSetItem(partner);
        }
        if (i % 10 == 0) {
            JPA.clear();
        }
        i++;
    }
    updateSyncContact(id, syncContactHistoric);
}
Also used : SyncContactHistoric(com.axelor.apps.base.db.SyncContactHistoric) SyncContact(com.axelor.apps.base.db.SyncContact) Person(com.google.api.services.people.v1.model.Person) Partner(com.axelor.apps.base.db.Partner)

Aggregations

SyncContact (com.axelor.apps.base.db.SyncContact)3 Partner (com.axelor.apps.base.db.Partner)2 SyncContactHistoric (com.axelor.apps.base.db.SyncContactHistoric)1 Person (com.google.api.services.people.v1.model.Person)1 Transactional (com.google.inject.persist.Transactional)1 HashSet (java.util.HashSet)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1