MS ExchangeService - get custom calendar (OR calendars list) - java

Using ExchangeService I need to get Calendar folder and retrieve all events there
It's done by this piece of code
private List getRoomCalendar() throws Exception {
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
ExchangeCredentials credentials = new WebCredentials(username, password);
service.setCredentials(credentials);
service.setUrl(new URI(msExchangeUrl));
FolderView fv = new FolderView(100);
fv.setTraversal(FolderTraversal.Deep);
FolderId confRoomFolderId = new FolderId(WellKnownFolderName.Calendar, new Mailbox(username));
System.out.println(confRoomFolderId.getFolderName());
List events = new ArrayList();
Date date = new Date();
try {
CalendarFolder calendarFolder = CalendarFolder.bind(service, confRoomFolderId);
CalendarView cView = new CalendarView(new DateTime(date).minusDays(1).toDate(),
new DateTime(date).plusDays(1).toDate(), 100);
cView.setPropertySet(new PropertySet(AppointmentSchema.Subject,
AppointmentSchema.Start,
AppointmentSchema.End));
// we can set other properties as well depending upon our need.
FindItemsResults appointments = calendarFolder.findAppointments(cView);
List<Appointment> appList = appointments.getItems();
for (Appointment appointment : appList) {
Map event = readEvent(appointment);
events.add(event);
}
} catch (Exception e) {
e.printStackTrace();
}
return events;
}
private Map readEvent(Appointment appointment) {
Map appointmentData = new HashMap();
try {
DateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
appointmentData.put("appointmentSubject", appointment.getSubject());
appointmentData.put("appointmentStartTime", df.format(appointment.getStart()));
appointmentData.put("appointmentEndTime", df.format(appointment.getEnd()));
} catch (ServiceLocalException e) {
e.printStackTrace();
}
return appointmentData;
}
Cool, it's working and returns these data
default MS Calendar
The question is: how can I get events for MY CUSTOM CALENDAR called name
see here
custom MS calendar

The solution is to create the folderView first. Afterwards, apply a search filter, find it using FindFolderResults.
PropertySet psPropset = new PropertySet(BasePropertySet.FirstClassProperties);
FolderView fvFolderView = new FolderView(1);
fvFolderView.setPropertySet(psPropset);
SearchFilter SfSearchFilter = new SearchFilter.IsEqualTo(FolderSchema.DisplayName,"name");
FindFoldersResults findFoldersResults = service.findFolders(confRoomFolderId, SfSearchFilter, fvFolderView);
System.out.println(findFoldersResults.getFolders().get(0).getDisplayName());

Related

Getting database values CODENAME ONE

I have an intermediate table that gets information from two other tables from the database (it gets their id), I'd like to show information of the other tables through that intermediate table in each of the others but it show me all of the information.
public showTheatreForm(Resources res, Theatre t) {
Toolbar tb=new Toolbar(true);
current=this;
setToolbar(tb);
getTitleArea().setUIID("Container");
setTitle("modifier actor");
getContentPane().setScrollVisible(false);
super.addSideMenu(res);
Label name = new Label((t.getName()));
Picker datePicker = new Picker();
datePicker.setDate(t.getRdate());
String datestring=(new SimpleDateFormat("yyyy-MM-dd")).format(datePicker.getDate());
Label date = new Label((datestring));
TextField description = new TextField((t.getDescription()));
TextField actors = new TextField((t.getTactor()));
//Label image = new Label((t.getImage()), "Image");
ImageViewer imavu;
try {
imavu = new ImageViewer(getImageFromServer(t.getImage()));
}
catch(Exception e) {
System.out.println(t.getImage());
imavu = new ImageViewer(res.getImage("s.png"));
}
description.setSingleLineTextArea(false);
actors.setSingleLineTextArea(false);
name.setUIID("NewsCenterLine");
date.setUIID("NewsCenterLine");
description.setUIID("NewsCenterLine");
imavu.setUIID("NewsCenterLine");
actors.setUIID("NewsCenterLine");
Label a = new Label("");
Label e = new Label ();
Container content = BoxLayout.encloseY(
e,a, (name),
createLineSeparator(), (actors),
createLineSeparator(),date,
createLineSeparator(), (description),
createLineSeparator(), (imavu)
);
add(content);
show();
}
And this is how I get it from the database:
public ArrayList<Theatre> ShowTheatre (){
ArrayList<Theatre> result=new ArrayList<>();
String url=Statics.BASE_URL+"/theatre/displayTheatre";
req.setUrl(url);
req.addResponseListener(new ActionListener<NetworkEvent>() {
#Override
public void actionPerformed(NetworkEvent evt) {
JSONParser Jsonp;
Jsonp=new JSONParser();
try{
Map<String,Object>mapTheatre= Jsonp.parseJSON(new CharArrayReader(new String(req.getResponseData()).toCharArray()));
List<Map<String,Object>> listofMaps = (List<Map<String,Object>>) mapTheatre.get("root");
for(Map<String,Object> obj : listofMaps)
{
Theatre th=new Theatre();
float id=Float.parseFloat(obj.get("id").toString());
String name=obj.get("name").toString();
String genre=obj.get("genre").toString();
String description=obj.get("description").toString();
String image=obj.get("image").toString();
String trailer=obj.get("trailer").toString();
String poster=obj.get("poster").toString();
String get=obj.get("theatreActors").toString();
th.setId((long)id);
th.setName(name);
th.setTactor(get);
System.out.println(get);
th.setDescription(description);
th.setImage(image);
th.setTrailer(trailer);
th.setPoster(poster);
th.setGenre(genre);
Map<String, Object> dd = (Map<String, Object>) obj.get("rdate");
float ll = Float.parseFloat(dd.get("timestamp").toString());
th.setRdate(new Date(((long) ll * 1000)));
}
result.add(th);
}
} catch (IOException ex) {
System.out.println(
"good");
}
}
});
NetworkManager.getInstance().addToQueueAndWait(req);
return result;
}
Result of the code
This is the result, but I only want to get the "name" and "date" or "description" from the intermediate table
My intermediate table
(the name of the table is theatreActors)

cal4j - Unexpected end of file Exception

I have currently no idea what´s here the issue and I asked kindly for help.
I´m generating a ics - File.
But if I would like to open the ics - File to get the Calender, I got the following error message:
net.fortuna.ical4j.data.ParserException: Error at line 1:Unexpected end of file
Here my information:
ical4j Version 3.0.1
Java: 8 Build 181
My output from the ics - File:
BEGIN:VCALENDAR PRODID:-//Ben Fortuna//iCal4j 1.0//EN VERSION:2.0
CALSCALE:GREGORIAN BEGIN:VEVENT DTSTAMP:20180826T165052Z
DTSTART:01180905T000000 DTEND:01180905T000000 SUMMARY:ddd
TZID:Europe/Berlin
UID:1535302250819-9ed0489f-0320-4a66-8f9c-4af0e62cdedd END:VEVENT
END:VCALENDAR
Here my code for generation the calender.ics - File:
public void createEvent(BookingDate bookingDate, Mandatory mandatory, Employee employee)
throws FileNotFoundException, IOException, ParserException, ConstraintViolationException {
// Create a TimeZone
System.setProperty("net.fortuna.ical4j.timezone.cache.impl", MapTimeZoneCache.class.getName());
TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry();
TimeZone timezone = registry.getTimeZone("Europe/Berlin");
VTimeZone tz = timezone.getVTimeZone();
String pathMandatoryFile = null;
String pathEmployeeFile = null;
// Reading the file and creating the calendar
Calendar icsCalendar = null;
FileOutputStream fout = null;
if (bookingDate.isCreateCalendarMandatoryEntry()) {
// timezone = registry.getTimeZone(mandatory.getTimeZone());
pathMandatoryFile = "calendar.ics";
fout = new FileOutputStream(pathMandatoryFile);
try {
FileInputStream fin = new FileInputStream(pathMandatoryFile);
CalendarBuilder builder = new CalendarBuilder();
icsCalendar = builder.build(fin);
} catch (Exception e) {
}
if (icsCalendar == null) {
icsCalendar = createNewCalender(pathMandatoryFile);
}
}
// Creating an event
java.util.Calendar startCal = java.util.Calendar.getInstance(timezone);
startCal.set(java.util.Calendar.YEAR, bookingDate.getStartDate().getYear());
startCal.set(java.util.Calendar.MONTH, bookingDate.getStartDate().getMonth());
startCal.set(java.util.Calendar.DAY_OF_MONTH, bookingDate.getStartDate().getDate());
startCal.set(java.util.Calendar.HOUR_OF_DAY, bookingDate.getStartDate().getHours());
startCal.clear(java.util.Calendar.MINUTE);
startCal.clear(java.util.Calendar.SECOND);
java.util.Calendar endCal = java.util.Calendar.getInstance(timezone);
endCal.set(java.util.Calendar.YEAR, bookingDate.getEndDate().getYear());
endCal.set(java.util.Calendar.MONTH, bookingDate.getEndDate().getMonth());
endCal.set(java.util.Calendar.DAY_OF_MONTH, bookingDate.getEndDate().getDate());
endCal.set(java.util.Calendar.HOUR_OF_DAY, bookingDate.getEndDate().getHours());
endCal.clear(java.util.Calendar.MINUTE);
endCal.clear(java.util.Calendar.SECOND);
net.fortuna.ical4j.model.DateTime dtStart = new DateTime(startCal.getTime());
net.fortuna.ical4j.model.DateTime dtEnd = new DateTime(endCal.getTime());
String eventName = bookingDate.getName();
VEvent meeting = new VEvent(dtStart, dtEnd, eventName);
// add timezone info..
meeting.getProperties().add(tz.getTimeZoneId());
String uidValue = bookingDate.getIdHash();
meeting.getProperties().add(new Uid(uidValue));
// Add the event and print
icsCalendar.getComponents().add(meeting);
CalendarOutputter outputter = new CalendarOutputter();
outputter.output(icsCalendar, fout);
}
private Calendar createNewCalender(String filePath) throws ValidationException, IOException {
// Saving an iCalendar file
FileOutputStream fout = new FileOutputStream(filePath);
Calendar calendar = new Calendar();
calendar.getProperties().add(new ProdId("-//Ben Fortuna//iCal4j 1.0//EN"));
calendar.getProperties().add(Version.VERSION_2_0);
calendar.getProperties().add(CalScale.GREGORIAN);
return calendar;
}
Can anybody help me, please.

Data insertion acts differently with two similar entities

I have two entities: Movie and Person in my simple Movie App. While I try to add initial data to database something strange is happening. Even though my both entities are very similar, inserting people works fine, while inserting movies result in having 11 (while array of 7 is passed as argument) movie elements with null fields in it:
I/System.out: [Movie{id=23, title='null', genre='null',
posterResource=null}, Movie{id=24, title='null', genre='null',
posterResource=null} ... Movie{id=33, title='null', genre='null',
posterResource=null}]
I/System.out: [Person{id=23, firstName='Brad', lastName='Pitt', age=55,
imgResource=2131165277}, Person{id=24, firstName='Edward',
lastName='Norton', age=49, imgResource=2131165286}, ... , Person{id=33,
firstName='Joaquin', lastName='Phoenix', age=44, imgResource=2131165293}]
Interior of my LocalDataSource, where I insert data:
private AppDatabase mDataBase;
public LocalDataSource(Context mContext) {
mDataBase = AppDatabase.getAppDatabase(mContext);
mDataBase.personDao().deleteAllPeople();
mDataBase.movieDao().deleteAllMovies();
setupTestMovieData();
setupTestActorsData();
setupTestMovieActorRelationship();
System.out.println(getAllMovies());
System.out.println(getAllActors());
}
public List<Movie> getAllMovies(){
return mDataBase.movieDao().loadAllMovie();
}
public List<Person> getAllActors(){
return mDataBase.personDao().loadAllPeople();
}
public List<Person> getActorsFromMovie(long movieId){
return mDataBase.actorMovieJoinDao().getActorsFromMovie(movieId);
}
private void setupTestMovieData() {
MovieDao dao = mDataBase.movieDao();
dao.insertMovie(getTestMovieArray());
}
private Movie[] getTestMovieArray() {
Movie[] movies = new Movie[7];
movies[0] = new Movie("Fight club", "Thriller", R.drawable.fightclub);
movies[1] = new Movie("Prestige", "Thriller",R.drawable.prestige);
movies[2] = new Movie("500 days of Summer","Drama", R.drawable.the500daysofsummer);
movies[3] = new Movie("Seven","Detective", R.drawable.kiler);
movies[4] = new Movie("Inception","Action", R.drawable.pulpfiction);
movies[5] = new Movie("American Hustle","Crime", R.drawable.phantomthread);
movies[6] = new Movie("Her","Drama", R.drawable.dancerinthedark);
return movies;
}
private void setupTestActorsData(){
PersonDao dao = mDataBase.personDao();
dao.insertPeople(getTestActorArray());
}
private Person[] getTestActorArray() {
Person[] actors = new Person[11];
actors[0] = createPerson("Brad", "Pitt", "18/12/1963", R.drawable.bradpitt);
actors[1] = createPerson("Edward", "Norton", "18/8/1969", R.drawable.edwardnorton);
actors[2] = createPerson("Helena", "Bonham-Carter", "26/5/1966", R.drawable.helenabonhamcarter);
actors[3] = createPerson("Joseph", "Gordon-Levitt", "17/2/1981", R.drawable.josephgordonlevitt);
actors[4] = createPerson("Zooey", "Deschanel", "17/1/1980", R.drawable.zooeydeschanel);
actors[5] = createPerson("Christian", "Bale", "30/1/1974", R.drawable.christianbale);
actors[6] = createPerson("Leonardo", "DiCaprio", "11/11/1974", R.drawable.leonardodicaprio);
actors[7] = createPerson("Morgan", "Freeman", "1/6/1937", R.drawable.morganfreeman);
actors[8] = createPerson("Amy", "Adams", "20/8/1974", R.drawable.amyadams);
actors[9] = createPerson("Scarlett", "Johansson", "22/11/1984", R.drawable.scarlettjohansson);
actors[10] = createPerson("Joaquin", "Phoenix", "28/10/1974", R.drawable.joaquinphoenix);
return actors;
}
private Person createPerson(String firstName, String lastName, String date, Integer imgResource){
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
GregorianCalendar gregorianCalendar = new GregorianCalendar();
try {
gregorianCalendar.setTime(sdf.parse(date));
} catch (ParseException e) {
e.printStackTrace();
}
return new Person(firstName, lastName, gregorianCalendar, imgResource);
}

Creating object array to pass in Constructor

Being a newbie to Java am finding it a bit difficult to come up with a neat code for my purpose.
The problem is,
class ElementID {
String name = "";
String value = "";
public ElementID (String name, String value) {
this.name = name;
this.value = value;
}
}
class HeaderID {
String ID = "";
Date cal;
ElementID[] elementID;
public HeaderID (String ID, Calender cal, ElementID[] elemID) {
this.ID = ID;
this.cal = cal;
this.elementID = elemID;
}
}
Now in another class inside a function i need to instantiate the HeaderID class.
And this is what i did so far and it doesn't work. The problem am facing is with regard to creating a single array of ElementID.
ElementID[] e = new ElementID[1];
e[0] = new ElementID("NAME", "VALUE");
// Error at this line
HeaderID ht = new HeaderID("ID", new Date(), e);
You cannot cast direct from Date to Calendar:
You declared:
public HeaderID (String ID, Calender cal, ElementID[] elemID) {
and you try to call:
HeaderID ht = new HeaderID("ID", new Date(), e); //Error at this line
// ^ this is expecting a Calendar Instance
OPTION A: You can change you declaration
public HeaderID (String ID, Date date, ElementID[] elemID) {
If you do this use your actual call:
HeaderID ht = new HeaderID("ID", new Date(), e);
OPTION B: change what you send to your actual declaration:
// create new calendar instance
Calendar cal = Calendar.getInstance();
// put desired Date
cal.setTime(new Date());
// make call with correct variable types
HeaderID ht = new HeaderID("ID", cal, e);

Parsing Date in string Database using getters/setters

I'm trying to get a Date to Gmt+7 from listview Adapter :
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
_teamlist.clear();
db = new DBHelper(getApplicationContext());
db.getWritableDatabase();
ArrayList<TeamModel> team_list = getTeams2();
for (int i = 0; i < team_list.size(); i++) {
String tdate = team_list.get(i).getTeamdate();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
sdf.setTimeZone(TimeZone.getTimeZone("GMT+7"));
Date datex = null;
try {
datex = sdf.parse(tdate);
} catch (ParseException e) {
e.printStackTrace();
}
TeamModel _TeamModel = new TeamModel();
_TeamModel.setTeamdate(datex); ///// here the probleme !!!!!
_teamlist.add(_TeamModel);
}
}
in this line '_TeamModel.setTeamdate(datex)' the error : "setTeamdate java.lang.String in TeamModel cannot be applied to java.util.Date "
My get/set class TeamModel:
public class TeamModel {
public String teamdate="";
....
public String getTeamdate() {
return teamdate;
}
public void setTeamdate(String teamdate) {
this.teamdate = teamdate;
}
}
i tried to change teamdate in this class to date from string but it mess up my DBHelper
thanks to "mithrop" for his help, this's what i did to fix the problem :
String tname = team_list.get(i).getTeamname();
String topponent = team_list.get(i).getTeamopponent();
String tdate111 = team_list.get(i).getTeamdate();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
sdf.setTimeZone(TimeZone.getTimeZone("GMT+9"));
Date datex = null;
try {
datex = sdf.parse(tdate111);
} catch (ParseException e) {
e.printStackTrace();
}
sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
String tdate = sdf.format(datex);
System.out.println(tdate);
TeamModel _TeamModel = new TeamModel();
_TeamModel.setTeamname(tname);
_TeamModel.setTeamopponent(topponent);
_TeamModel.setTeamdate(tdate);
_teamlist.add(_TeamModel);

Categories