use of com.octo.android.robospice.persistence.exception.SpiceException in project ETSMobile-Android2 by ApplETS.
the class DataManager method getDataFromSignet.
/**
* Robospice request manager for everything not related to Signet-Mobile the
* class (result) must be mapped with Gson
*
* @param request
* @param listener
* @return true if request is sent
*/
// public boolean sendRequest(TypedRequest request, RequestListener<Object>
// listener) {
//
// final Object key = request.createCacheKey();
// spiceManager.execute(request, key, DurationInMillis.ONE_SECOND,
// listener);
// return true;
// }
/**
* Send a request to Signet-Mobile Web Service
*
* @param method
* Int, methods are stored in SignetMethod
* @param creds
* User Credentials
* @param listener
* The callback
* @param params
* Some methods require more than the credentials pass them here
*/
public void getDataFromSignet(int method, final UserCredentials creds, final RequestListener<Object> listener, String... params) {
// inline asynctask
new AsyncTask<Object, Void, Object>() {
private Exception exception = null;
private Object result;
@Override
protected Object doInBackground(Object... params) {
try {
final int methodID = (Integer) params[0];
String[] reqParams = (String[]) params[1];
final SignetsMobileSoap signetsMobileSoap = new SignetsMobileSoap();
String username = "";
String password = "";
if (methodID < SignetMethods.BOTTIN_LIST_DEPT || methodID > SignetMethods.BOTTIN_GET_LIST_SERVICE_AND_EMP) {
username = creds.getUsername();
password = creds.getPassword();
}
switch(methodID) {
case SignetMethods.INFO_ETUDIANT:
result = signetsMobileSoap.infoEtudiant(username, password);
dbHelper.getDao(Etudiant.class).createOrUpdate((Etudiant) result);
break;
case SignetMethods.LIST_COURS:
result = signetsMobileSoap.listeCours(username, password);
break;
case SignetMethods.LIST_INT_SESSION:
String SesFin = reqParams[0];
String SesDebut = reqParams[1];
result = signetsMobileSoap.listeCoursIntervalleSessions(username, password, SesDebut, SesFin);
break;
case SignetMethods.LIST_SESSION:
result = signetsMobileSoap.listeSessions(username, password);
break;
case SignetMethods.LIST_PROGRAM:
result = signetsMobileSoap.listeProgrammes(username, password);
break;
case SignetMethods.LIST_COEQ:
String pNomElementEval = reqParams[0];
String pSession = reqParams[1];
String pGroupe = reqParams[2];
String pSigle = reqParams[3];
result = signetsMobileSoap.listeCoequipiers(username, password, pSigle, pGroupe, pSession, pNomElementEval);
break;
case SignetMethods.LIST_EVAL:
String pSession1 = reqParams[0];
String pGroupe1 = reqParams[1];
String pSigle1 = reqParams[2];
result = signetsMobileSoap.listeElementsEvaluation(username, password, pSigle1, pGroupe1, pSession1);
break;
case SignetMethods.LIST_HORAIRE_PROF:
String pSession2 = reqParams[0];
result = signetsMobileSoap.listeHoraireEtProf(username, password, pSession2);
break;
case SignetMethods.LIRE_HORAIRE:
String pSession3 = reqParams[0];
String prefixeSigleCours = reqParams[1];
result = signetsMobileSoap.lireHoraire(pSession3, prefixeSigleCours);
break;
case SignetMethods.LIRE_JOURS_REMPLACES:
String pSession4 = reqParams[0];
result = signetsMobileSoap.lireJoursRemplaces(pSession4);
break;
case SignetMethods.BOTTIN_LIST_DEPT:
result = new WebServiceSoap().GetListeDepartement();
break;
case SignetMethods.BOTTIN_GET_FICHE:
String numero = reqParams[0];
String PathFiche = reqParams[1];
result = new WebServiceSoap().GetFiche(numero, PathFiche);
break;
case SignetMethods.BOTTIN_GET_FICHE_DATA:
String Id = reqParams[0];
result = new WebServiceSoap().GetFicheData(Id);
break;
case SignetMethods.BOTTIN_GET_ALL:
result = new WebServiceSoap().Recherche(null, null, null);
break;
case SignetMethods.BOTTIN_GET_FICHE_BY_SERVICE:
String filtreServiceCode = reqParams[0];
result = new WebServiceSoap().Recherche(null, null, filtreServiceCode);
break;
case SignetMethods.BOTTIN_GET_LIST_SERVICE_AND_EMP:
ArrayOfService arrayOfService = new WebServiceSoap().GetListeDepartement();
HashMap<String, List<FicheEmploye>> listeEmployeByService = new HashMap<String, List<FicheEmploye>>();
ArrayOfFicheEmploye arrayOfFicheEmploye;
for (int i = 0; i < arrayOfService.size(); i++) {
Service service = arrayOfService.get(i);
arrayOfFicheEmploye = new WebServiceSoap().Recherche(null, null, "" + service.ServiceCode);
listeEmployeByService.put(service.Nom, arrayOfFicheEmploye);
}
result = listeEmployeByService;
break;
case SignetMethods.LIST_EXAMENS_FINAUX:
String pSession5 = reqParams[0];
result = signetsMobileSoap.listeHoraireExamensFin(username, password, pSession5);
break;
case SignetMethods.LIST_SEANCES:
String pCoursGroupe = reqParams[0];
String pSession6 = reqParams[1];
String pDateDebut = reqParams[2];
String pDateFin = reqParams[3];
result = signetsMobileSoap.lireHoraireDesSeances(username, password, pCoursGroupe, pSession6, pDateDebut, pDateFin);
break;
case SignetMethods.LIST_SEANCES_CURRENT_AND_NEXT_SESSION:
ListeDeSessions listeDeSessions = signetsMobileSoap.listeSessions(username, password);
listeSeances listeSeances = new listeSeances();
DateTime dt = new DateTime();
DateTime dtEnd = new DateTime();
for (Trimestre trimestre : listeDeSessions.liste) {
dtEnd = new DateTime(trimestre.dateFin);
if (dt.isBefore(dtEnd.plusDays(1))) {
listeSeances.ListeDesSeances.addAll(signetsMobileSoap.lireHoraireDesSeances(username, password, "", trimestre.abrege, "", "").ListeDesSeances);
}
}
result = listeSeances;
break;
case SignetMethods.LIST_EXAM_CURRENT_AND_NEXT_SESSION:
ListeDeSessions listeDeSessions2 = signetsMobileSoap.listeSessions(username, password);
listeHoraireExamensFinaux listeHoraireExamensFinaux = new listeHoraireExamensFinaux();
DateTime dt2 = new DateTime();
DateTime dtEnd2 = new DateTime();
for (Trimestre trimestre : listeDeSessions2.liste) {
dtEnd2 = new DateTime(trimestre.dateFin);
if (dt2.isBefore(dtEnd2.plusDays(1))) {
listeHoraireExamensFinaux.listeHoraire.addAll(signetsMobileSoap.listeHoraireExamensFin(username, password, trimestre.abrege).listeHoraire);
}
}
result = listeHoraireExamensFinaux;
break;
case SignetMethods.LIST_JOURSREMPLACES_CURRENT_AND_NEXT_SESSION:
ListeDeSessions listeDeSessions3 = signetsMobileSoap.listeSessions(username, password);
listeJoursRemplaces listeJoursRemplaces = new listeJoursRemplaces();
DateTime dt3 = new DateTime();
DateTime dtEnd3 = new DateTime();
for (Trimestre trimestre : listeDeSessions3.liste) {
dtEnd3 = new DateTime(trimestre.dateFin);
if (dt3.isBefore(dtEnd3.plusDays(1))) {
listeJoursRemplaces.listeJours.addAll(signetsMobileSoap.lireJoursRemplaces(trimestre.abrege).listeJours);
}
}
result = listeJoursRemplaces;
break;
default:
break;
}
} catch (Exception e) {
e.printStackTrace();
exception = e;
}
return null;
}
protected void onPostExecute(Object result2) {
if (exception != null) {
listener.onRequestFailure(new SpiceException("Couldn't get datas"));
} else {
listener.onRequestSuccess(result);
}
}
}.execute(method, params);
}
use of com.octo.android.robospice.persistence.exception.SpiceException in project ETSMobile-Android2 by ApplETS.
the class EventsFragment method onResume.
@Override
public void onResume() {
super.onResume();
expandableListAdapter.clearEvents();
progressBar.setVisibility(View.VISIBLE);
countSourcesLoaded = 0;
nbSources = 0;
progressBar.setProgress(0);
AppletsApiSourcesRequest requestSources = new AppletsApiSourcesRequest(getActivity());
String cacheKey = requestSources.createCacheKey();
spiceManager.execute(requestSources, cacheKey, DurationInMillis.ONE_MINUTE * 10, new RequestListener<SourceEvenementList>() {
@Override
public void onRequestFailure(SpiceException spiceException) {
spiceException.printStackTrace();
Toast.makeText(getActivity(), getString(R.string.SupportKit_errorCouldNotConnect), Toast.LENGTH_SHORT).show();
}
@Override
public void onRequestSuccess(SourceEvenementList sourceEvenements) {
progressBar.setMax(sourceEvenements.size());
EventsFragment.this.nbSources = sourceEvenements.size();
for (SourceEvenement source : sourceEvenements) {
AppletsApiEvenementsRequest requestEvents = new AppletsApiEvenementsRequest(getActivity(), source);
String cacheKey = requestEvents.createCacheKey();
spiceManager.execute(requestEvents, cacheKey, DurationInMillis.ONE_MINUTE * 10, EventsFragment.this);
}
}
});
}
use of com.octo.android.robospice.persistence.exception.SpiceException in project howabout-android by recomio.
the class MusicPlayerService method play.
@SuppressWarnings("deprecation")
private void play(final String trackTitle, final String artistName, String thumbnailUrl) {
Notification notification = new Notification(R.drawable.ic_launcher, trackTitle + " - " + artistName, System.currentTimeMillis());
Intent intent = new Intent(this, MusicPlaylistActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
notification.setLatestEventInfo(this, trackTitle, artistName, pendingIntent);
notification.flags |= Notification.FLAG_NO_CLEAR;
notification.flags |= Notification.FLAG_ONGOING_EVENT;
startForeground(NOTIFICATION_ID, notification);
playlistAdapter.setCurrentLyrics("");
isLoaded = false;
isLoading = true;
mediaPlayer.stop();
mediaPlayer.reset();
if (playInfoRequest != null) {
contentManager.cancel(playInfoRequest);
playInfoRequest = null;
}
playInfoRequest = new PlayInfoRequest(trackTitle, artistName);
contentManager.execute(playInfoRequest, new RequestListener<PlayInfo>() {
@Override
public void onRequestFailure(SpiceException e) {
if (groovesharkStreamUrlGetter != null) {
groovesharkStreamUrlGetter.isStopped(true);
}
if (e instanceof RequestCancelledException) {
return;
}
isLoading = false;
playlistAdapter.playNext();
playlistAdapter.notifyDataSetChanged();
Toast.makeText(MusicPlayerService.this, trackTitle + "(" + artistName + ")" + "\n 무료 스트리밍 음원을 찾지 못했습니다.", Toast.LENGTH_SHORT).show();
}
@Override
public void onRequestSuccess(final PlayInfo playInfo) {
playlistAdapter.setCurrentLyrics(playInfo.getLyrics());
Log.i("grooveshark", playInfo.getTrackTitle());
final String groovesharkSongId = playInfo.getTinysongId();
if (groovesharkSongId != null) {
HowaboutApplication application = (HowaboutApplication) getApplicationContext();
try {
groovesharkStreamUrlGetter = new GroovesharkStreamUrlGetter(application, groovesharkSongId, new OnGetGroovesharkStreamKey() {
@Override
public void sucess(String streamUrl) {
playInfo.setGroovesharkSongID(groovesharkSongId);
playInfo.setGroovesharkStreamUrl(streamUrl);
playStream(playInfo);
}
@Override
public void error(Exception e) {
playStream(playInfo);
}
});
groovesharkStreamUrlGetter.getGroovesharkStreamUrlAsync();
} catch (Exception e) {
playStream(playInfo);
}
} else {
playStream(playInfo);
}
}
});
}
use of com.octo.android.robospice.persistence.exception.SpiceException in project robospice by stephanenicolas.
the class DefaultRequestRunner method processRequest.
protected <T> void processRequest(final CachedSpiceRequest<T> request) {
final long startTime = System.currentTimeMillis();
Ln.d("Processing request : " + request);
T result = null;
// add a progress listener to the request to be notified of
// progress during load data from network
final RequestProgressListener requestProgressListener = requestProgressManager.createProgressListener(request);
request.setRequestProgressListener(requestProgressListener);
if (request.getRequestCacheKey() != null && request.getCacheDuration() != DurationInMillis.ALWAYS_EXPIRED) {
// First, search data in cache
try {
Ln.d("Loading request from cache : " + request);
request.setStatus(RequestStatus.READING_FROM_CACHE);
result = loadDataFromCache(request.getResultType(), request.getRequestCacheKey(), request.getCacheDuration());
// request
if (result != null) {
Ln.d("Request loaded from cache : " + request + " result=" + result);
requestProgressManager.notifyListenersOfRequestSuccess(request, result);
printRequestProcessingDuration(startTime, request);
return;
} else if (request.isAcceptingDirtyCache()) {
// as a fallback, some request may accept whatever is in the
// cache but still
// want an update from network.
result = loadDataFromCache(request.getResultType(), request.getRequestCacheKey(), DurationInMillis.ALWAYS_RETURNED);
if (result != null) {
requestProgressManager.notifyListenersOfRequestSuccessButDontCompleteRequest(request, result);
}
}
} catch (final SpiceException e) {
Ln.d(e, "Cache file could not be read.");
if (failOnCacheError) {
handleRetry(request, e);
printRequestProcessingDuration(startTime, request);
return;
}
cacheManager.removeDataFromCache(request.getResultType(), request.getRequestCacheKey());
Ln.d(e, "Cache file deleted.");
}
}
// if result is not in cache, load data from network
Ln.d("Cache content not available or expired or disabled");
if (!networkStateChecker.isNetworkAvailable(applicationContext) && !request.isOffline()) {
Ln.e("Network is down.");
if (!request.isCancelled()) {
// don't retry when there is no network
requestProgressManager.notifyListenersOfRequestFailure(request, new NoNetworkException());
}
printRequestProcessingDuration(startTime, request);
return;
}
// network is ok, load data from network
try {
if (request.isCancelled()) {
printRequestProcessingDuration(startTime, request);
return;
}
Ln.d("Calling network request.");
request.setStatus(RequestStatus.LOADING_FROM_NETWORK);
result = request.loadDataFromNetwork();
Ln.d("Network request call ended.");
} catch (final Exception e) {
if (!request.isCancelled()) {
Ln.e(e, "An exception occurred during request network execution :" + e.getMessage());
handleRetry(request, new NetworkException("Exception occurred during invocation of web service.", e));
} else {
Ln.e("An exception occurred during request network execution but request was cancelled, so listeners are not called.");
}
printRequestProcessingDuration(startTime, request);
return;
}
if (result != null && request.getRequestCacheKey() != null) {
// it to cache
try {
if (request.isCancelled()) {
printRequestProcessingDuration(startTime, request);
return;
}
Ln.d("Start caching content...");
request.setStatus(RequestStatus.WRITING_TO_CACHE);
result = saveDataToCacheAndReturnData(result, request.getRequestCacheKey());
if (request.isCancelled()) {
printRequestProcessingDuration(startTime, request);
return;
}
requestProgressManager.notifyListenersOfRequestSuccess(request, result);
printRequestProcessingDuration(startTime, request);
return;
} catch (final SpiceException e) {
Ln.d(e, "An exception occurred during service execution :" + e.getMessage());
if (failOnCacheError) {
handleRetry(request, e);
printRequestProcessingDuration(startTime, request);
return;
} else {
if (request.isCancelled()) {
printRequestProcessingDuration(startTime, request);
return;
}
// result can't be saved to
// cache but we reached that
// point after a success of load
// data from
// network
requestProgressManager.notifyListenersOfRequestSuccess(request, result);
}
cacheManager.removeDataFromCache(request.getResultType(), request.getRequestCacheKey());
Ln.d(e, "Cache file deleted.");
}
} else {
// result can't be saved to cache but we reached
// that point after a success of load data from
// network
requestProgressManager.notifyListenersOfRequestSuccess(request, result);
printRequestProcessingDuration(startTime, request);
return;
}
}
use of com.octo.android.robospice.persistence.exception.SpiceException in project ETSMobile-Android2 by ApplETS.
the class Utility method loadNotifications.
/**
* Gets MonÉTS notifications and update DB
* @param context
* @param requestListener
*/
public static void loadNotifications(Context context, final RequestListener<Object> requestListener) {
final SecurePreferences securePreferences = new SecurePreferences(context);
final boolean allNotifsLoaded = securePreferences.getBoolean(Constants.ALL_NOTIFS_LOADED, false);
MonETSNotificationsRequest monETSNotificationsRequest;
if (!allNotifsLoaded) {
monETSNotificationsRequest = new MonETSNotificationsRequest(context, false);
} else {
monETSNotificationsRequest = new MonETSNotificationsRequest(context, true);
}
final DataManager dataManager = DataManager.getInstance(context);
dataManager.start();
final DatabaseHelper databaseHelper = new DatabaseHelper(context);
dataManager.sendRequest(monETSNotificationsRequest, new RequestListener<Object>() {
@Override
public void onRequestFailure(SpiceException spiceException) {
requestListener.onRequestFailure(spiceException);
dataManager.stop();
}
@Override
public void onRequestSuccess(Object o) {
if (o instanceof MonETSNotificationList) {
try {
Dao<MonETSNotification, ?> dao = databaseHelper.getDao(MonETSNotification.class);
MonETSNotificationList list = (MonETSNotificationList) o;
for (MonETSNotification monETSNotification : list) {
dao.createOrUpdate(monETSNotification);
}
if (!allNotifsLoaded) {
securePreferences.edit().putBoolean(Constants.ALL_NOTIFS_LOADED, true).commit();
}
requestListener.onRequestSuccess(list);
} catch (SQLException e) {
e.printStackTrace();
}
}
dataManager.stop();
}
});
}
Aggregations