00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 package org.openmobileis.synchro.openmsp.server.synctarget.proxy;
00029
00030 import org.openmobileis.common.user.profil.Profil;
00031 import org.openmobileis.common.util.exception.SynchroException;
00032 import org.openmobileis.common.util.log.*;
00033 import org.openmobileis.synchro.openmsp.OpenMSPException;
00034 import org.openmobileis.synchro.openmsp.protocol.AbstractCommand;
00035 import org.openmobileis.synchro.openmsp.protocol.ContainerMessage;
00036 import org.openmobileis.synchro.openmsp.protocol.Message;
00037 import org.openmobileis.synchro.openmsp.protocol.Status;
00038 import org.openmobileis.synchro.openmsp.server.synctarget.OpenMSPSynchroTargetListener;
00039 import org.openmobileis.synchro.openmsp.server.synctarget.SyncTargetAnswer;
00040 import org.openmobileis.synchro.openmsp.server.synctarget.SynchroTargerManager;
00041 import org.openmobileis.synchro.openmsp.server.util.FileSystem;
00042 import org.openmobileis.synchro.security.auth.Credential;
00043 import org.openmobileis.common.context.*;
00044
00053 public class GenericProxySynchroTarget implements ProxySyncroTarget {
00054
00055 public GenericProxySynchroTarget() {
00056 }
00057
00058
00059 public void executeOpenMSPCommande(Credential cred, String listenerName, ContainerMessage container, Message answer, UserTerminal terminal, String version, Profil profil, FileSystem fileSystem) throws OpenMSPException {
00060
00061 if (!this.validateProfilAccess(listenerName, profil)) {
00062 Status status = new Status (((AbstractCommand)(container.getElement())).getCmdId(), Status.STATUS_UNAUTHORIZED) ;
00063 answer.add(status);
00064 LogManager.traceInfo(0, "Error rubric not found in profil validation for synchro listener :"+listenerName);
00065 return;
00066 }
00067 OpenMSPSynchroTargetListener listener = SynchroTargerManager.getManager().getSynchroTargetListener(listenerName, version, terminal);
00068 SyncTargetAnswer listenerAnswer = listener.processCommand(cred, container);
00069
00070
00071 if (listenerAnswer.answerfiles != null) {
00072 int size = listenerAnswer.answerfiles.length;
00073 for (int i=0; i<size; i++) {
00074 try {
00075 fileSystem.addFile(listenerAnswer.answerfiles[i]);
00076 } catch (Exception ex) {
00077 LogManager.trace(new SynchroException("file not synchronized continue", ex));
00078 Status status = new Status (((AbstractCommand)(container.getElement())).getCmdId(), Status.STATUS_FAILED) ;
00079 answer.add(status);
00080 return;
00081 }
00082 }
00083 }
00084 if (listenerAnswer.containerMessage != null) {
00085 int size = listenerAnswer.containerMessage.length;
00086 for (int i=0; i<size; i++) {
00087 answer.add(listenerAnswer.containerMessage[i]);
00088 }
00089 }
00090 }
00091
00092 protected boolean validateProfilAccess(String listenerName, Profil profil) {
00093 int size = profil.profilRubric.length;
00094 for (int i=0; i<size; i++) {
00095 if (listenerName.equals(profil.profilRubric[i].rubricName)) {
00096 return true;
00097 }
00098 }
00099 return false;
00100 }
00101 }