id
int64
22
34.9k
comment_id
int64
0
328
comment
stringlengths
2
2.55k
code
stringlengths
31
107k
classification
stringclasses
6 values
isFinished
bool
1 class
code_context_2
stringlengths
21
27.3k
code_context_10
stringlengths
29
27.3k
code_context_20
stringlengths
29
27.3k
15,951
9
// A Mate stages
public ExpressionStageOptions generateExpressionStageOptions() { List<String> allExpressionStagesRaw = retrieveExpressionStages.getDmelanogasterExpressionStages(); ExpressionStageOptions expressionStageOptions = new ExpressionStageOptions(); List<ExpressionStageGroup> expressionStageGroupList = new LinkedList<ExpressionStageGroup>(); List<ExpressionStage> allExpressionStages = new ArrayList<ExpressionStage>(allExpressionStagesRaw.size()); int idCounter = 0; for (String expressionStageString : allExpressionStagesRaw) { ExpressionStage expressionStage = new ExpressionStage(); expressionStage.setExpressionStageTitle(expressionStageString); expressionStage.setExpressionStageId("stage" + idCounter); expressionStage.setExpressionStageNumericalId(idCounter); allExpressionStages.add(expressionStage); idCounter++; } // Add expressionStageList to returned object expressionStageOptions.setExpressionStageList(allExpressionStages); /* * Add embryogenesis expressionStageGroup */ ExpressionStageGroup embryologyExpressionStageGroup = new ExpressionStageGroup(); embryologyExpressionStageGroup.setGroupTitle("embryogenesis"); embryologyExpressionStageGroup.setGroupId("group" + 0); embryologyExpressionStageGroup.setGroupNumericalId(0); List<ExpressionStage> embryologyExpressionStageList = new LinkedList<ExpressionStage>(); // Add embryo stages for (int i = 56; i <= 67; i++) { embryologyExpressionStageList.add(allExpressionStages.get(i)); } embryologyExpressionStageGroup.setExpressionStageList(embryologyExpressionStageList); expressionStageGroupList.add(embryologyExpressionStageGroup); /* * Add development expressionStageGroup */ ExpressionStageGroup developmentExpressionStageGroup = new ExpressionStageGroup(); developmentExpressionStageGroup.setGroupTitle("development"); developmentExpressionStageGroup.setGroupId("group" + 1); developmentExpressionStageGroup.setGroupNumericalId(1); List<ExpressionStage> developmentExpressionStageList = new LinkedList<ExpressionStage>(); // Add embryo stages for (int i = 56; i <= 67; i++) { developmentExpressionStageList.add(allExpressionStages.get(i)); } // larva stages for (int i = 75; i <= 81; i++) { developmentExpressionStageList.add(allExpressionStages.get(i)); } developmentExpressionStageList.add(allExpressionStages.get(97)); for (int i = 49; i <= 54; i++) { developmentExpressionStageList.add(allExpressionStages.get(i)); } for (int i = 38; i <= 41; i++) { developmentExpressionStageList.add(allExpressionStages.get(i)); } // TODO: Add the others developmentExpressionStageList.add(allExpressionStages.get(19)); developmentExpressionStageList.add(allExpressionStages.get(44)); developmentExpressionStageGroup.setExpressionStageList(developmentExpressionStageList); expressionStageGroupList.add(developmentExpressionStageGroup); /* * Add tissue expressionStageGroup */ ExpressionStageGroup tissueExpressionStageGroup = new ExpressionStageGroup(); tissueExpressionStageGroup.setGroupTitle("tissue"); tissueExpressionStageGroup.setGroupId("group" + 2); tissueExpressionStageGroup.setGroupNumericalId(2); List<ExpressionStage> tissueExpressionStageList = new LinkedList<ExpressionStage>(); // A Mate stages for (int i = 11; i <= 29; i++) { tissueExpressionStageList.add(allExpressionStages.get(i)); } for (int i = 32; i <= 37; i++) { tissueExpressionStageList.add(allExpressionStages.get(i)); } for (int i = 42; i <= 43; i++) { tissueExpressionStageList.add(allExpressionStages.get(i)); } for (int i = 47; i <= 48; i++) { tissueExpressionStageList.add(allExpressionStages.get(i)); } tissueExpressionStageGroup.setExpressionStageList(tissueExpressionStageList); expressionStageGroupList.add(tissueExpressionStageGroup); /* * Add treatment expressionStageGroup */ ExpressionStageGroup treatmentExpressionStageGroup = new ExpressionStageGroup(); treatmentExpressionStageGroup.setGroupTitle("treatment"); treatmentExpressionStageGroup.setGroupId("group" + 3); treatmentExpressionStageGroup.setGroupNumericalId(3); List<ExpressionStage> treatmentExpressionStageList = new LinkedList<ExpressionStage>(); // larva stages for (int i = 82; i <= 90; i++) { treatmentExpressionStageList.add(allExpressionStages.get(i)); } for (int i = 0; i <= 10; i++) { treatmentExpressionStageList.add(allExpressionStages.get(i)); } treatmentExpressionStageGroup.setExpressionStageList(treatmentExpressionStageList); expressionStageGroupList.add(treatmentExpressionStageGroup); /* * Add cell-line expressionStageGroup */ ExpressionStageGroup cellLineExpressionStageGroup = new ExpressionStageGroup(); cellLineExpressionStageGroup.setGroupTitle("cell-line"); cellLineExpressionStageGroup.setGroupId("group" + 4); cellLineExpressionStageGroup.setGroupNumericalId(4); List<ExpressionStage> cellLineExpressionStageList = new LinkedList<ExpressionStage>(); // Add embryo stages for (int i = 98; i <= 103; i++) { cellLineExpressionStageList.add(allExpressionStages.get(i)); } // larva stages for (int i = 68; i <= 74; i++) { cellLineExpressionStageList.add(allExpressionStages.get(i)); } for (int i = 91; i <= 96; i++) { cellLineExpressionStageList.add(allExpressionStages.get(i)); } for (int i = 45; i <= 46; i++) { cellLineExpressionStageList.add(allExpressionStages.get(i)); } for (int i = 30; i <= 31; i++) { cellLineExpressionStageList.add(allExpressionStages.get(i)); } cellLineExpressionStageList.add(allExpressionStages.get(55)); // TODO: Add the others cellLineExpressionStageGroup.setExpressionStageList(cellLineExpressionStageList); expressionStageGroupList.add(cellLineExpressionStageGroup); expressionStageOptions.setExpressionStageGroupList(expressionStageGroupList); return expressionStageOptions; }
NONSATD
true
tissueExpressionStageGroup.setGroupNumericalId(2); List<ExpressionStage> tissueExpressionStageList = new LinkedList<ExpressionStage>(); // A Mate stages for (int i = 11; i <= 29; i++) { tissueExpressionStageList.add(allExpressionStages.get(i));
developmentExpressionStageGroup.setExpressionStageList(developmentExpressionStageList); expressionStageGroupList.add(developmentExpressionStageGroup); /* * Add tissue expressionStageGroup */ ExpressionStageGroup tissueExpressionStageGroup = new ExpressionStageGroup(); tissueExpressionStageGroup.setGroupTitle("tissue"); tissueExpressionStageGroup.setGroupId("group" + 2); tissueExpressionStageGroup.setGroupNumericalId(2); List<ExpressionStage> tissueExpressionStageList = new LinkedList<ExpressionStage>(); // A Mate stages for (int i = 11; i <= 29; i++) { tissueExpressionStageList.add(allExpressionStages.get(i)); } for (int i = 32; i <= 37; i++) { tissueExpressionStageList.add(allExpressionStages.get(i)); } for (int i = 42; i <= 43; i++) { tissueExpressionStageList.add(allExpressionStages.get(i)); } for (int i = 47; i <= 48; i++) {
developmentExpressionStageList.add(allExpressionStages.get(97)); for (int i = 49; i <= 54; i++) { developmentExpressionStageList.add(allExpressionStages.get(i)); } for (int i = 38; i <= 41; i++) { developmentExpressionStageList.add(allExpressionStages.get(i)); } // TODO: Add the others developmentExpressionStageList.add(allExpressionStages.get(19)); developmentExpressionStageList.add(allExpressionStages.get(44)); developmentExpressionStageGroup.setExpressionStageList(developmentExpressionStageList); expressionStageGroupList.add(developmentExpressionStageGroup); /* * Add tissue expressionStageGroup */ ExpressionStageGroup tissueExpressionStageGroup = new ExpressionStageGroup(); tissueExpressionStageGroup.setGroupTitle("tissue"); tissueExpressionStageGroup.setGroupId("group" + 2); tissueExpressionStageGroup.setGroupNumericalId(2); List<ExpressionStage> tissueExpressionStageList = new LinkedList<ExpressionStage>(); // A Mate stages for (int i = 11; i <= 29; i++) { tissueExpressionStageList.add(allExpressionStages.get(i)); } for (int i = 32; i <= 37; i++) { tissueExpressionStageList.add(allExpressionStages.get(i)); } for (int i = 42; i <= 43; i++) { tissueExpressionStageList.add(allExpressionStages.get(i)); } for (int i = 47; i <= 48; i++) { tissueExpressionStageList.add(allExpressionStages.get(i)); } tissueExpressionStageGroup.setExpressionStageList(tissueExpressionStageList); expressionStageGroupList.add(tissueExpressionStageGroup); /* * Add treatment expressionStageGroup */ ExpressionStageGroup treatmentExpressionStageGroup = new ExpressionStageGroup(); treatmentExpressionStageGroup.setGroupTitle("treatment"); treatmentExpressionStageGroup.setGroupId("group" + 3);
15,951
10
/* * Add treatment expressionStageGroup */
public ExpressionStageOptions generateExpressionStageOptions() { List<String> allExpressionStagesRaw = retrieveExpressionStages.getDmelanogasterExpressionStages(); ExpressionStageOptions expressionStageOptions = new ExpressionStageOptions(); List<ExpressionStageGroup> expressionStageGroupList = new LinkedList<ExpressionStageGroup>(); List<ExpressionStage> allExpressionStages = new ArrayList<ExpressionStage>(allExpressionStagesRaw.size()); int idCounter = 0; for (String expressionStageString : allExpressionStagesRaw) { ExpressionStage expressionStage = new ExpressionStage(); expressionStage.setExpressionStageTitle(expressionStageString); expressionStage.setExpressionStageId("stage" + idCounter); expressionStage.setExpressionStageNumericalId(idCounter); allExpressionStages.add(expressionStage); idCounter++; } // Add expressionStageList to returned object expressionStageOptions.setExpressionStageList(allExpressionStages); /* * Add embryogenesis expressionStageGroup */ ExpressionStageGroup embryologyExpressionStageGroup = new ExpressionStageGroup(); embryologyExpressionStageGroup.setGroupTitle("embryogenesis"); embryologyExpressionStageGroup.setGroupId("group" + 0); embryologyExpressionStageGroup.setGroupNumericalId(0); List<ExpressionStage> embryologyExpressionStageList = new LinkedList<ExpressionStage>(); // Add embryo stages for (int i = 56; i <= 67; i++) { embryologyExpressionStageList.add(allExpressionStages.get(i)); } embryologyExpressionStageGroup.setExpressionStageList(embryologyExpressionStageList); expressionStageGroupList.add(embryologyExpressionStageGroup); /* * Add development expressionStageGroup */ ExpressionStageGroup developmentExpressionStageGroup = new ExpressionStageGroup(); developmentExpressionStageGroup.setGroupTitle("development"); developmentExpressionStageGroup.setGroupId("group" + 1); developmentExpressionStageGroup.setGroupNumericalId(1); List<ExpressionStage> developmentExpressionStageList = new LinkedList<ExpressionStage>(); // Add embryo stages for (int i = 56; i <= 67; i++) { developmentExpressionStageList.add(allExpressionStages.get(i)); } // larva stages for (int i = 75; i <= 81; i++) { developmentExpressionStageList.add(allExpressionStages.get(i)); } developmentExpressionStageList.add(allExpressionStages.get(97)); for (int i = 49; i <= 54; i++) { developmentExpressionStageList.add(allExpressionStages.get(i)); } for (int i = 38; i <= 41; i++) { developmentExpressionStageList.add(allExpressionStages.get(i)); } // TODO: Add the others developmentExpressionStageList.add(allExpressionStages.get(19)); developmentExpressionStageList.add(allExpressionStages.get(44)); developmentExpressionStageGroup.setExpressionStageList(developmentExpressionStageList); expressionStageGroupList.add(developmentExpressionStageGroup); /* * Add tissue expressionStageGroup */ ExpressionStageGroup tissueExpressionStageGroup = new ExpressionStageGroup(); tissueExpressionStageGroup.setGroupTitle("tissue"); tissueExpressionStageGroup.setGroupId("group" + 2); tissueExpressionStageGroup.setGroupNumericalId(2); List<ExpressionStage> tissueExpressionStageList = new LinkedList<ExpressionStage>(); // A Mate stages for (int i = 11; i <= 29; i++) { tissueExpressionStageList.add(allExpressionStages.get(i)); } for (int i = 32; i <= 37; i++) { tissueExpressionStageList.add(allExpressionStages.get(i)); } for (int i = 42; i <= 43; i++) { tissueExpressionStageList.add(allExpressionStages.get(i)); } for (int i = 47; i <= 48; i++) { tissueExpressionStageList.add(allExpressionStages.get(i)); } tissueExpressionStageGroup.setExpressionStageList(tissueExpressionStageList); expressionStageGroupList.add(tissueExpressionStageGroup); /* * Add treatment expressionStageGroup */ ExpressionStageGroup treatmentExpressionStageGroup = new ExpressionStageGroup(); treatmentExpressionStageGroup.setGroupTitle("treatment"); treatmentExpressionStageGroup.setGroupId("group" + 3); treatmentExpressionStageGroup.setGroupNumericalId(3); List<ExpressionStage> treatmentExpressionStageList = new LinkedList<ExpressionStage>(); // larva stages for (int i = 82; i <= 90; i++) { treatmentExpressionStageList.add(allExpressionStages.get(i)); } for (int i = 0; i <= 10; i++) { treatmentExpressionStageList.add(allExpressionStages.get(i)); } treatmentExpressionStageGroup.setExpressionStageList(treatmentExpressionStageList); expressionStageGroupList.add(treatmentExpressionStageGroup); /* * Add cell-line expressionStageGroup */ ExpressionStageGroup cellLineExpressionStageGroup = new ExpressionStageGroup(); cellLineExpressionStageGroup.setGroupTitle("cell-line"); cellLineExpressionStageGroup.setGroupId("group" + 4); cellLineExpressionStageGroup.setGroupNumericalId(4); List<ExpressionStage> cellLineExpressionStageList = new LinkedList<ExpressionStage>(); // Add embryo stages for (int i = 98; i <= 103; i++) { cellLineExpressionStageList.add(allExpressionStages.get(i)); } // larva stages for (int i = 68; i <= 74; i++) { cellLineExpressionStageList.add(allExpressionStages.get(i)); } for (int i = 91; i <= 96; i++) { cellLineExpressionStageList.add(allExpressionStages.get(i)); } for (int i = 45; i <= 46; i++) { cellLineExpressionStageList.add(allExpressionStages.get(i)); } for (int i = 30; i <= 31; i++) { cellLineExpressionStageList.add(allExpressionStages.get(i)); } cellLineExpressionStageList.add(allExpressionStages.get(55)); // TODO: Add the others cellLineExpressionStageGroup.setExpressionStageList(cellLineExpressionStageList); expressionStageGroupList.add(cellLineExpressionStageGroup); expressionStageOptions.setExpressionStageGroupList(expressionStageGroupList); return expressionStageOptions; }
NONSATD
true
// Add expressionStageList to returned object expressionStageOptions.setExpressionStageList(allExpressionStages); /* * Add embryogenesis expressionStageGroup */ ExpressionStageGroup embryologyExpressionStageGroup = new ExpressionStageGroup(); embryologyExpressionStageGroup.setGroupTitle("embryogenesis");
for (String expressionStageString : allExpressionStagesRaw) { ExpressionStage expressionStage = new ExpressionStage(); expressionStage.setExpressionStageTitle(expressionStageString); expressionStage.setExpressionStageId("stage" + idCounter); expressionStage.setExpressionStageNumericalId(idCounter); allExpressionStages.add(expressionStage); idCounter++; } // Add expressionStageList to returned object expressionStageOptions.setExpressionStageList(allExpressionStages); /* * Add embryogenesis expressionStageGroup */ ExpressionStageGroup embryologyExpressionStageGroup = new ExpressionStageGroup(); embryologyExpressionStageGroup.setGroupTitle("embryogenesis"); embryologyExpressionStageGroup.setGroupId("group" + 0); embryologyExpressionStageGroup.setGroupNumericalId(0); List<ExpressionStage> embryologyExpressionStageList = new LinkedList<ExpressionStage>(); // Add embryo stages for (int i = 56; i <= 67; i++) { embryologyExpressionStageList.add(allExpressionStages.get(i)); } embryologyExpressionStageGroup.setExpressionStageList(embryologyExpressionStageList);
public ExpressionStageOptions generateExpressionStageOptions() { List<String> allExpressionStagesRaw = retrieveExpressionStages.getDmelanogasterExpressionStages(); ExpressionStageOptions expressionStageOptions = new ExpressionStageOptions(); List<ExpressionStageGroup> expressionStageGroupList = new LinkedList<ExpressionStageGroup>(); List<ExpressionStage> allExpressionStages = new ArrayList<ExpressionStage>(allExpressionStagesRaw.size()); int idCounter = 0; for (String expressionStageString : allExpressionStagesRaw) { ExpressionStage expressionStage = new ExpressionStage(); expressionStage.setExpressionStageTitle(expressionStageString); expressionStage.setExpressionStageId("stage" + idCounter); expressionStage.setExpressionStageNumericalId(idCounter); allExpressionStages.add(expressionStage); idCounter++; } // Add expressionStageList to returned object expressionStageOptions.setExpressionStageList(allExpressionStages); /* * Add embryogenesis expressionStageGroup */ ExpressionStageGroup embryologyExpressionStageGroup = new ExpressionStageGroup(); embryologyExpressionStageGroup.setGroupTitle("embryogenesis"); embryologyExpressionStageGroup.setGroupId("group" + 0); embryologyExpressionStageGroup.setGroupNumericalId(0); List<ExpressionStage> embryologyExpressionStageList = new LinkedList<ExpressionStage>(); // Add embryo stages for (int i = 56; i <= 67; i++) { embryologyExpressionStageList.add(allExpressionStages.get(i)); } embryologyExpressionStageGroup.setExpressionStageList(embryologyExpressionStageList); expressionStageGroupList.add(embryologyExpressionStageGroup); /* * Add development expressionStageGroup */ ExpressionStageGroup developmentExpressionStageGroup = new ExpressionStageGroup(); developmentExpressionStageGroup.setGroupTitle("development"); developmentExpressionStageGroup.setGroupId("group" + 1); developmentExpressionStageGroup.setGroupNumericalId(1); List<ExpressionStage> developmentExpressionStageList = new LinkedList<ExpressionStage>(); // Add embryo stages
15,951
11
// larva stages
public ExpressionStageOptions generateExpressionStageOptions() { List<String> allExpressionStagesRaw = retrieveExpressionStages.getDmelanogasterExpressionStages(); ExpressionStageOptions expressionStageOptions = new ExpressionStageOptions(); List<ExpressionStageGroup> expressionStageGroupList = new LinkedList<ExpressionStageGroup>(); List<ExpressionStage> allExpressionStages = new ArrayList<ExpressionStage>(allExpressionStagesRaw.size()); int idCounter = 0; for (String expressionStageString : allExpressionStagesRaw) { ExpressionStage expressionStage = new ExpressionStage(); expressionStage.setExpressionStageTitle(expressionStageString); expressionStage.setExpressionStageId("stage" + idCounter); expressionStage.setExpressionStageNumericalId(idCounter); allExpressionStages.add(expressionStage); idCounter++; } // Add expressionStageList to returned object expressionStageOptions.setExpressionStageList(allExpressionStages); /* * Add embryogenesis expressionStageGroup */ ExpressionStageGroup embryologyExpressionStageGroup = new ExpressionStageGroup(); embryologyExpressionStageGroup.setGroupTitle("embryogenesis"); embryologyExpressionStageGroup.setGroupId("group" + 0); embryologyExpressionStageGroup.setGroupNumericalId(0); List<ExpressionStage> embryologyExpressionStageList = new LinkedList<ExpressionStage>(); // Add embryo stages for (int i = 56; i <= 67; i++) { embryologyExpressionStageList.add(allExpressionStages.get(i)); } embryologyExpressionStageGroup.setExpressionStageList(embryologyExpressionStageList); expressionStageGroupList.add(embryologyExpressionStageGroup); /* * Add development expressionStageGroup */ ExpressionStageGroup developmentExpressionStageGroup = new ExpressionStageGroup(); developmentExpressionStageGroup.setGroupTitle("development"); developmentExpressionStageGroup.setGroupId("group" + 1); developmentExpressionStageGroup.setGroupNumericalId(1); List<ExpressionStage> developmentExpressionStageList = new LinkedList<ExpressionStage>(); // Add embryo stages for (int i = 56; i <= 67; i++) { developmentExpressionStageList.add(allExpressionStages.get(i)); } // larva stages for (int i = 75; i <= 81; i++) { developmentExpressionStageList.add(allExpressionStages.get(i)); } developmentExpressionStageList.add(allExpressionStages.get(97)); for (int i = 49; i <= 54; i++) { developmentExpressionStageList.add(allExpressionStages.get(i)); } for (int i = 38; i <= 41; i++) { developmentExpressionStageList.add(allExpressionStages.get(i)); } // TODO: Add the others developmentExpressionStageList.add(allExpressionStages.get(19)); developmentExpressionStageList.add(allExpressionStages.get(44)); developmentExpressionStageGroup.setExpressionStageList(developmentExpressionStageList); expressionStageGroupList.add(developmentExpressionStageGroup); /* * Add tissue expressionStageGroup */ ExpressionStageGroup tissueExpressionStageGroup = new ExpressionStageGroup(); tissueExpressionStageGroup.setGroupTitle("tissue"); tissueExpressionStageGroup.setGroupId("group" + 2); tissueExpressionStageGroup.setGroupNumericalId(2); List<ExpressionStage> tissueExpressionStageList = new LinkedList<ExpressionStage>(); // A Mate stages for (int i = 11; i <= 29; i++) { tissueExpressionStageList.add(allExpressionStages.get(i)); } for (int i = 32; i <= 37; i++) { tissueExpressionStageList.add(allExpressionStages.get(i)); } for (int i = 42; i <= 43; i++) { tissueExpressionStageList.add(allExpressionStages.get(i)); } for (int i = 47; i <= 48; i++) { tissueExpressionStageList.add(allExpressionStages.get(i)); } tissueExpressionStageGroup.setExpressionStageList(tissueExpressionStageList); expressionStageGroupList.add(tissueExpressionStageGroup); /* * Add treatment expressionStageGroup */ ExpressionStageGroup treatmentExpressionStageGroup = new ExpressionStageGroup(); treatmentExpressionStageGroup.setGroupTitle("treatment"); treatmentExpressionStageGroup.setGroupId("group" + 3); treatmentExpressionStageGroup.setGroupNumericalId(3); List<ExpressionStage> treatmentExpressionStageList = new LinkedList<ExpressionStage>(); // larva stages for (int i = 82; i <= 90; i++) { treatmentExpressionStageList.add(allExpressionStages.get(i)); } for (int i = 0; i <= 10; i++) { treatmentExpressionStageList.add(allExpressionStages.get(i)); } treatmentExpressionStageGroup.setExpressionStageList(treatmentExpressionStageList); expressionStageGroupList.add(treatmentExpressionStageGroup); /* * Add cell-line expressionStageGroup */ ExpressionStageGroup cellLineExpressionStageGroup = new ExpressionStageGroup(); cellLineExpressionStageGroup.setGroupTitle("cell-line"); cellLineExpressionStageGroup.setGroupId("group" + 4); cellLineExpressionStageGroup.setGroupNumericalId(4); List<ExpressionStage> cellLineExpressionStageList = new LinkedList<ExpressionStage>(); // Add embryo stages for (int i = 98; i <= 103; i++) { cellLineExpressionStageList.add(allExpressionStages.get(i)); } // larva stages for (int i = 68; i <= 74; i++) { cellLineExpressionStageList.add(allExpressionStages.get(i)); } for (int i = 91; i <= 96; i++) { cellLineExpressionStageList.add(allExpressionStages.get(i)); } for (int i = 45; i <= 46; i++) { cellLineExpressionStageList.add(allExpressionStages.get(i)); } for (int i = 30; i <= 31; i++) { cellLineExpressionStageList.add(allExpressionStages.get(i)); } cellLineExpressionStageList.add(allExpressionStages.get(55)); // TODO: Add the others cellLineExpressionStageGroup.setExpressionStageList(cellLineExpressionStageList); expressionStageGroupList.add(cellLineExpressionStageGroup); expressionStageOptions.setExpressionStageGroupList(expressionStageGroupList); return expressionStageOptions; }
NONSATD
true
developmentExpressionStageList.add(allExpressionStages.get(i)); } // larva stages for (int i = 75; i <= 81; i++) { developmentExpressionStageList.add(allExpressionStages.get(i));
*/ ExpressionStageGroup developmentExpressionStageGroup = new ExpressionStageGroup(); developmentExpressionStageGroup.setGroupTitle("development"); developmentExpressionStageGroup.setGroupId("group" + 1); developmentExpressionStageGroup.setGroupNumericalId(1); List<ExpressionStage> developmentExpressionStageList = new LinkedList<ExpressionStage>(); // Add embryo stages for (int i = 56; i <= 67; i++) { developmentExpressionStageList.add(allExpressionStages.get(i)); } // larva stages for (int i = 75; i <= 81; i++) { developmentExpressionStageList.add(allExpressionStages.get(i)); } developmentExpressionStageList.add(allExpressionStages.get(97)); for (int i = 49; i <= 54; i++) { developmentExpressionStageList.add(allExpressionStages.get(i)); } for (int i = 38; i <= 41; i++) { developmentExpressionStageList.add(allExpressionStages.get(i)); }
embryologyExpressionStageGroup.setGroupNumericalId(0); List<ExpressionStage> embryologyExpressionStageList = new LinkedList<ExpressionStage>(); // Add embryo stages for (int i = 56; i <= 67; i++) { embryologyExpressionStageList.add(allExpressionStages.get(i)); } embryologyExpressionStageGroup.setExpressionStageList(embryologyExpressionStageList); expressionStageGroupList.add(embryologyExpressionStageGroup); /* * Add development expressionStageGroup */ ExpressionStageGroup developmentExpressionStageGroup = new ExpressionStageGroup(); developmentExpressionStageGroup.setGroupTitle("development"); developmentExpressionStageGroup.setGroupId("group" + 1); developmentExpressionStageGroup.setGroupNumericalId(1); List<ExpressionStage> developmentExpressionStageList = new LinkedList<ExpressionStage>(); // Add embryo stages for (int i = 56; i <= 67; i++) { developmentExpressionStageList.add(allExpressionStages.get(i)); } // larva stages for (int i = 75; i <= 81; i++) { developmentExpressionStageList.add(allExpressionStages.get(i)); } developmentExpressionStageList.add(allExpressionStages.get(97)); for (int i = 49; i <= 54; i++) { developmentExpressionStageList.add(allExpressionStages.get(i)); } for (int i = 38; i <= 41; i++) { developmentExpressionStageList.add(allExpressionStages.get(i)); } // TODO: Add the others developmentExpressionStageList.add(allExpressionStages.get(19)); developmentExpressionStageList.add(allExpressionStages.get(44)); developmentExpressionStageGroup.setExpressionStageList(developmentExpressionStageList); expressionStageGroupList.add(developmentExpressionStageGroup); /* * Add tissue expressionStageGroup */ ExpressionStageGroup tissueExpressionStageGroup = new ExpressionStageGroup(); tissueExpressionStageGroup.setGroupTitle("tissue");
15,951
12
/* * Add cell-line expressionStageGroup */
public ExpressionStageOptions generateExpressionStageOptions() { List<String> allExpressionStagesRaw = retrieveExpressionStages.getDmelanogasterExpressionStages(); ExpressionStageOptions expressionStageOptions = new ExpressionStageOptions(); List<ExpressionStageGroup> expressionStageGroupList = new LinkedList<ExpressionStageGroup>(); List<ExpressionStage> allExpressionStages = new ArrayList<ExpressionStage>(allExpressionStagesRaw.size()); int idCounter = 0; for (String expressionStageString : allExpressionStagesRaw) { ExpressionStage expressionStage = new ExpressionStage(); expressionStage.setExpressionStageTitle(expressionStageString); expressionStage.setExpressionStageId("stage" + idCounter); expressionStage.setExpressionStageNumericalId(idCounter); allExpressionStages.add(expressionStage); idCounter++; } // Add expressionStageList to returned object expressionStageOptions.setExpressionStageList(allExpressionStages); /* * Add embryogenesis expressionStageGroup */ ExpressionStageGroup embryologyExpressionStageGroup = new ExpressionStageGroup(); embryologyExpressionStageGroup.setGroupTitle("embryogenesis"); embryologyExpressionStageGroup.setGroupId("group" + 0); embryologyExpressionStageGroup.setGroupNumericalId(0); List<ExpressionStage> embryologyExpressionStageList = new LinkedList<ExpressionStage>(); // Add embryo stages for (int i = 56; i <= 67; i++) { embryologyExpressionStageList.add(allExpressionStages.get(i)); } embryologyExpressionStageGroup.setExpressionStageList(embryologyExpressionStageList); expressionStageGroupList.add(embryologyExpressionStageGroup); /* * Add development expressionStageGroup */ ExpressionStageGroup developmentExpressionStageGroup = new ExpressionStageGroup(); developmentExpressionStageGroup.setGroupTitle("development"); developmentExpressionStageGroup.setGroupId("group" + 1); developmentExpressionStageGroup.setGroupNumericalId(1); List<ExpressionStage> developmentExpressionStageList = new LinkedList<ExpressionStage>(); // Add embryo stages for (int i = 56; i <= 67; i++) { developmentExpressionStageList.add(allExpressionStages.get(i)); } // larva stages for (int i = 75; i <= 81; i++) { developmentExpressionStageList.add(allExpressionStages.get(i)); } developmentExpressionStageList.add(allExpressionStages.get(97)); for (int i = 49; i <= 54; i++) { developmentExpressionStageList.add(allExpressionStages.get(i)); } for (int i = 38; i <= 41; i++) { developmentExpressionStageList.add(allExpressionStages.get(i)); } // TODO: Add the others developmentExpressionStageList.add(allExpressionStages.get(19)); developmentExpressionStageList.add(allExpressionStages.get(44)); developmentExpressionStageGroup.setExpressionStageList(developmentExpressionStageList); expressionStageGroupList.add(developmentExpressionStageGroup); /* * Add tissue expressionStageGroup */ ExpressionStageGroup tissueExpressionStageGroup = new ExpressionStageGroup(); tissueExpressionStageGroup.setGroupTitle("tissue"); tissueExpressionStageGroup.setGroupId("group" + 2); tissueExpressionStageGroup.setGroupNumericalId(2); List<ExpressionStage> tissueExpressionStageList = new LinkedList<ExpressionStage>(); // A Mate stages for (int i = 11; i <= 29; i++) { tissueExpressionStageList.add(allExpressionStages.get(i)); } for (int i = 32; i <= 37; i++) { tissueExpressionStageList.add(allExpressionStages.get(i)); } for (int i = 42; i <= 43; i++) { tissueExpressionStageList.add(allExpressionStages.get(i)); } for (int i = 47; i <= 48; i++) { tissueExpressionStageList.add(allExpressionStages.get(i)); } tissueExpressionStageGroup.setExpressionStageList(tissueExpressionStageList); expressionStageGroupList.add(tissueExpressionStageGroup); /* * Add treatment expressionStageGroup */ ExpressionStageGroup treatmentExpressionStageGroup = new ExpressionStageGroup(); treatmentExpressionStageGroup.setGroupTitle("treatment"); treatmentExpressionStageGroup.setGroupId("group" + 3); treatmentExpressionStageGroup.setGroupNumericalId(3); List<ExpressionStage> treatmentExpressionStageList = new LinkedList<ExpressionStage>(); // larva stages for (int i = 82; i <= 90; i++) { treatmentExpressionStageList.add(allExpressionStages.get(i)); } for (int i = 0; i <= 10; i++) { treatmentExpressionStageList.add(allExpressionStages.get(i)); } treatmentExpressionStageGroup.setExpressionStageList(treatmentExpressionStageList); expressionStageGroupList.add(treatmentExpressionStageGroup); /* * Add cell-line expressionStageGroup */ ExpressionStageGroup cellLineExpressionStageGroup = new ExpressionStageGroup(); cellLineExpressionStageGroup.setGroupTitle("cell-line"); cellLineExpressionStageGroup.setGroupId("group" + 4); cellLineExpressionStageGroup.setGroupNumericalId(4); List<ExpressionStage> cellLineExpressionStageList = new LinkedList<ExpressionStage>(); // Add embryo stages for (int i = 98; i <= 103; i++) { cellLineExpressionStageList.add(allExpressionStages.get(i)); } // larva stages for (int i = 68; i <= 74; i++) { cellLineExpressionStageList.add(allExpressionStages.get(i)); } for (int i = 91; i <= 96; i++) { cellLineExpressionStageList.add(allExpressionStages.get(i)); } for (int i = 45; i <= 46; i++) { cellLineExpressionStageList.add(allExpressionStages.get(i)); } for (int i = 30; i <= 31; i++) { cellLineExpressionStageList.add(allExpressionStages.get(i)); } cellLineExpressionStageList.add(allExpressionStages.get(55)); // TODO: Add the others cellLineExpressionStageGroup.setExpressionStageList(cellLineExpressionStageList); expressionStageGroupList.add(cellLineExpressionStageGroup); expressionStageOptions.setExpressionStageGroupList(expressionStageGroupList); return expressionStageOptions; }
NONSATD
true
// Add expressionStageList to returned object expressionStageOptions.setExpressionStageList(allExpressionStages); /* * Add embryogenesis expressionStageGroup */ ExpressionStageGroup embryologyExpressionStageGroup = new ExpressionStageGroup(); embryologyExpressionStageGroup.setGroupTitle("embryogenesis");
for (String expressionStageString : allExpressionStagesRaw) { ExpressionStage expressionStage = new ExpressionStage(); expressionStage.setExpressionStageTitle(expressionStageString); expressionStage.setExpressionStageId("stage" + idCounter); expressionStage.setExpressionStageNumericalId(idCounter); allExpressionStages.add(expressionStage); idCounter++; } // Add expressionStageList to returned object expressionStageOptions.setExpressionStageList(allExpressionStages); /* * Add embryogenesis expressionStageGroup */ ExpressionStageGroup embryologyExpressionStageGroup = new ExpressionStageGroup(); embryologyExpressionStageGroup.setGroupTitle("embryogenesis"); embryologyExpressionStageGroup.setGroupId("group" + 0); embryologyExpressionStageGroup.setGroupNumericalId(0); List<ExpressionStage> embryologyExpressionStageList = new LinkedList<ExpressionStage>(); // Add embryo stages for (int i = 56; i <= 67; i++) { embryologyExpressionStageList.add(allExpressionStages.get(i)); } embryologyExpressionStageGroup.setExpressionStageList(embryologyExpressionStageList);
public ExpressionStageOptions generateExpressionStageOptions() { List<String> allExpressionStagesRaw = retrieveExpressionStages.getDmelanogasterExpressionStages(); ExpressionStageOptions expressionStageOptions = new ExpressionStageOptions(); List<ExpressionStageGroup> expressionStageGroupList = new LinkedList<ExpressionStageGroup>(); List<ExpressionStage> allExpressionStages = new ArrayList<ExpressionStage>(allExpressionStagesRaw.size()); int idCounter = 0; for (String expressionStageString : allExpressionStagesRaw) { ExpressionStage expressionStage = new ExpressionStage(); expressionStage.setExpressionStageTitle(expressionStageString); expressionStage.setExpressionStageId("stage" + idCounter); expressionStage.setExpressionStageNumericalId(idCounter); allExpressionStages.add(expressionStage); idCounter++; } // Add expressionStageList to returned object expressionStageOptions.setExpressionStageList(allExpressionStages); /* * Add embryogenesis expressionStageGroup */ ExpressionStageGroup embryologyExpressionStageGroup = new ExpressionStageGroup(); embryologyExpressionStageGroup.setGroupTitle("embryogenesis"); embryologyExpressionStageGroup.setGroupId("group" + 0); embryologyExpressionStageGroup.setGroupNumericalId(0); List<ExpressionStage> embryologyExpressionStageList = new LinkedList<ExpressionStage>(); // Add embryo stages for (int i = 56; i <= 67; i++) { embryologyExpressionStageList.add(allExpressionStages.get(i)); } embryologyExpressionStageGroup.setExpressionStageList(embryologyExpressionStageList); expressionStageGroupList.add(embryologyExpressionStageGroup); /* * Add development expressionStageGroup */ ExpressionStageGroup developmentExpressionStageGroup = new ExpressionStageGroup(); developmentExpressionStageGroup.setGroupTitle("development"); developmentExpressionStageGroup.setGroupId("group" + 1); developmentExpressionStageGroup.setGroupNumericalId(1); List<ExpressionStage> developmentExpressionStageList = new LinkedList<ExpressionStage>(); // Add embryo stages
15,951
13
// Add embryo stages
public ExpressionStageOptions generateExpressionStageOptions() { List<String> allExpressionStagesRaw = retrieveExpressionStages.getDmelanogasterExpressionStages(); ExpressionStageOptions expressionStageOptions = new ExpressionStageOptions(); List<ExpressionStageGroup> expressionStageGroupList = new LinkedList<ExpressionStageGroup>(); List<ExpressionStage> allExpressionStages = new ArrayList<ExpressionStage>(allExpressionStagesRaw.size()); int idCounter = 0; for (String expressionStageString : allExpressionStagesRaw) { ExpressionStage expressionStage = new ExpressionStage(); expressionStage.setExpressionStageTitle(expressionStageString); expressionStage.setExpressionStageId("stage" + idCounter); expressionStage.setExpressionStageNumericalId(idCounter); allExpressionStages.add(expressionStage); idCounter++; } // Add expressionStageList to returned object expressionStageOptions.setExpressionStageList(allExpressionStages); /* * Add embryogenesis expressionStageGroup */ ExpressionStageGroup embryologyExpressionStageGroup = new ExpressionStageGroup(); embryologyExpressionStageGroup.setGroupTitle("embryogenesis"); embryologyExpressionStageGroup.setGroupId("group" + 0); embryologyExpressionStageGroup.setGroupNumericalId(0); List<ExpressionStage> embryologyExpressionStageList = new LinkedList<ExpressionStage>(); // Add embryo stages for (int i = 56; i <= 67; i++) { embryologyExpressionStageList.add(allExpressionStages.get(i)); } embryologyExpressionStageGroup.setExpressionStageList(embryologyExpressionStageList); expressionStageGroupList.add(embryologyExpressionStageGroup); /* * Add development expressionStageGroup */ ExpressionStageGroup developmentExpressionStageGroup = new ExpressionStageGroup(); developmentExpressionStageGroup.setGroupTitle("development"); developmentExpressionStageGroup.setGroupId("group" + 1); developmentExpressionStageGroup.setGroupNumericalId(1); List<ExpressionStage> developmentExpressionStageList = new LinkedList<ExpressionStage>(); // Add embryo stages for (int i = 56; i <= 67; i++) { developmentExpressionStageList.add(allExpressionStages.get(i)); } // larva stages for (int i = 75; i <= 81; i++) { developmentExpressionStageList.add(allExpressionStages.get(i)); } developmentExpressionStageList.add(allExpressionStages.get(97)); for (int i = 49; i <= 54; i++) { developmentExpressionStageList.add(allExpressionStages.get(i)); } for (int i = 38; i <= 41; i++) { developmentExpressionStageList.add(allExpressionStages.get(i)); } // TODO: Add the others developmentExpressionStageList.add(allExpressionStages.get(19)); developmentExpressionStageList.add(allExpressionStages.get(44)); developmentExpressionStageGroup.setExpressionStageList(developmentExpressionStageList); expressionStageGroupList.add(developmentExpressionStageGroup); /* * Add tissue expressionStageGroup */ ExpressionStageGroup tissueExpressionStageGroup = new ExpressionStageGroup(); tissueExpressionStageGroup.setGroupTitle("tissue"); tissueExpressionStageGroup.setGroupId("group" + 2); tissueExpressionStageGroup.setGroupNumericalId(2); List<ExpressionStage> tissueExpressionStageList = new LinkedList<ExpressionStage>(); // A Mate stages for (int i = 11; i <= 29; i++) { tissueExpressionStageList.add(allExpressionStages.get(i)); } for (int i = 32; i <= 37; i++) { tissueExpressionStageList.add(allExpressionStages.get(i)); } for (int i = 42; i <= 43; i++) { tissueExpressionStageList.add(allExpressionStages.get(i)); } for (int i = 47; i <= 48; i++) { tissueExpressionStageList.add(allExpressionStages.get(i)); } tissueExpressionStageGroup.setExpressionStageList(tissueExpressionStageList); expressionStageGroupList.add(tissueExpressionStageGroup); /* * Add treatment expressionStageGroup */ ExpressionStageGroup treatmentExpressionStageGroup = new ExpressionStageGroup(); treatmentExpressionStageGroup.setGroupTitle("treatment"); treatmentExpressionStageGroup.setGroupId("group" + 3); treatmentExpressionStageGroup.setGroupNumericalId(3); List<ExpressionStage> treatmentExpressionStageList = new LinkedList<ExpressionStage>(); // larva stages for (int i = 82; i <= 90; i++) { treatmentExpressionStageList.add(allExpressionStages.get(i)); } for (int i = 0; i <= 10; i++) { treatmentExpressionStageList.add(allExpressionStages.get(i)); } treatmentExpressionStageGroup.setExpressionStageList(treatmentExpressionStageList); expressionStageGroupList.add(treatmentExpressionStageGroup); /* * Add cell-line expressionStageGroup */ ExpressionStageGroup cellLineExpressionStageGroup = new ExpressionStageGroup(); cellLineExpressionStageGroup.setGroupTitle("cell-line"); cellLineExpressionStageGroup.setGroupId("group" + 4); cellLineExpressionStageGroup.setGroupNumericalId(4); List<ExpressionStage> cellLineExpressionStageList = new LinkedList<ExpressionStage>(); // Add embryo stages for (int i = 98; i <= 103; i++) { cellLineExpressionStageList.add(allExpressionStages.get(i)); } // larva stages for (int i = 68; i <= 74; i++) { cellLineExpressionStageList.add(allExpressionStages.get(i)); } for (int i = 91; i <= 96; i++) { cellLineExpressionStageList.add(allExpressionStages.get(i)); } for (int i = 45; i <= 46; i++) { cellLineExpressionStageList.add(allExpressionStages.get(i)); } for (int i = 30; i <= 31; i++) { cellLineExpressionStageList.add(allExpressionStages.get(i)); } cellLineExpressionStageList.add(allExpressionStages.get(55)); // TODO: Add the others cellLineExpressionStageGroup.setExpressionStageList(cellLineExpressionStageList); expressionStageGroupList.add(cellLineExpressionStageGroup); expressionStageOptions.setExpressionStageGroupList(expressionStageGroupList); return expressionStageOptions; }
NONSATD
true
embryologyExpressionStageGroup.setGroupNumericalId(0); List<ExpressionStage> embryologyExpressionStageList = new LinkedList<ExpressionStage>(); // Add embryo stages for (int i = 56; i <= 67; i++) { embryologyExpressionStageList.add(allExpressionStages.get(i));
// Add expressionStageList to returned object expressionStageOptions.setExpressionStageList(allExpressionStages); /* * Add embryogenesis expressionStageGroup */ ExpressionStageGroup embryologyExpressionStageGroup = new ExpressionStageGroup(); embryologyExpressionStageGroup.setGroupTitle("embryogenesis"); embryologyExpressionStageGroup.setGroupId("group" + 0); embryologyExpressionStageGroup.setGroupNumericalId(0); List<ExpressionStage> embryologyExpressionStageList = new LinkedList<ExpressionStage>(); // Add embryo stages for (int i = 56; i <= 67; i++) { embryologyExpressionStageList.add(allExpressionStages.get(i)); } embryologyExpressionStageGroup.setExpressionStageList(embryologyExpressionStageList); expressionStageGroupList.add(embryologyExpressionStageGroup); /* * Add development expressionStageGroup */ ExpressionStageGroup developmentExpressionStageGroup = new ExpressionStageGroup(); developmentExpressionStageGroup.setGroupTitle("development");
List<ExpressionStage> allExpressionStages = new ArrayList<ExpressionStage>(allExpressionStagesRaw.size()); int idCounter = 0; for (String expressionStageString : allExpressionStagesRaw) { ExpressionStage expressionStage = new ExpressionStage(); expressionStage.setExpressionStageTitle(expressionStageString); expressionStage.setExpressionStageId("stage" + idCounter); expressionStage.setExpressionStageNumericalId(idCounter); allExpressionStages.add(expressionStage); idCounter++; } // Add expressionStageList to returned object expressionStageOptions.setExpressionStageList(allExpressionStages); /* * Add embryogenesis expressionStageGroup */ ExpressionStageGroup embryologyExpressionStageGroup = new ExpressionStageGroup(); embryologyExpressionStageGroup.setGroupTitle("embryogenesis"); embryologyExpressionStageGroup.setGroupId("group" + 0); embryologyExpressionStageGroup.setGroupNumericalId(0); List<ExpressionStage> embryologyExpressionStageList = new LinkedList<ExpressionStage>(); // Add embryo stages for (int i = 56; i <= 67; i++) { embryologyExpressionStageList.add(allExpressionStages.get(i)); } embryologyExpressionStageGroup.setExpressionStageList(embryologyExpressionStageList); expressionStageGroupList.add(embryologyExpressionStageGroup); /* * Add development expressionStageGroup */ ExpressionStageGroup developmentExpressionStageGroup = new ExpressionStageGroup(); developmentExpressionStageGroup.setGroupTitle("development"); developmentExpressionStageGroup.setGroupId("group" + 1); developmentExpressionStageGroup.setGroupNumericalId(1); List<ExpressionStage> developmentExpressionStageList = new LinkedList<ExpressionStage>(); // Add embryo stages for (int i = 56; i <= 67; i++) { developmentExpressionStageList.add(allExpressionStages.get(i)); } // larva stages for (int i = 75; i <= 81; i++) { developmentExpressionStageList.add(allExpressionStages.get(i));
15,951
14
// larva stages
public ExpressionStageOptions generateExpressionStageOptions() { List<String> allExpressionStagesRaw = retrieveExpressionStages.getDmelanogasterExpressionStages(); ExpressionStageOptions expressionStageOptions = new ExpressionStageOptions(); List<ExpressionStageGroup> expressionStageGroupList = new LinkedList<ExpressionStageGroup>(); List<ExpressionStage> allExpressionStages = new ArrayList<ExpressionStage>(allExpressionStagesRaw.size()); int idCounter = 0; for (String expressionStageString : allExpressionStagesRaw) { ExpressionStage expressionStage = new ExpressionStage(); expressionStage.setExpressionStageTitle(expressionStageString); expressionStage.setExpressionStageId("stage" + idCounter); expressionStage.setExpressionStageNumericalId(idCounter); allExpressionStages.add(expressionStage); idCounter++; } // Add expressionStageList to returned object expressionStageOptions.setExpressionStageList(allExpressionStages); /* * Add embryogenesis expressionStageGroup */ ExpressionStageGroup embryologyExpressionStageGroup = new ExpressionStageGroup(); embryologyExpressionStageGroup.setGroupTitle("embryogenesis"); embryologyExpressionStageGroup.setGroupId("group" + 0); embryologyExpressionStageGroup.setGroupNumericalId(0); List<ExpressionStage> embryologyExpressionStageList = new LinkedList<ExpressionStage>(); // Add embryo stages for (int i = 56; i <= 67; i++) { embryologyExpressionStageList.add(allExpressionStages.get(i)); } embryologyExpressionStageGroup.setExpressionStageList(embryologyExpressionStageList); expressionStageGroupList.add(embryologyExpressionStageGroup); /* * Add development expressionStageGroup */ ExpressionStageGroup developmentExpressionStageGroup = new ExpressionStageGroup(); developmentExpressionStageGroup.setGroupTitle("development"); developmentExpressionStageGroup.setGroupId("group" + 1); developmentExpressionStageGroup.setGroupNumericalId(1); List<ExpressionStage> developmentExpressionStageList = new LinkedList<ExpressionStage>(); // Add embryo stages for (int i = 56; i <= 67; i++) { developmentExpressionStageList.add(allExpressionStages.get(i)); } // larva stages for (int i = 75; i <= 81; i++) { developmentExpressionStageList.add(allExpressionStages.get(i)); } developmentExpressionStageList.add(allExpressionStages.get(97)); for (int i = 49; i <= 54; i++) { developmentExpressionStageList.add(allExpressionStages.get(i)); } for (int i = 38; i <= 41; i++) { developmentExpressionStageList.add(allExpressionStages.get(i)); } // TODO: Add the others developmentExpressionStageList.add(allExpressionStages.get(19)); developmentExpressionStageList.add(allExpressionStages.get(44)); developmentExpressionStageGroup.setExpressionStageList(developmentExpressionStageList); expressionStageGroupList.add(developmentExpressionStageGroup); /* * Add tissue expressionStageGroup */ ExpressionStageGroup tissueExpressionStageGroup = new ExpressionStageGroup(); tissueExpressionStageGroup.setGroupTitle("tissue"); tissueExpressionStageGroup.setGroupId("group" + 2); tissueExpressionStageGroup.setGroupNumericalId(2); List<ExpressionStage> tissueExpressionStageList = new LinkedList<ExpressionStage>(); // A Mate stages for (int i = 11; i <= 29; i++) { tissueExpressionStageList.add(allExpressionStages.get(i)); } for (int i = 32; i <= 37; i++) { tissueExpressionStageList.add(allExpressionStages.get(i)); } for (int i = 42; i <= 43; i++) { tissueExpressionStageList.add(allExpressionStages.get(i)); } for (int i = 47; i <= 48; i++) { tissueExpressionStageList.add(allExpressionStages.get(i)); } tissueExpressionStageGroup.setExpressionStageList(tissueExpressionStageList); expressionStageGroupList.add(tissueExpressionStageGroup); /* * Add treatment expressionStageGroup */ ExpressionStageGroup treatmentExpressionStageGroup = new ExpressionStageGroup(); treatmentExpressionStageGroup.setGroupTitle("treatment"); treatmentExpressionStageGroup.setGroupId("group" + 3); treatmentExpressionStageGroup.setGroupNumericalId(3); List<ExpressionStage> treatmentExpressionStageList = new LinkedList<ExpressionStage>(); // larva stages for (int i = 82; i <= 90; i++) { treatmentExpressionStageList.add(allExpressionStages.get(i)); } for (int i = 0; i <= 10; i++) { treatmentExpressionStageList.add(allExpressionStages.get(i)); } treatmentExpressionStageGroup.setExpressionStageList(treatmentExpressionStageList); expressionStageGroupList.add(treatmentExpressionStageGroup); /* * Add cell-line expressionStageGroup */ ExpressionStageGroup cellLineExpressionStageGroup = new ExpressionStageGroup(); cellLineExpressionStageGroup.setGroupTitle("cell-line"); cellLineExpressionStageGroup.setGroupId("group" + 4); cellLineExpressionStageGroup.setGroupNumericalId(4); List<ExpressionStage> cellLineExpressionStageList = new LinkedList<ExpressionStage>(); // Add embryo stages for (int i = 98; i <= 103; i++) { cellLineExpressionStageList.add(allExpressionStages.get(i)); } // larva stages for (int i = 68; i <= 74; i++) { cellLineExpressionStageList.add(allExpressionStages.get(i)); } for (int i = 91; i <= 96; i++) { cellLineExpressionStageList.add(allExpressionStages.get(i)); } for (int i = 45; i <= 46; i++) { cellLineExpressionStageList.add(allExpressionStages.get(i)); } for (int i = 30; i <= 31; i++) { cellLineExpressionStageList.add(allExpressionStages.get(i)); } cellLineExpressionStageList.add(allExpressionStages.get(55)); // TODO: Add the others cellLineExpressionStageGroup.setExpressionStageList(cellLineExpressionStageList); expressionStageGroupList.add(cellLineExpressionStageGroup); expressionStageOptions.setExpressionStageGroupList(expressionStageGroupList); return expressionStageOptions; }
NONSATD
true
developmentExpressionStageList.add(allExpressionStages.get(i)); } // larva stages for (int i = 75; i <= 81; i++) { developmentExpressionStageList.add(allExpressionStages.get(i));
*/ ExpressionStageGroup developmentExpressionStageGroup = new ExpressionStageGroup(); developmentExpressionStageGroup.setGroupTitle("development"); developmentExpressionStageGroup.setGroupId("group" + 1); developmentExpressionStageGroup.setGroupNumericalId(1); List<ExpressionStage> developmentExpressionStageList = new LinkedList<ExpressionStage>(); // Add embryo stages for (int i = 56; i <= 67; i++) { developmentExpressionStageList.add(allExpressionStages.get(i)); } // larva stages for (int i = 75; i <= 81; i++) { developmentExpressionStageList.add(allExpressionStages.get(i)); } developmentExpressionStageList.add(allExpressionStages.get(97)); for (int i = 49; i <= 54; i++) { developmentExpressionStageList.add(allExpressionStages.get(i)); } for (int i = 38; i <= 41; i++) { developmentExpressionStageList.add(allExpressionStages.get(i)); }
embryologyExpressionStageGroup.setGroupNumericalId(0); List<ExpressionStage> embryologyExpressionStageList = new LinkedList<ExpressionStage>(); // Add embryo stages for (int i = 56; i <= 67; i++) { embryologyExpressionStageList.add(allExpressionStages.get(i)); } embryologyExpressionStageGroup.setExpressionStageList(embryologyExpressionStageList); expressionStageGroupList.add(embryologyExpressionStageGroup); /* * Add development expressionStageGroup */ ExpressionStageGroup developmentExpressionStageGroup = new ExpressionStageGroup(); developmentExpressionStageGroup.setGroupTitle("development"); developmentExpressionStageGroup.setGroupId("group" + 1); developmentExpressionStageGroup.setGroupNumericalId(1); List<ExpressionStage> developmentExpressionStageList = new LinkedList<ExpressionStage>(); // Add embryo stages for (int i = 56; i <= 67; i++) { developmentExpressionStageList.add(allExpressionStages.get(i)); } // larva stages for (int i = 75; i <= 81; i++) { developmentExpressionStageList.add(allExpressionStages.get(i)); } developmentExpressionStageList.add(allExpressionStages.get(97)); for (int i = 49; i <= 54; i++) { developmentExpressionStageList.add(allExpressionStages.get(i)); } for (int i = 38; i <= 41; i++) { developmentExpressionStageList.add(allExpressionStages.get(i)); } // TODO: Add the others developmentExpressionStageList.add(allExpressionStages.get(19)); developmentExpressionStageList.add(allExpressionStages.get(44)); developmentExpressionStageGroup.setExpressionStageList(developmentExpressionStageList); expressionStageGroupList.add(developmentExpressionStageGroup); /* * Add tissue expressionStageGroup */ ExpressionStageGroup tissueExpressionStageGroup = new ExpressionStageGroup(); tissueExpressionStageGroup.setGroupTitle("tissue");
15,951
15
// TODO: Add the others
public ExpressionStageOptions generateExpressionStageOptions() { List<String> allExpressionStagesRaw = retrieveExpressionStages.getDmelanogasterExpressionStages(); ExpressionStageOptions expressionStageOptions = new ExpressionStageOptions(); List<ExpressionStageGroup> expressionStageGroupList = new LinkedList<ExpressionStageGroup>(); List<ExpressionStage> allExpressionStages = new ArrayList<ExpressionStage>(allExpressionStagesRaw.size()); int idCounter = 0; for (String expressionStageString : allExpressionStagesRaw) { ExpressionStage expressionStage = new ExpressionStage(); expressionStage.setExpressionStageTitle(expressionStageString); expressionStage.setExpressionStageId("stage" + idCounter); expressionStage.setExpressionStageNumericalId(idCounter); allExpressionStages.add(expressionStage); idCounter++; } // Add expressionStageList to returned object expressionStageOptions.setExpressionStageList(allExpressionStages); /* * Add embryogenesis expressionStageGroup */ ExpressionStageGroup embryologyExpressionStageGroup = new ExpressionStageGroup(); embryologyExpressionStageGroup.setGroupTitle("embryogenesis"); embryologyExpressionStageGroup.setGroupId("group" + 0); embryologyExpressionStageGroup.setGroupNumericalId(0); List<ExpressionStage> embryologyExpressionStageList = new LinkedList<ExpressionStage>(); // Add embryo stages for (int i = 56; i <= 67; i++) { embryologyExpressionStageList.add(allExpressionStages.get(i)); } embryologyExpressionStageGroup.setExpressionStageList(embryologyExpressionStageList); expressionStageGroupList.add(embryologyExpressionStageGroup); /* * Add development expressionStageGroup */ ExpressionStageGroup developmentExpressionStageGroup = new ExpressionStageGroup(); developmentExpressionStageGroup.setGroupTitle("development"); developmentExpressionStageGroup.setGroupId("group" + 1); developmentExpressionStageGroup.setGroupNumericalId(1); List<ExpressionStage> developmentExpressionStageList = new LinkedList<ExpressionStage>(); // Add embryo stages for (int i = 56; i <= 67; i++) { developmentExpressionStageList.add(allExpressionStages.get(i)); } // larva stages for (int i = 75; i <= 81; i++) { developmentExpressionStageList.add(allExpressionStages.get(i)); } developmentExpressionStageList.add(allExpressionStages.get(97)); for (int i = 49; i <= 54; i++) { developmentExpressionStageList.add(allExpressionStages.get(i)); } for (int i = 38; i <= 41; i++) { developmentExpressionStageList.add(allExpressionStages.get(i)); } // TODO: Add the others developmentExpressionStageList.add(allExpressionStages.get(19)); developmentExpressionStageList.add(allExpressionStages.get(44)); developmentExpressionStageGroup.setExpressionStageList(developmentExpressionStageList); expressionStageGroupList.add(developmentExpressionStageGroup); /* * Add tissue expressionStageGroup */ ExpressionStageGroup tissueExpressionStageGroup = new ExpressionStageGroup(); tissueExpressionStageGroup.setGroupTitle("tissue"); tissueExpressionStageGroup.setGroupId("group" + 2); tissueExpressionStageGroup.setGroupNumericalId(2); List<ExpressionStage> tissueExpressionStageList = new LinkedList<ExpressionStage>(); // A Mate stages for (int i = 11; i <= 29; i++) { tissueExpressionStageList.add(allExpressionStages.get(i)); } for (int i = 32; i <= 37; i++) { tissueExpressionStageList.add(allExpressionStages.get(i)); } for (int i = 42; i <= 43; i++) { tissueExpressionStageList.add(allExpressionStages.get(i)); } for (int i = 47; i <= 48; i++) { tissueExpressionStageList.add(allExpressionStages.get(i)); } tissueExpressionStageGroup.setExpressionStageList(tissueExpressionStageList); expressionStageGroupList.add(tissueExpressionStageGroup); /* * Add treatment expressionStageGroup */ ExpressionStageGroup treatmentExpressionStageGroup = new ExpressionStageGroup(); treatmentExpressionStageGroup.setGroupTitle("treatment"); treatmentExpressionStageGroup.setGroupId("group" + 3); treatmentExpressionStageGroup.setGroupNumericalId(3); List<ExpressionStage> treatmentExpressionStageList = new LinkedList<ExpressionStage>(); // larva stages for (int i = 82; i <= 90; i++) { treatmentExpressionStageList.add(allExpressionStages.get(i)); } for (int i = 0; i <= 10; i++) { treatmentExpressionStageList.add(allExpressionStages.get(i)); } treatmentExpressionStageGroup.setExpressionStageList(treatmentExpressionStageList); expressionStageGroupList.add(treatmentExpressionStageGroup); /* * Add cell-line expressionStageGroup */ ExpressionStageGroup cellLineExpressionStageGroup = new ExpressionStageGroup(); cellLineExpressionStageGroup.setGroupTitle("cell-line"); cellLineExpressionStageGroup.setGroupId("group" + 4); cellLineExpressionStageGroup.setGroupNumericalId(4); List<ExpressionStage> cellLineExpressionStageList = new LinkedList<ExpressionStage>(); // Add embryo stages for (int i = 98; i <= 103; i++) { cellLineExpressionStageList.add(allExpressionStages.get(i)); } // larva stages for (int i = 68; i <= 74; i++) { cellLineExpressionStageList.add(allExpressionStages.get(i)); } for (int i = 91; i <= 96; i++) { cellLineExpressionStageList.add(allExpressionStages.get(i)); } for (int i = 45; i <= 46; i++) { cellLineExpressionStageList.add(allExpressionStages.get(i)); } for (int i = 30; i <= 31; i++) { cellLineExpressionStageList.add(allExpressionStages.get(i)); } cellLineExpressionStageList.add(allExpressionStages.get(55)); // TODO: Add the others cellLineExpressionStageGroup.setExpressionStageList(cellLineExpressionStageList); expressionStageGroupList.add(cellLineExpressionStageGroup); expressionStageOptions.setExpressionStageGroupList(expressionStageGroupList); return expressionStageOptions; }
IMPLEMENTATION
true
developmentExpressionStageList.add(allExpressionStages.get(i)); } // TODO: Add the others developmentExpressionStageList.add(allExpressionStages.get(19)); developmentExpressionStageList.add(allExpressionStages.get(44));
for (int i = 75; i <= 81; i++) { developmentExpressionStageList.add(allExpressionStages.get(i)); } developmentExpressionStageList.add(allExpressionStages.get(97)); for (int i = 49; i <= 54; i++) { developmentExpressionStageList.add(allExpressionStages.get(i)); } for (int i = 38; i <= 41; i++) { developmentExpressionStageList.add(allExpressionStages.get(i)); } // TODO: Add the others developmentExpressionStageList.add(allExpressionStages.get(19)); developmentExpressionStageList.add(allExpressionStages.get(44)); developmentExpressionStageGroup.setExpressionStageList(developmentExpressionStageList); expressionStageGroupList.add(developmentExpressionStageGroup); /* * Add tissue expressionStageGroup */ ExpressionStageGroup tissueExpressionStageGroup = new ExpressionStageGroup(); tissueExpressionStageGroup.setGroupTitle("tissue"); tissueExpressionStageGroup.setGroupId("group" + 2);
ExpressionStageGroup developmentExpressionStageGroup = new ExpressionStageGroup(); developmentExpressionStageGroup.setGroupTitle("development"); developmentExpressionStageGroup.setGroupId("group" + 1); developmentExpressionStageGroup.setGroupNumericalId(1); List<ExpressionStage> developmentExpressionStageList = new LinkedList<ExpressionStage>(); // Add embryo stages for (int i = 56; i <= 67; i++) { developmentExpressionStageList.add(allExpressionStages.get(i)); } // larva stages for (int i = 75; i <= 81; i++) { developmentExpressionStageList.add(allExpressionStages.get(i)); } developmentExpressionStageList.add(allExpressionStages.get(97)); for (int i = 49; i <= 54; i++) { developmentExpressionStageList.add(allExpressionStages.get(i)); } for (int i = 38; i <= 41; i++) { developmentExpressionStageList.add(allExpressionStages.get(i)); } // TODO: Add the others developmentExpressionStageList.add(allExpressionStages.get(19)); developmentExpressionStageList.add(allExpressionStages.get(44)); developmentExpressionStageGroup.setExpressionStageList(developmentExpressionStageList); expressionStageGroupList.add(developmentExpressionStageGroup); /* * Add tissue expressionStageGroup */ ExpressionStageGroup tissueExpressionStageGroup = new ExpressionStageGroup(); tissueExpressionStageGroup.setGroupTitle("tissue"); tissueExpressionStageGroup.setGroupId("group" + 2); tissueExpressionStageGroup.setGroupNumericalId(2); List<ExpressionStage> tissueExpressionStageList = new LinkedList<ExpressionStage>(); // A Mate stages for (int i = 11; i <= 29; i++) { tissueExpressionStageList.add(allExpressionStages.get(i)); } for (int i = 32; i <= 37; i++) { tissueExpressionStageList.add(allExpressionStages.get(i)); } for (int i = 42; i <= 43; i++) {
7,766
0
//fail("Test not implemented yet."); //TODO: do later
@Test public void testPaginate() throws Exception { //fail("Test not implemented yet."); //TODO: do later }
TEST
true
@Test public void testPaginate() throws Exception { //fail("Test not implemented yet."); //TODO: do later }
@Test public void testPaginate() throws Exception { //fail("Test not implemented yet."); //TODO: do later }
@Test public void testPaginate() throws Exception { //fail("Test not implemented yet."); //TODO: do later }
24,154
0
/** * Create Mono that completes exceptionally with exception `IllegalStateException`. */
@Test public void trouble_maker() { Mono<String> trouble = null; //todo: change this line StepVerifier.create(trouble) .expectError(IllegalStateException.class) .verify(); }
NONSATD
true
@Test public void trouble_maker() { Mono<String> trouble = null; //todo: change this line StepVerifier.create(trouble) .expectError(IllegalStateException.class) .verify(); }
@Test public void trouble_maker() { Mono<String> trouble = null; //todo: change this line StepVerifier.create(trouble) .expectError(IllegalStateException.class) .verify(); }
@Test public void trouble_maker() { Mono<String> trouble = null; //todo: change this line StepVerifier.create(trouble) .expectError(IllegalStateException.class) .verify(); }
24,154
1
//todo: change this line
@Test public void trouble_maker() { Mono<String> trouble = null; //todo: change this line StepVerifier.create(trouble) .expectError(IllegalStateException.class) .verify(); }
DESIGN
true
@Test public void trouble_maker() { Mono<String> trouble = null; //todo: change this line StepVerifier.create(trouble) .expectError(IllegalStateException.class)
@Test public void trouble_maker() { Mono<String> trouble = null; //todo: change this line StepVerifier.create(trouble) .expectError(IllegalStateException.class) .verify(); }
@Test public void trouble_maker() { Mono<String> trouble = null; //todo: change this line StepVerifier.create(trouble) .expectError(IllegalStateException.class) .verify(); }
15,967
0
// We don't paginate this call. So we should make sure the number of reads is tolerable. // TODO: Think about paginating this call.
public Table<Locator, String, String> getMetadataValues(Set<Locator> locators) { ColumnFamily CF = CassandraModel.CF_METRIC_METADATA; boolean isBatch = locators.size() > 1; Table<Locator, String, String> metaTable = HashBasedTable.create(); Timer.Context ctx = isBatch ? Instrumentation.getBatchReadTimerContext(CF) : Instrumentation.getReadTimerContext(CF); try { // We don't paginate this call. So we should make sure the number of reads is tolerable. // TODO: Think about paginating this call. OperationResult<Rows<Locator, String>> query = keyspace .prepareQuery(CF) .getKeySlice(locators) .execute(); for (Row<Locator, String> row : query.getResult()) { ColumnList<String> columns = row.getColumns(); for (Column<String> column : columns) { String metaValue = column.getValue(StringMetadataSerializer.get()); String metaKey = column.getName(); metaTable.put(row.getKey(), metaKey, metaValue); } } } catch (ConnectionException e) { if (e instanceof NotFoundException) { // TODO: Not really sure what happens when one of the keys is not found. Instrumentation.markNotFound(CF); } else { if (isBatch) { Instrumentation.markBatchReadError(e); } else { Instrumentation.markReadError(e); } } log.warn((isBatch ? "Batch " : "") + " read query failed for column family " + CF.getName(), e); } finally { ctx.stop(); } return metaTable; }
DESIGN
true
Timer.Context ctx = isBatch ? Instrumentation.getBatchReadTimerContext(CF) : Instrumentation.getReadTimerContext(CF); try { // We don't paginate this call. So we should make sure the number of reads is tolerable. // TODO: Think about paginating this call. OperationResult<Rows<Locator, String>> query = keyspace .prepareQuery(CF)
public Table<Locator, String, String> getMetadataValues(Set<Locator> locators) { ColumnFamily CF = CassandraModel.CF_METRIC_METADATA; boolean isBatch = locators.size() > 1; Table<Locator, String, String> metaTable = HashBasedTable.create(); Timer.Context ctx = isBatch ? Instrumentation.getBatchReadTimerContext(CF) : Instrumentation.getReadTimerContext(CF); try { // We don't paginate this call. So we should make sure the number of reads is tolerable. // TODO: Think about paginating this call. OperationResult<Rows<Locator, String>> query = keyspace .prepareQuery(CF) .getKeySlice(locators) .execute(); for (Row<Locator, String> row : query.getResult()) { ColumnList<String> columns = row.getColumns(); for (Column<String> column : columns) { String metaValue = column.getValue(StringMetadataSerializer.get()); String metaKey = column.getName(); metaTable.put(row.getKey(), metaKey, metaValue);
public Table<Locator, String, String> getMetadataValues(Set<Locator> locators) { ColumnFamily CF = CassandraModel.CF_METRIC_METADATA; boolean isBatch = locators.size() > 1; Table<Locator, String, String> metaTable = HashBasedTable.create(); Timer.Context ctx = isBatch ? Instrumentation.getBatchReadTimerContext(CF) : Instrumentation.getReadTimerContext(CF); try { // We don't paginate this call. So we should make sure the number of reads is tolerable. // TODO: Think about paginating this call. OperationResult<Rows<Locator, String>> query = keyspace .prepareQuery(CF) .getKeySlice(locators) .execute(); for (Row<Locator, String> row : query.getResult()) { ColumnList<String> columns = row.getColumns(); for (Column<String> column : columns) { String metaValue = column.getValue(StringMetadataSerializer.get()); String metaKey = column.getName(); metaTable.put(row.getKey(), metaKey, metaValue); } } } catch (ConnectionException e) { if (e instanceof NotFoundException) { // TODO: Not really sure what happens when one of the keys is not found. Instrumentation.markNotFound(CF); } else { if (isBatch) { Instrumentation.markBatchReadError(e); } else { Instrumentation.markReadError(e); } } log.warn((isBatch ? "Batch " : "") + " read query failed for column family " + CF.getName(), e);
15,967
1
// TODO: Not really sure what happens when one of the keys is not found.
public Table<Locator, String, String> getMetadataValues(Set<Locator> locators) { ColumnFamily CF = CassandraModel.CF_METRIC_METADATA; boolean isBatch = locators.size() > 1; Table<Locator, String, String> metaTable = HashBasedTable.create(); Timer.Context ctx = isBatch ? Instrumentation.getBatchReadTimerContext(CF) : Instrumentation.getReadTimerContext(CF); try { // We don't paginate this call. So we should make sure the number of reads is tolerable. // TODO: Think about paginating this call. OperationResult<Rows<Locator, String>> query = keyspace .prepareQuery(CF) .getKeySlice(locators) .execute(); for (Row<Locator, String> row : query.getResult()) { ColumnList<String> columns = row.getColumns(); for (Column<String> column : columns) { String metaValue = column.getValue(StringMetadataSerializer.get()); String metaKey = column.getName(); metaTable.put(row.getKey(), metaKey, metaValue); } } } catch (ConnectionException e) { if (e instanceof NotFoundException) { // TODO: Not really sure what happens when one of the keys is not found. Instrumentation.markNotFound(CF); } else { if (isBatch) { Instrumentation.markBatchReadError(e); } else { Instrumentation.markReadError(e); } } log.warn((isBatch ? "Batch " : "") + " read query failed for column family " + CF.getName(), e); } finally { ctx.stop(); } return metaTable; }
DESIGN
true
} } catch (ConnectionException e) { if (e instanceof NotFoundException) { // TODO: Not really sure what happens when one of the keys is not found. Instrumentation.markNotFound(CF); } else {
.execute(); for (Row<Locator, String> row : query.getResult()) { ColumnList<String> columns = row.getColumns(); for (Column<String> column : columns) { String metaValue = column.getValue(StringMetadataSerializer.get()); String metaKey = column.getName(); metaTable.put(row.getKey(), metaKey, metaValue); } } } catch (ConnectionException e) { if (e instanceof NotFoundException) { // TODO: Not really sure what happens when one of the keys is not found. Instrumentation.markNotFound(CF); } else { if (isBatch) { Instrumentation.markBatchReadError(e); } else { Instrumentation.markReadError(e); } } log.warn((isBatch ? "Batch " : "") + " read query failed for column family " + CF.getName(), e); } finally { ctx.stop(); } return metaTable;
ColumnFamily CF = CassandraModel.CF_METRIC_METADATA; boolean isBatch = locators.size() > 1; Table<Locator, String, String> metaTable = HashBasedTable.create(); Timer.Context ctx = isBatch ? Instrumentation.getBatchReadTimerContext(CF) : Instrumentation.getReadTimerContext(CF); try { // We don't paginate this call. So we should make sure the number of reads is tolerable. // TODO: Think about paginating this call. OperationResult<Rows<Locator, String>> query = keyspace .prepareQuery(CF) .getKeySlice(locators) .execute(); for (Row<Locator, String> row : query.getResult()) { ColumnList<String> columns = row.getColumns(); for (Column<String> column : columns) { String metaValue = column.getValue(StringMetadataSerializer.get()); String metaKey = column.getName(); metaTable.put(row.getKey(), metaKey, metaValue); } } } catch (ConnectionException e) { if (e instanceof NotFoundException) { // TODO: Not really sure what happens when one of the keys is not found. Instrumentation.markNotFound(CF); } else { if (isBatch) { Instrumentation.markBatchReadError(e); } else { Instrumentation.markReadError(e); } } log.warn((isBatch ? "Batch " : "") + " read query failed for column family " + CF.getName(), e); } finally { ctx.stop(); } return metaTable; }
15,968
0
// We don't paginate this call. So we should make sure the number of reads is tolerable. // TODO: Think about paginating this call.
private Map<Locator, ColumnList<Long>> getColumnsFromDB(List<Locator> locators, ColumnFamily<Locator, Long> CF, Range range) { if (range.getStart() > range.getStop()) { throw new RuntimeException(String.format("Invalid rollup range: ", range.toString())); } boolean isBatch = locators.size() != 1; final Map<Locator, ColumnList<Long>> columns = new HashMap<Locator, ColumnList<Long>>(); final RangeBuilder rangeBuilder = new RangeBuilder().setStart(range.getStart()).setEnd(range.getStop()); Timer.Context ctx = isBatch ? Instrumentation.getBatchReadTimerContext(CF) : Instrumentation.getReadTimerContext(CF); try { // We don't paginate this call. So we should make sure the number of reads is tolerable. // TODO: Think about paginating this call. OperationResult<Rows<Locator, Long>> query = keyspace .prepareQuery(CF) .getKeySlice(locators) .withColumnRange(rangeBuilder.build()) .execute(); for (Row<Locator, Long> row : query.getResult()) { columns.put(row.getKey(), row.getColumns()); } } catch (ConnectionException e) { if (e instanceof NotFoundException) { // TODO: Not really sure what happens when one of the keys is not found. Instrumentation.markNotFound(CF); } else { if (isBatch) { Instrumentation.markBatchReadError(e); } else { Instrumentation.markReadError(e); } } log.warn((isBatch ? "Batch " : "") + " read query failed for column family " + CF.getName(), e); } finally { ctx.stop(); } return columns; }
DESIGN
true
Timer.Context ctx = isBatch ? Instrumentation.getBatchReadTimerContext(CF) : Instrumentation.getReadTimerContext(CF); try { // We don't paginate this call. So we should make sure the number of reads is tolerable. // TODO: Think about paginating this call. OperationResult<Rows<Locator, Long>> query = keyspace .prepareQuery(CF)
private Map<Locator, ColumnList<Long>> getColumnsFromDB(List<Locator> locators, ColumnFamily<Locator, Long> CF, Range range) { if (range.getStart() > range.getStop()) { throw new RuntimeException(String.format("Invalid rollup range: ", range.toString())); } boolean isBatch = locators.size() != 1; final Map<Locator, ColumnList<Long>> columns = new HashMap<Locator, ColumnList<Long>>(); final RangeBuilder rangeBuilder = new RangeBuilder().setStart(range.getStart()).setEnd(range.getStop()); Timer.Context ctx = isBatch ? Instrumentation.getBatchReadTimerContext(CF) : Instrumentation.getReadTimerContext(CF); try { // We don't paginate this call. So we should make sure the number of reads is tolerable. // TODO: Think about paginating this call. OperationResult<Rows<Locator, Long>> query = keyspace .prepareQuery(CF) .getKeySlice(locators) .withColumnRange(rangeBuilder.build()) .execute(); for (Row<Locator, Long> row : query.getResult()) { columns.put(row.getKey(), row.getColumns()); } } catch (ConnectionException e) { if (e instanceof NotFoundException) { // TODO: Not really sure what happens when one of the keys is not found.
private Map<Locator, ColumnList<Long>> getColumnsFromDB(List<Locator> locators, ColumnFamily<Locator, Long> CF, Range range) { if (range.getStart() > range.getStop()) { throw new RuntimeException(String.format("Invalid rollup range: ", range.toString())); } boolean isBatch = locators.size() != 1; final Map<Locator, ColumnList<Long>> columns = new HashMap<Locator, ColumnList<Long>>(); final RangeBuilder rangeBuilder = new RangeBuilder().setStart(range.getStart()).setEnd(range.getStop()); Timer.Context ctx = isBatch ? Instrumentation.getBatchReadTimerContext(CF) : Instrumentation.getReadTimerContext(CF); try { // We don't paginate this call. So we should make sure the number of reads is tolerable. // TODO: Think about paginating this call. OperationResult<Rows<Locator, Long>> query = keyspace .prepareQuery(CF) .getKeySlice(locators) .withColumnRange(rangeBuilder.build()) .execute(); for (Row<Locator, Long> row : query.getResult()) { columns.put(row.getKey(), row.getColumns()); } } catch (ConnectionException e) { if (e instanceof NotFoundException) { // TODO: Not really sure what happens when one of the keys is not found. Instrumentation.markNotFound(CF); } else { if (isBatch) { Instrumentation.markBatchReadError(e); } else { Instrumentation.markReadError(e); } } log.warn((isBatch ? "Batch " : "") + " read query failed for column family " + CF.getName(), e); } finally { ctx.stop(); } return columns;
15,968
1
// TODO: Not really sure what happens when one of the keys is not found.
private Map<Locator, ColumnList<Long>> getColumnsFromDB(List<Locator> locators, ColumnFamily<Locator, Long> CF, Range range) { if (range.getStart() > range.getStop()) { throw new RuntimeException(String.format("Invalid rollup range: ", range.toString())); } boolean isBatch = locators.size() != 1; final Map<Locator, ColumnList<Long>> columns = new HashMap<Locator, ColumnList<Long>>(); final RangeBuilder rangeBuilder = new RangeBuilder().setStart(range.getStart()).setEnd(range.getStop()); Timer.Context ctx = isBatch ? Instrumentation.getBatchReadTimerContext(CF) : Instrumentation.getReadTimerContext(CF); try { // We don't paginate this call. So we should make sure the number of reads is tolerable. // TODO: Think about paginating this call. OperationResult<Rows<Locator, Long>> query = keyspace .prepareQuery(CF) .getKeySlice(locators) .withColumnRange(rangeBuilder.build()) .execute(); for (Row<Locator, Long> row : query.getResult()) { columns.put(row.getKey(), row.getColumns()); } } catch (ConnectionException e) { if (e instanceof NotFoundException) { // TODO: Not really sure what happens when one of the keys is not found. Instrumentation.markNotFound(CF); } else { if (isBatch) { Instrumentation.markBatchReadError(e); } else { Instrumentation.markReadError(e); } } log.warn((isBatch ? "Batch " : "") + " read query failed for column family " + CF.getName(), e); } finally { ctx.stop(); } return columns; }
DESIGN
true
} } catch (ConnectionException e) { if (e instanceof NotFoundException) { // TODO: Not really sure what happens when one of the keys is not found. Instrumentation.markNotFound(CF); } else {
// TODO: Think about paginating this call. OperationResult<Rows<Locator, Long>> query = keyspace .prepareQuery(CF) .getKeySlice(locators) .withColumnRange(rangeBuilder.build()) .execute(); for (Row<Locator, Long> row : query.getResult()) { columns.put(row.getKey(), row.getColumns()); } } catch (ConnectionException e) { if (e instanceof NotFoundException) { // TODO: Not really sure what happens when one of the keys is not found. Instrumentation.markNotFound(CF); } else { if (isBatch) { Instrumentation.markBatchReadError(e); } else { Instrumentation.markReadError(e); } } log.warn((isBatch ? "Batch " : "") + " read query failed for column family " + CF.getName(), e); } finally { ctx.stop(); } return columns;
Range range) { if (range.getStart() > range.getStop()) { throw new RuntimeException(String.format("Invalid rollup range: ", range.toString())); } boolean isBatch = locators.size() != 1; final Map<Locator, ColumnList<Long>> columns = new HashMap<Locator, ColumnList<Long>>(); final RangeBuilder rangeBuilder = new RangeBuilder().setStart(range.getStart()).setEnd(range.getStop()); Timer.Context ctx = isBatch ? Instrumentation.getBatchReadTimerContext(CF) : Instrumentation.getReadTimerContext(CF); try { // We don't paginate this call. So we should make sure the number of reads is tolerable. // TODO: Think about paginating this call. OperationResult<Rows<Locator, Long>> query = keyspace .prepareQuery(CF) .getKeySlice(locators) .withColumnRange(rangeBuilder.build()) .execute(); for (Row<Locator, Long> row : query.getResult()) { columns.put(row.getKey(), row.getColumns()); } } catch (ConnectionException e) { if (e instanceof NotFoundException) { // TODO: Not really sure what happens when one of the keys is not found. Instrumentation.markNotFound(CF); } else { if (isBatch) { Instrumentation.markBatchReadError(e); } else { Instrumentation.markReadError(e); } } log.warn((isBatch ? "Batch " : "") + " read query failed for column family " + CF.getName(), e); } finally { ctx.stop(); } return columns; }
24,160
0
/** * Create Callable that increments the counter and returns the counter value, and then use `repeat()` operator to create Flux that emits * values from 0 to 10. */
@Test public void repeat() { AtomicInteger counter = new AtomicInteger(0); Flux<Integer> repeated = null; //todo: change this line System.out.println("Repeat: "); StepVerifier.create(repeated.doOnNext(System.out::println)) .expectNext(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) .verifyComplete(); }
NONSATD
true
@Test public void repeat() { AtomicInteger counter = new AtomicInteger(0); Flux<Integer> repeated = null; //todo: change this line System.out.println("Repeat: "); StepVerifier.create(repeated.doOnNext(System.out::println)) .expectNext(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) .verifyComplete(); }
@Test public void repeat() { AtomicInteger counter = new AtomicInteger(0); Flux<Integer> repeated = null; //todo: change this line System.out.println("Repeat: "); StepVerifier.create(repeated.doOnNext(System.out::println)) .expectNext(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) .verifyComplete(); }
@Test public void repeat() { AtomicInteger counter = new AtomicInteger(0); Flux<Integer> repeated = null; //todo: change this line System.out.println("Repeat: "); StepVerifier.create(repeated.doOnNext(System.out::println)) .expectNext(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) .verifyComplete(); }
24,160
1
//todo: change this line
@Test public void repeat() { AtomicInteger counter = new AtomicInteger(0); Flux<Integer> repeated = null; //todo: change this line System.out.println("Repeat: "); StepVerifier.create(repeated.doOnNext(System.out::println)) .expectNext(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) .verifyComplete(); }
DESIGN
true
public void repeat() { AtomicInteger counter = new AtomicInteger(0); Flux<Integer> repeated = null; //todo: change this line System.out.println("Repeat: "); StepVerifier.create(repeated.doOnNext(System.out::println))
@Test public void repeat() { AtomicInteger counter = new AtomicInteger(0); Flux<Integer> repeated = null; //todo: change this line System.out.println("Repeat: "); StepVerifier.create(repeated.doOnNext(System.out::println)) .expectNext(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) .verifyComplete(); }
@Test public void repeat() { AtomicInteger counter = new AtomicInteger(0); Flux<Integer> repeated = null; //todo: change this line System.out.println("Repeat: "); StepVerifier.create(repeated.doOnNext(System.out::println)) .expectNext(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) .verifyComplete(); }
7,781
0
// TODO: use sane arg parsing
public static void main(String args[]) throws FileNotFoundException { // TODO: use sane arg parsing if (args.length != 7 && args.length != 8) { throw new RuntimeException("usage: Processor trace-file tcg-dump-out inst-info-dump hierarchy-dump test-case-name test-method-name tested-class [output-package]"); } String traceFileName = args[0]; String tcgDump = args[1]; String iiDump = args[2]; String hierDump = args[3]; String testCaseName = args[4]; String testMethodName = args[5]; ClassName testedClass = ClassName.fromDotted(args[6]); String outputPackage = args.length == 8 ? args[7] : testedClass.dottedPackageName(); Hierarchy hierarchy = Hierarchy.createFromFile(hierDump); TestCaseGenerator tcg = new TestCaseGenerator(testCaseName, outputPackage); TestMethodGenerator tmg = new TestMethodGenerator(testMethodName, hierarchy, true); tcg.addChunk(tmg); InputStream in = new FileInputStream(traceFileName); Deserializer<TraceEvent> d = Deserializer.getDeserializer(in, TraceEvent.class); Map<Instance, InstanceInfo> iis = readInstanceInfos(iiDump); Processor p = new Processor(tmg, testedClass, iis, hierarchy); d.process(p); PrintStream ps = new PrintStream(tcgDump); Serializer<TestCaseGenerator> s = Serializer.getSerializer(ps); s.write(tcg); s.close(); }
DESIGN
true
public static void main(String args[]) throws FileNotFoundException { // TODO: use sane arg parsing if (args.length != 7 && args.length != 8) { throw new RuntimeException("usage: Processor trace-file tcg-dump-out inst-info-dump hierarchy-dump test-case-name test-method-name tested-class [output-package]");
public static void main(String args[]) throws FileNotFoundException { // TODO: use sane arg parsing if (args.length != 7 && args.length != 8) { throw new RuntimeException("usage: Processor trace-file tcg-dump-out inst-info-dump hierarchy-dump test-case-name test-method-name tested-class [output-package]"); } String traceFileName = args[0]; String tcgDump = args[1]; String iiDump = args[2]; String hierDump = args[3]; String testCaseName = args[4]; String testMethodName = args[5]; ClassName testedClass = ClassName.fromDotted(args[6]);
public static void main(String args[]) throws FileNotFoundException { // TODO: use sane arg parsing if (args.length != 7 && args.length != 8) { throw new RuntimeException("usage: Processor trace-file tcg-dump-out inst-info-dump hierarchy-dump test-case-name test-method-name tested-class [output-package]"); } String traceFileName = args[0]; String tcgDump = args[1]; String iiDump = args[2]; String hierDump = args[3]; String testCaseName = args[4]; String testMethodName = args[5]; ClassName testedClass = ClassName.fromDotted(args[6]); String outputPackage = args.length == 8 ? args[7] : testedClass.dottedPackageName(); Hierarchy hierarchy = Hierarchy.createFromFile(hierDump); TestCaseGenerator tcg = new TestCaseGenerator(testCaseName, outputPackage); TestMethodGenerator tmg = new TestMethodGenerator(testMethodName, hierarchy, true); tcg.addChunk(tmg);
7,810
0
/** * Returns true if UGV currently engaged in overtaking manoeuvre. * TODO - May want to do some testing to make sure that the UGV start mode * is initialised to OvertakeStage.NOT_OVERTAKING in the constructor, and * reset at appropriate points through the simulation. * @return boolean (return true if UGV is overtaking, else false) */
public boolean isOvertaking() { if (overtakeStage != OvertakeStage.NOT_OVERTAKING) { return true; } else { return false; } }
IMPLEMENTATION
true
public boolean isOvertaking() { if (overtakeStage != OvertakeStage.NOT_OVERTAKING) { return true; } else { return false; } }
public boolean isOvertaking() { if (overtakeStage != OvertakeStage.NOT_OVERTAKING) { return true; } else { return false; } }
public boolean isOvertaking() { if (overtakeStage != OvertakeStage.NOT_OVERTAKING) { return true; } else { return false; } }
7,812
0
/* (non-Javadoc) * @see prefuse.action.Action#run(double) */
@Override public void run(double frac) { logger.trace("run -> begin of method"); try { workingDataset = new GranularityAggregationTree(sourceDataset.getDataColumnSchema(),granularities.length+1); ArrayList<TemporalObject> currentBranches = new ArrayList<TemporalObject>(); ArrayList<ArrayList<TemporalObject>> currentLeaves = new ArrayList<ArrayList<TemporalObject>>(); for(TemporalObject iO : sourceDataset.temporalObjects()) { long inf = iO.getTemporalElement().asGeneric().getGranule().getInf(); int i = 0; for(TemporalObject iB : currentBranches) { if (iB.getTemporalElement().asGeneric().getGranule().contains(inf)) { currentLeaves.get(i).add(iO); break; } i++; } if(i >= currentBranches.size()) { Granule newGranule = new Granule(inf,inf,granularities[0]); Instant newTe = workingDataset.addInstant(newGranule); currentBranches.add(workingDataset.addTemporalObject(newTe)); ArrayList<TemporalObject> leaves = new ArrayList<TemporalObject>(); leaves.add(iO); currentLeaves.add(leaves); } } long[] roots = new long[currentBranches.size()]; for(int i=0; i<currentBranches.size(); i++) roots[i] = currentBranches.get(i).getId(); if (granularities.length > 1) { for(int i=1; i<granularities.length;i++) { ArrayList<ArrayList<TemporalObject>> futureLeaves = new ArrayList<ArrayList<TemporalObject>>(); ArrayList<TemporalObject> futureBranches = new ArrayList<TemporalObject>(); int whichChild = 0; for(int k=0; k<currentLeaves.size();k++) { ArrayList<TemporalObject> iCurrentLeaves = currentLeaves.get(k); while(iCurrentLeaves.size() > 0) { TemporalObject currentLeave = iCurrentLeaves.get(0); iCurrentLeaves.remove(0); TemporalObject targetBranch = null; long inf = currentLeave.getTemporalElement().asGeneric().getInf(); long sup = currentLeave.getTemporalElement().asGeneric().getSup(); whichChild = 0; for(int l=0; l<k; l++) whichChild += currentBranches.get(l).getChildCount(); for(TemporalObject potentialBranch : currentBranches.get(k).childObjects()) { if (potentialBranch.getTemporalElement().asGeneric().getGranule().contains(inf)) { targetBranch = potentialBranch; break; } whichChild++; } if (targetBranch == null) { Granule newGranule = new Granule(inf,sup,granularities[i]); Instant newTe = workingDataset.addInstant(newGranule); targetBranch = workingDataset.addTemporalObject(newTe); futureBranches.add(targetBranch); futureLeaves.add(new ArrayList<TemporalObject>()); whichChild = futureLeaves.size() - 1; currentBranches.get(k).linkWithChild(targetBranch); } futureLeaves.get(whichChild).add(currentLeave); } } if(i==granularities.length-1) { for(int j=0; j<futureBranches.size(); j++ ) { aggregate(futureBranches.get(j),futureLeaves.get(j),granularities.length-1); } } else { currentBranches = futureBranches; currentLeaves = futureLeaves; } } for(long iRoot : roots) aggregate(workingDataset.getTemporalObject(iRoot),0); } else { for(int i=0; i<roots.length; i++) aggregate(workingDataset.getTemporalObject(roots[i]),currentLeaves.get(i),0); } // TODO this could be cleaned for (long rootId : roots) { workingDataset.getTemporalObject(rootId).setRoot(true); } } catch (TemporalDataException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } }
NONSATD
true
@Override public void run(double frac) { logger.trace("run -> begin of method"); try { workingDataset = new GranularityAggregationTree(sourceDataset.getDataColumnSchema(),granularities.length+1); ArrayList<TemporalObject> currentBranches = new ArrayList<TemporalObject>(); ArrayList<ArrayList<TemporalObject>> currentLeaves = new ArrayList<ArrayList<TemporalObject>>(); for(TemporalObject iO : sourceDataset.temporalObjects()) { long inf = iO.getTemporalElement().asGeneric().getGranule().getInf(); int i = 0; for(TemporalObject iB : currentBranches) { if (iB.getTemporalElement().asGeneric().getGranule().contains(inf)) { currentLeaves.get(i).add(iO); break; } i++; } if(i >= currentBranches.size()) { Granule newGranule = new Granule(inf,inf,granularities[0]); Instant newTe = workingDataset.addInstant(newGranule); currentBranches.add(workingDataset.addTemporalObject(newTe)); ArrayList<TemporalObject> leaves = new ArrayList<TemporalObject>(); leaves.add(iO); currentLeaves.add(leaves); } } long[] roots = new long[currentBranches.size()]; for(int i=0; i<currentBranches.size(); i++) roots[i] = currentBranches.get(i).getId(); if (granularities.length > 1) { for(int i=1; i<granularities.length;i++) { ArrayList<ArrayList<TemporalObject>> futureLeaves = new ArrayList<ArrayList<TemporalObject>>(); ArrayList<TemporalObject> futureBranches = new ArrayList<TemporalObject>(); int whichChild = 0; for(int k=0; k<currentLeaves.size();k++) { ArrayList<TemporalObject> iCurrentLeaves = currentLeaves.get(k); while(iCurrentLeaves.size() > 0) { TemporalObject currentLeave = iCurrentLeaves.get(0); iCurrentLeaves.remove(0); TemporalObject targetBranch = null; long inf = currentLeave.getTemporalElement().asGeneric().getInf(); long sup = currentLeave.getTemporalElement().asGeneric().getSup(); whichChild = 0; for(int l=0; l<k; l++) whichChild += currentBranches.get(l).getChildCount(); for(TemporalObject potentialBranch : currentBranches.get(k).childObjects()) { if (potentialBranch.getTemporalElement().asGeneric().getGranule().contains(inf)) { targetBranch = potentialBranch; break; } whichChild++; } if (targetBranch == null) { Granule newGranule = new Granule(inf,sup,granularities[i]); Instant newTe = workingDataset.addInstant(newGranule); targetBranch = workingDataset.addTemporalObject(newTe); futureBranches.add(targetBranch); futureLeaves.add(new ArrayList<TemporalObject>()); whichChild = futureLeaves.size() - 1; currentBranches.get(k).linkWithChild(targetBranch); } futureLeaves.get(whichChild).add(currentLeave); } } if(i==granularities.length-1) { for(int j=0; j<futureBranches.size(); j++ ) { aggregate(futureBranches.get(j),futureLeaves.get(j),granularities.length-1); } } else { currentBranches = futureBranches; currentLeaves = futureLeaves; } } for(long iRoot : roots) aggregate(workingDataset.getTemporalObject(iRoot),0); } else { for(int i=0; i<roots.length; i++) aggregate(workingDataset.getTemporalObject(roots[i]),currentLeaves.get(i),0); } // TODO this could be cleaned for (long rootId : roots) { workingDataset.getTemporalObject(rootId).setRoot(true); } } catch (TemporalDataException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } }
@Override public void run(double frac) { logger.trace("run -> begin of method"); try { workingDataset = new GranularityAggregationTree(sourceDataset.getDataColumnSchema(),granularities.length+1); ArrayList<TemporalObject> currentBranches = new ArrayList<TemporalObject>(); ArrayList<ArrayList<TemporalObject>> currentLeaves = new ArrayList<ArrayList<TemporalObject>>(); for(TemporalObject iO : sourceDataset.temporalObjects()) { long inf = iO.getTemporalElement().asGeneric().getGranule().getInf(); int i = 0; for(TemporalObject iB : currentBranches) { if (iB.getTemporalElement().asGeneric().getGranule().contains(inf)) { currentLeaves.get(i).add(iO); break; } i++; } if(i >= currentBranches.size()) { Granule newGranule = new Granule(inf,inf,granularities[0]); Instant newTe = workingDataset.addInstant(newGranule); currentBranches.add(workingDataset.addTemporalObject(newTe)); ArrayList<TemporalObject> leaves = new ArrayList<TemporalObject>(); leaves.add(iO); currentLeaves.add(leaves); } } long[] roots = new long[currentBranches.size()]; for(int i=0; i<currentBranches.size(); i++) roots[i] = currentBranches.get(i).getId(); if (granularities.length > 1) { for(int i=1; i<granularities.length;i++) { ArrayList<ArrayList<TemporalObject>> futureLeaves = new ArrayList<ArrayList<TemporalObject>>(); ArrayList<TemporalObject> futureBranches = new ArrayList<TemporalObject>(); int whichChild = 0; for(int k=0; k<currentLeaves.size();k++) { ArrayList<TemporalObject> iCurrentLeaves = currentLeaves.get(k); while(iCurrentLeaves.size() > 0) { TemporalObject currentLeave = iCurrentLeaves.get(0); iCurrentLeaves.remove(0); TemporalObject targetBranch = null; long inf = currentLeave.getTemporalElement().asGeneric().getInf(); long sup = currentLeave.getTemporalElement().asGeneric().getSup(); whichChild = 0; for(int l=0; l<k; l++) whichChild += currentBranches.get(l).getChildCount(); for(TemporalObject potentialBranch : currentBranches.get(k).childObjects()) { if (potentialBranch.getTemporalElement().asGeneric().getGranule().contains(inf)) { targetBranch = potentialBranch; break; } whichChild++; } if (targetBranch == null) { Granule newGranule = new Granule(inf,sup,granularities[i]); Instant newTe = workingDataset.addInstant(newGranule); targetBranch = workingDataset.addTemporalObject(newTe); futureBranches.add(targetBranch); futureLeaves.add(new ArrayList<TemporalObject>()); whichChild = futureLeaves.size() - 1; currentBranches.get(k).linkWithChild(targetBranch); } futureLeaves.get(whichChild).add(currentLeave); } } if(i==granularities.length-1) { for(int j=0; j<futureBranches.size(); j++ ) { aggregate(futureBranches.get(j),futureLeaves.get(j),granularities.length-1); } } else { currentBranches = futureBranches; currentLeaves = futureLeaves; } } for(long iRoot : roots) aggregate(workingDataset.getTemporalObject(iRoot),0); } else { for(int i=0; i<roots.length; i++) aggregate(workingDataset.getTemporalObject(roots[i]),currentLeaves.get(i),0); } // TODO this could be cleaned for (long rootId : roots) { workingDataset.getTemporalObject(rootId).setRoot(true); } } catch (TemporalDataException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } }
@Override public void run(double frac) { logger.trace("run -> begin of method"); try { workingDataset = new GranularityAggregationTree(sourceDataset.getDataColumnSchema(),granularities.length+1); ArrayList<TemporalObject> currentBranches = new ArrayList<TemporalObject>(); ArrayList<ArrayList<TemporalObject>> currentLeaves = new ArrayList<ArrayList<TemporalObject>>(); for(TemporalObject iO : sourceDataset.temporalObjects()) { long inf = iO.getTemporalElement().asGeneric().getGranule().getInf(); int i = 0; for(TemporalObject iB : currentBranches) { if (iB.getTemporalElement().asGeneric().getGranule().contains(inf)) { currentLeaves.get(i).add(iO); break; } i++; } if(i >= currentBranches.size()) { Granule newGranule = new Granule(inf,inf,granularities[0]); Instant newTe = workingDataset.addInstant(newGranule); currentBranches.add(workingDataset.addTemporalObject(newTe)); ArrayList<TemporalObject> leaves = new ArrayList<TemporalObject>(); leaves.add(iO); currentLeaves.add(leaves); } } long[] roots = new long[currentBranches.size()]; for(int i=0; i<currentBranches.size(); i++) roots[i] = currentBranches.get(i).getId(); if (granularities.length > 1) { for(int i=1; i<granularities.length;i++) { ArrayList<ArrayList<TemporalObject>> futureLeaves = new ArrayList<ArrayList<TemporalObject>>(); ArrayList<TemporalObject> futureBranches = new ArrayList<TemporalObject>(); int whichChild = 0; for(int k=0; k<currentLeaves.size();k++) { ArrayList<TemporalObject> iCurrentLeaves = currentLeaves.get(k); while(iCurrentLeaves.size() > 0) { TemporalObject currentLeave = iCurrentLeaves.get(0); iCurrentLeaves.remove(0); TemporalObject targetBranch = null; long inf = currentLeave.getTemporalElement().asGeneric().getInf(); long sup = currentLeave.getTemporalElement().asGeneric().getSup(); whichChild = 0; for(int l=0; l<k; l++) whichChild += currentBranches.get(l).getChildCount(); for(TemporalObject potentialBranch : currentBranches.get(k).childObjects()) { if (potentialBranch.getTemporalElement().asGeneric().getGranule().contains(inf)) { targetBranch = potentialBranch; break; } whichChild++; } if (targetBranch == null) { Granule newGranule = new Granule(inf,sup,granularities[i]); Instant newTe = workingDataset.addInstant(newGranule); targetBranch = workingDataset.addTemporalObject(newTe); futureBranches.add(targetBranch); futureLeaves.add(new ArrayList<TemporalObject>()); whichChild = futureLeaves.size() - 1; currentBranches.get(k).linkWithChild(targetBranch); } futureLeaves.get(whichChild).add(currentLeave); } } if(i==granularities.length-1) { for(int j=0; j<futureBranches.size(); j++ ) { aggregate(futureBranches.get(j),futureLeaves.get(j),granularities.length-1); } } else { currentBranches = futureBranches; currentLeaves = futureLeaves; } } for(long iRoot : roots) aggregate(workingDataset.getTemporalObject(iRoot),0); } else { for(int i=0; i<roots.length; i++) aggregate(workingDataset.getTemporalObject(roots[i]),currentLeaves.get(i),0); } // TODO this could be cleaned for (long rootId : roots) { workingDataset.getTemporalObject(rootId).setRoot(true); } } catch (TemporalDataException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } }
7,812
1
// TODO this could be cleaned
@Override public void run(double frac) { logger.trace("run -> begin of method"); try { workingDataset = new GranularityAggregationTree(sourceDataset.getDataColumnSchema(),granularities.length+1); ArrayList<TemporalObject> currentBranches = new ArrayList<TemporalObject>(); ArrayList<ArrayList<TemporalObject>> currentLeaves = new ArrayList<ArrayList<TemporalObject>>(); for(TemporalObject iO : sourceDataset.temporalObjects()) { long inf = iO.getTemporalElement().asGeneric().getGranule().getInf(); int i = 0; for(TemporalObject iB : currentBranches) { if (iB.getTemporalElement().asGeneric().getGranule().contains(inf)) { currentLeaves.get(i).add(iO); break; } i++; } if(i >= currentBranches.size()) { Granule newGranule = new Granule(inf,inf,granularities[0]); Instant newTe = workingDataset.addInstant(newGranule); currentBranches.add(workingDataset.addTemporalObject(newTe)); ArrayList<TemporalObject> leaves = new ArrayList<TemporalObject>(); leaves.add(iO); currentLeaves.add(leaves); } } long[] roots = new long[currentBranches.size()]; for(int i=0; i<currentBranches.size(); i++) roots[i] = currentBranches.get(i).getId(); if (granularities.length > 1) { for(int i=1; i<granularities.length;i++) { ArrayList<ArrayList<TemporalObject>> futureLeaves = new ArrayList<ArrayList<TemporalObject>>(); ArrayList<TemporalObject> futureBranches = new ArrayList<TemporalObject>(); int whichChild = 0; for(int k=0; k<currentLeaves.size();k++) { ArrayList<TemporalObject> iCurrentLeaves = currentLeaves.get(k); while(iCurrentLeaves.size() > 0) { TemporalObject currentLeave = iCurrentLeaves.get(0); iCurrentLeaves.remove(0); TemporalObject targetBranch = null; long inf = currentLeave.getTemporalElement().asGeneric().getInf(); long sup = currentLeave.getTemporalElement().asGeneric().getSup(); whichChild = 0; for(int l=0; l<k; l++) whichChild += currentBranches.get(l).getChildCount(); for(TemporalObject potentialBranch : currentBranches.get(k).childObjects()) { if (potentialBranch.getTemporalElement().asGeneric().getGranule().contains(inf)) { targetBranch = potentialBranch; break; } whichChild++; } if (targetBranch == null) { Granule newGranule = new Granule(inf,sup,granularities[i]); Instant newTe = workingDataset.addInstant(newGranule); targetBranch = workingDataset.addTemporalObject(newTe); futureBranches.add(targetBranch); futureLeaves.add(new ArrayList<TemporalObject>()); whichChild = futureLeaves.size() - 1; currentBranches.get(k).linkWithChild(targetBranch); } futureLeaves.get(whichChild).add(currentLeave); } } if(i==granularities.length-1) { for(int j=0; j<futureBranches.size(); j++ ) { aggregate(futureBranches.get(j),futureLeaves.get(j),granularities.length-1); } } else { currentBranches = futureBranches; currentLeaves = futureLeaves; } } for(long iRoot : roots) aggregate(workingDataset.getTemporalObject(iRoot),0); } else { for(int i=0; i<roots.length; i++) aggregate(workingDataset.getTemporalObject(roots[i]),currentLeaves.get(i),0); } // TODO this could be cleaned for (long rootId : roots) { workingDataset.getTemporalObject(rootId).setRoot(true); } } catch (TemporalDataException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } }
DESIGN
true
aggregate(workingDataset.getTemporalObject(roots[i]),currentLeaves.get(i),0); } // TODO this could be cleaned for (long rootId : roots) { workingDataset.getTemporalObject(rootId).setRoot(true);
currentBranches = futureBranches; currentLeaves = futureLeaves; } } for(long iRoot : roots) aggregate(workingDataset.getTemporalObject(iRoot),0); } else { for(int i=0; i<roots.length; i++) aggregate(workingDataset.getTemporalObject(roots[i]),currentLeaves.get(i),0); } // TODO this could be cleaned for (long rootId : roots) { workingDataset.getTemporalObject(rootId).setRoot(true); } } catch (TemporalDataException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } }
currentBranches.get(k).linkWithChild(targetBranch); } futureLeaves.get(whichChild).add(currentLeave); } } if(i==granularities.length-1) { for(int j=0; j<futureBranches.size(); j++ ) { aggregate(futureBranches.get(j),futureLeaves.get(j),granularities.length-1); } } else { currentBranches = futureBranches; currentLeaves = futureLeaves; } } for(long iRoot : roots) aggregate(workingDataset.getTemporalObject(iRoot),0); } else { for(int i=0; i<roots.length; i++) aggregate(workingDataset.getTemporalObject(roots[i]),currentLeaves.get(i),0); } // TODO this could be cleaned for (long rootId : roots) { workingDataset.getTemporalObject(rootId).setRoot(true); } } catch (TemporalDataException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } }
7,812
2
// TODO Auto-generated catch block
@Override public void run(double frac) { logger.trace("run -> begin of method"); try { workingDataset = new GranularityAggregationTree(sourceDataset.getDataColumnSchema(),granularities.length+1); ArrayList<TemporalObject> currentBranches = new ArrayList<TemporalObject>(); ArrayList<ArrayList<TemporalObject>> currentLeaves = new ArrayList<ArrayList<TemporalObject>>(); for(TemporalObject iO : sourceDataset.temporalObjects()) { long inf = iO.getTemporalElement().asGeneric().getGranule().getInf(); int i = 0; for(TemporalObject iB : currentBranches) { if (iB.getTemporalElement().asGeneric().getGranule().contains(inf)) { currentLeaves.get(i).add(iO); break; } i++; } if(i >= currentBranches.size()) { Granule newGranule = new Granule(inf,inf,granularities[0]); Instant newTe = workingDataset.addInstant(newGranule); currentBranches.add(workingDataset.addTemporalObject(newTe)); ArrayList<TemporalObject> leaves = new ArrayList<TemporalObject>(); leaves.add(iO); currentLeaves.add(leaves); } } long[] roots = new long[currentBranches.size()]; for(int i=0; i<currentBranches.size(); i++) roots[i] = currentBranches.get(i).getId(); if (granularities.length > 1) { for(int i=1; i<granularities.length;i++) { ArrayList<ArrayList<TemporalObject>> futureLeaves = new ArrayList<ArrayList<TemporalObject>>(); ArrayList<TemporalObject> futureBranches = new ArrayList<TemporalObject>(); int whichChild = 0; for(int k=0; k<currentLeaves.size();k++) { ArrayList<TemporalObject> iCurrentLeaves = currentLeaves.get(k); while(iCurrentLeaves.size() > 0) { TemporalObject currentLeave = iCurrentLeaves.get(0); iCurrentLeaves.remove(0); TemporalObject targetBranch = null; long inf = currentLeave.getTemporalElement().asGeneric().getInf(); long sup = currentLeave.getTemporalElement().asGeneric().getSup(); whichChild = 0; for(int l=0; l<k; l++) whichChild += currentBranches.get(l).getChildCount(); for(TemporalObject potentialBranch : currentBranches.get(k).childObjects()) { if (potentialBranch.getTemporalElement().asGeneric().getGranule().contains(inf)) { targetBranch = potentialBranch; break; } whichChild++; } if (targetBranch == null) { Granule newGranule = new Granule(inf,sup,granularities[i]); Instant newTe = workingDataset.addInstant(newGranule); targetBranch = workingDataset.addTemporalObject(newTe); futureBranches.add(targetBranch); futureLeaves.add(new ArrayList<TemporalObject>()); whichChild = futureLeaves.size() - 1; currentBranches.get(k).linkWithChild(targetBranch); } futureLeaves.get(whichChild).add(currentLeave); } } if(i==granularities.length-1) { for(int j=0; j<futureBranches.size(); j++ ) { aggregate(futureBranches.get(j),futureLeaves.get(j),granularities.length-1); } } else { currentBranches = futureBranches; currentLeaves = futureLeaves; } } for(long iRoot : roots) aggregate(workingDataset.getTemporalObject(iRoot),0); } else { for(int i=0; i<roots.length; i++) aggregate(workingDataset.getTemporalObject(roots[i]),currentLeaves.get(i),0); } // TODO this could be cleaned for (long rootId : roots) { workingDataset.getTemporalObject(rootId).setRoot(true); } } catch (TemporalDataException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } }
DESIGN
true
} } catch (TemporalDataException e1) { // TODO Auto-generated catch block e1.printStackTrace(); }
aggregate(workingDataset.getTemporalObject(iRoot),0); } else { for(int i=0; i<roots.length; i++) aggregate(workingDataset.getTemporalObject(roots[i]),currentLeaves.get(i),0); } // TODO this could be cleaned for (long rootId : roots) { workingDataset.getTemporalObject(rootId).setRoot(true); } } catch (TemporalDataException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } }
if(i==granularities.length-1) { for(int j=0; j<futureBranches.size(); j++ ) { aggregate(futureBranches.get(j),futureLeaves.get(j),granularities.length-1); } } else { currentBranches = futureBranches; currentLeaves = futureLeaves; } } for(long iRoot : roots) aggregate(workingDataset.getTemporalObject(iRoot),0); } else { for(int i=0; i<roots.length; i++) aggregate(workingDataset.getTemporalObject(roots[i]),currentLeaves.get(i),0); } // TODO this could be cleaned for (long rootId : roots) { workingDataset.getTemporalObject(rootId).setRoot(true); } } catch (TemporalDataException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } }
16,008
0
/** * Lets the AI player make an automated move. * * Here, the AI player calculates a fitting next field which he then marks * trying to win the tic tac toe game. */
@Override public void makeMove() { // TODO Not just randomly select a tile to mark while (true) { try { List<Tile> tiles = getGameLogic().getTerritory().getTiles(); Tile tile = tiles.get(GameLogic.RANDOM.nextInt(tiles.size())); tile.setMarkedPlayer(this); getGameLogic().endMove(); return; } catch (TileAreadyMarkedException e) { } } }
NONSATD
true
@Override public void makeMove() { // TODO Not just randomly select a tile to mark while (true) { try { List<Tile> tiles = getGameLogic().getTerritory().getTiles(); Tile tile = tiles.get(GameLogic.RANDOM.nextInt(tiles.size())); tile.setMarkedPlayer(this); getGameLogic().endMove(); return; } catch (TileAreadyMarkedException e) { } } }
@Override public void makeMove() { // TODO Not just randomly select a tile to mark while (true) { try { List<Tile> tiles = getGameLogic().getTerritory().getTiles(); Tile tile = tiles.get(GameLogic.RANDOM.nextInt(tiles.size())); tile.setMarkedPlayer(this); getGameLogic().endMove(); return; } catch (TileAreadyMarkedException e) { } } }
@Override public void makeMove() { // TODO Not just randomly select a tile to mark while (true) { try { List<Tile> tiles = getGameLogic().getTerritory().getTiles(); Tile tile = tiles.get(GameLogic.RANDOM.nextInt(tiles.size())); tile.setMarkedPlayer(this); getGameLogic().endMove(); return; } catch (TileAreadyMarkedException e) { } } }
16,008
1
// TODO Not just randomly select a tile to mark
@Override public void makeMove() { // TODO Not just randomly select a tile to mark while (true) { try { List<Tile> tiles = getGameLogic().getTerritory().getTiles(); Tile tile = tiles.get(GameLogic.RANDOM.nextInt(tiles.size())); tile.setMarkedPlayer(this); getGameLogic().endMove(); return; } catch (TileAreadyMarkedException e) { } } }
DESIGN
true
@Override public void makeMove() { // TODO Not just randomly select a tile to mark while (true) { try {
@Override public void makeMove() { // TODO Not just randomly select a tile to mark while (true) { try { List<Tile> tiles = getGameLogic().getTerritory().getTiles(); Tile tile = tiles.get(GameLogic.RANDOM.nextInt(tiles.size())); tile.setMarkedPlayer(this); getGameLogic().endMove(); return; } catch (TileAreadyMarkedException e) { } }
@Override public void makeMove() { // TODO Not just randomly select a tile to mark while (true) { try { List<Tile> tiles = getGameLogic().getTerritory().getTiles(); Tile tile = tiles.get(GameLogic.RANDOM.nextInt(tiles.size())); tile.setMarkedPlayer(this); getGameLogic().endMove(); return; } catch (TileAreadyMarkedException e) { } } }
7,823
0
// Evaluate a segmented funtion for a single value. Return -1 if no valid segment found . // If fn type is 0, perform an interpolation on the table
private static double EvalSegmentedFn(final cmsToneCurve g, double R) { int i; for (i = g.nSegments-1; i >= 0 ; --i) { // Check for domain if ((R > g.Segments[i].x0) && (R <= g.Segments[i].x1)) { // Type == 0 means segment is sampled if (g.Segments[i].Type == 0) { float R1 = (float)(R - g.Segments[i].x0); float[] Out = new float[1]; // Setup the table (TODO: clean that) g.SegInterp[i].Table = g.Segments[i].SampledPoints; g.SegInterp[i].Interpolation.getFloat().run(new float[]{R1}, Out, g.SegInterp[i]); return Out[0]; } else { return g.Evals[i].run(g.Segments[i].Type, g.Segments[i].Params, R); } } } return MINUS_INF; }
NONSATD
true
private static double EvalSegmentedFn(final cmsToneCurve g, double R) { int i; for (i = g.nSegments-1; i >= 0 ; --i) { // Check for domain if ((R > g.Segments[i].x0) && (R <= g.Segments[i].x1)) { // Type == 0 means segment is sampled if (g.Segments[i].Type == 0) { float R1 = (float)(R - g.Segments[i].x0); float[] Out = new float[1]; // Setup the table (TODO: clean that) g.SegInterp[i].Table = g.Segments[i].SampledPoints; g.SegInterp[i].Interpolation.getFloat().run(new float[]{R1}, Out, g.SegInterp[i]); return Out[0]; } else { return g.Evals[i].run(g.Segments[i].Type, g.Segments[i].Params, R); } } } return MINUS_INF; }
private static double EvalSegmentedFn(final cmsToneCurve g, double R) { int i; for (i = g.nSegments-1; i >= 0 ; --i) { // Check for domain if ((R > g.Segments[i].x0) && (R <= g.Segments[i].x1)) { // Type == 0 means segment is sampled if (g.Segments[i].Type == 0) { float R1 = (float)(R - g.Segments[i].x0); float[] Out = new float[1]; // Setup the table (TODO: clean that) g.SegInterp[i].Table = g.Segments[i].SampledPoints; g.SegInterp[i].Interpolation.getFloat().run(new float[]{R1}, Out, g.SegInterp[i]); return Out[0]; } else { return g.Evals[i].run(g.Segments[i].Type, g.Segments[i].Params, R); } } } return MINUS_INF; }
private static double EvalSegmentedFn(final cmsToneCurve g, double R) { int i; for (i = g.nSegments-1; i >= 0 ; --i) { // Check for domain if ((R > g.Segments[i].x0) && (R <= g.Segments[i].x1)) { // Type == 0 means segment is sampled if (g.Segments[i].Type == 0) { float R1 = (float)(R - g.Segments[i].x0); float[] Out = new float[1]; // Setup the table (TODO: clean that) g.SegInterp[i].Table = g.Segments[i].SampledPoints; g.SegInterp[i].Interpolation.getFloat().run(new float[]{R1}, Out, g.SegInterp[i]); return Out[0]; } else { return g.Evals[i].run(g.Segments[i].Type, g.Segments[i].Params, R); } } } return MINUS_INF; }
7,823
1
// Check for domain
private static double EvalSegmentedFn(final cmsToneCurve g, double R) { int i; for (i = g.nSegments-1; i >= 0 ; --i) { // Check for domain if ((R > g.Segments[i].x0) && (R <= g.Segments[i].x1)) { // Type == 0 means segment is sampled if (g.Segments[i].Type == 0) { float R1 = (float)(R - g.Segments[i].x0); float[] Out = new float[1]; // Setup the table (TODO: clean that) g.SegInterp[i].Table = g.Segments[i].SampledPoints; g.SegInterp[i].Interpolation.getFloat().run(new float[]{R1}, Out, g.SegInterp[i]); return Out[0]; } else { return g.Evals[i].run(g.Segments[i].Type, g.Segments[i].Params, R); } } } return MINUS_INF; }
NONSATD
true
for (i = g.nSegments-1; i >= 0 ; --i) { // Check for domain if ((R > g.Segments[i].x0) && (R <= g.Segments[i].x1)) {
private static double EvalSegmentedFn(final cmsToneCurve g, double R) { int i; for (i = g.nSegments-1; i >= 0 ; --i) { // Check for domain if ((R > g.Segments[i].x0) && (R <= g.Segments[i].x1)) { // Type == 0 means segment is sampled if (g.Segments[i].Type == 0) { float R1 = (float)(R - g.Segments[i].x0); float[] Out = new float[1]; // Setup the table (TODO: clean that) g.SegInterp[i].Table = g.Segments[i].SampledPoints; g.SegInterp[i].Interpolation.getFloat().run(new float[]{R1}, Out, g.SegInterp[i]);
private static double EvalSegmentedFn(final cmsToneCurve g, double R) { int i; for (i = g.nSegments-1; i >= 0 ; --i) { // Check for domain if ((R > g.Segments[i].x0) && (R <= g.Segments[i].x1)) { // Type == 0 means segment is sampled if (g.Segments[i].Type == 0) { float R1 = (float)(R - g.Segments[i].x0); float[] Out = new float[1]; // Setup the table (TODO: clean that) g.SegInterp[i].Table = g.Segments[i].SampledPoints; g.SegInterp[i].Interpolation.getFloat().run(new float[]{R1}, Out, g.SegInterp[i]); return Out[0]; } else { return g.Evals[i].run(g.Segments[i].Type, g.Segments[i].Params, R); } } } return MINUS_INF; }
7,823
2
// Type == 0 means segment is sampled
private static double EvalSegmentedFn(final cmsToneCurve g, double R) { int i; for (i = g.nSegments-1; i >= 0 ; --i) { // Check for domain if ((R > g.Segments[i].x0) && (R <= g.Segments[i].x1)) { // Type == 0 means segment is sampled if (g.Segments[i].Type == 0) { float R1 = (float)(R - g.Segments[i].x0); float[] Out = new float[1]; // Setup the table (TODO: clean that) g.SegInterp[i].Table = g.Segments[i].SampledPoints; g.SegInterp[i].Interpolation.getFloat().run(new float[]{R1}, Out, g.SegInterp[i]); return Out[0]; } else { return g.Evals[i].run(g.Segments[i].Type, g.Segments[i].Params, R); } } } return MINUS_INF; }
NONSATD
true
if ((R > g.Segments[i].x0) && (R <= g.Segments[i].x1)) { // Type == 0 means segment is sampled if (g.Segments[i].Type == 0) {
private static double EvalSegmentedFn(final cmsToneCurve g, double R) { int i; for (i = g.nSegments-1; i >= 0 ; --i) { // Check for domain if ((R > g.Segments[i].x0) && (R <= g.Segments[i].x1)) { // Type == 0 means segment is sampled if (g.Segments[i].Type == 0) { float R1 = (float)(R - g.Segments[i].x0); float[] Out = new float[1]; // Setup the table (TODO: clean that) g.SegInterp[i].Table = g.Segments[i].SampledPoints; g.SegInterp[i].Interpolation.getFloat().run(new float[]{R1}, Out, g.SegInterp[i]); return Out[0]; } else
private static double EvalSegmentedFn(final cmsToneCurve g, double R) { int i; for (i = g.nSegments-1; i >= 0 ; --i) { // Check for domain if ((R > g.Segments[i].x0) && (R <= g.Segments[i].x1)) { // Type == 0 means segment is sampled if (g.Segments[i].Type == 0) { float R1 = (float)(R - g.Segments[i].x0); float[] Out = new float[1]; // Setup the table (TODO: clean that) g.SegInterp[i].Table = g.Segments[i].SampledPoints; g.SegInterp[i].Interpolation.getFloat().run(new float[]{R1}, Out, g.SegInterp[i]); return Out[0]; } else { return g.Evals[i].run(g.Segments[i].Type, g.Segments[i].Params, R); } } } return MINUS_INF; }
7,823
3
// Setup the table (TODO: clean that)
private static double EvalSegmentedFn(final cmsToneCurve g, double R) { int i; for (i = g.nSegments-1; i >= 0 ; --i) { // Check for domain if ((R > g.Segments[i].x0) && (R <= g.Segments[i].x1)) { // Type == 0 means segment is sampled if (g.Segments[i].Type == 0) { float R1 = (float)(R - g.Segments[i].x0); float[] Out = new float[1]; // Setup the table (TODO: clean that) g.SegInterp[i].Table = g.Segments[i].SampledPoints; g.SegInterp[i].Interpolation.getFloat().run(new float[]{R1}, Out, g.SegInterp[i]); return Out[0]; } else { return g.Evals[i].run(g.Segments[i].Type, g.Segments[i].Params, R); } } } return MINUS_INF; }
DESIGN
true
float R1 = (float)(R - g.Segments[i].x0); float[] Out = new float[1]; // Setup the table (TODO: clean that) g.SegInterp[i].Table = g.Segments[i].SampledPoints; g.SegInterp[i].Interpolation.getFloat().run(new float[]{R1}, Out, g.SegInterp[i]);
for (i = g.nSegments-1; i >= 0 ; --i) { // Check for domain if ((R > g.Segments[i].x0) && (R <= g.Segments[i].x1)) { // Type == 0 means segment is sampled if (g.Segments[i].Type == 0) { float R1 = (float)(R - g.Segments[i].x0); float[] Out = new float[1]; // Setup the table (TODO: clean that) g.SegInterp[i].Table = g.Segments[i].SampledPoints; g.SegInterp[i].Interpolation.getFloat().run(new float[]{R1}, Out, g.SegInterp[i]); return Out[0]; } else { return g.Evals[i].run(g.Segments[i].Type, g.Segments[i].Params, R); } } }
private static double EvalSegmentedFn(final cmsToneCurve g, double R) { int i; for (i = g.nSegments-1; i >= 0 ; --i) { // Check for domain if ((R > g.Segments[i].x0) && (R <= g.Segments[i].x1)) { // Type == 0 means segment is sampled if (g.Segments[i].Type == 0) { float R1 = (float)(R - g.Segments[i].x0); float[] Out = new float[1]; // Setup the table (TODO: clean that) g.SegInterp[i].Table = g.Segments[i].SampledPoints; g.SegInterp[i].Interpolation.getFloat().run(new float[]{R1}, Out, g.SegInterp[i]); return Out[0]; } else { return g.Evals[i].run(g.Segments[i].Type, g.Segments[i].Params, R); } } } return MINUS_INF; }
7,837
0
// TODO: Support APNG animated images?
public Image LoadImageAnim(String fileName, int frames) { Image image = new Image(); int framesCount = 1; if (SUPPORT_FILEFORMAT_GIF) { if (rCore.IsFileExtension(fileName, ".gif")) { byte[] fileData = null; try{ BufferedImage tmpImg = ImageIO.read(new File(fileName)); ByteArrayOutputStream os = new ByteArrayOutputStream(); ImageIO.write(tmpImg, rCore.GetFileExtension(fileName).substring(1), os); fileData = os.toByteArray(); } catch (IOException exception) { exception.printStackTrace(); } if (fileData != null) { try (MemoryStack stack = MemoryStack.stackPush()) { IntBuffer widthBuffer = stack.mallocInt(1); IntBuffer heightBuffer = stack.mallocInt(1); IntBuffer compBuffer = stack.mallocInt(1); PointerBuffer delaysBuffer = null; IntBuffer framesBuffer = stack.mallocInt(1); framesBuffer.put(framesCount).flip(); ByteBuffer fileDataBuffer = MemoryUtil.memAlloc(fileData.length); fileDataBuffer.put(fileData).flip(); ByteBuffer imgBuffer = STBImage.stbi_load_gif_from_memory(fileDataBuffer, delaysBuffer, widthBuffer, heightBuffer, framesBuffer, compBuffer, 4); image.width = widthBuffer.get(); image.height = heightBuffer.get(); image.mipmaps = 1; image.format = RL_PIXELFORMAT_UNCOMPRESSED_R8G8B8A8; if (imgBuffer != null) { byte[] bytes = new byte[imgBuffer.capacity()]; for (int i = 0; i < bytes.length; i++) { bytes[i] = imgBuffer.get(); } image.setData(bytes); } fileData = null; } } } } else{ image = LoadImage(fileName); } // TODO: Support APNG animated images? frames = framesCount; return image; }
IMPLEMENTATION
true
image = LoadImage(fileName); } // TODO: Support APNG animated images? frames = framesCount; return image;
image.setData(bytes); } fileData = null; } } } } else{ image = LoadImage(fileName); } // TODO: Support APNG animated images? frames = framesCount; return image; }
widthBuffer, heightBuffer, framesBuffer, compBuffer, 4); image.width = widthBuffer.get(); image.height = heightBuffer.get(); image.mipmaps = 1; image.format = RL_PIXELFORMAT_UNCOMPRESSED_R8G8B8A8; if (imgBuffer != null) { byte[] bytes = new byte[imgBuffer.capacity()]; for (int i = 0; i < bytes.length; i++) { bytes[i] = imgBuffer.get(); } image.setData(bytes); } fileData = null; } } } } else{ image = LoadImage(fileName); } // TODO: Support APNG animated images? frames = framesCount; return image; }
16,039
0
/** * Ugly DP * * @param n * @return */
public static List<String> generateParenthesis1(int n) { Set<String>[] dp = new Set[n + 1]; Set<String> first = new HashSet<>(); first.add(""); dp[0] = first; for (int i = 1; i <= n; i++) { Set<String> set = new HashSet<>(); for (String pre : dp[i - 1]) { set.add("(" + pre + ")"); } for (int m = 1; m < i; m++) { for (String p1 : dp[m]) { for (String p2 : dp[i - m]) { set.add(p1 + p2); set.add(p2 + p1); } } } dp[i] = set; } return new ArrayList<>(dp[n]); }
DESIGN
true
public static List<String> generateParenthesis1(int n) { Set<String>[] dp = new Set[n + 1]; Set<String> first = new HashSet<>(); first.add(""); dp[0] = first; for (int i = 1; i <= n; i++) { Set<String> set = new HashSet<>(); for (String pre : dp[i - 1]) { set.add("(" + pre + ")"); } for (int m = 1; m < i; m++) { for (String p1 : dp[m]) { for (String p2 : dp[i - m]) { set.add(p1 + p2); set.add(p2 + p1); } } } dp[i] = set; } return new ArrayList<>(dp[n]); }
public static List<String> generateParenthesis1(int n) { Set<String>[] dp = new Set[n + 1]; Set<String> first = new HashSet<>(); first.add(""); dp[0] = first; for (int i = 1; i <= n; i++) { Set<String> set = new HashSet<>(); for (String pre : dp[i - 1]) { set.add("(" + pre + ")"); } for (int m = 1; m < i; m++) { for (String p1 : dp[m]) { for (String p2 : dp[i - m]) { set.add(p1 + p2); set.add(p2 + p1); } } } dp[i] = set; } return new ArrayList<>(dp[n]); }
public static List<String> generateParenthesis1(int n) { Set<String>[] dp = new Set[n + 1]; Set<String> first = new HashSet<>(); first.add(""); dp[0] = first; for (int i = 1; i <= n; i++) { Set<String> set = new HashSet<>(); for (String pre : dp[i - 1]) { set.add("(" + pre + ")"); } for (int m = 1; m < i; m++) { for (String p1 : dp[m]) { for (String p2 : dp[i - m]) { set.add(p1 + p2); set.add(p2 + p1); } } } dp[i] = set; } return new ArrayList<>(dp[n]); }
7,861
0
//FindBugs is not smart enough to infer that actual type of this.currentState //is IiaSuiteState not just SuiteState
@Override @SuppressFBWarnings("BC_UNCONFIRMED_CAST") protected void runApiSpecificTests(HttpSecurityDescription securityDescription) throws SuiteBroken { this.currentState.selectedHeiId = getParameterValue(HEI_ID_PARAMETER, this::getSelectedHeiId); }
DESIGN
true
@Override @SuppressFBWarnings("BC_UNCONFIRMED_CAST") protected void runApiSpecificTests(HttpSecurityDescription securityDescription) throws SuiteBroken { this.currentState.selectedHeiId = getParameterValue(HEI_ID_PARAMETER, this::getSelectedHeiId); }
@Override @SuppressFBWarnings("BC_UNCONFIRMED_CAST") protected void runApiSpecificTests(HttpSecurityDescription securityDescription) throws SuiteBroken { this.currentState.selectedHeiId = getParameterValue(HEI_ID_PARAMETER, this::getSelectedHeiId); }
@Override @SuppressFBWarnings("BC_UNCONFIRMED_CAST") protected void runApiSpecificTests(HttpSecurityDescription securityDescription) throws SuiteBroken { this.currentState.selectedHeiId = getParameterValue(HEI_ID_PARAMETER, this::getSelectedHeiId); }
16,061
0
/** * {@inheritDoc} */
@Override protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception { DataColumnSpec[] allColSpecs = new DataColumnSpec[1]; allColSpecs[0] = new DataColumnSpecCreator("url", StringCell.TYPE).createSpec(); DataTableSpec outputSpec = new DataTableSpec(allColSpecs); // System.out.println("calling execute"+resultUrl.getStringValue()); // the execution context will provide us with storage capacity, in this // case a data container to which we will add rows sequentially // Note, this container can also handle arbitrary big data tables, it // will buffer to disc if necessary. BufferedDataContainer container = exec.createDataContainer(outputSpec); DataCell[] cells = new DataCell[1]; String urlTemplate = resultUrl.getStringValue(); Iterator<DataRow> varIt = inData[0].iterator(); DataTableSpec dts = inData[0].getDataTableSpec(); String[] colNames = dts.getColumnNames(); if(varIt.hasNext()){ //while(varIt.hasNext()){ DataRow current = varIt.next(); Iterator<DataCell> cellIt = current.iterator(); int colCount = 0; while(cellIt.hasNext()){ DataCell currentCell= cellIt.next(); String curVar = colNames[colCount]; String curVal = currentCell.toString(); //System.out.println("curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(urlTemplate.indexOf(curVar)==-1){ System.out.println("1curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); urlTemplate = urlTemplate+"&"+curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8"); System.out.println("2curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); }else{ System.out.println("3curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); String configValue = ""; if(urlTemplate.indexOf("&"+curVar)!=-1){ configValue = urlTemplate.substring(urlTemplate.indexOf("&"+curVar)+curVar.length()+2,urlTemplate.indexOf("]",urlTemplate.indexOf(curVar))); }else if(urlTemplate.indexOf("?"+curVar)!=-1){ configValue = urlTemplate.substring(urlTemplate.indexOf("?"+curVar)+curVar.length()+2,urlTemplate.indexOf("]",urlTemplate.indexOf(curVar))); } System.out.println("4curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(configValue.endsWith("&")){ configValue = configValue.substring(0,configValue.length()-1); //get rid of the & } if(colCount==0){ urlTemplate +="&"; } System.out.println("5curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(!configValue.equals("")){ System.out.println("6curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); System.out.println("config var: "+curVar+" with configValue:"+ configValue+ ", is overwritten with value: "+currentCell.toString() ); urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"&]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")+"&"); urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")); }else{ //System.out.println("now we are here"); System.out.println("7curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(urlTemplate.endsWith("&")||urlTemplate.endsWith("?")){ //urlTemplate = urlTemplate.substring(0,urlTemplate.length()-1); urlTemplate = urlTemplate+curVar+"="+URLEncoder.encode(curVal,"UTF-8"); }else{ urlTemplate = "&"+urlTemplate+curVar+"="+URLEncoder.encode(curVal,"UTF-8"); } //urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"&]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")+"&"); //urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")); //System.out.println("urlTemplate before:"+doubleStr+", and after:"+urlTemplate); } } colCount++; } } System.out.println("yy:"+urlTemplate); //urlTemplate =urlTemplate.replaceAll("\\[.*?\\]", ""); urlTemplate =urlTemplate.replaceAll("\\[", ""); urlTemplate =urlTemplate.replaceAll("\\]", ""); urlTemplate =urlTemplate.replaceAll("%28", "("); urlTemplate =urlTemplate.replaceAll("%29", ")"); //urlTemplate =urlTemplate.replaceAll("%5B", "["); //strange that this is needed....API issue? //urlTemplate =urlTemplate.replaceAll("%5D", "]"); System.out.println("yy:"+urlTemplate); if(urlTemplate.endsWith("&")){ urlTemplate = urlTemplate.substring(0,urlTemplate.length()-1); } //urlTemplate = urlTemplate.substring(0, urlTemplate.length()-1); //System.out.println("urlTemplate became "+urlTemplate); cells[0] = new StringCell(urlTemplate); DataRow row = new DefaultRow("aboutCell", cells); container.addRowToTable(row); container.close(); BufferedDataTable out = container.getTable(); // TODO: Return a BufferedDataTable for each output port return new BufferedDataTable[]{out}; }
NONSATD
true
@Override protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception { DataColumnSpec[] allColSpecs = new DataColumnSpec[1]; allColSpecs[0] = new DataColumnSpecCreator("url", StringCell.TYPE).createSpec(); DataTableSpec outputSpec = new DataTableSpec(allColSpecs); // System.out.println("calling execute"+resultUrl.getStringValue()); // the execution context will provide us with storage capacity, in this // case a data container to which we will add rows sequentially // Note, this container can also handle arbitrary big data tables, it // will buffer to disc if necessary. BufferedDataContainer container = exec.createDataContainer(outputSpec); DataCell[] cells = new DataCell[1]; String urlTemplate = resultUrl.getStringValue(); Iterator<DataRow> varIt = inData[0].iterator(); DataTableSpec dts = inData[0].getDataTableSpec(); String[] colNames = dts.getColumnNames(); if(varIt.hasNext()){ //while(varIt.hasNext()){ DataRow current = varIt.next(); Iterator<DataCell> cellIt = current.iterator(); int colCount = 0; while(cellIt.hasNext()){ DataCell currentCell= cellIt.next(); String curVar = colNames[colCount]; String curVal = currentCell.toString(); //System.out.println("curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(urlTemplate.indexOf(curVar)==-1){ System.out.println("1curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); urlTemplate = urlTemplate+"&"+curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8"); System.out.println("2curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); }else{ System.out.println("3curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); String configValue = ""; if(urlTemplate.indexOf("&"+curVar)!=-1){ configValue = urlTemplate.substring(urlTemplate.indexOf("&"+curVar)+curVar.length()+2,urlTemplate.indexOf("]",urlTemplate.indexOf(curVar))); }else if(urlTemplate.indexOf("?"+curVar)!=-1){ configValue = urlTemplate.substring(urlTemplate.indexOf("?"+curVar)+curVar.length()+2,urlTemplate.indexOf("]",urlTemplate.indexOf(curVar))); } System.out.println("4curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(configValue.endsWith("&")){ configValue = configValue.substring(0,configValue.length()-1); //get rid of the & } if(colCount==0){ urlTemplate +="&"; } System.out.println("5curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(!configValue.equals("")){ System.out.println("6curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); System.out.println("config var: "+curVar+" with configValue:"+ configValue+ ", is overwritten with value: "+currentCell.toString() ); urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"&]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")+"&"); urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")); }else{ //System.out.println("now we are here"); System.out.println("7curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(urlTemplate.endsWith("&")||urlTemplate.endsWith("?")){ //urlTemplate = urlTemplate.substring(0,urlTemplate.length()-1); urlTemplate = urlTemplate+curVar+"="+URLEncoder.encode(curVal,"UTF-8"); }else{ urlTemplate = "&"+urlTemplate+curVar+"="+URLEncoder.encode(curVal,"UTF-8"); } //urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"&]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")+"&"); //urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")); //System.out.println("urlTemplate before:"+doubleStr+", and after:"+urlTemplate); } } colCount++; } } System.out.println("yy:"+urlTemplate); //urlTemplate =urlTemplate.replaceAll("\\[.*?\\]", ""); urlTemplate =urlTemplate.replaceAll("\\[", ""); urlTemplate =urlTemplate.replaceAll("\\]", ""); urlTemplate =urlTemplate.replaceAll("%28", "("); urlTemplate =urlTemplate.replaceAll("%29", ")"); //urlTemplate =urlTemplate.replaceAll("%5B", "["); //strange that this is needed....API issue? //urlTemplate =urlTemplate.replaceAll("%5D", "]"); System.out.println("yy:"+urlTemplate); if(urlTemplate.endsWith("&")){ urlTemplate = urlTemplate.substring(0,urlTemplate.length()-1); } //urlTemplate = urlTemplate.substring(0, urlTemplate.length()-1); //System.out.println("urlTemplate became "+urlTemplate); cells[0] = new StringCell(urlTemplate); DataRow row = new DefaultRow("aboutCell", cells); container.addRowToTable(row); container.close(); BufferedDataTable out = container.getTable(); // TODO: Return a BufferedDataTable for each output port return new BufferedDataTable[]{out}; }
@Override protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception { DataColumnSpec[] allColSpecs = new DataColumnSpec[1]; allColSpecs[0] = new DataColumnSpecCreator("url", StringCell.TYPE).createSpec(); DataTableSpec outputSpec = new DataTableSpec(allColSpecs); // System.out.println("calling execute"+resultUrl.getStringValue()); // the execution context will provide us with storage capacity, in this // case a data container to which we will add rows sequentially // Note, this container can also handle arbitrary big data tables, it // will buffer to disc if necessary. BufferedDataContainer container = exec.createDataContainer(outputSpec); DataCell[] cells = new DataCell[1]; String urlTemplate = resultUrl.getStringValue(); Iterator<DataRow> varIt = inData[0].iterator(); DataTableSpec dts = inData[0].getDataTableSpec(); String[] colNames = dts.getColumnNames(); if(varIt.hasNext()){ //while(varIt.hasNext()){ DataRow current = varIt.next(); Iterator<DataCell> cellIt = current.iterator(); int colCount = 0; while(cellIt.hasNext()){ DataCell currentCell= cellIt.next(); String curVar = colNames[colCount]; String curVal = currentCell.toString(); //System.out.println("curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(urlTemplate.indexOf(curVar)==-1){ System.out.println("1curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); urlTemplate = urlTemplate+"&"+curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8"); System.out.println("2curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); }else{ System.out.println("3curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); String configValue = ""; if(urlTemplate.indexOf("&"+curVar)!=-1){ configValue = urlTemplate.substring(urlTemplate.indexOf("&"+curVar)+curVar.length()+2,urlTemplate.indexOf("]",urlTemplate.indexOf(curVar))); }else if(urlTemplate.indexOf("?"+curVar)!=-1){ configValue = urlTemplate.substring(urlTemplate.indexOf("?"+curVar)+curVar.length()+2,urlTemplate.indexOf("]",urlTemplate.indexOf(curVar))); } System.out.println("4curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(configValue.endsWith("&")){ configValue = configValue.substring(0,configValue.length()-1); //get rid of the & } if(colCount==0){ urlTemplate +="&"; } System.out.println("5curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(!configValue.equals("")){ System.out.println("6curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); System.out.println("config var: "+curVar+" with configValue:"+ configValue+ ", is overwritten with value: "+currentCell.toString() ); urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"&]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")+"&"); urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")); }else{ //System.out.println("now we are here"); System.out.println("7curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(urlTemplate.endsWith("&")||urlTemplate.endsWith("?")){ //urlTemplate = urlTemplate.substring(0,urlTemplate.length()-1); urlTemplate = urlTemplate+curVar+"="+URLEncoder.encode(curVal,"UTF-8"); }else{ urlTemplate = "&"+urlTemplate+curVar+"="+URLEncoder.encode(curVal,"UTF-8"); } //urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"&]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")+"&"); //urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")); //System.out.println("urlTemplate before:"+doubleStr+", and after:"+urlTemplate); } } colCount++; } } System.out.println("yy:"+urlTemplate); //urlTemplate =urlTemplate.replaceAll("\\[.*?\\]", ""); urlTemplate =urlTemplate.replaceAll("\\[", ""); urlTemplate =urlTemplate.replaceAll("\\]", ""); urlTemplate =urlTemplate.replaceAll("%28", "("); urlTemplate =urlTemplate.replaceAll("%29", ")"); //urlTemplate =urlTemplate.replaceAll("%5B", "["); //strange that this is needed....API issue? //urlTemplate =urlTemplate.replaceAll("%5D", "]"); System.out.println("yy:"+urlTemplate); if(urlTemplate.endsWith("&")){ urlTemplate = urlTemplate.substring(0,urlTemplate.length()-1); } //urlTemplate = urlTemplate.substring(0, urlTemplate.length()-1); //System.out.println("urlTemplate became "+urlTemplate); cells[0] = new StringCell(urlTemplate); DataRow row = new DefaultRow("aboutCell", cells); container.addRowToTable(row); container.close(); BufferedDataTable out = container.getTable(); // TODO: Return a BufferedDataTable for each output port return new BufferedDataTable[]{out}; }
@Override protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception { DataColumnSpec[] allColSpecs = new DataColumnSpec[1]; allColSpecs[0] = new DataColumnSpecCreator("url", StringCell.TYPE).createSpec(); DataTableSpec outputSpec = new DataTableSpec(allColSpecs); // System.out.println("calling execute"+resultUrl.getStringValue()); // the execution context will provide us with storage capacity, in this // case a data container to which we will add rows sequentially // Note, this container can also handle arbitrary big data tables, it // will buffer to disc if necessary. BufferedDataContainer container = exec.createDataContainer(outputSpec); DataCell[] cells = new DataCell[1]; String urlTemplate = resultUrl.getStringValue(); Iterator<DataRow> varIt = inData[0].iterator(); DataTableSpec dts = inData[0].getDataTableSpec(); String[] colNames = dts.getColumnNames(); if(varIt.hasNext()){ //while(varIt.hasNext()){ DataRow current = varIt.next(); Iterator<DataCell> cellIt = current.iterator(); int colCount = 0; while(cellIt.hasNext()){ DataCell currentCell= cellIt.next(); String curVar = colNames[colCount]; String curVal = currentCell.toString(); //System.out.println("curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(urlTemplate.indexOf(curVar)==-1){ System.out.println("1curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); urlTemplate = urlTemplate+"&"+curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8"); System.out.println("2curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); }else{ System.out.println("3curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); String configValue = ""; if(urlTemplate.indexOf("&"+curVar)!=-1){ configValue = urlTemplate.substring(urlTemplate.indexOf("&"+curVar)+curVar.length()+2,urlTemplate.indexOf("]",urlTemplate.indexOf(curVar))); }else if(urlTemplate.indexOf("?"+curVar)!=-1){ configValue = urlTemplate.substring(urlTemplate.indexOf("?"+curVar)+curVar.length()+2,urlTemplate.indexOf("]",urlTemplate.indexOf(curVar))); } System.out.println("4curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(configValue.endsWith("&")){ configValue = configValue.substring(0,configValue.length()-1); //get rid of the & } if(colCount==0){ urlTemplate +="&"; } System.out.println("5curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(!configValue.equals("")){ System.out.println("6curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); System.out.println("config var: "+curVar+" with configValue:"+ configValue+ ", is overwritten with value: "+currentCell.toString() ); urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"&]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")+"&"); urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")); }else{ //System.out.println("now we are here"); System.out.println("7curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(urlTemplate.endsWith("&")||urlTemplate.endsWith("?")){ //urlTemplate = urlTemplate.substring(0,urlTemplate.length()-1); urlTemplate = urlTemplate+curVar+"="+URLEncoder.encode(curVal,"UTF-8"); }else{ urlTemplate = "&"+urlTemplate+curVar+"="+URLEncoder.encode(curVal,"UTF-8"); } //urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"&]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")+"&"); //urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")); //System.out.println("urlTemplate before:"+doubleStr+", and after:"+urlTemplate); } } colCount++; } } System.out.println("yy:"+urlTemplate); //urlTemplate =urlTemplate.replaceAll("\\[.*?\\]", ""); urlTemplate =urlTemplate.replaceAll("\\[", ""); urlTemplate =urlTemplate.replaceAll("\\]", ""); urlTemplate =urlTemplate.replaceAll("%28", "("); urlTemplate =urlTemplate.replaceAll("%29", ")"); //urlTemplate =urlTemplate.replaceAll("%5B", "["); //strange that this is needed....API issue? //urlTemplate =urlTemplate.replaceAll("%5D", "]"); System.out.println("yy:"+urlTemplate); if(urlTemplate.endsWith("&")){ urlTemplate = urlTemplate.substring(0,urlTemplate.length()-1); } //urlTemplate = urlTemplate.substring(0, urlTemplate.length()-1); //System.out.println("urlTemplate became "+urlTemplate); cells[0] = new StringCell(urlTemplate); DataRow row = new DefaultRow("aboutCell", cells); container.addRowToTable(row); container.close(); BufferedDataTable out = container.getTable(); // TODO: Return a BufferedDataTable for each output port return new BufferedDataTable[]{out}; }
16,061
1
// System.out.println("calling execute"+resultUrl.getStringValue()); // the execution context will provide us with storage capacity, in this // case a data container to which we will add rows sequentially // Note, this container can also handle arbitrary big data tables, it // will buffer to disc if necessary.
@Override protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception { DataColumnSpec[] allColSpecs = new DataColumnSpec[1]; allColSpecs[0] = new DataColumnSpecCreator("url", StringCell.TYPE).createSpec(); DataTableSpec outputSpec = new DataTableSpec(allColSpecs); // System.out.println("calling execute"+resultUrl.getStringValue()); // the execution context will provide us with storage capacity, in this // case a data container to which we will add rows sequentially // Note, this container can also handle arbitrary big data tables, it // will buffer to disc if necessary. BufferedDataContainer container = exec.createDataContainer(outputSpec); DataCell[] cells = new DataCell[1]; String urlTemplate = resultUrl.getStringValue(); Iterator<DataRow> varIt = inData[0].iterator(); DataTableSpec dts = inData[0].getDataTableSpec(); String[] colNames = dts.getColumnNames(); if(varIt.hasNext()){ //while(varIt.hasNext()){ DataRow current = varIt.next(); Iterator<DataCell> cellIt = current.iterator(); int colCount = 0; while(cellIt.hasNext()){ DataCell currentCell= cellIt.next(); String curVar = colNames[colCount]; String curVal = currentCell.toString(); //System.out.println("curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(urlTemplate.indexOf(curVar)==-1){ System.out.println("1curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); urlTemplate = urlTemplate+"&"+curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8"); System.out.println("2curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); }else{ System.out.println("3curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); String configValue = ""; if(urlTemplate.indexOf("&"+curVar)!=-1){ configValue = urlTemplate.substring(urlTemplate.indexOf("&"+curVar)+curVar.length()+2,urlTemplate.indexOf("]",urlTemplate.indexOf(curVar))); }else if(urlTemplate.indexOf("?"+curVar)!=-1){ configValue = urlTemplate.substring(urlTemplate.indexOf("?"+curVar)+curVar.length()+2,urlTemplate.indexOf("]",urlTemplate.indexOf(curVar))); } System.out.println("4curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(configValue.endsWith("&")){ configValue = configValue.substring(0,configValue.length()-1); //get rid of the & } if(colCount==0){ urlTemplate +="&"; } System.out.println("5curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(!configValue.equals("")){ System.out.println("6curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); System.out.println("config var: "+curVar+" with configValue:"+ configValue+ ", is overwritten with value: "+currentCell.toString() ); urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"&]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")+"&"); urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")); }else{ //System.out.println("now we are here"); System.out.println("7curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(urlTemplate.endsWith("&")||urlTemplate.endsWith("?")){ //urlTemplate = urlTemplate.substring(0,urlTemplate.length()-1); urlTemplate = urlTemplate+curVar+"="+URLEncoder.encode(curVal,"UTF-8"); }else{ urlTemplate = "&"+urlTemplate+curVar+"="+URLEncoder.encode(curVal,"UTF-8"); } //urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"&]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")+"&"); //urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")); //System.out.println("urlTemplate before:"+doubleStr+", and after:"+urlTemplate); } } colCount++; } } System.out.println("yy:"+urlTemplate); //urlTemplate =urlTemplate.replaceAll("\\[.*?\\]", ""); urlTemplate =urlTemplate.replaceAll("\\[", ""); urlTemplate =urlTemplate.replaceAll("\\]", ""); urlTemplate =urlTemplate.replaceAll("%28", "("); urlTemplate =urlTemplate.replaceAll("%29", ")"); //urlTemplate =urlTemplate.replaceAll("%5B", "["); //strange that this is needed....API issue? //urlTemplate =urlTemplate.replaceAll("%5D", "]"); System.out.println("yy:"+urlTemplate); if(urlTemplate.endsWith("&")){ urlTemplate = urlTemplate.substring(0,urlTemplate.length()-1); } //urlTemplate = urlTemplate.substring(0, urlTemplate.length()-1); //System.out.println("urlTemplate became "+urlTemplate); cells[0] = new StringCell(urlTemplate); DataRow row = new DefaultRow("aboutCell", cells); container.addRowToTable(row); container.close(); BufferedDataTable out = container.getTable(); // TODO: Return a BufferedDataTable for each output port return new BufferedDataTable[]{out}; }
NONSATD
true
new DataColumnSpecCreator("url", StringCell.TYPE).createSpec(); DataTableSpec outputSpec = new DataTableSpec(allColSpecs); // System.out.println("calling execute"+resultUrl.getStringValue()); // the execution context will provide us with storage capacity, in this // case a data container to which we will add rows sequentially // Note, this container can also handle arbitrary big data tables, it // will buffer to disc if necessary. BufferedDataContainer container = exec.createDataContainer(outputSpec); DataCell[] cells = new DataCell[1];
@Override protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception { DataColumnSpec[] allColSpecs = new DataColumnSpec[1]; allColSpecs[0] = new DataColumnSpecCreator("url", StringCell.TYPE).createSpec(); DataTableSpec outputSpec = new DataTableSpec(allColSpecs); // System.out.println("calling execute"+resultUrl.getStringValue()); // the execution context will provide us with storage capacity, in this // case a data container to which we will add rows sequentially // Note, this container can also handle arbitrary big data tables, it // will buffer to disc if necessary. BufferedDataContainer container = exec.createDataContainer(outputSpec); DataCell[] cells = new DataCell[1]; String urlTemplate = resultUrl.getStringValue(); Iterator<DataRow> varIt = inData[0].iterator(); DataTableSpec dts = inData[0].getDataTableSpec(); String[] colNames = dts.getColumnNames(); if(varIt.hasNext()){ //while(varIt.hasNext()){ DataRow current = varIt.next(); Iterator<DataCell> cellIt = current.iterator();
@Override protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception { DataColumnSpec[] allColSpecs = new DataColumnSpec[1]; allColSpecs[0] = new DataColumnSpecCreator("url", StringCell.TYPE).createSpec(); DataTableSpec outputSpec = new DataTableSpec(allColSpecs); // System.out.println("calling execute"+resultUrl.getStringValue()); // the execution context will provide us with storage capacity, in this // case a data container to which we will add rows sequentially // Note, this container can also handle arbitrary big data tables, it // will buffer to disc if necessary. BufferedDataContainer container = exec.createDataContainer(outputSpec); DataCell[] cells = new DataCell[1]; String urlTemplate = resultUrl.getStringValue(); Iterator<DataRow> varIt = inData[0].iterator(); DataTableSpec dts = inData[0].getDataTableSpec(); String[] colNames = dts.getColumnNames(); if(varIt.hasNext()){ //while(varIt.hasNext()){ DataRow current = varIt.next(); Iterator<DataCell> cellIt = current.iterator(); int colCount = 0; while(cellIt.hasNext()){ DataCell currentCell= cellIt.next(); String curVar = colNames[colCount]; String curVal = currentCell.toString(); //System.out.println("curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(urlTemplate.indexOf(curVar)==-1){ System.out.println("1curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); urlTemplate = urlTemplate+"&"+curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8"); System.out.println("2curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate);
16,061
2
//while(varIt.hasNext()){
@Override protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception { DataColumnSpec[] allColSpecs = new DataColumnSpec[1]; allColSpecs[0] = new DataColumnSpecCreator("url", StringCell.TYPE).createSpec(); DataTableSpec outputSpec = new DataTableSpec(allColSpecs); // System.out.println("calling execute"+resultUrl.getStringValue()); // the execution context will provide us with storage capacity, in this // case a data container to which we will add rows sequentially // Note, this container can also handle arbitrary big data tables, it // will buffer to disc if necessary. BufferedDataContainer container = exec.createDataContainer(outputSpec); DataCell[] cells = new DataCell[1]; String urlTemplate = resultUrl.getStringValue(); Iterator<DataRow> varIt = inData[0].iterator(); DataTableSpec dts = inData[0].getDataTableSpec(); String[] colNames = dts.getColumnNames(); if(varIt.hasNext()){ //while(varIt.hasNext()){ DataRow current = varIt.next(); Iterator<DataCell> cellIt = current.iterator(); int colCount = 0; while(cellIt.hasNext()){ DataCell currentCell= cellIt.next(); String curVar = colNames[colCount]; String curVal = currentCell.toString(); //System.out.println("curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(urlTemplate.indexOf(curVar)==-1){ System.out.println("1curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); urlTemplate = urlTemplate+"&"+curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8"); System.out.println("2curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); }else{ System.out.println("3curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); String configValue = ""; if(urlTemplate.indexOf("&"+curVar)!=-1){ configValue = urlTemplate.substring(urlTemplate.indexOf("&"+curVar)+curVar.length()+2,urlTemplate.indexOf("]",urlTemplate.indexOf(curVar))); }else if(urlTemplate.indexOf("?"+curVar)!=-1){ configValue = urlTemplate.substring(urlTemplate.indexOf("?"+curVar)+curVar.length()+2,urlTemplate.indexOf("]",urlTemplate.indexOf(curVar))); } System.out.println("4curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(configValue.endsWith("&")){ configValue = configValue.substring(0,configValue.length()-1); //get rid of the & } if(colCount==0){ urlTemplate +="&"; } System.out.println("5curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(!configValue.equals("")){ System.out.println("6curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); System.out.println("config var: "+curVar+" with configValue:"+ configValue+ ", is overwritten with value: "+currentCell.toString() ); urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"&]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")+"&"); urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")); }else{ //System.out.println("now we are here"); System.out.println("7curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(urlTemplate.endsWith("&")||urlTemplate.endsWith("?")){ //urlTemplate = urlTemplate.substring(0,urlTemplate.length()-1); urlTemplate = urlTemplate+curVar+"="+URLEncoder.encode(curVal,"UTF-8"); }else{ urlTemplate = "&"+urlTemplate+curVar+"="+URLEncoder.encode(curVal,"UTF-8"); } //urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"&]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")+"&"); //urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")); //System.out.println("urlTemplate before:"+doubleStr+", and after:"+urlTemplate); } } colCount++; } } System.out.println("yy:"+urlTemplate); //urlTemplate =urlTemplate.replaceAll("\\[.*?\\]", ""); urlTemplate =urlTemplate.replaceAll("\\[", ""); urlTemplate =urlTemplate.replaceAll("\\]", ""); urlTemplate =urlTemplate.replaceAll("%28", "("); urlTemplate =urlTemplate.replaceAll("%29", ")"); //urlTemplate =urlTemplate.replaceAll("%5B", "["); //strange that this is needed....API issue? //urlTemplate =urlTemplate.replaceAll("%5D", "]"); System.out.println("yy:"+urlTemplate); if(urlTemplate.endsWith("&")){ urlTemplate = urlTemplate.substring(0,urlTemplate.length()-1); } //urlTemplate = urlTemplate.substring(0, urlTemplate.length()-1); //System.out.println("urlTemplate became "+urlTemplate); cells[0] = new StringCell(urlTemplate); DataRow row = new DefaultRow("aboutCell", cells); container.addRowToTable(row); container.close(); BufferedDataTable out = container.getTable(); // TODO: Return a BufferedDataTable for each output port return new BufferedDataTable[]{out}; }
NONSATD
true
String[] colNames = dts.getColumnNames(); if(varIt.hasNext()){ //while(varIt.hasNext()){ DataRow current = varIt.next(); Iterator<DataCell> cellIt = current.iterator();
// case a data container to which we will add rows sequentially // Note, this container can also handle arbitrary big data tables, it // will buffer to disc if necessary. BufferedDataContainer container = exec.createDataContainer(outputSpec); DataCell[] cells = new DataCell[1]; String urlTemplate = resultUrl.getStringValue(); Iterator<DataRow> varIt = inData[0].iterator(); DataTableSpec dts = inData[0].getDataTableSpec(); String[] colNames = dts.getColumnNames(); if(varIt.hasNext()){ //while(varIt.hasNext()){ DataRow current = varIt.next(); Iterator<DataCell> cellIt = current.iterator(); int colCount = 0; while(cellIt.hasNext()){ DataCell currentCell= cellIt.next(); String curVar = colNames[colCount]; String curVal = currentCell.toString(); //System.out.println("curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(urlTemplate.indexOf(curVar)==-1){ System.out.println("1curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate);
@Override protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception { DataColumnSpec[] allColSpecs = new DataColumnSpec[1]; allColSpecs[0] = new DataColumnSpecCreator("url", StringCell.TYPE).createSpec(); DataTableSpec outputSpec = new DataTableSpec(allColSpecs); // System.out.println("calling execute"+resultUrl.getStringValue()); // the execution context will provide us with storage capacity, in this // case a data container to which we will add rows sequentially // Note, this container can also handle arbitrary big data tables, it // will buffer to disc if necessary. BufferedDataContainer container = exec.createDataContainer(outputSpec); DataCell[] cells = new DataCell[1]; String urlTemplate = resultUrl.getStringValue(); Iterator<DataRow> varIt = inData[0].iterator(); DataTableSpec dts = inData[0].getDataTableSpec(); String[] colNames = dts.getColumnNames(); if(varIt.hasNext()){ //while(varIt.hasNext()){ DataRow current = varIt.next(); Iterator<DataCell> cellIt = current.iterator(); int colCount = 0; while(cellIt.hasNext()){ DataCell currentCell= cellIt.next(); String curVar = colNames[colCount]; String curVal = currentCell.toString(); //System.out.println("curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(urlTemplate.indexOf(curVar)==-1){ System.out.println("1curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); urlTemplate = urlTemplate+"&"+curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8"); System.out.println("2curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); }else{ System.out.println("3curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); String configValue = ""; if(urlTemplate.indexOf("&"+curVar)!=-1){ configValue = urlTemplate.substring(urlTemplate.indexOf("&"+curVar)+curVar.length()+2,urlTemplate.indexOf("]",urlTemplate.indexOf(curVar))); }else if(urlTemplate.indexOf("?"+curVar)!=-1){ configValue = urlTemplate.substring(urlTemplate.indexOf("?"+curVar)+curVar.length()+2,urlTemplate.indexOf("]",urlTemplate.indexOf(curVar))); }
16,061
3
//System.out.println("curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate);
@Override protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception { DataColumnSpec[] allColSpecs = new DataColumnSpec[1]; allColSpecs[0] = new DataColumnSpecCreator("url", StringCell.TYPE).createSpec(); DataTableSpec outputSpec = new DataTableSpec(allColSpecs); // System.out.println("calling execute"+resultUrl.getStringValue()); // the execution context will provide us with storage capacity, in this // case a data container to which we will add rows sequentially // Note, this container can also handle arbitrary big data tables, it // will buffer to disc if necessary. BufferedDataContainer container = exec.createDataContainer(outputSpec); DataCell[] cells = new DataCell[1]; String urlTemplate = resultUrl.getStringValue(); Iterator<DataRow> varIt = inData[0].iterator(); DataTableSpec dts = inData[0].getDataTableSpec(); String[] colNames = dts.getColumnNames(); if(varIt.hasNext()){ //while(varIt.hasNext()){ DataRow current = varIt.next(); Iterator<DataCell> cellIt = current.iterator(); int colCount = 0; while(cellIt.hasNext()){ DataCell currentCell= cellIt.next(); String curVar = colNames[colCount]; String curVal = currentCell.toString(); //System.out.println("curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(urlTemplate.indexOf(curVar)==-1){ System.out.println("1curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); urlTemplate = urlTemplate+"&"+curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8"); System.out.println("2curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); }else{ System.out.println("3curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); String configValue = ""; if(urlTemplate.indexOf("&"+curVar)!=-1){ configValue = urlTemplate.substring(urlTemplate.indexOf("&"+curVar)+curVar.length()+2,urlTemplate.indexOf("]",urlTemplate.indexOf(curVar))); }else if(urlTemplate.indexOf("?"+curVar)!=-1){ configValue = urlTemplate.substring(urlTemplate.indexOf("?"+curVar)+curVar.length()+2,urlTemplate.indexOf("]",urlTemplate.indexOf(curVar))); } System.out.println("4curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(configValue.endsWith("&")){ configValue = configValue.substring(0,configValue.length()-1); //get rid of the & } if(colCount==0){ urlTemplate +="&"; } System.out.println("5curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(!configValue.equals("")){ System.out.println("6curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); System.out.println("config var: "+curVar+" with configValue:"+ configValue+ ", is overwritten with value: "+currentCell.toString() ); urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"&]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")+"&"); urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")); }else{ //System.out.println("now we are here"); System.out.println("7curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(urlTemplate.endsWith("&")||urlTemplate.endsWith("?")){ //urlTemplate = urlTemplate.substring(0,urlTemplate.length()-1); urlTemplate = urlTemplate+curVar+"="+URLEncoder.encode(curVal,"UTF-8"); }else{ urlTemplate = "&"+urlTemplate+curVar+"="+URLEncoder.encode(curVal,"UTF-8"); } //urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"&]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")+"&"); //urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")); //System.out.println("urlTemplate before:"+doubleStr+", and after:"+urlTemplate); } } colCount++; } } System.out.println("yy:"+urlTemplate); //urlTemplate =urlTemplate.replaceAll("\\[.*?\\]", ""); urlTemplate =urlTemplate.replaceAll("\\[", ""); urlTemplate =urlTemplate.replaceAll("\\]", ""); urlTemplate =urlTemplate.replaceAll("%28", "("); urlTemplate =urlTemplate.replaceAll("%29", ")"); //urlTemplate =urlTemplate.replaceAll("%5B", "["); //strange that this is needed....API issue? //urlTemplate =urlTemplate.replaceAll("%5D", "]"); System.out.println("yy:"+urlTemplate); if(urlTemplate.endsWith("&")){ urlTemplate = urlTemplate.substring(0,urlTemplate.length()-1); } //urlTemplate = urlTemplate.substring(0, urlTemplate.length()-1); //System.out.println("urlTemplate became "+urlTemplate); cells[0] = new StringCell(urlTemplate); DataRow row = new DefaultRow("aboutCell", cells); container.addRowToTable(row); container.close(); BufferedDataTable out = container.getTable(); // TODO: Return a BufferedDataTable for each output port return new BufferedDataTable[]{out}; }
NONSATD
true
String curVar = colNames[colCount]; String curVal = currentCell.toString(); //System.out.println("curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(urlTemplate.indexOf(curVar)==-1){ System.out.println("1curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate);
String[] colNames = dts.getColumnNames(); if(varIt.hasNext()){ //while(varIt.hasNext()){ DataRow current = varIt.next(); Iterator<DataCell> cellIt = current.iterator(); int colCount = 0; while(cellIt.hasNext()){ DataCell currentCell= cellIt.next(); String curVar = colNames[colCount]; String curVal = currentCell.toString(); //System.out.println("curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(urlTemplate.indexOf(curVar)==-1){ System.out.println("1curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); urlTemplate = urlTemplate+"&"+curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8"); System.out.println("2curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); }else{ System.out.println("3curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); String configValue = ""; if(urlTemplate.indexOf("&"+curVar)!=-1){ configValue = urlTemplate.substring(urlTemplate.indexOf("&"+curVar)+curVar.length()+2,urlTemplate.indexOf("]",urlTemplate.indexOf(curVar))); }else if(urlTemplate.indexOf("?"+curVar)!=-1){
// System.out.println("calling execute"+resultUrl.getStringValue()); // the execution context will provide us with storage capacity, in this // case a data container to which we will add rows sequentially // Note, this container can also handle arbitrary big data tables, it // will buffer to disc if necessary. BufferedDataContainer container = exec.createDataContainer(outputSpec); DataCell[] cells = new DataCell[1]; String urlTemplate = resultUrl.getStringValue(); Iterator<DataRow> varIt = inData[0].iterator(); DataTableSpec dts = inData[0].getDataTableSpec(); String[] colNames = dts.getColumnNames(); if(varIt.hasNext()){ //while(varIt.hasNext()){ DataRow current = varIt.next(); Iterator<DataCell> cellIt = current.iterator(); int colCount = 0; while(cellIt.hasNext()){ DataCell currentCell= cellIt.next(); String curVar = colNames[colCount]; String curVal = currentCell.toString(); //System.out.println("curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(urlTemplate.indexOf(curVar)==-1){ System.out.println("1curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); urlTemplate = urlTemplate+"&"+curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8"); System.out.println("2curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); }else{ System.out.println("3curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); String configValue = ""; if(urlTemplate.indexOf("&"+curVar)!=-1){ configValue = urlTemplate.substring(urlTemplate.indexOf("&"+curVar)+curVar.length()+2,urlTemplate.indexOf("]",urlTemplate.indexOf(curVar))); }else if(urlTemplate.indexOf("?"+curVar)!=-1){ configValue = urlTemplate.substring(urlTemplate.indexOf("?"+curVar)+curVar.length()+2,urlTemplate.indexOf("]",urlTemplate.indexOf(curVar))); } System.out.println("4curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(configValue.endsWith("&")){ configValue = configValue.substring(0,configValue.length()-1); //get rid of the & } if(colCount==0){ urlTemplate +="&"; } System.out.println("5curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate);
16,061
4
//get rid of the &
@Override protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception { DataColumnSpec[] allColSpecs = new DataColumnSpec[1]; allColSpecs[0] = new DataColumnSpecCreator("url", StringCell.TYPE).createSpec(); DataTableSpec outputSpec = new DataTableSpec(allColSpecs); // System.out.println("calling execute"+resultUrl.getStringValue()); // the execution context will provide us with storage capacity, in this // case a data container to which we will add rows sequentially // Note, this container can also handle arbitrary big data tables, it // will buffer to disc if necessary. BufferedDataContainer container = exec.createDataContainer(outputSpec); DataCell[] cells = new DataCell[1]; String urlTemplate = resultUrl.getStringValue(); Iterator<DataRow> varIt = inData[0].iterator(); DataTableSpec dts = inData[0].getDataTableSpec(); String[] colNames = dts.getColumnNames(); if(varIt.hasNext()){ //while(varIt.hasNext()){ DataRow current = varIt.next(); Iterator<DataCell> cellIt = current.iterator(); int colCount = 0; while(cellIt.hasNext()){ DataCell currentCell= cellIt.next(); String curVar = colNames[colCount]; String curVal = currentCell.toString(); //System.out.println("curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(urlTemplate.indexOf(curVar)==-1){ System.out.println("1curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); urlTemplate = urlTemplate+"&"+curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8"); System.out.println("2curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); }else{ System.out.println("3curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); String configValue = ""; if(urlTemplate.indexOf("&"+curVar)!=-1){ configValue = urlTemplate.substring(urlTemplate.indexOf("&"+curVar)+curVar.length()+2,urlTemplate.indexOf("]",urlTemplate.indexOf(curVar))); }else if(urlTemplate.indexOf("?"+curVar)!=-1){ configValue = urlTemplate.substring(urlTemplate.indexOf("?"+curVar)+curVar.length()+2,urlTemplate.indexOf("]",urlTemplate.indexOf(curVar))); } System.out.println("4curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(configValue.endsWith("&")){ configValue = configValue.substring(0,configValue.length()-1); //get rid of the & } if(colCount==0){ urlTemplate +="&"; } System.out.println("5curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(!configValue.equals("")){ System.out.println("6curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); System.out.println("config var: "+curVar+" with configValue:"+ configValue+ ", is overwritten with value: "+currentCell.toString() ); urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"&]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")+"&"); urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")); }else{ //System.out.println("now we are here"); System.out.println("7curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(urlTemplate.endsWith("&")||urlTemplate.endsWith("?")){ //urlTemplate = urlTemplate.substring(0,urlTemplate.length()-1); urlTemplate = urlTemplate+curVar+"="+URLEncoder.encode(curVal,"UTF-8"); }else{ urlTemplate = "&"+urlTemplate+curVar+"="+URLEncoder.encode(curVal,"UTF-8"); } //urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"&]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")+"&"); //urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")); //System.out.println("urlTemplate before:"+doubleStr+", and after:"+urlTemplate); } } colCount++; } } System.out.println("yy:"+urlTemplate); //urlTemplate =urlTemplate.replaceAll("\\[.*?\\]", ""); urlTemplate =urlTemplate.replaceAll("\\[", ""); urlTemplate =urlTemplate.replaceAll("\\]", ""); urlTemplate =urlTemplate.replaceAll("%28", "("); urlTemplate =urlTemplate.replaceAll("%29", ")"); //urlTemplate =urlTemplate.replaceAll("%5B", "["); //strange that this is needed....API issue? //urlTemplate =urlTemplate.replaceAll("%5D", "]"); System.out.println("yy:"+urlTemplate); if(urlTemplate.endsWith("&")){ urlTemplate = urlTemplate.substring(0,urlTemplate.length()-1); } //urlTemplate = urlTemplate.substring(0, urlTemplate.length()-1); //System.out.println("urlTemplate became "+urlTemplate); cells[0] = new StringCell(urlTemplate); DataRow row = new DefaultRow("aboutCell", cells); container.addRowToTable(row); container.close(); BufferedDataTable out = container.getTable(); // TODO: Return a BufferedDataTable for each output port return new BufferedDataTable[]{out}; }
NONSATD
true
System.out.println("4curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(configValue.endsWith("&")){ configValue = configValue.substring(0,configValue.length()-1); //get rid of the & } if(colCount==0){
}else{ System.out.println("3curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); String configValue = ""; if(urlTemplate.indexOf("&"+curVar)!=-1){ configValue = urlTemplate.substring(urlTemplate.indexOf("&"+curVar)+curVar.length()+2,urlTemplate.indexOf("]",urlTemplate.indexOf(curVar))); }else if(urlTemplate.indexOf("?"+curVar)!=-1){ configValue = urlTemplate.substring(urlTemplate.indexOf("?"+curVar)+curVar.length()+2,urlTemplate.indexOf("]",urlTemplate.indexOf(curVar))); } System.out.println("4curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(configValue.endsWith("&")){ configValue = configValue.substring(0,configValue.length()-1); //get rid of the & } if(colCount==0){ urlTemplate +="&"; } System.out.println("5curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(!configValue.equals("")){ System.out.println("6curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); System.out.println("config var: "+curVar+" with configValue:"+ configValue+ ", is overwritten with value: "+currentCell.toString() ); urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"&]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")+"&"); urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8"));
int colCount = 0; while(cellIt.hasNext()){ DataCell currentCell= cellIt.next(); String curVar = colNames[colCount]; String curVal = currentCell.toString(); //System.out.println("curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(urlTemplate.indexOf(curVar)==-1){ System.out.println("1curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); urlTemplate = urlTemplate+"&"+curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8"); System.out.println("2curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); }else{ System.out.println("3curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); String configValue = ""; if(urlTemplate.indexOf("&"+curVar)!=-1){ configValue = urlTemplate.substring(urlTemplate.indexOf("&"+curVar)+curVar.length()+2,urlTemplate.indexOf("]",urlTemplate.indexOf(curVar))); }else if(urlTemplate.indexOf("?"+curVar)!=-1){ configValue = urlTemplate.substring(urlTemplate.indexOf("?"+curVar)+curVar.length()+2,urlTemplate.indexOf("]",urlTemplate.indexOf(curVar))); } System.out.println("4curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(configValue.endsWith("&")){ configValue = configValue.substring(0,configValue.length()-1); //get rid of the & } if(colCount==0){ urlTemplate +="&"; } System.out.println("5curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(!configValue.equals("")){ System.out.println("6curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); System.out.println("config var: "+curVar+" with configValue:"+ configValue+ ", is overwritten with value: "+currentCell.toString() ); urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"&]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")+"&"); urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")); }else{ //System.out.println("now we are here"); System.out.println("7curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(urlTemplate.endsWith("&")||urlTemplate.endsWith("?")){ //urlTemplate = urlTemplate.substring(0,urlTemplate.length()-1); urlTemplate = urlTemplate+curVar+"="+URLEncoder.encode(curVal,"UTF-8"); }else{ urlTemplate = "&"+urlTemplate+curVar+"="+URLEncoder.encode(curVal,"UTF-8"); } //urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"&]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")+"&");
16,061
5
//System.out.println("now we are here");
@Override protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception { DataColumnSpec[] allColSpecs = new DataColumnSpec[1]; allColSpecs[0] = new DataColumnSpecCreator("url", StringCell.TYPE).createSpec(); DataTableSpec outputSpec = new DataTableSpec(allColSpecs); // System.out.println("calling execute"+resultUrl.getStringValue()); // the execution context will provide us with storage capacity, in this // case a data container to which we will add rows sequentially // Note, this container can also handle arbitrary big data tables, it // will buffer to disc if necessary. BufferedDataContainer container = exec.createDataContainer(outputSpec); DataCell[] cells = new DataCell[1]; String urlTemplate = resultUrl.getStringValue(); Iterator<DataRow> varIt = inData[0].iterator(); DataTableSpec dts = inData[0].getDataTableSpec(); String[] colNames = dts.getColumnNames(); if(varIt.hasNext()){ //while(varIt.hasNext()){ DataRow current = varIt.next(); Iterator<DataCell> cellIt = current.iterator(); int colCount = 0; while(cellIt.hasNext()){ DataCell currentCell= cellIt.next(); String curVar = colNames[colCount]; String curVal = currentCell.toString(); //System.out.println("curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(urlTemplate.indexOf(curVar)==-1){ System.out.println("1curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); urlTemplate = urlTemplate+"&"+curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8"); System.out.println("2curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); }else{ System.out.println("3curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); String configValue = ""; if(urlTemplate.indexOf("&"+curVar)!=-1){ configValue = urlTemplate.substring(urlTemplate.indexOf("&"+curVar)+curVar.length()+2,urlTemplate.indexOf("]",urlTemplate.indexOf(curVar))); }else if(urlTemplate.indexOf("?"+curVar)!=-1){ configValue = urlTemplate.substring(urlTemplate.indexOf("?"+curVar)+curVar.length()+2,urlTemplate.indexOf("]",urlTemplate.indexOf(curVar))); } System.out.println("4curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(configValue.endsWith("&")){ configValue = configValue.substring(0,configValue.length()-1); //get rid of the & } if(colCount==0){ urlTemplate +="&"; } System.out.println("5curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(!configValue.equals("")){ System.out.println("6curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); System.out.println("config var: "+curVar+" with configValue:"+ configValue+ ", is overwritten with value: "+currentCell.toString() ); urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"&]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")+"&"); urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")); }else{ //System.out.println("now we are here"); System.out.println("7curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(urlTemplate.endsWith("&")||urlTemplate.endsWith("?")){ //urlTemplate = urlTemplate.substring(0,urlTemplate.length()-1); urlTemplate = urlTemplate+curVar+"="+URLEncoder.encode(curVal,"UTF-8"); }else{ urlTemplate = "&"+urlTemplate+curVar+"="+URLEncoder.encode(curVal,"UTF-8"); } //urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"&]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")+"&"); //urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")); //System.out.println("urlTemplate before:"+doubleStr+", and after:"+urlTemplate); } } colCount++; } } System.out.println("yy:"+urlTemplate); //urlTemplate =urlTemplate.replaceAll("\\[.*?\\]", ""); urlTemplate =urlTemplate.replaceAll("\\[", ""); urlTemplate =urlTemplate.replaceAll("\\]", ""); urlTemplate =urlTemplate.replaceAll("%28", "("); urlTemplate =urlTemplate.replaceAll("%29", ")"); //urlTemplate =urlTemplate.replaceAll("%5B", "["); //strange that this is needed....API issue? //urlTemplate =urlTemplate.replaceAll("%5D", "]"); System.out.println("yy:"+urlTemplate); if(urlTemplate.endsWith("&")){ urlTemplate = urlTemplate.substring(0,urlTemplate.length()-1); } //urlTemplate = urlTemplate.substring(0, urlTemplate.length()-1); //System.out.println("urlTemplate became "+urlTemplate); cells[0] = new StringCell(urlTemplate); DataRow row = new DefaultRow("aboutCell", cells); container.addRowToTable(row); container.close(); BufferedDataTable out = container.getTable(); // TODO: Return a BufferedDataTable for each output port return new BufferedDataTable[]{out}; }
NONSATD
true
urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")); }else{ //System.out.println("now we are here"); System.out.println("7curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(urlTemplate.endsWith("&")||urlTemplate.endsWith("?")){
if(colCount==0){ urlTemplate +="&"; } System.out.println("5curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(!configValue.equals("")){ System.out.println("6curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); System.out.println("config var: "+curVar+" with configValue:"+ configValue+ ", is overwritten with value: "+currentCell.toString() ); urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"&]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")+"&"); urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")); }else{ //System.out.println("now we are here"); System.out.println("7curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(urlTemplate.endsWith("&")||urlTemplate.endsWith("?")){ //urlTemplate = urlTemplate.substring(0,urlTemplate.length()-1); urlTemplate = urlTemplate+curVar+"="+URLEncoder.encode(curVal,"UTF-8"); }else{ urlTemplate = "&"+urlTemplate+curVar+"="+URLEncoder.encode(curVal,"UTF-8"); } //urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"&]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")+"&"); //urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")); //System.out.println("urlTemplate before:"+doubleStr+", and after:"+urlTemplate);
String configValue = ""; if(urlTemplate.indexOf("&"+curVar)!=-1){ configValue = urlTemplate.substring(urlTemplate.indexOf("&"+curVar)+curVar.length()+2,urlTemplate.indexOf("]",urlTemplate.indexOf(curVar))); }else if(urlTemplate.indexOf("?"+curVar)!=-1){ configValue = urlTemplate.substring(urlTemplate.indexOf("?"+curVar)+curVar.length()+2,urlTemplate.indexOf("]",urlTemplate.indexOf(curVar))); } System.out.println("4curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(configValue.endsWith("&")){ configValue = configValue.substring(0,configValue.length()-1); //get rid of the & } if(colCount==0){ urlTemplate +="&"; } System.out.println("5curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(!configValue.equals("")){ System.out.println("6curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); System.out.println("config var: "+curVar+" with configValue:"+ configValue+ ", is overwritten with value: "+currentCell.toString() ); urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"&]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")+"&"); urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")); }else{ //System.out.println("now we are here"); System.out.println("7curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(urlTemplate.endsWith("&")||urlTemplate.endsWith("?")){ //urlTemplate = urlTemplate.substring(0,urlTemplate.length()-1); urlTemplate = urlTemplate+curVar+"="+URLEncoder.encode(curVal,"UTF-8"); }else{ urlTemplate = "&"+urlTemplate+curVar+"="+URLEncoder.encode(curVal,"UTF-8"); } //urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"&]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")+"&"); //urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")); //System.out.println("urlTemplate before:"+doubleStr+", and after:"+urlTemplate); } } colCount++; } } System.out.println("yy:"+urlTemplate); //urlTemplate =urlTemplate.replaceAll("\\[.*?\\]", ""); urlTemplate =urlTemplate.replaceAll("\\[", ""); urlTemplate =urlTemplate.replaceAll("\\]", ""); urlTemplate =urlTemplate.replaceAll("%28", "(");
16,061
6
//urlTemplate = urlTemplate.substring(0,urlTemplate.length()-1);
@Override protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception { DataColumnSpec[] allColSpecs = new DataColumnSpec[1]; allColSpecs[0] = new DataColumnSpecCreator("url", StringCell.TYPE).createSpec(); DataTableSpec outputSpec = new DataTableSpec(allColSpecs); // System.out.println("calling execute"+resultUrl.getStringValue()); // the execution context will provide us with storage capacity, in this // case a data container to which we will add rows sequentially // Note, this container can also handle arbitrary big data tables, it // will buffer to disc if necessary. BufferedDataContainer container = exec.createDataContainer(outputSpec); DataCell[] cells = new DataCell[1]; String urlTemplate = resultUrl.getStringValue(); Iterator<DataRow> varIt = inData[0].iterator(); DataTableSpec dts = inData[0].getDataTableSpec(); String[] colNames = dts.getColumnNames(); if(varIt.hasNext()){ //while(varIt.hasNext()){ DataRow current = varIt.next(); Iterator<DataCell> cellIt = current.iterator(); int colCount = 0; while(cellIt.hasNext()){ DataCell currentCell= cellIt.next(); String curVar = colNames[colCount]; String curVal = currentCell.toString(); //System.out.println("curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(urlTemplate.indexOf(curVar)==-1){ System.out.println("1curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); urlTemplate = urlTemplate+"&"+curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8"); System.out.println("2curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); }else{ System.out.println("3curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); String configValue = ""; if(urlTemplate.indexOf("&"+curVar)!=-1){ configValue = urlTemplate.substring(urlTemplate.indexOf("&"+curVar)+curVar.length()+2,urlTemplate.indexOf("]",urlTemplate.indexOf(curVar))); }else if(urlTemplate.indexOf("?"+curVar)!=-1){ configValue = urlTemplate.substring(urlTemplate.indexOf("?"+curVar)+curVar.length()+2,urlTemplate.indexOf("]",urlTemplate.indexOf(curVar))); } System.out.println("4curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(configValue.endsWith("&")){ configValue = configValue.substring(0,configValue.length()-1); //get rid of the & } if(colCount==0){ urlTemplate +="&"; } System.out.println("5curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(!configValue.equals("")){ System.out.println("6curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); System.out.println("config var: "+curVar+" with configValue:"+ configValue+ ", is overwritten with value: "+currentCell.toString() ); urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"&]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")+"&"); urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")); }else{ //System.out.println("now we are here"); System.out.println("7curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(urlTemplate.endsWith("&")||urlTemplate.endsWith("?")){ //urlTemplate = urlTemplate.substring(0,urlTemplate.length()-1); urlTemplate = urlTemplate+curVar+"="+URLEncoder.encode(curVal,"UTF-8"); }else{ urlTemplate = "&"+urlTemplate+curVar+"="+URLEncoder.encode(curVal,"UTF-8"); } //urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"&]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")+"&"); //urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")); //System.out.println("urlTemplate before:"+doubleStr+", and after:"+urlTemplate); } } colCount++; } } System.out.println("yy:"+urlTemplate); //urlTemplate =urlTemplate.replaceAll("\\[.*?\\]", ""); urlTemplate =urlTemplate.replaceAll("\\[", ""); urlTemplate =urlTemplate.replaceAll("\\]", ""); urlTemplate =urlTemplate.replaceAll("%28", "("); urlTemplate =urlTemplate.replaceAll("%29", ")"); //urlTemplate =urlTemplate.replaceAll("%5B", "["); //strange that this is needed....API issue? //urlTemplate =urlTemplate.replaceAll("%5D", "]"); System.out.println("yy:"+urlTemplate); if(urlTemplate.endsWith("&")){ urlTemplate = urlTemplate.substring(0,urlTemplate.length()-1); } //urlTemplate = urlTemplate.substring(0, urlTemplate.length()-1); //System.out.println("urlTemplate became "+urlTemplate); cells[0] = new StringCell(urlTemplate); DataRow row = new DefaultRow("aboutCell", cells); container.addRowToTable(row); container.close(); BufferedDataTable out = container.getTable(); // TODO: Return a BufferedDataTable for each output port return new BufferedDataTable[]{out}; }
NONSATD
true
System.out.println("7curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(urlTemplate.endsWith("&")||urlTemplate.endsWith("?")){ //urlTemplate = urlTemplate.substring(0,urlTemplate.length()-1); urlTemplate = urlTemplate+curVar+"="+URLEncoder.encode(curVal,"UTF-8"); }else{
System.out.println("5curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(!configValue.equals("")){ System.out.println("6curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); System.out.println("config var: "+curVar+" with configValue:"+ configValue+ ", is overwritten with value: "+currentCell.toString() ); urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"&]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")+"&"); urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")); }else{ //System.out.println("now we are here"); System.out.println("7curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(urlTemplate.endsWith("&")||urlTemplate.endsWith("?")){ //urlTemplate = urlTemplate.substring(0,urlTemplate.length()-1); urlTemplate = urlTemplate+curVar+"="+URLEncoder.encode(curVal,"UTF-8"); }else{ urlTemplate = "&"+urlTemplate+curVar+"="+URLEncoder.encode(curVal,"UTF-8"); } //urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"&]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")+"&"); //urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")); //System.out.println("urlTemplate before:"+doubleStr+", and after:"+urlTemplate); } } colCount++;
}else if(urlTemplate.indexOf("?"+curVar)!=-1){ configValue = urlTemplate.substring(urlTemplate.indexOf("?"+curVar)+curVar.length()+2,urlTemplate.indexOf("]",urlTemplate.indexOf(curVar))); } System.out.println("4curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(configValue.endsWith("&")){ configValue = configValue.substring(0,configValue.length()-1); //get rid of the & } if(colCount==0){ urlTemplate +="&"; } System.out.println("5curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(!configValue.equals("")){ System.out.println("6curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); System.out.println("config var: "+curVar+" with configValue:"+ configValue+ ", is overwritten with value: "+currentCell.toString() ); urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"&]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")+"&"); urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")); }else{ //System.out.println("now we are here"); System.out.println("7curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(urlTemplate.endsWith("&")||urlTemplate.endsWith("?")){ //urlTemplate = urlTemplate.substring(0,urlTemplate.length()-1); urlTemplate = urlTemplate+curVar+"="+URLEncoder.encode(curVal,"UTF-8"); }else{ urlTemplate = "&"+urlTemplate+curVar+"="+URLEncoder.encode(curVal,"UTF-8"); } //urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"&]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")+"&"); //urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")); //System.out.println("urlTemplate before:"+doubleStr+", and after:"+urlTemplate); } } colCount++; } } System.out.println("yy:"+urlTemplate); //urlTemplate =urlTemplate.replaceAll("\\[.*?\\]", ""); urlTemplate =urlTemplate.replaceAll("\\[", ""); urlTemplate =urlTemplate.replaceAll("\\]", ""); urlTemplate =urlTemplate.replaceAll("%28", "("); urlTemplate =urlTemplate.replaceAll("%29", ")"); //urlTemplate =urlTemplate.replaceAll("%5B", "["); //strange that this is needed....API issue? //urlTemplate =urlTemplate.replaceAll("%5D", "]");
16,061
7
//urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"&]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")+"&"); //urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")); //System.out.println("urlTemplate before:"+doubleStr+", and after:"+urlTemplate);
@Override protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception { DataColumnSpec[] allColSpecs = new DataColumnSpec[1]; allColSpecs[0] = new DataColumnSpecCreator("url", StringCell.TYPE).createSpec(); DataTableSpec outputSpec = new DataTableSpec(allColSpecs); // System.out.println("calling execute"+resultUrl.getStringValue()); // the execution context will provide us with storage capacity, in this // case a data container to which we will add rows sequentially // Note, this container can also handle arbitrary big data tables, it // will buffer to disc if necessary. BufferedDataContainer container = exec.createDataContainer(outputSpec); DataCell[] cells = new DataCell[1]; String urlTemplate = resultUrl.getStringValue(); Iterator<DataRow> varIt = inData[0].iterator(); DataTableSpec dts = inData[0].getDataTableSpec(); String[] colNames = dts.getColumnNames(); if(varIt.hasNext()){ //while(varIt.hasNext()){ DataRow current = varIt.next(); Iterator<DataCell> cellIt = current.iterator(); int colCount = 0; while(cellIt.hasNext()){ DataCell currentCell= cellIt.next(); String curVar = colNames[colCount]; String curVal = currentCell.toString(); //System.out.println("curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(urlTemplate.indexOf(curVar)==-1){ System.out.println("1curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); urlTemplate = urlTemplate+"&"+curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8"); System.out.println("2curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); }else{ System.out.println("3curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); String configValue = ""; if(urlTemplate.indexOf("&"+curVar)!=-1){ configValue = urlTemplate.substring(urlTemplate.indexOf("&"+curVar)+curVar.length()+2,urlTemplate.indexOf("]",urlTemplate.indexOf(curVar))); }else if(urlTemplate.indexOf("?"+curVar)!=-1){ configValue = urlTemplate.substring(urlTemplate.indexOf("?"+curVar)+curVar.length()+2,urlTemplate.indexOf("]",urlTemplate.indexOf(curVar))); } System.out.println("4curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(configValue.endsWith("&")){ configValue = configValue.substring(0,configValue.length()-1); //get rid of the & } if(colCount==0){ urlTemplate +="&"; } System.out.println("5curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(!configValue.equals("")){ System.out.println("6curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); System.out.println("config var: "+curVar+" with configValue:"+ configValue+ ", is overwritten with value: "+currentCell.toString() ); urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"&]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")+"&"); urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")); }else{ //System.out.println("now we are here"); System.out.println("7curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(urlTemplate.endsWith("&")||urlTemplate.endsWith("?")){ //urlTemplate = urlTemplate.substring(0,urlTemplate.length()-1); urlTemplate = urlTemplate+curVar+"="+URLEncoder.encode(curVal,"UTF-8"); }else{ urlTemplate = "&"+urlTemplate+curVar+"="+URLEncoder.encode(curVal,"UTF-8"); } //urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"&]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")+"&"); //urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")); //System.out.println("urlTemplate before:"+doubleStr+", and after:"+urlTemplate); } } colCount++; } } System.out.println("yy:"+urlTemplate); //urlTemplate =urlTemplate.replaceAll("\\[.*?\\]", ""); urlTemplate =urlTemplate.replaceAll("\\[", ""); urlTemplate =urlTemplate.replaceAll("\\]", ""); urlTemplate =urlTemplate.replaceAll("%28", "("); urlTemplate =urlTemplate.replaceAll("%29", ")"); //urlTemplate =urlTemplate.replaceAll("%5B", "["); //strange that this is needed....API issue? //urlTemplate =urlTemplate.replaceAll("%5D", "]"); System.out.println("yy:"+urlTemplate); if(urlTemplate.endsWith("&")){ urlTemplate = urlTemplate.substring(0,urlTemplate.length()-1); } //urlTemplate = urlTemplate.substring(0, urlTemplate.length()-1); //System.out.println("urlTemplate became "+urlTemplate); cells[0] = new StringCell(urlTemplate); DataRow row = new DefaultRow("aboutCell", cells); container.addRowToTable(row); container.close(); BufferedDataTable out = container.getTable(); // TODO: Return a BufferedDataTable for each output port return new BufferedDataTable[]{out}; }
NONSATD
true
urlTemplate = "&"+urlTemplate+curVar+"="+URLEncoder.encode(curVal,"UTF-8"); } //urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"&]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")+"&"); //urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")); //System.out.println("urlTemplate before:"+doubleStr+", and after:"+urlTemplate); } }
urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")); }else{ //System.out.println("now we are here"); System.out.println("7curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(urlTemplate.endsWith("&")||urlTemplate.endsWith("?")){ //urlTemplate = urlTemplate.substring(0,urlTemplate.length()-1); urlTemplate = urlTemplate+curVar+"="+URLEncoder.encode(curVal,"UTF-8"); }else{ urlTemplate = "&"+urlTemplate+curVar+"="+URLEncoder.encode(curVal,"UTF-8"); } //urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"&]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")+"&"); //urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")); //System.out.println("urlTemplate before:"+doubleStr+", and after:"+urlTemplate); } } colCount++; } } System.out.println("yy:"+urlTemplate); //urlTemplate =urlTemplate.replaceAll("\\[.*?\\]", ""); urlTemplate =urlTemplate.replaceAll("\\[", ""); urlTemplate =urlTemplate.replaceAll("\\]", ""); urlTemplate =urlTemplate.replaceAll("%28", "(");
configValue = configValue.substring(0,configValue.length()-1); //get rid of the & } if(colCount==0){ urlTemplate +="&"; } System.out.println("5curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(!configValue.equals("")){ System.out.println("6curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); System.out.println("config var: "+curVar+" with configValue:"+ configValue+ ", is overwritten with value: "+currentCell.toString() ); urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"&]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")+"&"); urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")); }else{ //System.out.println("now we are here"); System.out.println("7curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(urlTemplate.endsWith("&")||urlTemplate.endsWith("?")){ //urlTemplate = urlTemplate.substring(0,urlTemplate.length()-1); urlTemplate = urlTemplate+curVar+"="+URLEncoder.encode(curVal,"UTF-8"); }else{ urlTemplate = "&"+urlTemplate+curVar+"="+URLEncoder.encode(curVal,"UTF-8"); } //urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"&]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")+"&"); //urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")); //System.out.println("urlTemplate before:"+doubleStr+", and after:"+urlTemplate); } } colCount++; } } System.out.println("yy:"+urlTemplate); //urlTemplate =urlTemplate.replaceAll("\\[.*?\\]", ""); urlTemplate =urlTemplate.replaceAll("\\[", ""); urlTemplate =urlTemplate.replaceAll("\\]", ""); urlTemplate =urlTemplate.replaceAll("%28", "("); urlTemplate =urlTemplate.replaceAll("%29", ")"); //urlTemplate =urlTemplate.replaceAll("%5B", "["); //strange that this is needed....API issue? //urlTemplate =urlTemplate.replaceAll("%5D", "]"); System.out.println("yy:"+urlTemplate); if(urlTemplate.endsWith("&")){ urlTemplate = urlTemplate.substring(0,urlTemplate.length()-1); } //urlTemplate = urlTemplate.substring(0, urlTemplate.length()-1); //System.out.println("urlTemplate became "+urlTemplate); cells[0] = new StringCell(urlTemplate);
16,061
8
//urlTemplate =urlTemplate.replaceAll("\\[.*?\\]", "");
@Override protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception { DataColumnSpec[] allColSpecs = new DataColumnSpec[1]; allColSpecs[0] = new DataColumnSpecCreator("url", StringCell.TYPE).createSpec(); DataTableSpec outputSpec = new DataTableSpec(allColSpecs); // System.out.println("calling execute"+resultUrl.getStringValue()); // the execution context will provide us with storage capacity, in this // case a data container to which we will add rows sequentially // Note, this container can also handle arbitrary big data tables, it // will buffer to disc if necessary. BufferedDataContainer container = exec.createDataContainer(outputSpec); DataCell[] cells = new DataCell[1]; String urlTemplate = resultUrl.getStringValue(); Iterator<DataRow> varIt = inData[0].iterator(); DataTableSpec dts = inData[0].getDataTableSpec(); String[] colNames = dts.getColumnNames(); if(varIt.hasNext()){ //while(varIt.hasNext()){ DataRow current = varIt.next(); Iterator<DataCell> cellIt = current.iterator(); int colCount = 0; while(cellIt.hasNext()){ DataCell currentCell= cellIt.next(); String curVar = colNames[colCount]; String curVal = currentCell.toString(); //System.out.println("curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(urlTemplate.indexOf(curVar)==-1){ System.out.println("1curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); urlTemplate = urlTemplate+"&"+curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8"); System.out.println("2curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); }else{ System.out.println("3curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); String configValue = ""; if(urlTemplate.indexOf("&"+curVar)!=-1){ configValue = urlTemplate.substring(urlTemplate.indexOf("&"+curVar)+curVar.length()+2,urlTemplate.indexOf("]",urlTemplate.indexOf(curVar))); }else if(urlTemplate.indexOf("?"+curVar)!=-1){ configValue = urlTemplate.substring(urlTemplate.indexOf("?"+curVar)+curVar.length()+2,urlTemplate.indexOf("]",urlTemplate.indexOf(curVar))); } System.out.println("4curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(configValue.endsWith("&")){ configValue = configValue.substring(0,configValue.length()-1); //get rid of the & } if(colCount==0){ urlTemplate +="&"; } System.out.println("5curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(!configValue.equals("")){ System.out.println("6curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); System.out.println("config var: "+curVar+" with configValue:"+ configValue+ ", is overwritten with value: "+currentCell.toString() ); urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"&]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")+"&"); urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")); }else{ //System.out.println("now we are here"); System.out.println("7curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(urlTemplate.endsWith("&")||urlTemplate.endsWith("?")){ //urlTemplate = urlTemplate.substring(0,urlTemplate.length()-1); urlTemplate = urlTemplate+curVar+"="+URLEncoder.encode(curVal,"UTF-8"); }else{ urlTemplate = "&"+urlTemplate+curVar+"="+URLEncoder.encode(curVal,"UTF-8"); } //urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"&]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")+"&"); //urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")); //System.out.println("urlTemplate before:"+doubleStr+", and after:"+urlTemplate); } } colCount++; } } System.out.println("yy:"+urlTemplate); //urlTemplate =urlTemplate.replaceAll("\\[.*?\\]", ""); urlTemplate =urlTemplate.replaceAll("\\[", ""); urlTemplate =urlTemplate.replaceAll("\\]", ""); urlTemplate =urlTemplate.replaceAll("%28", "("); urlTemplate =urlTemplate.replaceAll("%29", ")"); //urlTemplate =urlTemplate.replaceAll("%5B", "["); //strange that this is needed....API issue? //urlTemplate =urlTemplate.replaceAll("%5D", "]"); System.out.println("yy:"+urlTemplate); if(urlTemplate.endsWith("&")){ urlTemplate = urlTemplate.substring(0,urlTemplate.length()-1); } //urlTemplate = urlTemplate.substring(0, urlTemplate.length()-1); //System.out.println("urlTemplate became "+urlTemplate); cells[0] = new StringCell(urlTemplate); DataRow row = new DefaultRow("aboutCell", cells); container.addRowToTable(row); container.close(); BufferedDataTable out = container.getTable(); // TODO: Return a BufferedDataTable for each output port return new BufferedDataTable[]{out}; }
NONSATD
true
} System.out.println("yy:"+urlTemplate); //urlTemplate =urlTemplate.replaceAll("\\[.*?\\]", ""); urlTemplate =urlTemplate.replaceAll("\\[", ""); urlTemplate =urlTemplate.replaceAll("\\]", "");
} //urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"&]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")+"&"); //urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")); //System.out.println("urlTemplate before:"+doubleStr+", and after:"+urlTemplate); } } colCount++; } } System.out.println("yy:"+urlTemplate); //urlTemplate =urlTemplate.replaceAll("\\[.*?\\]", ""); urlTemplate =urlTemplate.replaceAll("\\[", ""); urlTemplate =urlTemplate.replaceAll("\\]", ""); urlTemplate =urlTemplate.replaceAll("%28", "("); urlTemplate =urlTemplate.replaceAll("%29", ")"); //urlTemplate =urlTemplate.replaceAll("%5B", "["); //strange that this is needed....API issue? //urlTemplate =urlTemplate.replaceAll("%5D", "]"); System.out.println("yy:"+urlTemplate); if(urlTemplate.endsWith("&")){ urlTemplate = urlTemplate.substring(0,urlTemplate.length()-1); }
urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"&]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")+"&"); urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")); }else{ //System.out.println("now we are here"); System.out.println("7curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(urlTemplate.endsWith("&")||urlTemplate.endsWith("?")){ //urlTemplate = urlTemplate.substring(0,urlTemplate.length()-1); urlTemplate = urlTemplate+curVar+"="+URLEncoder.encode(curVal,"UTF-8"); }else{ urlTemplate = "&"+urlTemplate+curVar+"="+URLEncoder.encode(curVal,"UTF-8"); } //urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"&]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")+"&"); //urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")); //System.out.println("urlTemplate before:"+doubleStr+", and after:"+urlTemplate); } } colCount++; } } System.out.println("yy:"+urlTemplate); //urlTemplate =urlTemplate.replaceAll("\\[.*?\\]", ""); urlTemplate =urlTemplate.replaceAll("\\[", ""); urlTemplate =urlTemplate.replaceAll("\\]", ""); urlTemplate =urlTemplate.replaceAll("%28", "("); urlTemplate =urlTemplate.replaceAll("%29", ")"); //urlTemplate =urlTemplate.replaceAll("%5B", "["); //strange that this is needed....API issue? //urlTemplate =urlTemplate.replaceAll("%5D", "]"); System.out.println("yy:"+urlTemplate); if(urlTemplate.endsWith("&")){ urlTemplate = urlTemplate.substring(0,urlTemplate.length()-1); } //urlTemplate = urlTemplate.substring(0, urlTemplate.length()-1); //System.out.println("urlTemplate became "+urlTemplate); cells[0] = new StringCell(urlTemplate); DataRow row = new DefaultRow("aboutCell", cells); container.addRowToTable(row); container.close(); BufferedDataTable out = container.getTable(); // TODO: Return a BufferedDataTable for each output port return new BufferedDataTable[]{out}; }
16,061
9
//urlTemplate =urlTemplate.replaceAll("%5B", "["); //strange that this is needed....API issue? //urlTemplate =urlTemplate.replaceAll("%5D", "]");
@Override protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception { DataColumnSpec[] allColSpecs = new DataColumnSpec[1]; allColSpecs[0] = new DataColumnSpecCreator("url", StringCell.TYPE).createSpec(); DataTableSpec outputSpec = new DataTableSpec(allColSpecs); // System.out.println("calling execute"+resultUrl.getStringValue()); // the execution context will provide us with storage capacity, in this // case a data container to which we will add rows sequentially // Note, this container can also handle arbitrary big data tables, it // will buffer to disc if necessary. BufferedDataContainer container = exec.createDataContainer(outputSpec); DataCell[] cells = new DataCell[1]; String urlTemplate = resultUrl.getStringValue(); Iterator<DataRow> varIt = inData[0].iterator(); DataTableSpec dts = inData[0].getDataTableSpec(); String[] colNames = dts.getColumnNames(); if(varIt.hasNext()){ //while(varIt.hasNext()){ DataRow current = varIt.next(); Iterator<DataCell> cellIt = current.iterator(); int colCount = 0; while(cellIt.hasNext()){ DataCell currentCell= cellIt.next(); String curVar = colNames[colCount]; String curVal = currentCell.toString(); //System.out.println("curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(urlTemplate.indexOf(curVar)==-1){ System.out.println("1curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); urlTemplate = urlTemplate+"&"+curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8"); System.out.println("2curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); }else{ System.out.println("3curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); String configValue = ""; if(urlTemplate.indexOf("&"+curVar)!=-1){ configValue = urlTemplate.substring(urlTemplate.indexOf("&"+curVar)+curVar.length()+2,urlTemplate.indexOf("]",urlTemplate.indexOf(curVar))); }else if(urlTemplate.indexOf("?"+curVar)!=-1){ configValue = urlTemplate.substring(urlTemplate.indexOf("?"+curVar)+curVar.length()+2,urlTemplate.indexOf("]",urlTemplate.indexOf(curVar))); } System.out.println("4curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(configValue.endsWith("&")){ configValue = configValue.substring(0,configValue.length()-1); //get rid of the & } if(colCount==0){ urlTemplate +="&"; } System.out.println("5curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(!configValue.equals("")){ System.out.println("6curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); System.out.println("config var: "+curVar+" with configValue:"+ configValue+ ", is overwritten with value: "+currentCell.toString() ); urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"&]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")+"&"); urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")); }else{ //System.out.println("now we are here"); System.out.println("7curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(urlTemplate.endsWith("&")||urlTemplate.endsWith("?")){ //urlTemplate = urlTemplate.substring(0,urlTemplate.length()-1); urlTemplate = urlTemplate+curVar+"="+URLEncoder.encode(curVal,"UTF-8"); }else{ urlTemplate = "&"+urlTemplate+curVar+"="+URLEncoder.encode(curVal,"UTF-8"); } //urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"&]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")+"&"); //urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")); //System.out.println("urlTemplate before:"+doubleStr+", and after:"+urlTemplate); } } colCount++; } } System.out.println("yy:"+urlTemplate); //urlTemplate =urlTemplate.replaceAll("\\[.*?\\]", ""); urlTemplate =urlTemplate.replaceAll("\\[", ""); urlTemplate =urlTemplate.replaceAll("\\]", ""); urlTemplate =urlTemplate.replaceAll("%28", "("); urlTemplate =urlTemplate.replaceAll("%29", ")"); //urlTemplate =urlTemplate.replaceAll("%5B", "["); //strange that this is needed....API issue? //urlTemplate =urlTemplate.replaceAll("%5D", "]"); System.out.println("yy:"+urlTemplate); if(urlTemplate.endsWith("&")){ urlTemplate = urlTemplate.substring(0,urlTemplate.length()-1); } //urlTemplate = urlTemplate.substring(0, urlTemplate.length()-1); //System.out.println("urlTemplate became "+urlTemplate); cells[0] = new StringCell(urlTemplate); DataRow row = new DefaultRow("aboutCell", cells); container.addRowToTable(row); container.close(); BufferedDataTable out = container.getTable(); // TODO: Return a BufferedDataTable for each output port return new BufferedDataTable[]{out}; }
DEFECT
true
urlTemplate =urlTemplate.replaceAll("%28", "("); urlTemplate =urlTemplate.replaceAll("%29", ")"); //urlTemplate =urlTemplate.replaceAll("%5B", "["); //strange that this is needed....API issue? //urlTemplate =urlTemplate.replaceAll("%5D", "]"); System.out.println("yy:"+urlTemplate); if(urlTemplate.endsWith("&")){
} colCount++; } } System.out.println("yy:"+urlTemplate); //urlTemplate =urlTemplate.replaceAll("\\[.*?\\]", ""); urlTemplate =urlTemplate.replaceAll("\\[", ""); urlTemplate =urlTemplate.replaceAll("\\]", ""); urlTemplate =urlTemplate.replaceAll("%28", "("); urlTemplate =urlTemplate.replaceAll("%29", ")"); //urlTemplate =urlTemplate.replaceAll("%5B", "["); //strange that this is needed....API issue? //urlTemplate =urlTemplate.replaceAll("%5D", "]"); System.out.println("yy:"+urlTemplate); if(urlTemplate.endsWith("&")){ urlTemplate = urlTemplate.substring(0,urlTemplate.length()-1); } //urlTemplate = urlTemplate.substring(0, urlTemplate.length()-1); //System.out.println("urlTemplate became "+urlTemplate); cells[0] = new StringCell(urlTemplate); DataRow row = new DefaultRow("aboutCell", cells); container.addRowToTable(row); container.close();
if(urlTemplate.endsWith("&")||urlTemplate.endsWith("?")){ //urlTemplate = urlTemplate.substring(0,urlTemplate.length()-1); urlTemplate = urlTemplate+curVar+"="+URLEncoder.encode(curVal,"UTF-8"); }else{ urlTemplate = "&"+urlTemplate+curVar+"="+URLEncoder.encode(curVal,"UTF-8"); } //urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"&]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")+"&"); //urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")); //System.out.println("urlTemplate before:"+doubleStr+", and after:"+urlTemplate); } } colCount++; } } System.out.println("yy:"+urlTemplate); //urlTemplate =urlTemplate.replaceAll("\\[.*?\\]", ""); urlTemplate =urlTemplate.replaceAll("\\[", ""); urlTemplate =urlTemplate.replaceAll("\\]", ""); urlTemplate =urlTemplate.replaceAll("%28", "("); urlTemplate =urlTemplate.replaceAll("%29", ")"); //urlTemplate =urlTemplate.replaceAll("%5B", "["); //strange that this is needed....API issue? //urlTemplate =urlTemplate.replaceAll("%5D", "]"); System.out.println("yy:"+urlTemplate); if(urlTemplate.endsWith("&")){ urlTemplate = urlTemplate.substring(0,urlTemplate.length()-1); } //urlTemplate = urlTemplate.substring(0, urlTemplate.length()-1); //System.out.println("urlTemplate became "+urlTemplate); cells[0] = new StringCell(urlTemplate); DataRow row = new DefaultRow("aboutCell", cells); container.addRowToTable(row); container.close(); BufferedDataTable out = container.getTable(); // TODO: Return a BufferedDataTable for each output port return new BufferedDataTable[]{out}; }
16,061
10
//urlTemplate = urlTemplate.substring(0, urlTemplate.length()-1); //System.out.println("urlTemplate became "+urlTemplate);
@Override protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception { DataColumnSpec[] allColSpecs = new DataColumnSpec[1]; allColSpecs[0] = new DataColumnSpecCreator("url", StringCell.TYPE).createSpec(); DataTableSpec outputSpec = new DataTableSpec(allColSpecs); // System.out.println("calling execute"+resultUrl.getStringValue()); // the execution context will provide us with storage capacity, in this // case a data container to which we will add rows sequentially // Note, this container can also handle arbitrary big data tables, it // will buffer to disc if necessary. BufferedDataContainer container = exec.createDataContainer(outputSpec); DataCell[] cells = new DataCell[1]; String urlTemplate = resultUrl.getStringValue(); Iterator<DataRow> varIt = inData[0].iterator(); DataTableSpec dts = inData[0].getDataTableSpec(); String[] colNames = dts.getColumnNames(); if(varIt.hasNext()){ //while(varIt.hasNext()){ DataRow current = varIt.next(); Iterator<DataCell> cellIt = current.iterator(); int colCount = 0; while(cellIt.hasNext()){ DataCell currentCell= cellIt.next(); String curVar = colNames[colCount]; String curVal = currentCell.toString(); //System.out.println("curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(urlTemplate.indexOf(curVar)==-1){ System.out.println("1curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); urlTemplate = urlTemplate+"&"+curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8"); System.out.println("2curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); }else{ System.out.println("3curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); String configValue = ""; if(urlTemplate.indexOf("&"+curVar)!=-1){ configValue = urlTemplate.substring(urlTemplate.indexOf("&"+curVar)+curVar.length()+2,urlTemplate.indexOf("]",urlTemplate.indexOf(curVar))); }else if(urlTemplate.indexOf("?"+curVar)!=-1){ configValue = urlTemplate.substring(urlTemplate.indexOf("?"+curVar)+curVar.length()+2,urlTemplate.indexOf("]",urlTemplate.indexOf(curVar))); } System.out.println("4curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(configValue.endsWith("&")){ configValue = configValue.substring(0,configValue.length()-1); //get rid of the & } if(colCount==0){ urlTemplate +="&"; } System.out.println("5curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(!configValue.equals("")){ System.out.println("6curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); System.out.println("config var: "+curVar+" with configValue:"+ configValue+ ", is overwritten with value: "+currentCell.toString() ); urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"&]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")+"&"); urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")); }else{ //System.out.println("now we are here"); System.out.println("7curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(urlTemplate.endsWith("&")||urlTemplate.endsWith("?")){ //urlTemplate = urlTemplate.substring(0,urlTemplate.length()-1); urlTemplate = urlTemplate+curVar+"="+URLEncoder.encode(curVal,"UTF-8"); }else{ urlTemplate = "&"+urlTemplate+curVar+"="+URLEncoder.encode(curVal,"UTF-8"); } //urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"&]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")+"&"); //urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")); //System.out.println("urlTemplate before:"+doubleStr+", and after:"+urlTemplate); } } colCount++; } } System.out.println("yy:"+urlTemplate); //urlTemplate =urlTemplate.replaceAll("\\[.*?\\]", ""); urlTemplate =urlTemplate.replaceAll("\\[", ""); urlTemplate =urlTemplate.replaceAll("\\]", ""); urlTemplate =urlTemplate.replaceAll("%28", "("); urlTemplate =urlTemplate.replaceAll("%29", ")"); //urlTemplate =urlTemplate.replaceAll("%5B", "["); //strange that this is needed....API issue? //urlTemplate =urlTemplate.replaceAll("%5D", "]"); System.out.println("yy:"+urlTemplate); if(urlTemplate.endsWith("&")){ urlTemplate = urlTemplate.substring(0,urlTemplate.length()-1); } //urlTemplate = urlTemplate.substring(0, urlTemplate.length()-1); //System.out.println("urlTemplate became "+urlTemplate); cells[0] = new StringCell(urlTemplate); DataRow row = new DefaultRow("aboutCell", cells); container.addRowToTable(row); container.close(); BufferedDataTable out = container.getTable(); // TODO: Return a BufferedDataTable for each output port return new BufferedDataTable[]{out}; }
NONSATD
true
urlTemplate = urlTemplate.substring(0,urlTemplate.length()-1); } //urlTemplate = urlTemplate.substring(0, urlTemplate.length()-1); //System.out.println("urlTemplate became "+urlTemplate); cells[0] = new StringCell(urlTemplate); DataRow row = new DefaultRow("aboutCell", cells);
urlTemplate =urlTemplate.replaceAll("\\[", ""); urlTemplate =urlTemplate.replaceAll("\\]", ""); urlTemplate =urlTemplate.replaceAll("%28", "("); urlTemplate =urlTemplate.replaceAll("%29", ")"); //urlTemplate =urlTemplate.replaceAll("%5B", "["); //strange that this is needed....API issue? //urlTemplate =urlTemplate.replaceAll("%5D", "]"); System.out.println("yy:"+urlTemplate); if(urlTemplate.endsWith("&")){ urlTemplate = urlTemplate.substring(0,urlTemplate.length()-1); } //urlTemplate = urlTemplate.substring(0, urlTemplate.length()-1); //System.out.println("urlTemplate became "+urlTemplate); cells[0] = new StringCell(urlTemplate); DataRow row = new DefaultRow("aboutCell", cells); container.addRowToTable(row); container.close(); BufferedDataTable out = container.getTable(); // TODO: Return a BufferedDataTable for each output port return new BufferedDataTable[]{out}; }
//urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"&]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")+"&"); //urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")); //System.out.println("urlTemplate before:"+doubleStr+", and after:"+urlTemplate); } } colCount++; } } System.out.println("yy:"+urlTemplate); //urlTemplate =urlTemplate.replaceAll("\\[.*?\\]", ""); urlTemplate =urlTemplate.replaceAll("\\[", ""); urlTemplate =urlTemplate.replaceAll("\\]", ""); urlTemplate =urlTemplate.replaceAll("%28", "("); urlTemplate =urlTemplate.replaceAll("%29", ")"); //urlTemplate =urlTemplate.replaceAll("%5B", "["); //strange that this is needed....API issue? //urlTemplate =urlTemplate.replaceAll("%5D", "]"); System.out.println("yy:"+urlTemplate); if(urlTemplate.endsWith("&")){ urlTemplate = urlTemplate.substring(0,urlTemplate.length()-1); } //urlTemplate = urlTemplate.substring(0, urlTemplate.length()-1); //System.out.println("urlTemplate became "+urlTemplate); cells[0] = new StringCell(urlTemplate); DataRow row = new DefaultRow("aboutCell", cells); container.addRowToTable(row); container.close(); BufferedDataTable out = container.getTable(); // TODO: Return a BufferedDataTable for each output port return new BufferedDataTable[]{out}; }
16,061
11
// TODO: Return a BufferedDataTable for each output port
@Override protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception { DataColumnSpec[] allColSpecs = new DataColumnSpec[1]; allColSpecs[0] = new DataColumnSpecCreator("url", StringCell.TYPE).createSpec(); DataTableSpec outputSpec = new DataTableSpec(allColSpecs); // System.out.println("calling execute"+resultUrl.getStringValue()); // the execution context will provide us with storage capacity, in this // case a data container to which we will add rows sequentially // Note, this container can also handle arbitrary big data tables, it // will buffer to disc if necessary. BufferedDataContainer container = exec.createDataContainer(outputSpec); DataCell[] cells = new DataCell[1]; String urlTemplate = resultUrl.getStringValue(); Iterator<DataRow> varIt = inData[0].iterator(); DataTableSpec dts = inData[0].getDataTableSpec(); String[] colNames = dts.getColumnNames(); if(varIt.hasNext()){ //while(varIt.hasNext()){ DataRow current = varIt.next(); Iterator<DataCell> cellIt = current.iterator(); int colCount = 0; while(cellIt.hasNext()){ DataCell currentCell= cellIt.next(); String curVar = colNames[colCount]; String curVal = currentCell.toString(); //System.out.println("curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(urlTemplate.indexOf(curVar)==-1){ System.out.println("1curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); urlTemplate = urlTemplate+"&"+curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8"); System.out.println("2curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); }else{ System.out.println("3curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); String configValue = ""; if(urlTemplate.indexOf("&"+curVar)!=-1){ configValue = urlTemplate.substring(urlTemplate.indexOf("&"+curVar)+curVar.length()+2,urlTemplate.indexOf("]",urlTemplate.indexOf(curVar))); }else if(urlTemplate.indexOf("?"+curVar)!=-1){ configValue = urlTemplate.substring(urlTemplate.indexOf("?"+curVar)+curVar.length()+2,urlTemplate.indexOf("]",urlTemplate.indexOf(curVar))); } System.out.println("4curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(configValue.endsWith("&")){ configValue = configValue.substring(0,configValue.length()-1); //get rid of the & } if(colCount==0){ urlTemplate +="&"; } System.out.println("5curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(!configValue.equals("")){ System.out.println("6curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); System.out.println("config var: "+curVar+" with configValue:"+ configValue+ ", is overwritten with value: "+currentCell.toString() ); urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"&]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")+"&"); urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")); }else{ //System.out.println("now we are here"); System.out.println("7curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate); if(urlTemplate.endsWith("&")||urlTemplate.endsWith("?")){ //urlTemplate = urlTemplate.substring(0,urlTemplate.length()-1); urlTemplate = urlTemplate+curVar+"="+URLEncoder.encode(curVal,"UTF-8"); }else{ urlTemplate = "&"+urlTemplate+curVar+"="+URLEncoder.encode(curVal,"UTF-8"); } //urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"&]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")+"&"); //urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")); //System.out.println("urlTemplate before:"+doubleStr+", and after:"+urlTemplate); } } colCount++; } } System.out.println("yy:"+urlTemplate); //urlTemplate =urlTemplate.replaceAll("\\[.*?\\]", ""); urlTemplate =urlTemplate.replaceAll("\\[", ""); urlTemplate =urlTemplate.replaceAll("\\]", ""); urlTemplate =urlTemplate.replaceAll("%28", "("); urlTemplate =urlTemplate.replaceAll("%29", ")"); //urlTemplate =urlTemplate.replaceAll("%5B", "["); //strange that this is needed....API issue? //urlTemplate =urlTemplate.replaceAll("%5D", "]"); System.out.println("yy:"+urlTemplate); if(urlTemplate.endsWith("&")){ urlTemplate = urlTemplate.substring(0,urlTemplate.length()-1); } //urlTemplate = urlTemplate.substring(0, urlTemplate.length()-1); //System.out.println("urlTemplate became "+urlTemplate); cells[0] = new StringCell(urlTemplate); DataRow row = new DefaultRow("aboutCell", cells); container.addRowToTable(row); container.close(); BufferedDataTable out = container.getTable(); // TODO: Return a BufferedDataTable for each output port return new BufferedDataTable[]{out}; }
IMPLEMENTATION
true
container.close(); BufferedDataTable out = container.getTable(); // TODO: Return a BufferedDataTable for each output port return new BufferedDataTable[]{out}; }
if(urlTemplate.endsWith("&")){ urlTemplate = urlTemplate.substring(0,urlTemplate.length()-1); } //urlTemplate = urlTemplate.substring(0, urlTemplate.length()-1); //System.out.println("urlTemplate became "+urlTemplate); cells[0] = new StringCell(urlTemplate); DataRow row = new DefaultRow("aboutCell", cells); container.addRowToTable(row); container.close(); BufferedDataTable out = container.getTable(); // TODO: Return a BufferedDataTable for each output port return new BufferedDataTable[]{out}; }
} System.out.println("yy:"+urlTemplate); //urlTemplate =urlTemplate.replaceAll("\\[.*?\\]", ""); urlTemplate =urlTemplate.replaceAll("\\[", ""); urlTemplate =urlTemplate.replaceAll("\\]", ""); urlTemplate =urlTemplate.replaceAll("%28", "("); urlTemplate =urlTemplate.replaceAll("%29", ")"); //urlTemplate =urlTemplate.replaceAll("%5B", "["); //strange that this is needed....API issue? //urlTemplate =urlTemplate.replaceAll("%5D", "]"); System.out.println("yy:"+urlTemplate); if(urlTemplate.endsWith("&")){ urlTemplate = urlTemplate.substring(0,urlTemplate.length()-1); } //urlTemplate = urlTemplate.substring(0, urlTemplate.length()-1); //System.out.println("urlTemplate became "+urlTemplate); cells[0] = new StringCell(urlTemplate); DataRow row = new DefaultRow("aboutCell", cells); container.addRowToTable(row); container.close(); BufferedDataTable out = container.getTable(); // TODO: Return a BufferedDataTable for each output port return new BufferedDataTable[]{out}; }
16,078
0
// to do: code goes here.
void SetupDataDialog_componentAdded(java.awt.event.ContainerEvent event) { // to do: code goes here. }
IMPLEMENTATION
true
void SetupDataDialog_componentAdded(java.awt.event.ContainerEvent event) { // to do: code goes here. }
void SetupDataDialog_componentAdded(java.awt.event.ContainerEvent event) { // to do: code goes here. }
void SetupDataDialog_componentAdded(java.awt.event.ContainerEvent event) { // to do: code goes here. }
7,891
0
//TODO @Test if findCommentsByPostId_returns_PostId_not_found
@Test public void findAllSubComments_for_comment_returns_collection_status_isFound() throws Exception{ when(commentService.findCommentsByCommentParentId(anyInt())).thenReturn(Arrays.asList(comments)); when(userService.findUserById(anyInt())).thenReturn(Optional.of(user)); when(commentLikeService.checkIfCommentIsLiked(any(Comment.class), any(User.class))).thenReturn(true); ResultActions results = mockMvc .perform( get("/microblogging/v1/comment/2?requestedUserId=1")) .andDo(print()); results .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(jsonPath("$.*").isArray()) .andExpect(jsonPath("$.*",hasSize(4))) .andReturn(); }
TEST
true
@Test public void findAllSubComments_for_comment_returns_collection_status_isFound() throws Exception{ when(commentService.findCommentsByCommentParentId(anyInt())).thenReturn(Arrays.asList(comments)); when(userService.findUserById(anyInt())).thenReturn(Optional.of(user)); when(commentLikeService.checkIfCommentIsLiked(any(Comment.class), any(User.class))).thenReturn(true); ResultActions results = mockMvc .perform( get("/microblogging/v1/comment/2?requestedUserId=1")) .andDo(print()); results .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(jsonPath("$.*").isArray()) .andExpect(jsonPath("$.*",hasSize(4))) .andReturn(); }
@Test public void findAllSubComments_for_comment_returns_collection_status_isFound() throws Exception{ when(commentService.findCommentsByCommentParentId(anyInt())).thenReturn(Arrays.asList(comments)); when(userService.findUserById(anyInt())).thenReturn(Optional.of(user)); when(commentLikeService.checkIfCommentIsLiked(any(Comment.class), any(User.class))).thenReturn(true); ResultActions results = mockMvc .perform( get("/microblogging/v1/comment/2?requestedUserId=1")) .andDo(print()); results .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(jsonPath("$.*").isArray()) .andExpect(jsonPath("$.*",hasSize(4))) .andReturn(); }
@Test public void findAllSubComments_for_comment_returns_collection_status_isFound() throws Exception{ when(commentService.findCommentsByCommentParentId(anyInt())).thenReturn(Arrays.asList(comments)); when(userService.findUserById(anyInt())).thenReturn(Optional.of(user)); when(commentLikeService.checkIfCommentIsLiked(any(Comment.class), any(User.class))).thenReturn(true); ResultActions results = mockMvc .perform( get("/microblogging/v1/comment/2?requestedUserId=1")) .andDo(print()); results .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(jsonPath("$.*").isArray()) .andExpect(jsonPath("$.*",hasSize(4))) .andReturn(); }
7,893
0
/** We are going to try to construct a BwEvent object from a VEvent. This * may represent a new event or an update to a pre-existing event. In any * case, the VEvent probably has insufficient information to completely * reconstitute the event object so we'll get the uid first and retrieve * the event if it exists. * * <p>To put it another way we're doing a diff then update. * * <p>If it doesn't exist, we'll first fill in the appropriate fields, * (non-public, creator, created etc) then for both cases update the * remaining fields from the VEvent. * * <p>Recurring events present some challenges. If there is no recurrence * id the vevent represents the master entity which defines the recurrence * rules. If a recurrence id is present then the vevent represents a * recurrence instance override and we should not attempt to retrieve the * actual object but the referenced instance. * * <p>Also, note that we sorted the components first so we get the master * before any instances. * * <p>If DTSTART, RRULE, EXRULE have changed (also RDATE, EXDATE?) then any * existing overrides are unusable. We should delete all overrides and replace * with new ones. * * <p>For an update we have to keep track of which fields were present in * the vevent and set all absent fields to null in the BwEvent. * * @param cb IcalCallback object * @param cal Needed so we can retrieve the event. * @param ical Icalendar we are converting into. We check its events for * overrides. * @param val VEvent object * @param mergeAttendees True if we should only update our own attendee. * @return Response with status and EventInfo object representing new entry or updated entry */
public static GetEntityResponse<EventInfo> toEvent( final IcalCallback cb, final BwCalendar cal, final Icalendar ical, final Component val, final boolean mergeAttendees) { final var resp = new GetEntityResponse<EventInfo>(); if (val == null) { return Response.notOk(resp, failed, "No component supplied"); } String currentPrincipal = null; final BwPrincipal principal = cb.getPrincipal(); if (principal != null) { currentPrincipal = principal.getPrincipalRef(); } final Holder<Boolean> hasXparams = new Holder<>(Boolean.FALSE); final int methodType = ical.getMethodType(); String attUri = null; if (mergeAttendees) { // We'll need this later. attUri = cb.getCaladdr(cb.getPrincipal().getPrincipalRef()); } final String colPath; if (cal == null) { colPath = null; } else { colPath = cal.getPath(); } try { final PropertyList<Property> pl = val.getProperties(); boolean vpoll = false; boolean event = false; boolean task = false; if (pl == null) { // Empty component return Response.notOk(resp, failed, "Empty component"); } final int entityType; if (val instanceof VEvent) { entityType = IcalDefs.entityTypeEvent; event = true; } else if (val instanceof VToDo) { entityType = IcalDefs.entityTypeTodo; task = true; } else if (val instanceof VJournal) { entityType = IcalDefs.entityTypeJournal; } else if (val instanceof VFreeBusy) { entityType = IcalDefs.entityTypeFreeAndBusy; } else if (val instanceof VAvailability) { entityType = IcalDefs.entityTypeVavailability; } else if (val instanceof Available) { entityType = IcalDefs.entityTypeAvailable; } else if (val instanceof VPoll) { entityType = IcalDefs.entityTypeVpoll; vpoll = true; } else { return Response.error(resp, "org.bedework.invalid.component.type: " + val.getName()); } // Get the guid from the component String guid = null; final Uid uidp = pl.getProperty(Property.UID); if (uidp != null) { testXparams(uidp, hasXparams); guid = uidp.getValue(); } if (guid == null) { /* XXX A guid is required - but are there devices out there without a * guid - and if so how do we handle it? */ return Response.notOk(resp, failed, CalFacadeException.noGuid); } /* See if we have a recurrence id */ BwDateTime ridObj = null; String rid = null; TimeZone ridTz = null; final RecurrenceId ridp = pl.getProperty(Property.RECURRENCE_ID); if (ridp != null) { testXparams(ridp, hasXparams); ridObj = BwDateTime.makeBwDateTime(ridp); if (ridObj.getRange() != null) { /* XXX What do I do with it? */ logger.warn("TRANS-TO_EVENT: Got a recurrence id range"); } rid = ridObj.getDate(); } EventInfo masterEI = null; EventInfo evinfo = null; final BwEvent ev; /* If we have a recurrence id see if we already have the master (we should * get a master + all its overrides). * * If so find the override and use the annnotation or if no override, * make one. * * If no override retrieve the event, add it to our table and then locate the * annotation. * * If there is no annotation, create one. * * It's possible we have been sent 'detached' instances of a recurring * event. This may happen if we are invited to one or more instances of a * meeting. In this case we try to retrieve the master and if it doesn't * exist we manufacture one. We consider such an instance an update to * that instance only and leave the others alone. */ /* We need this in a couple of places */ final DtStart dtStart = pl.getProperty(Property.DTSTART); /* if (rid != null) { // See if we have a new master event. If so create a proxy to that event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI == null) { masterEI = makeNewEvent(cb, chg, entityType, guid, cal); BwEvent e = masterEI.getEvent(); // XXX This seems bogus DtStart mdtStart; String bogusDate = "19980118T230000"; if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + "Z"); } else if (dtStart.getTimeZone() == null) { mdtStart = new DtStart(bogusDate); } else { mdtStart = new DtStart(bogusDate + "Z", dtStart.getTimeZone()); } setDates(e, mdtStart, null, null, chg); e.setRecurring(true); e.addRdate(ridObj); e.setSuppressed(true); ical.addComponent(masterEI); } if (masterEI != null) { evinfo = masterEI.findOverride(rid); } } */ /* If this is a recurrence instance see if we can find the master We only need this because the master may follow the overrides. */ if (rid != null) { // See if we have a new master event. If so create a proxy to this event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI != null) { evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; } } if ((evinfo == null) && (cal != null) && (cal.getCalType() != BwCalendar.calTypeInbox) && (cal.getCalType() != BwCalendar.calTypePendingInbox) && (cal.getCalType() != BwCalendar.calTypeOutbox)) { if (logger.debug()) { logger.debug("TRANS-TO_EVENT: try to fetch event with guid=" + guid); } final GetEntitiesResponse<EventInfo> eisResp = cb.getEvent(colPath, guid); if (eisResp.isError()) { return Response.fromResponse(resp, eisResp); } final var eis = eisResp.getEntities(); if (!Util.isEmpty(eis)) { if (eis.size() > 1) { // DORECUR - wrong again return Response.notOk(resp, failed, "More than one event returned for guid."); } evinfo = eis.iterator().next(); } if (logger.debug()) { if (evinfo != null) { logger.debug("TRANS-TO_EVENT: fetched event with guid"); } else { logger.debug("TRANS-TO_EVENT: did not find event with guid"); } } if (evinfo != null) { if (rid != null) { // We just retrieved it's master masterEI = evinfo; masterEI.setInstanceOnly(true); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; ical.addComponent(masterEI); } else if (methodType == ScheduleMethods.methodTypeCancel) { // This should never have an rid for cancel of entire event. evinfo.setInstanceOnly(evinfo.getEvent().getSuppressed()); } else { // Presumably sent an update for the entire event. No longer suppressed master evinfo.getEvent().setSuppressed(false); } } else if (rid != null) { /* Manufacture a master for the instance */ masterEI = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); final BwEvent e = masterEI.getEvent(); // XXX This seems bogus final DtStart mdtStart; final String bogusDate = "19980118"; final String bogusTime = "T230000"; // Base dtstart on the recurrence id. final boolean isDateType = ridObj.getDateType(); if (isDateType) { mdtStart = new DtStart(new Date(bogusDate)); } else if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + bogusTime + "Z"); } else if (ridObj.getTzid() == null) { mdtStart = new DtStart(bogusDate + bogusTime); } else { mdtStart = new DtStart(bogusDate + bogusTime, Timezones.getTz(ridObj.getTzid())); } IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), masterEI, mdtStart, null, null); e.setRecurring(true); // e.addRdate(ridObj); final var sum = (Summary)pl.getProperty(Property.SUMMARY); e.setSummary(sum.getValue()); e.setSuppressed(true); ical.addComponent(masterEI); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; masterEI.setInstanceOnly(rid != null); } } if (evinfo == null) { evinfo = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); } else if (evinfo.getEvent().getEntityType() != entityType) { return Response.notOk(resp, failed, "org.bedework.mismatched.entity.type: " + val); } final ChangeTable chg = evinfo.getChangeset( cb.getPrincipal().getPrincipalRef()); if (rid != null) { final String evrid = evinfo.getEvent().getRecurrenceId(); if ((evrid == null) || (!evrid.equals(rid))) { logger. warn("Mismatched rid ev=" + evrid + " expected " + rid); chg.changed(PropertyInfoIndex.RECURRENCE_ID, evrid, rid); // XXX spurious??? } if (masterEI.getEvent().getSuppressed()) { masterEI.getEvent().addRdate(ridObj); } } ev = evinfo.getEvent(); ev.setScheduleMethod(methodType); DtEnd dtEnd = null; if (entityType == IcalDefs.entityTypeTodo) { final Due due = pl.getProperty(Property.DUE); if (due != null ) { dtEnd = new DtEnd(due.getParameters(), due.getValue()); } } else { dtEnd = pl.getProperty(Property.DTEND); } final Duration duration = pl.getProperty(Property.DURATION); IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), evinfo, dtStart, dtEnd, duration); for (final Property prop: pl) { testXparams(prop, hasXparams); //debug("ical prop " + prop.getClass().getName()); String pval = prop.getValue(); if ((pval != null) && (pval.length() == 0)) { pval = null; } final PropertyInfoIndex pi; if (prop instanceof XProperty) { pi = PropertyInfoIndex.XPROP; } else { pi = PropertyInfoIndex.fromName(prop.getName()); } if (pi == null) { logger.debug("Unknown property with name " + prop.getName() + " class " + prop.getClass() + " and value " + pval); continue; } chg.present(pi); switch (pi) { case ACCEPT_RESPONSE: /* ------------------- Accept Response -------------------- */ String sval = prop.getValue(); if (chg.changed(pi, ev.getPollAcceptResponse(), sval)) { ev.setPollAcceptResponse(sval); } break; case ATTACH: /* ------------------- Attachment -------------------- */ chg.addValue(pi, IcalUtil.getAttachment((Attach)prop)); break; case ATTENDEE: /* ------------------- Attendee -------------------- */ if (methodType == ScheduleMethods.methodTypePublish) { if (cb.getStrictness() == IcalCallback.conformanceStrict) { return Response.notOk(resp, failed, CalFacadeException.attendeesInPublish); } //if (cb.getStrictness() == IcalCallback.conformanceWarn) { // warn("Had attendees for PUBLISH"); //} } final Attendee attPr = (Attendee)prop; if (evinfo.getNewEvent() || !mergeAttendees) { chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { final String pUri = cb.getCaladdr(attPr.getValue()); if (pUri.equals(attUri)) { /* Only update for our own attendee * We're doing a PUT and this must be the attendee updating their * partstat. We don't allow them to change other attendees * whatever the PUT content says. */ chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { // Use the value we currently have boolean found = false; for (final BwAttendee att: ev.getAttendees()) { if (pUri.equals(att.getAttendeeUri())) { chg.addValue(pi, att.clone()); found = true; break; } } if (!found) { // An added attendee final BwAttendee att = IcalUtil .getAttendee(cb, attPr); att.setPartstat(IcalDefs.partstatValNeedsAction); chg.addValue(pi, att); } } } break; case BUSYTYPE: final int ibt = BwEvent.fromBusyTypeString(pval); if (chg.changed(pi, ev.getBusyType(), ibt)) { ev.setBusyType(ibt); } break; case CATEGORIES: /* ------------------- Categories -------------------- */ final Categories cats = (Categories)prop; final TextList cl = cats.getCategories(); String lang = IcalUtil.getLang(cats); if (cl != null) { /* Got some categories */ for (final String wd: cl) { if (wd == null) { continue; } final BwString key = new BwString(lang, wd); final var fcResp = cb.findCategory(key); final BwCategory cat; if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isNotFound()) { cat = BwCategory.makeCategory(); cat.setWord(key); cb.addCategory(cat); } else { cat = fcResp.getEntity(); } chg.addValue(pi, cat); } } break; case CLASS: /* ------------------- Class -------------------- */ if (chg.changed(pi, ev.getClassification(), pval)) { ev.setClassification(pval); } break; case COMMENT: /* ------------------- Comment -------------------- */ chg.addValue(pi, new BwString(null, pval)); break; case COMPLETED: /* ------------------- Completed -------------------- */ if (chg.changed(pi, ev.getCompleted(), pval)) { ev.setCompleted(pval); } break; case CONCEPT: /* ------------------- Concept -------------------- */ final Concept c = (Concept)prop; final String cval = c.getValue(); if (cval != null) { /* Got a concept */ chg.addValue(PropertyInfoIndex.XPROP, BwXproperty.makeIcalProperty("CONCEPT", null, cval)); } break; case CONTACT: /* ------------------- Contact -------------------- */ final String altrep = getAltRepPar(prop); lang = IcalUtil.getLang(prop); final String uid = getUidPar(prop); final BwString nm = new BwString(lang, pval); BwContact contact = null; if (uid != null) { final var fcResp = cb.getContact(uid); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { final var fcResp = cb.findContact(nm); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { contact = BwContact.makeContact(); contact.setCn(nm); contact.setLink(altrep); cb.addContact(contact); } else { contact.setCn(nm); contact.setLink(altrep); } chg.addValue(pi, contact); break; case CREATED: /* ------------------- Created -------------------- */ if (chg.changed(pi, ev.getCreated(), pval)) { ev.setCreated(pval); } break; case DESCRIPTION: /* ------------------- Description -------------------- */ if (chg.changed(pi, ev.getDescription(), pval)) { ev.setDescription(pval); } break; case DTEND: /* ------------------- DtEnd -------------------- */ break; case DTSTAMP: /* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval); break; case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE: /* -------------------- Due ------------------------ */ break; case DURATION: /* ------------------- Duration -------------------- */ break; case EXDATE: /* ------------------- ExDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case EXRULE: /* ------------------- ExRule -------------------- */ chg.addValue(pi, pval); break; case FREEBUSY: /* ------------------- freebusy -------------------- */ final FreeBusy fbusy = (FreeBusy)prop; final PeriodList perpl = fbusy.getPeriods(); final Parameter par = IcalUtil.getParameter(fbusy, "FBTYPE"); final int fbtype; if (par == null) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY)) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY_TENTATIVE)) { fbtype = BwFreeBusyComponent.typeBusyTentative; } else if (par.equals(FbType.BUSY_UNAVAILABLE)) { fbtype = BwFreeBusyComponent.typeBusyUnavailable; } else if (par.equals(FbType.FREE)) { fbtype = BwFreeBusyComponent.typeFree; } else { if (logger.debug()) { logger.debug("Unsupported parameter " + par.getName()); } return Response.notOk(resp, failed, "Unsupported parameter " + par.getName()); } final BwFreeBusyComponent fbc = new BwFreeBusyComponent(); fbc.setType(fbtype); for (final Period per : perpl) { fbc.addPeriod(per); } ev.addFreeBusyPeriod(fbc); break; case GEO: /* ------------------- Geo -------------------- */ final Geo g = (Geo)prop; final BwGeo geo = new BwGeo(g.getLatitude(), g.getLongitude()); if (chg.changed(pi, ev.getGeo(), geo)) { ev.setGeo(geo); } break; case LAST_MODIFIED: /* ------------------- LastModified -------------------- */ if (chg.changed(pi, ev.getLastmod(), pval)) { ev.setLastmod(pval); } break; case LOCATION: /* ------------------- Location -------------------- */ BwLocation loc = null; //String uid = getUidPar(prop); /* At the moment Mozilla lightning is broken and this leads to all * sorts of problems. if (uid != null) { loc = cb.getLocation(uid); } */ lang = IcalUtil.getLang(prop); BwString addr = null; if (pval != null) { if (loc == null) { addr = new BwString(lang, pval); final var fcResp = cb.findLocation(addr); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { loc = fcResp.getEntity(); } } if (loc == null) { loc = BwLocation.makeLocation(); loc.setAddress(addr); cb.addLocation(loc); } } final BwLocation evloc = ev.getLocation(); if (chg.changed(pi, evloc, loc)) { // CHGTBL - this only shows that it's a different location object ev.setLocation(loc); } else if ((loc != null) && (evloc != null)) { // See if the value is changed final String evval = evloc.getAddress().getValue(); final String inval = loc.getAddress().getValue(); if (!evval.equals(inval)) { chg.changed(pi, evval, inval); evloc.getAddress().setValue(inval); } } break; case ORGANIZER: /* ------------------- Organizer -------------------- */ final BwOrganizer org = IcalUtil.getOrganizer(cb, (Organizer)prop); final BwOrganizer evorg = ev.getOrganizer(); final BwOrganizer evorgCopy; if (evorg == null) { evorgCopy = null; } else { evorgCopy = (BwOrganizer)evorg.clone(); } if (chg.changed(pi, evorgCopy, org)) { if (evorg == null) { ev.setOrganizer(org); } else { evorg.update(org); } } break; case PERCENT_COMPLETE: /* ------------------- PercentComplete -------------------- */ Integer ival = ((PercentComplete)prop).getPercentage(); if (chg.changed(pi, ev.getPercentComplete(), ival)) { ev.setPercentComplete(ival); } break; case POLL_MODE: /* ------------------- Poll mode -------------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollMode(), sval)) { ev.setPollMode(sval); } break; case POLL_PROPERTIES: /* ------------------- Poll properties ---------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollProperties(), sval)) { ev.setPollProperties(sval); } break; case POLL_WINNER: /* ------------------- Poll winner -------------------- */ ival = ((PollWinner)prop).getPollwinner(); if (chg.changed(pi, ev.getPollWinner(), ival)) { ev.setPollWinner(ival); } break; case PRIORITY: /* ------------------- Priority -------------------- */ ival = ((Priority)prop).getLevel(); if (chg.changed(pi, ev.getPriority(), ival)) { ev.setPriority(ival); } break; case RDATE: /* ------------------- RDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case RECURRENCE_ID: /* ------------------- RecurrenceID -------------------- */ // Done above break; case RELATED_TO: /* ------------------- RelatedTo -------------------- */ final RelatedTo irelto = (RelatedTo)prop; final BwRelatedTo relto = new BwRelatedTo(); final String parval = IcalUtil.getParameterVal(irelto, "RELTYPE"); if (parval != null) { relto.setRelType(parval); } relto.setValue(irelto.getValue()); if (chg.changed(pi, ev.getRelatedTo(), relto)) { ev.setRelatedTo(relto); } break; case REQUEST_STATUS: /* ------------------- RequestStatus -------------------- */ final BwRequestStatus rs = BwRequestStatus .fromRequestStatus((RequestStatus)prop); chg.addValue(pi, rs); break; case RESOURCES: /* ------------------- Resources -------------------- */ final TextList rl = ((Resources)prop).getResources(); if (rl != null) { /* Got some resources */ lang = IcalUtil.getLang(prop); for (final String s: rl) { final BwString rsrc = new BwString(lang, s); chg.addValue(pi, rsrc); } } break; case RRULE: /* ------------------- RRule -------------------- */ chg.addValue(pi, pval); break; case SEQUENCE: /* ------------------- Sequence -------------------- */ final int seq = ((Sequence)prop).getSequenceNo(); if (seq != ev.getSequence()) { chg.changed(pi, ev.getSequence(), seq); ev.setSequence(seq); } break; case STATUS: /* ------------------- Status -------------------- */ if (chg.changed(pi, ev.getStatus(), pval)) { ev.setStatus(pval); } break; case SUMMARY: /* ------------------- Summary -------------------- */ if (chg.changed(pi, ev.getSummary(), pval)) { ev.setSummary(pval); } break; case TRANSP: /* ------------------- Transp -------------------- */ if (chg.changed(pi, ev.getPeruserTransparency( cb.getPrincipal() .getPrincipalRef()), pval)) { final BwXproperty pu = ev.setPeruserTransparency( cb.getPrincipal().getPrincipalRef(), pval); if (pu != null) { chg.addValue(PropertyInfoIndex.XPROP, pu); } } break; case UID: /* ------------------- Uid -------------------- */ /* We did this above */ break; case URL: /* ------------------- Url -------------------- */ if (chg.changed(pi, ev.getLink(), pval)) { ev.setLink(pval); } break; case XPROP: /* ------------------------- x-property --------------------------- */ final String name = prop.getName(); if (name.equalsIgnoreCase(BwXproperty.bedeworkCost)) { if (chg.changed(PropertyInfoIndex.COST, ev.getCost(), pval)) { ev.setCost(pval); } break; } if (name.equalsIgnoreCase(BwXproperty.xBedeworkCategories)) { if (checkCategory(cb, chg, ev, null, pval)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkLocation)) { if (checkLocation(cb, chg, ev, prop)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkContact)) { if (checkContact(cb, chg, ev, null, pval)) { break; } } /* See if this is an x-category that can be converted to a real category */ final XProperty xp = (XProperty)prop; chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(name, xp.getParameters() .toString(), pval)); break; default: if (logger.debug()) { logger.debug("Unsupported property with index " + pi + "; class " + prop.getClass() + " and value " + pval); } } } /* =================== Process sub-components =============== */ final ComponentList<Component> subComps; if (val instanceof ComponentContainer) { subComps = ((ComponentContainer<Component>)val).getComponents(); } else { subComps = null; } final Set<Integer> pids; if (vpoll) { pids = new TreeSet<>(); final BwEvent vp = evinfo.getEvent(); if (!Util.isEmpty(vp.getPollItems())) { vp.clearPollItems(); } } else { pids = null; } if (!Util.isEmpty(subComps)) { for (final var subComp: subComps) { if (subComp instanceof Available) { if (!(val instanceof VAvailability)) { return Response.error(resp, "AVAILABLE only valid in VAVAILABLE"); } final var avlResp = processAvailable(cb, cal, ical, (VAvailability)val, (Available)subComp, evinfo); if (!avlResp.isOk()) { return Response.fromResponse(resp, avlResp); } continue; } if (subComp instanceof Participant) { if (vpoll) { final var vresp = processVoter(cb, (VPoll)val, (Participant)subComp, evinfo, chg, mergeAttendees); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Participant object"); continue; } if (subComp instanceof VResource) { logger.warn("Unimplemented VResource object"); continue; } if (subComp instanceof VLocation) { logger.warn("Unimplemented VLocation object"); continue; } if (subComp instanceof VAlarm) { final var aresp = VAlarmUtil.processAlarm(cb, val, (VAlarm)subComp, ev, currentPrincipal, chg); if (!aresp.isOk()) { return Response.fromResponse(resp, aresp); } continue; } if (vpoll && (event || task)) { final var vresp = processCandidate((VPoll)val, subComp, evinfo, pids, chg); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Component object: " + subComp); } } /* Fix up timestamps. */ if (ev.getCreated() == null) { if (ev.getLastmod() != null) { ev.setCreated(ev.getLastmod()); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); } else { ev.updateDtstamp(); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } } if (ev.getLastmod() == null) { // created cannot be null now ev.setLastmod(ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } processTimezones(ev, ical, chg); /* Remove any recipients and originator */ if (ev.getRecipients() != null) { ev.getRecipients().clear(); } ev.setOriginator(null); if (hasXparams.value) { /* Save a text copy of the entire event as an x-property */ final Component valCopy = val.copy(); /* Remove potentially large values */ final Description desp = valCopy.getProperty(Property.DESCRIPTION); if (desp != null) { desp.setValue(null); } final Attach attachp = valCopy.getProperty(Property.ATTACH); // Don't store the entire attachment - we just need the parameters. if (attachp != null) { final Value v = attachp.getParameter(Parameter.VALUE); if (v != null) { attachp.setValue(String.valueOf(attachp.getValue().hashCode())); } } chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(BwXproperty.bedeworkIcal, null, valCopy.toString())); } chg.processChanges(ev, true, false); ev.setRecurring(ev.isRecurringEntity()); if (logger.debug()) { logger.debug(chg.toString()); logger.debug(ev.toString()); } if (masterEI != null) { // Just return notfound as this event is on its override list return Response.notFound(resp); } resp.setEntity(evinfo); return resp; } catch (final Throwable t) { if (logger.debug()) { logger.error(t); } return Response.error(resp, t); } }
NONSATD
true
public static GetEntityResponse<EventInfo> toEvent( final IcalCallback cb, final BwCalendar cal, final Icalendar ical, final Component val, final boolean mergeAttendees) { final var resp = new GetEntityResponse<EventInfo>(); if (val == null) { return Response.notOk(resp, failed, "No component supplied"); } String currentPrincipal = null; final BwPrincipal principal = cb.getPrincipal(); if (principal != null) { currentPrincipal = principal.getPrincipalRef(); } final Holder<Boolean> hasXparams = new Holder<>(Boolean.FALSE); final int methodType = ical.getMethodType(); String attUri = null; if (mergeAttendees) { // We'll need this later. attUri = cb.getCaladdr(cb.getPrincipal().getPrincipalRef()); } final String colPath; if (cal == null) { colPath = null; } else { colPath = cal.getPath(); } try { final PropertyList<Property> pl = val.getProperties(); boolean vpoll = false; boolean event = false; boolean task = false; if (pl == null) { // Empty component return Response.notOk(resp, failed, "Empty component"); } final int entityType; if (val instanceof VEvent) { entityType = IcalDefs.entityTypeEvent; event = true; } else if (val instanceof VToDo) { entityType = IcalDefs.entityTypeTodo; task = true; } else if (val instanceof VJournal) { entityType = IcalDefs.entityTypeJournal; } else if (val instanceof VFreeBusy) { entityType = IcalDefs.entityTypeFreeAndBusy; } else if (val instanceof VAvailability) { entityType = IcalDefs.entityTypeVavailability; } else if (val instanceof Available) { entityType = IcalDefs.entityTypeAvailable; } else if (val instanceof VPoll) { entityType = IcalDefs.entityTypeVpoll; vpoll = true; } else { return Response.error(resp, "org.bedework.invalid.component.type: " + val.getName()); } // Get the guid from the component String guid = null; final Uid uidp = pl.getProperty(Property.UID); if (uidp != null) { testXparams(uidp, hasXparams); guid = uidp.getValue(); } if (guid == null) { /* XXX A guid is required - but are there devices out there without a * guid - and if so how do we handle it? */ return Response.notOk(resp, failed, CalFacadeException.noGuid); } /* See if we have a recurrence id */ BwDateTime ridObj = null; String rid = null; TimeZone ridTz = null; final RecurrenceId ridp = pl.getProperty(Property.RECURRENCE_ID); if (ridp != null) { testXparams(ridp, hasXparams); ridObj = BwDateTime.makeBwDateTime(ridp); if (ridObj.getRange() != null) { /* XXX What do I do with it? */ logger.warn("TRANS-TO_EVENT: Got a recurrence id range"); } rid = ridObj.getDate(); } EventInfo masterEI = null; EventInfo evinfo = null; final BwEvent ev; /* If we have a recurrence id see if we already have the master (we should * get a master + all its overrides). * * If so find the override and use the annnotation or if no override, * make one. * * If no override retrieve the event, add it to our table and then locate the * annotation. * * If there is no annotation, create one. * * It's possible we have been sent 'detached' instances of a recurring * event. This may happen if we are invited to one or more instances of a * meeting. In this case we try to retrieve the master and if it doesn't * exist we manufacture one. We consider such an instance an update to * that instance only and leave the others alone. */ /* We need this in a couple of places */ final DtStart dtStart = pl.getProperty(Property.DTSTART); /* if (rid != null) { // See if we have a new master event. If so create a proxy to that event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI == null) { masterEI = makeNewEvent(cb, chg, entityType, guid, cal); BwEvent e = masterEI.getEvent(); // XXX This seems bogus DtStart mdtStart; String bogusDate = "19980118T230000"; if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + "Z"); } else if (dtStart.getTimeZone() == null) { mdtStart = new DtStart(bogusDate); } else { mdtStart = new DtStart(bogusDate + "Z", dtStart.getTimeZone()); } setDates(e, mdtStart, null, null, chg); e.setRecurring(true); e.addRdate(ridObj); e.setSuppressed(true); ical.addComponent(masterEI); } if (masterEI != null) { evinfo = masterEI.findOverride(rid); } } */ /* If this is a recurrence instance see if we can find the master We only need this because the master may follow the overrides. */ if (rid != null) { // See if we have a new master event. If so create a proxy to this event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI != null) { evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; } } if ((evinfo == null) && (cal != null) && (cal.getCalType() != BwCalendar.calTypeInbox) && (cal.getCalType() != BwCalendar.calTypePendingInbox) && (cal.getCalType() != BwCalendar.calTypeOutbox)) { if (logger.debug()) { logger.debug("TRANS-TO_EVENT: try to fetch event with guid=" + guid); } final GetEntitiesResponse<EventInfo> eisResp = cb.getEvent(colPath, guid); if (eisResp.isError()) { return Response.fromResponse(resp, eisResp); } final var eis = eisResp.getEntities(); if (!Util.isEmpty(eis)) { if (eis.size() > 1) { // DORECUR - wrong again return Response.notOk(resp, failed, "More than one event returned for guid."); } evinfo = eis.iterator().next(); } if (logger.debug()) { if (evinfo != null) { logger.debug("TRANS-TO_EVENT: fetched event with guid"); } else { logger.debug("TRANS-TO_EVENT: did not find event with guid"); } } if (evinfo != null) { if (rid != null) { // We just retrieved it's master masterEI = evinfo; masterEI.setInstanceOnly(true); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; ical.addComponent(masterEI); } else if (methodType == ScheduleMethods.methodTypeCancel) { // This should never have an rid for cancel of entire event. evinfo.setInstanceOnly(evinfo.getEvent().getSuppressed()); } else { // Presumably sent an update for the entire event. No longer suppressed master evinfo.getEvent().setSuppressed(false); } } else if (rid != null) { /* Manufacture a master for the instance */ masterEI = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); final BwEvent e = masterEI.getEvent(); // XXX This seems bogus final DtStart mdtStart; final String bogusDate = "19980118"; final String bogusTime = "T230000"; // Base dtstart on the recurrence id. final boolean isDateType = ridObj.getDateType(); if (isDateType) { mdtStart = new DtStart(new Date(bogusDate)); } else if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + bogusTime + "Z"); } else if (ridObj.getTzid() == null) { mdtStart = new DtStart(bogusDate + bogusTime); } else { mdtStart = new DtStart(bogusDate + bogusTime, Timezones.getTz(ridObj.getTzid())); } IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), masterEI, mdtStart, null, null); e.setRecurring(true); // e.addRdate(ridObj); final var sum = (Summary)pl.getProperty(Property.SUMMARY); e.setSummary(sum.getValue()); e.setSuppressed(true); ical.addComponent(masterEI); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; masterEI.setInstanceOnly(rid != null); } } if (evinfo == null) { evinfo = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); } else if (evinfo.getEvent().getEntityType() != entityType) { return Response.notOk(resp, failed, "org.bedework.mismatched.entity.type: " + val); } final ChangeTable chg = evinfo.getChangeset( cb.getPrincipal().getPrincipalRef()); if (rid != null) { final String evrid = evinfo.getEvent().getRecurrenceId(); if ((evrid == null) || (!evrid.equals(rid))) { logger. warn("Mismatched rid ev=" + evrid + " expected " + rid); chg.changed(PropertyInfoIndex.RECURRENCE_ID, evrid, rid); // XXX spurious??? } if (masterEI.getEvent().getSuppressed()) { masterEI.getEvent().addRdate(ridObj); } } ev = evinfo.getEvent(); ev.setScheduleMethod(methodType); DtEnd dtEnd = null; if (entityType == IcalDefs.entityTypeTodo) { final Due due = pl.getProperty(Property.DUE); if (due != null ) { dtEnd = new DtEnd(due.getParameters(), due.getValue()); } } else { dtEnd = pl.getProperty(Property.DTEND); } final Duration duration = pl.getProperty(Property.DURATION); IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), evinfo, dtStart, dtEnd, duration); for (final Property prop: pl) { testXparams(prop, hasXparams); //debug("ical prop " + prop.getClass().getName()); String pval = prop.getValue(); if ((pval != null) && (pval.length() == 0)) { pval = null; } final PropertyInfoIndex pi; if (prop instanceof XProperty) { pi = PropertyInfoIndex.XPROP; } else { pi = PropertyInfoIndex.fromName(prop.getName()); } if (pi == null) { logger.debug("Unknown property with name " + prop.getName() + " class " + prop.getClass() + " and value " + pval); continue; } chg.present(pi); switch (pi) { case ACCEPT_RESPONSE: /* ------------------- Accept Response -------------------- */ String sval = prop.getValue(); if (chg.changed(pi, ev.getPollAcceptResponse(), sval)) { ev.setPollAcceptResponse(sval); } break; case ATTACH: /* ------------------- Attachment -------------------- */ chg.addValue(pi, IcalUtil.getAttachment((Attach)prop)); break; case ATTENDEE: /* ------------------- Attendee -------------------- */ if (methodType == ScheduleMethods.methodTypePublish) { if (cb.getStrictness() == IcalCallback.conformanceStrict) { return Response.notOk(resp, failed, CalFacadeException.attendeesInPublish); } //if (cb.getStrictness() == IcalCallback.conformanceWarn) { // warn("Had attendees for PUBLISH"); //} } final Attendee attPr = (Attendee)prop; if (evinfo.getNewEvent() || !mergeAttendees) { chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { final String pUri = cb.getCaladdr(attPr.getValue()); if (pUri.equals(attUri)) { /* Only update for our own attendee * We're doing a PUT and this must be the attendee updating their * partstat. We don't allow them to change other attendees * whatever the PUT content says. */ chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { // Use the value we currently have boolean found = false; for (final BwAttendee att: ev.getAttendees()) { if (pUri.equals(att.getAttendeeUri())) { chg.addValue(pi, att.clone()); found = true; break; } } if (!found) { // An added attendee final BwAttendee att = IcalUtil .getAttendee(cb, attPr); att.setPartstat(IcalDefs.partstatValNeedsAction); chg.addValue(pi, att); } } } break; case BUSYTYPE: final int ibt = BwEvent.fromBusyTypeString(pval); if (chg.changed(pi, ev.getBusyType(), ibt)) { ev.setBusyType(ibt); } break; case CATEGORIES: /* ------------------- Categories -------------------- */ final Categories cats = (Categories)prop; final TextList cl = cats.getCategories(); String lang = IcalUtil.getLang(cats); if (cl != null) { /* Got some categories */ for (final String wd: cl) { if (wd == null) { continue; } final BwString key = new BwString(lang, wd); final var fcResp = cb.findCategory(key); final BwCategory cat; if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isNotFound()) { cat = BwCategory.makeCategory(); cat.setWord(key); cb.addCategory(cat); } else { cat = fcResp.getEntity(); } chg.addValue(pi, cat); } } break; case CLASS: /* ------------------- Class -------------------- */ if (chg.changed(pi, ev.getClassification(), pval)) { ev.setClassification(pval); } break; case COMMENT: /* ------------------- Comment -------------------- */ chg.addValue(pi, new BwString(null, pval)); break; case COMPLETED: /* ------------------- Completed -------------------- */ if (chg.changed(pi, ev.getCompleted(), pval)) { ev.setCompleted(pval); } break; case CONCEPT: /* ------------------- Concept -------------------- */ final Concept c = (Concept)prop; final String cval = c.getValue(); if (cval != null) { /* Got a concept */ chg.addValue(PropertyInfoIndex.XPROP, BwXproperty.makeIcalProperty("CONCEPT", null, cval)); } break; case CONTACT: /* ------------------- Contact -------------------- */ final String altrep = getAltRepPar(prop); lang = IcalUtil.getLang(prop); final String uid = getUidPar(prop); final BwString nm = new BwString(lang, pval); BwContact contact = null; if (uid != null) { final var fcResp = cb.getContact(uid); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { final var fcResp = cb.findContact(nm); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { contact = BwContact.makeContact(); contact.setCn(nm); contact.setLink(altrep); cb.addContact(contact); } else { contact.setCn(nm); contact.setLink(altrep); } chg.addValue(pi, contact); break; case CREATED: /* ------------------- Created -------------------- */ if (chg.changed(pi, ev.getCreated(), pval)) { ev.setCreated(pval); } break; case DESCRIPTION: /* ------------------- Description -------------------- */ if (chg.changed(pi, ev.getDescription(), pval)) { ev.setDescription(pval); } break; case DTEND: /* ------------------- DtEnd -------------------- */ break; case DTSTAMP: /* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval); break; case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE: /* -------------------- Due ------------------------ */ break; case DURATION: /* ------------------- Duration -------------------- */ break; case EXDATE: /* ------------------- ExDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case EXRULE: /* ------------------- ExRule -------------------- */ chg.addValue(pi, pval); break; case FREEBUSY: /* ------------------- freebusy -------------------- */ final FreeBusy fbusy = (FreeBusy)prop; final PeriodList perpl = fbusy.getPeriods(); final Parameter par = IcalUtil.getParameter(fbusy, "FBTYPE"); final int fbtype; if (par == null) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY)) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY_TENTATIVE)) { fbtype = BwFreeBusyComponent.typeBusyTentative; } else if (par.equals(FbType.BUSY_UNAVAILABLE)) { fbtype = BwFreeBusyComponent.typeBusyUnavailable; } else if (par.equals(FbType.FREE)) { fbtype = BwFreeBusyComponent.typeFree; } else { if (logger.debug()) { logger.debug("Unsupported parameter " + par.getName()); } return Response.notOk(resp, failed, "Unsupported parameter " + par.getName()); } final BwFreeBusyComponent fbc = new BwFreeBusyComponent(); fbc.setType(fbtype); for (final Period per : perpl) { fbc.addPeriod(per); } ev.addFreeBusyPeriod(fbc); break; case GEO: /* ------------------- Geo -------------------- */ final Geo g = (Geo)prop; final BwGeo geo = new BwGeo(g.getLatitude(), g.getLongitude()); if (chg.changed(pi, ev.getGeo(), geo)) { ev.setGeo(geo); } break; case LAST_MODIFIED: /* ------------------- LastModified -------------------- */ if (chg.changed(pi, ev.getLastmod(), pval)) { ev.setLastmod(pval); } break; case LOCATION: /* ------------------- Location -------------------- */ BwLocation loc = null; //String uid = getUidPar(prop); /* At the moment Mozilla lightning is broken and this leads to all * sorts of problems. if (uid != null) { loc = cb.getLocation(uid); } */ lang = IcalUtil.getLang(prop); BwString addr = null; if (pval != null) { if (loc == null) { addr = new BwString(lang, pval); final var fcResp = cb.findLocation(addr); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { loc = fcResp.getEntity(); } } if (loc == null) { loc = BwLocation.makeLocation(); loc.setAddress(addr); cb.addLocation(loc); } } final BwLocation evloc = ev.getLocation(); if (chg.changed(pi, evloc, loc)) { // CHGTBL - this only shows that it's a different location object ev.setLocation(loc); } else if ((loc != null) && (evloc != null)) { // See if the value is changed final String evval = evloc.getAddress().getValue(); final String inval = loc.getAddress().getValue(); if (!evval.equals(inval)) { chg.changed(pi, evval, inval); evloc.getAddress().setValue(inval); } } break; case ORGANIZER: /* ------------------- Organizer -------------------- */ final BwOrganizer org = IcalUtil.getOrganizer(cb, (Organizer)prop); final BwOrganizer evorg = ev.getOrganizer(); final BwOrganizer evorgCopy; if (evorg == null) { evorgCopy = null; } else { evorgCopy = (BwOrganizer)evorg.clone(); } if (chg.changed(pi, evorgCopy, org)) { if (evorg == null) { ev.setOrganizer(org); } else { evorg.update(org); } } break; case PERCENT_COMPLETE: /* ------------------- PercentComplete -------------------- */ Integer ival = ((PercentComplete)prop).getPercentage(); if (chg.changed(pi, ev.getPercentComplete(), ival)) { ev.setPercentComplete(ival); } break; case POLL_MODE: /* ------------------- Poll mode -------------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollMode(), sval)) { ev.setPollMode(sval); } break; case POLL_PROPERTIES: /* ------------------- Poll properties ---------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollProperties(), sval)) { ev.setPollProperties(sval); } break; case POLL_WINNER: /* ------------------- Poll winner -------------------- */ ival = ((PollWinner)prop).getPollwinner(); if (chg.changed(pi, ev.getPollWinner(), ival)) { ev.setPollWinner(ival); } break; case PRIORITY: /* ------------------- Priority -------------------- */ ival = ((Priority)prop).getLevel(); if (chg.changed(pi, ev.getPriority(), ival)) { ev.setPriority(ival); } break; case RDATE: /* ------------------- RDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case RECURRENCE_ID: /* ------------------- RecurrenceID -------------------- */ // Done above break; case RELATED_TO: /* ------------------- RelatedTo -------------------- */ final RelatedTo irelto = (RelatedTo)prop; final BwRelatedTo relto = new BwRelatedTo(); final String parval = IcalUtil.getParameterVal(irelto, "RELTYPE"); if (parval != null) { relto.setRelType(parval); } relto.setValue(irelto.getValue()); if (chg.changed(pi, ev.getRelatedTo(), relto)) { ev.setRelatedTo(relto); } break; case REQUEST_STATUS: /* ------------------- RequestStatus -------------------- */ final BwRequestStatus rs = BwRequestStatus .fromRequestStatus((RequestStatus)prop); chg.addValue(pi, rs); break; case RESOURCES: /* ------------------- Resources -------------------- */ final TextList rl = ((Resources)prop).getResources(); if (rl != null) { /* Got some resources */ lang = IcalUtil.getLang(prop); for (final String s: rl) { final BwString rsrc = new BwString(lang, s); chg.addValue(pi, rsrc); } } break; case RRULE: /* ------------------- RRule -------------------- */ chg.addValue(pi, pval); break; case SEQUENCE: /* ------------------- Sequence -------------------- */ final int seq = ((Sequence)prop).getSequenceNo(); if (seq != ev.getSequence()) { chg.changed(pi, ev.getSequence(), seq); ev.setSequence(seq); } break; case STATUS: /* ------------------- Status -------------------- */ if (chg.changed(pi, ev.getStatus(), pval)) { ev.setStatus(pval); } break; case SUMMARY: /* ------------------- Summary -------------------- */ if (chg.changed(pi, ev.getSummary(), pval)) { ev.setSummary(pval); } break; case TRANSP: /* ------------------- Transp -------------------- */ if (chg.changed(pi, ev.getPeruserTransparency( cb.getPrincipal() .getPrincipalRef()), pval)) { final BwXproperty pu = ev.setPeruserTransparency( cb.getPrincipal().getPrincipalRef(), pval); if (pu != null) { chg.addValue(PropertyInfoIndex.XPROP, pu); } } break; case UID: /* ------------------- Uid -------------------- */ /* We did this above */ break; case URL: /* ------------------- Url -------------------- */ if (chg.changed(pi, ev.getLink(), pval)) { ev.setLink(pval); } break; case XPROP: /* ------------------------- x-property --------------------------- */ final String name = prop.getName(); if (name.equalsIgnoreCase(BwXproperty.bedeworkCost)) { if (chg.changed(PropertyInfoIndex.COST, ev.getCost(), pval)) { ev.setCost(pval); } break; } if (name.equalsIgnoreCase(BwXproperty.xBedeworkCategories)) { if (checkCategory(cb, chg, ev, null, pval)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkLocation)) { if (checkLocation(cb, chg, ev, prop)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkContact)) { if (checkContact(cb, chg, ev, null, pval)) { break; } } /* See if this is an x-category that can be converted to a real category */ final XProperty xp = (XProperty)prop; chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(name, xp.getParameters() .toString(), pval)); break; default: if (logger.debug()) { logger.debug("Unsupported property with index " + pi + "; class " + prop.getClass() + " and value " + pval); } } } /* =================== Process sub-components =============== */ final ComponentList<Component> subComps; if (val instanceof ComponentContainer) { subComps = ((ComponentContainer<Component>)val).getComponents(); } else { subComps = null; } final Set<Integer> pids; if (vpoll) { pids = new TreeSet<>(); final BwEvent vp = evinfo.getEvent(); if (!Util.isEmpty(vp.getPollItems())) { vp.clearPollItems(); } } else { pids = null; } if (!Util.isEmpty(subComps)) { for (final var subComp: subComps) { if (subComp instanceof Available) { if (!(val instanceof VAvailability)) { return Response.error(resp, "AVAILABLE only valid in VAVAILABLE"); } final var avlResp = processAvailable(cb, cal, ical, (VAvailability)val, (Available)subComp, evinfo); if (!avlResp.isOk()) { return Response.fromResponse(resp, avlResp); } continue; } if (subComp instanceof Participant) { if (vpoll) { final var vresp = processVoter(cb, (VPoll)val, (Participant)subComp, evinfo, chg, mergeAttendees); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Participant object"); continue; } if (subComp instanceof VResource) { logger.warn("Unimplemented VResource object"); continue; } if (subComp instanceof VLocation) { logger.warn("Unimplemented VLocation object"); continue; } if (subComp instanceof VAlarm) { final var aresp = VAlarmUtil.processAlarm(cb, val, (VAlarm)subComp, ev, currentPrincipal, chg); if (!aresp.isOk()) { return Response.fromResponse(resp, aresp); } continue; } if (vpoll && (event || task)) { final var vresp = processCandidate((VPoll)val, subComp, evinfo, pids, chg); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Component object: " + subComp); } } /* Fix up timestamps. */ if (ev.getCreated() == null) { if (ev.getLastmod() != null) { ev.setCreated(ev.getLastmod()); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); } else { ev.updateDtstamp(); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } } if (ev.getLastmod() == null) { // created cannot be null now ev.setLastmod(ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } processTimezones(ev, ical, chg); /* Remove any recipients and originator */ if (ev.getRecipients() != null) { ev.getRecipients().clear(); } ev.setOriginator(null); if (hasXparams.value) { /* Save a text copy of the entire event as an x-property */ final Component valCopy = val.copy(); /* Remove potentially large values */ final Description desp = valCopy.getProperty(Property.DESCRIPTION); if (desp != null) { desp.setValue(null); } final Attach attachp = valCopy.getProperty(Property.ATTACH); // Don't store the entire attachment - we just need the parameters. if (attachp != null) { final Value v = attachp.getParameter(Parameter.VALUE); if (v != null) { attachp.setValue(String.valueOf(attachp.getValue().hashCode())); } } chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(BwXproperty.bedeworkIcal, null, valCopy.toString())); } chg.processChanges(ev, true, false); ev.setRecurring(ev.isRecurringEntity()); if (logger.debug()) { logger.debug(chg.toString()); logger.debug(ev.toString()); } if (masterEI != null) { // Just return notfound as this event is on its override list return Response.notFound(resp); } resp.setEntity(evinfo); return resp; } catch (final Throwable t) { if (logger.debug()) { logger.error(t); } return Response.error(resp, t); } }
public static GetEntityResponse<EventInfo> toEvent( final IcalCallback cb, final BwCalendar cal, final Icalendar ical, final Component val, final boolean mergeAttendees) { final var resp = new GetEntityResponse<EventInfo>(); if (val == null) { return Response.notOk(resp, failed, "No component supplied"); } String currentPrincipal = null; final BwPrincipal principal = cb.getPrincipal(); if (principal != null) { currentPrincipal = principal.getPrincipalRef(); } final Holder<Boolean> hasXparams = new Holder<>(Boolean.FALSE); final int methodType = ical.getMethodType(); String attUri = null; if (mergeAttendees) { // We'll need this later. attUri = cb.getCaladdr(cb.getPrincipal().getPrincipalRef()); } final String colPath; if (cal == null) { colPath = null; } else { colPath = cal.getPath(); } try { final PropertyList<Property> pl = val.getProperties(); boolean vpoll = false; boolean event = false; boolean task = false; if (pl == null) { // Empty component return Response.notOk(resp, failed, "Empty component"); } final int entityType; if (val instanceof VEvent) { entityType = IcalDefs.entityTypeEvent; event = true; } else if (val instanceof VToDo) { entityType = IcalDefs.entityTypeTodo; task = true; } else if (val instanceof VJournal) { entityType = IcalDefs.entityTypeJournal; } else if (val instanceof VFreeBusy) { entityType = IcalDefs.entityTypeFreeAndBusy; } else if (val instanceof VAvailability) { entityType = IcalDefs.entityTypeVavailability; } else if (val instanceof Available) { entityType = IcalDefs.entityTypeAvailable; } else if (val instanceof VPoll) { entityType = IcalDefs.entityTypeVpoll; vpoll = true; } else { return Response.error(resp, "org.bedework.invalid.component.type: " + val.getName()); } // Get the guid from the component String guid = null; final Uid uidp = pl.getProperty(Property.UID); if (uidp != null) { testXparams(uidp, hasXparams); guid = uidp.getValue(); } if (guid == null) { /* XXX A guid is required - but are there devices out there without a * guid - and if so how do we handle it? */ return Response.notOk(resp, failed, CalFacadeException.noGuid); } /* See if we have a recurrence id */ BwDateTime ridObj = null; String rid = null; TimeZone ridTz = null; final RecurrenceId ridp = pl.getProperty(Property.RECURRENCE_ID); if (ridp != null) { testXparams(ridp, hasXparams); ridObj = BwDateTime.makeBwDateTime(ridp); if (ridObj.getRange() != null) { /* XXX What do I do with it? */ logger.warn("TRANS-TO_EVENT: Got a recurrence id range"); } rid = ridObj.getDate(); } EventInfo masterEI = null; EventInfo evinfo = null; final BwEvent ev; /* If we have a recurrence id see if we already have the master (we should * get a master + all its overrides). * * If so find the override and use the annnotation or if no override, * make one. * * If no override retrieve the event, add it to our table and then locate the * annotation. * * If there is no annotation, create one. * * It's possible we have been sent 'detached' instances of a recurring * event. This may happen if we are invited to one or more instances of a * meeting. In this case we try to retrieve the master and if it doesn't * exist we manufacture one. We consider such an instance an update to * that instance only and leave the others alone. */ /* We need this in a couple of places */ final DtStart dtStart = pl.getProperty(Property.DTSTART); /* if (rid != null) { // See if we have a new master event. If so create a proxy to that event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI == null) { masterEI = makeNewEvent(cb, chg, entityType, guid, cal); BwEvent e = masterEI.getEvent(); // XXX This seems bogus DtStart mdtStart; String bogusDate = "19980118T230000"; if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + "Z"); } else if (dtStart.getTimeZone() == null) { mdtStart = new DtStart(bogusDate); } else { mdtStart = new DtStart(bogusDate + "Z", dtStart.getTimeZone()); } setDates(e, mdtStart, null, null, chg); e.setRecurring(true); e.addRdate(ridObj); e.setSuppressed(true); ical.addComponent(masterEI); } if (masterEI != null) { evinfo = masterEI.findOverride(rid); } } */ /* If this is a recurrence instance see if we can find the master We only need this because the master may follow the overrides. */ if (rid != null) { // See if we have a new master event. If so create a proxy to this event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI != null) { evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; } } if ((evinfo == null) && (cal != null) && (cal.getCalType() != BwCalendar.calTypeInbox) && (cal.getCalType() != BwCalendar.calTypePendingInbox) && (cal.getCalType() != BwCalendar.calTypeOutbox)) { if (logger.debug()) { logger.debug("TRANS-TO_EVENT: try to fetch event with guid=" + guid); } final GetEntitiesResponse<EventInfo> eisResp = cb.getEvent(colPath, guid); if (eisResp.isError()) { return Response.fromResponse(resp, eisResp); } final var eis = eisResp.getEntities(); if (!Util.isEmpty(eis)) { if (eis.size() > 1) { // DORECUR - wrong again return Response.notOk(resp, failed, "More than one event returned for guid."); } evinfo = eis.iterator().next(); } if (logger.debug()) { if (evinfo != null) { logger.debug("TRANS-TO_EVENT: fetched event with guid"); } else { logger.debug("TRANS-TO_EVENT: did not find event with guid"); } } if (evinfo != null) { if (rid != null) { // We just retrieved it's master masterEI = evinfo; masterEI.setInstanceOnly(true); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; ical.addComponent(masterEI); } else if (methodType == ScheduleMethods.methodTypeCancel) { // This should never have an rid for cancel of entire event. evinfo.setInstanceOnly(evinfo.getEvent().getSuppressed()); } else { // Presumably sent an update for the entire event. No longer suppressed master evinfo.getEvent().setSuppressed(false); } } else if (rid != null) { /* Manufacture a master for the instance */ masterEI = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); final BwEvent e = masterEI.getEvent(); // XXX This seems bogus final DtStart mdtStart; final String bogusDate = "19980118"; final String bogusTime = "T230000"; // Base dtstart on the recurrence id. final boolean isDateType = ridObj.getDateType(); if (isDateType) { mdtStart = new DtStart(new Date(bogusDate)); } else if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + bogusTime + "Z"); } else if (ridObj.getTzid() == null) { mdtStart = new DtStart(bogusDate + bogusTime); } else { mdtStart = new DtStart(bogusDate + bogusTime, Timezones.getTz(ridObj.getTzid())); } IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), masterEI, mdtStart, null, null); e.setRecurring(true); // e.addRdate(ridObj); final var sum = (Summary)pl.getProperty(Property.SUMMARY); e.setSummary(sum.getValue()); e.setSuppressed(true); ical.addComponent(masterEI); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; masterEI.setInstanceOnly(rid != null); } } if (evinfo == null) { evinfo = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); } else if (evinfo.getEvent().getEntityType() != entityType) { return Response.notOk(resp, failed, "org.bedework.mismatched.entity.type: " + val); } final ChangeTable chg = evinfo.getChangeset( cb.getPrincipal().getPrincipalRef()); if (rid != null) { final String evrid = evinfo.getEvent().getRecurrenceId(); if ((evrid == null) || (!evrid.equals(rid))) { logger. warn("Mismatched rid ev=" + evrid + " expected " + rid); chg.changed(PropertyInfoIndex.RECURRENCE_ID, evrid, rid); // XXX spurious??? } if (masterEI.getEvent().getSuppressed()) { masterEI.getEvent().addRdate(ridObj); } } ev = evinfo.getEvent(); ev.setScheduleMethod(methodType); DtEnd dtEnd = null; if (entityType == IcalDefs.entityTypeTodo) { final Due due = pl.getProperty(Property.DUE); if (due != null ) { dtEnd = new DtEnd(due.getParameters(), due.getValue()); } } else { dtEnd = pl.getProperty(Property.DTEND); } final Duration duration = pl.getProperty(Property.DURATION); IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), evinfo, dtStart, dtEnd, duration); for (final Property prop: pl) { testXparams(prop, hasXparams); //debug("ical prop " + prop.getClass().getName()); String pval = prop.getValue(); if ((pval != null) && (pval.length() == 0)) { pval = null; } final PropertyInfoIndex pi; if (prop instanceof XProperty) { pi = PropertyInfoIndex.XPROP; } else { pi = PropertyInfoIndex.fromName(prop.getName()); } if (pi == null) { logger.debug("Unknown property with name " + prop.getName() + " class " + prop.getClass() + " and value " + pval); continue; } chg.present(pi); switch (pi) { case ACCEPT_RESPONSE: /* ------------------- Accept Response -------------------- */ String sval = prop.getValue(); if (chg.changed(pi, ev.getPollAcceptResponse(), sval)) { ev.setPollAcceptResponse(sval); } break; case ATTACH: /* ------------------- Attachment -------------------- */ chg.addValue(pi, IcalUtil.getAttachment((Attach)prop)); break; case ATTENDEE: /* ------------------- Attendee -------------------- */ if (methodType == ScheduleMethods.methodTypePublish) { if (cb.getStrictness() == IcalCallback.conformanceStrict) { return Response.notOk(resp, failed, CalFacadeException.attendeesInPublish); } //if (cb.getStrictness() == IcalCallback.conformanceWarn) { // warn("Had attendees for PUBLISH"); //} } final Attendee attPr = (Attendee)prop; if (evinfo.getNewEvent() || !mergeAttendees) { chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { final String pUri = cb.getCaladdr(attPr.getValue()); if (pUri.equals(attUri)) { /* Only update for our own attendee * We're doing a PUT and this must be the attendee updating their * partstat. We don't allow them to change other attendees * whatever the PUT content says. */ chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { // Use the value we currently have boolean found = false; for (final BwAttendee att: ev.getAttendees()) { if (pUri.equals(att.getAttendeeUri())) { chg.addValue(pi, att.clone()); found = true; break; } } if (!found) { // An added attendee final BwAttendee att = IcalUtil .getAttendee(cb, attPr); att.setPartstat(IcalDefs.partstatValNeedsAction); chg.addValue(pi, att); } } } break; case BUSYTYPE: final int ibt = BwEvent.fromBusyTypeString(pval); if (chg.changed(pi, ev.getBusyType(), ibt)) { ev.setBusyType(ibt); } break; case CATEGORIES: /* ------------------- Categories -------------------- */ final Categories cats = (Categories)prop; final TextList cl = cats.getCategories(); String lang = IcalUtil.getLang(cats); if (cl != null) { /* Got some categories */ for (final String wd: cl) { if (wd == null) { continue; } final BwString key = new BwString(lang, wd); final var fcResp = cb.findCategory(key); final BwCategory cat; if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isNotFound()) { cat = BwCategory.makeCategory(); cat.setWord(key); cb.addCategory(cat); } else { cat = fcResp.getEntity(); } chg.addValue(pi, cat); } } break; case CLASS: /* ------------------- Class -------------------- */ if (chg.changed(pi, ev.getClassification(), pval)) { ev.setClassification(pval); } break; case COMMENT: /* ------------------- Comment -------------------- */ chg.addValue(pi, new BwString(null, pval)); break; case COMPLETED: /* ------------------- Completed -------------------- */ if (chg.changed(pi, ev.getCompleted(), pval)) { ev.setCompleted(pval); } break; case CONCEPT: /* ------------------- Concept -------------------- */ final Concept c = (Concept)prop; final String cval = c.getValue(); if (cval != null) { /* Got a concept */ chg.addValue(PropertyInfoIndex.XPROP, BwXproperty.makeIcalProperty("CONCEPT", null, cval)); } break; case CONTACT: /* ------------------- Contact -------------------- */ final String altrep = getAltRepPar(prop); lang = IcalUtil.getLang(prop); final String uid = getUidPar(prop); final BwString nm = new BwString(lang, pval); BwContact contact = null; if (uid != null) { final var fcResp = cb.getContact(uid); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { final var fcResp = cb.findContact(nm); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { contact = BwContact.makeContact(); contact.setCn(nm); contact.setLink(altrep); cb.addContact(contact); } else { contact.setCn(nm); contact.setLink(altrep); } chg.addValue(pi, contact); break; case CREATED: /* ------------------- Created -------------------- */ if (chg.changed(pi, ev.getCreated(), pval)) { ev.setCreated(pval); } break; case DESCRIPTION: /* ------------------- Description -------------------- */ if (chg.changed(pi, ev.getDescription(), pval)) { ev.setDescription(pval); } break; case DTEND: /* ------------------- DtEnd -------------------- */ break; case DTSTAMP: /* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval); break; case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE: /* -------------------- Due ------------------------ */ break; case DURATION: /* ------------------- Duration -------------------- */ break; case EXDATE: /* ------------------- ExDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case EXRULE: /* ------------------- ExRule -------------------- */ chg.addValue(pi, pval); break; case FREEBUSY: /* ------------------- freebusy -------------------- */ final FreeBusy fbusy = (FreeBusy)prop; final PeriodList perpl = fbusy.getPeriods(); final Parameter par = IcalUtil.getParameter(fbusy, "FBTYPE"); final int fbtype; if (par == null) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY)) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY_TENTATIVE)) { fbtype = BwFreeBusyComponent.typeBusyTentative; } else if (par.equals(FbType.BUSY_UNAVAILABLE)) { fbtype = BwFreeBusyComponent.typeBusyUnavailable; } else if (par.equals(FbType.FREE)) { fbtype = BwFreeBusyComponent.typeFree; } else { if (logger.debug()) { logger.debug("Unsupported parameter " + par.getName()); } return Response.notOk(resp, failed, "Unsupported parameter " + par.getName()); } final BwFreeBusyComponent fbc = new BwFreeBusyComponent(); fbc.setType(fbtype); for (final Period per : perpl) { fbc.addPeriod(per); } ev.addFreeBusyPeriod(fbc); break; case GEO: /* ------------------- Geo -------------------- */ final Geo g = (Geo)prop; final BwGeo geo = new BwGeo(g.getLatitude(), g.getLongitude()); if (chg.changed(pi, ev.getGeo(), geo)) { ev.setGeo(geo); } break; case LAST_MODIFIED: /* ------------------- LastModified -------------------- */ if (chg.changed(pi, ev.getLastmod(), pval)) { ev.setLastmod(pval); } break; case LOCATION: /* ------------------- Location -------------------- */ BwLocation loc = null; //String uid = getUidPar(prop); /* At the moment Mozilla lightning is broken and this leads to all * sorts of problems. if (uid != null) { loc = cb.getLocation(uid); } */ lang = IcalUtil.getLang(prop); BwString addr = null; if (pval != null) { if (loc == null) { addr = new BwString(lang, pval); final var fcResp = cb.findLocation(addr); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { loc = fcResp.getEntity(); } } if (loc == null) { loc = BwLocation.makeLocation(); loc.setAddress(addr); cb.addLocation(loc); } } final BwLocation evloc = ev.getLocation(); if (chg.changed(pi, evloc, loc)) { // CHGTBL - this only shows that it's a different location object ev.setLocation(loc); } else if ((loc != null) && (evloc != null)) { // See if the value is changed final String evval = evloc.getAddress().getValue(); final String inval = loc.getAddress().getValue(); if (!evval.equals(inval)) { chg.changed(pi, evval, inval); evloc.getAddress().setValue(inval); } } break; case ORGANIZER: /* ------------------- Organizer -------------------- */ final BwOrganizer org = IcalUtil.getOrganizer(cb, (Organizer)prop); final BwOrganizer evorg = ev.getOrganizer(); final BwOrganizer evorgCopy; if (evorg == null) { evorgCopy = null; } else { evorgCopy = (BwOrganizer)evorg.clone(); } if (chg.changed(pi, evorgCopy, org)) { if (evorg == null) { ev.setOrganizer(org); } else { evorg.update(org); } } break; case PERCENT_COMPLETE: /* ------------------- PercentComplete -------------------- */ Integer ival = ((PercentComplete)prop).getPercentage(); if (chg.changed(pi, ev.getPercentComplete(), ival)) { ev.setPercentComplete(ival); } break; case POLL_MODE: /* ------------------- Poll mode -------------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollMode(), sval)) { ev.setPollMode(sval); } break; case POLL_PROPERTIES: /* ------------------- Poll properties ---------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollProperties(), sval)) { ev.setPollProperties(sval); } break; case POLL_WINNER: /* ------------------- Poll winner -------------------- */ ival = ((PollWinner)prop).getPollwinner(); if (chg.changed(pi, ev.getPollWinner(), ival)) { ev.setPollWinner(ival); } break; case PRIORITY: /* ------------------- Priority -------------------- */ ival = ((Priority)prop).getLevel(); if (chg.changed(pi, ev.getPriority(), ival)) { ev.setPriority(ival); } break; case RDATE: /* ------------------- RDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case RECURRENCE_ID: /* ------------------- RecurrenceID -------------------- */ // Done above break; case RELATED_TO: /* ------------------- RelatedTo -------------------- */ final RelatedTo irelto = (RelatedTo)prop; final BwRelatedTo relto = new BwRelatedTo(); final String parval = IcalUtil.getParameterVal(irelto, "RELTYPE"); if (parval != null) { relto.setRelType(parval); } relto.setValue(irelto.getValue()); if (chg.changed(pi, ev.getRelatedTo(), relto)) { ev.setRelatedTo(relto); } break; case REQUEST_STATUS: /* ------------------- RequestStatus -------------------- */ final BwRequestStatus rs = BwRequestStatus .fromRequestStatus((RequestStatus)prop); chg.addValue(pi, rs); break; case RESOURCES: /* ------------------- Resources -------------------- */ final TextList rl = ((Resources)prop).getResources(); if (rl != null) { /* Got some resources */ lang = IcalUtil.getLang(prop); for (final String s: rl) { final BwString rsrc = new BwString(lang, s); chg.addValue(pi, rsrc); } } break; case RRULE: /* ------------------- RRule -------------------- */ chg.addValue(pi, pval); break; case SEQUENCE: /* ------------------- Sequence -------------------- */ final int seq = ((Sequence)prop).getSequenceNo(); if (seq != ev.getSequence()) { chg.changed(pi, ev.getSequence(), seq); ev.setSequence(seq); } break; case STATUS: /* ------------------- Status -------------------- */ if (chg.changed(pi, ev.getStatus(), pval)) { ev.setStatus(pval); } break; case SUMMARY: /* ------------------- Summary -------------------- */ if (chg.changed(pi, ev.getSummary(), pval)) { ev.setSummary(pval); } break; case TRANSP: /* ------------------- Transp -------------------- */ if (chg.changed(pi, ev.getPeruserTransparency( cb.getPrincipal() .getPrincipalRef()), pval)) { final BwXproperty pu = ev.setPeruserTransparency( cb.getPrincipal().getPrincipalRef(), pval); if (pu != null) { chg.addValue(PropertyInfoIndex.XPROP, pu); } } break; case UID: /* ------------------- Uid -------------------- */ /* We did this above */ break; case URL: /* ------------------- Url -------------------- */ if (chg.changed(pi, ev.getLink(), pval)) { ev.setLink(pval); } break; case XPROP: /* ------------------------- x-property --------------------------- */ final String name = prop.getName(); if (name.equalsIgnoreCase(BwXproperty.bedeworkCost)) { if (chg.changed(PropertyInfoIndex.COST, ev.getCost(), pval)) { ev.setCost(pval); } break; } if (name.equalsIgnoreCase(BwXproperty.xBedeworkCategories)) { if (checkCategory(cb, chg, ev, null, pval)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkLocation)) { if (checkLocation(cb, chg, ev, prop)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkContact)) { if (checkContact(cb, chg, ev, null, pval)) { break; } } /* See if this is an x-category that can be converted to a real category */ final XProperty xp = (XProperty)prop; chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(name, xp.getParameters() .toString(), pval)); break; default: if (logger.debug()) { logger.debug("Unsupported property with index " + pi + "; class " + prop.getClass() + " and value " + pval); } } } /* =================== Process sub-components =============== */ final ComponentList<Component> subComps; if (val instanceof ComponentContainer) { subComps = ((ComponentContainer<Component>)val).getComponents(); } else { subComps = null; } final Set<Integer> pids; if (vpoll) { pids = new TreeSet<>(); final BwEvent vp = evinfo.getEvent(); if (!Util.isEmpty(vp.getPollItems())) { vp.clearPollItems(); } } else { pids = null; } if (!Util.isEmpty(subComps)) { for (final var subComp: subComps) { if (subComp instanceof Available) { if (!(val instanceof VAvailability)) { return Response.error(resp, "AVAILABLE only valid in VAVAILABLE"); } final var avlResp = processAvailable(cb, cal, ical, (VAvailability)val, (Available)subComp, evinfo); if (!avlResp.isOk()) { return Response.fromResponse(resp, avlResp); } continue; } if (subComp instanceof Participant) { if (vpoll) { final var vresp = processVoter(cb, (VPoll)val, (Participant)subComp, evinfo, chg, mergeAttendees); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Participant object"); continue; } if (subComp instanceof VResource) { logger.warn("Unimplemented VResource object"); continue; } if (subComp instanceof VLocation) { logger.warn("Unimplemented VLocation object"); continue; } if (subComp instanceof VAlarm) { final var aresp = VAlarmUtil.processAlarm(cb, val, (VAlarm)subComp, ev, currentPrincipal, chg); if (!aresp.isOk()) { return Response.fromResponse(resp, aresp); } continue; } if (vpoll && (event || task)) { final var vresp = processCandidate((VPoll)val, subComp, evinfo, pids, chg); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Component object: " + subComp); } } /* Fix up timestamps. */ if (ev.getCreated() == null) { if (ev.getLastmod() != null) { ev.setCreated(ev.getLastmod()); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); } else { ev.updateDtstamp(); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } } if (ev.getLastmod() == null) { // created cannot be null now ev.setLastmod(ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } processTimezones(ev, ical, chg); /* Remove any recipients and originator */ if (ev.getRecipients() != null) { ev.getRecipients().clear(); } ev.setOriginator(null); if (hasXparams.value) { /* Save a text copy of the entire event as an x-property */ final Component valCopy = val.copy(); /* Remove potentially large values */ final Description desp = valCopy.getProperty(Property.DESCRIPTION); if (desp != null) { desp.setValue(null); } final Attach attachp = valCopy.getProperty(Property.ATTACH); // Don't store the entire attachment - we just need the parameters. if (attachp != null) { final Value v = attachp.getParameter(Parameter.VALUE); if (v != null) { attachp.setValue(String.valueOf(attachp.getValue().hashCode())); } } chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(BwXproperty.bedeworkIcal, null, valCopy.toString())); } chg.processChanges(ev, true, false); ev.setRecurring(ev.isRecurringEntity()); if (logger.debug()) { logger.debug(chg.toString()); logger.debug(ev.toString()); } if (masterEI != null) { // Just return notfound as this event is on its override list return Response.notFound(resp); } resp.setEntity(evinfo); return resp; } catch (final Throwable t) { if (logger.debug()) { logger.error(t); } return Response.error(resp, t); } }
public static GetEntityResponse<EventInfo> toEvent( final IcalCallback cb, final BwCalendar cal, final Icalendar ical, final Component val, final boolean mergeAttendees) { final var resp = new GetEntityResponse<EventInfo>(); if (val == null) { return Response.notOk(resp, failed, "No component supplied"); } String currentPrincipal = null; final BwPrincipal principal = cb.getPrincipal(); if (principal != null) { currentPrincipal = principal.getPrincipalRef(); } final Holder<Boolean> hasXparams = new Holder<>(Boolean.FALSE); final int methodType = ical.getMethodType(); String attUri = null; if (mergeAttendees) { // We'll need this later. attUri = cb.getCaladdr(cb.getPrincipal().getPrincipalRef()); } final String colPath; if (cal == null) { colPath = null; } else { colPath = cal.getPath(); } try { final PropertyList<Property> pl = val.getProperties(); boolean vpoll = false; boolean event = false; boolean task = false; if (pl == null) { // Empty component return Response.notOk(resp, failed, "Empty component"); } final int entityType; if (val instanceof VEvent) { entityType = IcalDefs.entityTypeEvent; event = true; } else if (val instanceof VToDo) { entityType = IcalDefs.entityTypeTodo; task = true; } else if (val instanceof VJournal) { entityType = IcalDefs.entityTypeJournal; } else if (val instanceof VFreeBusy) { entityType = IcalDefs.entityTypeFreeAndBusy; } else if (val instanceof VAvailability) { entityType = IcalDefs.entityTypeVavailability; } else if (val instanceof Available) { entityType = IcalDefs.entityTypeAvailable; } else if (val instanceof VPoll) { entityType = IcalDefs.entityTypeVpoll; vpoll = true; } else { return Response.error(resp, "org.bedework.invalid.component.type: " + val.getName()); } // Get the guid from the component String guid = null; final Uid uidp = pl.getProperty(Property.UID); if (uidp != null) { testXparams(uidp, hasXparams); guid = uidp.getValue(); } if (guid == null) { /* XXX A guid is required - but are there devices out there without a * guid - and if so how do we handle it? */ return Response.notOk(resp, failed, CalFacadeException.noGuid); } /* See if we have a recurrence id */ BwDateTime ridObj = null; String rid = null; TimeZone ridTz = null; final RecurrenceId ridp = pl.getProperty(Property.RECURRENCE_ID); if (ridp != null) { testXparams(ridp, hasXparams); ridObj = BwDateTime.makeBwDateTime(ridp); if (ridObj.getRange() != null) { /* XXX What do I do with it? */ logger.warn("TRANS-TO_EVENT: Got a recurrence id range"); } rid = ridObj.getDate(); } EventInfo masterEI = null; EventInfo evinfo = null; final BwEvent ev; /* If we have a recurrence id see if we already have the master (we should * get a master + all its overrides). * * If so find the override and use the annnotation or if no override, * make one. * * If no override retrieve the event, add it to our table and then locate the * annotation. * * If there is no annotation, create one. * * It's possible we have been sent 'detached' instances of a recurring * event. This may happen if we are invited to one or more instances of a * meeting. In this case we try to retrieve the master and if it doesn't * exist we manufacture one. We consider such an instance an update to * that instance only and leave the others alone. */ /* We need this in a couple of places */ final DtStart dtStart = pl.getProperty(Property.DTSTART); /* if (rid != null) { // See if we have a new master event. If so create a proxy to that event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI == null) { masterEI = makeNewEvent(cb, chg, entityType, guid, cal); BwEvent e = masterEI.getEvent(); // XXX This seems bogus DtStart mdtStart; String bogusDate = "19980118T230000"; if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + "Z"); } else if (dtStart.getTimeZone() == null) { mdtStart = new DtStart(bogusDate); } else { mdtStart = new DtStart(bogusDate + "Z", dtStart.getTimeZone()); } setDates(e, mdtStart, null, null, chg); e.setRecurring(true); e.addRdate(ridObj); e.setSuppressed(true); ical.addComponent(masterEI); } if (masterEI != null) { evinfo = masterEI.findOverride(rid); } } */ /* If this is a recurrence instance see if we can find the master We only need this because the master may follow the overrides. */ if (rid != null) { // See if we have a new master event. If so create a proxy to this event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI != null) { evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; } } if ((evinfo == null) && (cal != null) && (cal.getCalType() != BwCalendar.calTypeInbox) && (cal.getCalType() != BwCalendar.calTypePendingInbox) && (cal.getCalType() != BwCalendar.calTypeOutbox)) { if (logger.debug()) { logger.debug("TRANS-TO_EVENT: try to fetch event with guid=" + guid); } final GetEntitiesResponse<EventInfo> eisResp = cb.getEvent(colPath, guid); if (eisResp.isError()) { return Response.fromResponse(resp, eisResp); } final var eis = eisResp.getEntities(); if (!Util.isEmpty(eis)) { if (eis.size() > 1) { // DORECUR - wrong again return Response.notOk(resp, failed, "More than one event returned for guid."); } evinfo = eis.iterator().next(); } if (logger.debug()) { if (evinfo != null) { logger.debug("TRANS-TO_EVENT: fetched event with guid"); } else { logger.debug("TRANS-TO_EVENT: did not find event with guid"); } } if (evinfo != null) { if (rid != null) { // We just retrieved it's master masterEI = evinfo; masterEI.setInstanceOnly(true); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; ical.addComponent(masterEI); } else if (methodType == ScheduleMethods.methodTypeCancel) { // This should never have an rid for cancel of entire event. evinfo.setInstanceOnly(evinfo.getEvent().getSuppressed()); } else { // Presumably sent an update for the entire event. No longer suppressed master evinfo.getEvent().setSuppressed(false); } } else if (rid != null) { /* Manufacture a master for the instance */ masterEI = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); final BwEvent e = masterEI.getEvent(); // XXX This seems bogus final DtStart mdtStart; final String bogusDate = "19980118"; final String bogusTime = "T230000"; // Base dtstart on the recurrence id. final boolean isDateType = ridObj.getDateType(); if (isDateType) { mdtStart = new DtStart(new Date(bogusDate)); } else if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + bogusTime + "Z"); } else if (ridObj.getTzid() == null) { mdtStart = new DtStart(bogusDate + bogusTime); } else { mdtStart = new DtStart(bogusDate + bogusTime, Timezones.getTz(ridObj.getTzid())); } IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), masterEI, mdtStart, null, null); e.setRecurring(true); // e.addRdate(ridObj); final var sum = (Summary)pl.getProperty(Property.SUMMARY); e.setSummary(sum.getValue()); e.setSuppressed(true); ical.addComponent(masterEI); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; masterEI.setInstanceOnly(rid != null); } } if (evinfo == null) { evinfo = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); } else if (evinfo.getEvent().getEntityType() != entityType) { return Response.notOk(resp, failed, "org.bedework.mismatched.entity.type: " + val); } final ChangeTable chg = evinfo.getChangeset( cb.getPrincipal().getPrincipalRef()); if (rid != null) { final String evrid = evinfo.getEvent().getRecurrenceId(); if ((evrid == null) || (!evrid.equals(rid))) { logger. warn("Mismatched rid ev=" + evrid + " expected " + rid); chg.changed(PropertyInfoIndex.RECURRENCE_ID, evrid, rid); // XXX spurious??? } if (masterEI.getEvent().getSuppressed()) { masterEI.getEvent().addRdate(ridObj); } } ev = evinfo.getEvent(); ev.setScheduleMethod(methodType); DtEnd dtEnd = null; if (entityType == IcalDefs.entityTypeTodo) { final Due due = pl.getProperty(Property.DUE); if (due != null ) { dtEnd = new DtEnd(due.getParameters(), due.getValue()); } } else { dtEnd = pl.getProperty(Property.DTEND); } final Duration duration = pl.getProperty(Property.DURATION); IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), evinfo, dtStart, dtEnd, duration); for (final Property prop: pl) { testXparams(prop, hasXparams); //debug("ical prop " + prop.getClass().getName()); String pval = prop.getValue(); if ((pval != null) && (pval.length() == 0)) { pval = null; } final PropertyInfoIndex pi; if (prop instanceof XProperty) { pi = PropertyInfoIndex.XPROP; } else { pi = PropertyInfoIndex.fromName(prop.getName()); } if (pi == null) { logger.debug("Unknown property with name " + prop.getName() + " class " + prop.getClass() + " and value " + pval); continue; } chg.present(pi); switch (pi) { case ACCEPT_RESPONSE: /* ------------------- Accept Response -------------------- */ String sval = prop.getValue(); if (chg.changed(pi, ev.getPollAcceptResponse(), sval)) { ev.setPollAcceptResponse(sval); } break; case ATTACH: /* ------------------- Attachment -------------------- */ chg.addValue(pi, IcalUtil.getAttachment((Attach)prop)); break; case ATTENDEE: /* ------------------- Attendee -------------------- */ if (methodType == ScheduleMethods.methodTypePublish) { if (cb.getStrictness() == IcalCallback.conformanceStrict) { return Response.notOk(resp, failed, CalFacadeException.attendeesInPublish); } //if (cb.getStrictness() == IcalCallback.conformanceWarn) { // warn("Had attendees for PUBLISH"); //} } final Attendee attPr = (Attendee)prop; if (evinfo.getNewEvent() || !mergeAttendees) { chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { final String pUri = cb.getCaladdr(attPr.getValue()); if (pUri.equals(attUri)) { /* Only update for our own attendee * We're doing a PUT and this must be the attendee updating their * partstat. We don't allow them to change other attendees * whatever the PUT content says. */ chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { // Use the value we currently have boolean found = false; for (final BwAttendee att: ev.getAttendees()) { if (pUri.equals(att.getAttendeeUri())) { chg.addValue(pi, att.clone()); found = true; break; } } if (!found) { // An added attendee final BwAttendee att = IcalUtil .getAttendee(cb, attPr); att.setPartstat(IcalDefs.partstatValNeedsAction); chg.addValue(pi, att); } } } break; case BUSYTYPE: final int ibt = BwEvent.fromBusyTypeString(pval); if (chg.changed(pi, ev.getBusyType(), ibt)) { ev.setBusyType(ibt); } break; case CATEGORIES: /* ------------------- Categories -------------------- */ final Categories cats = (Categories)prop; final TextList cl = cats.getCategories(); String lang = IcalUtil.getLang(cats); if (cl != null) { /* Got some categories */ for (final String wd: cl) { if (wd == null) { continue; } final BwString key = new BwString(lang, wd); final var fcResp = cb.findCategory(key); final BwCategory cat; if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isNotFound()) { cat = BwCategory.makeCategory(); cat.setWord(key); cb.addCategory(cat); } else { cat = fcResp.getEntity(); } chg.addValue(pi, cat); } } break; case CLASS: /* ------------------- Class -------------------- */ if (chg.changed(pi, ev.getClassification(), pval)) { ev.setClassification(pval); } break; case COMMENT: /* ------------------- Comment -------------------- */ chg.addValue(pi, new BwString(null, pval)); break; case COMPLETED: /* ------------------- Completed -------------------- */ if (chg.changed(pi, ev.getCompleted(), pval)) { ev.setCompleted(pval); } break; case CONCEPT: /* ------------------- Concept -------------------- */ final Concept c = (Concept)prop; final String cval = c.getValue(); if (cval != null) { /* Got a concept */ chg.addValue(PropertyInfoIndex.XPROP, BwXproperty.makeIcalProperty("CONCEPT", null, cval)); } break; case CONTACT: /* ------------------- Contact -------------------- */ final String altrep = getAltRepPar(prop); lang = IcalUtil.getLang(prop); final String uid = getUidPar(prop); final BwString nm = new BwString(lang, pval); BwContact contact = null; if (uid != null) { final var fcResp = cb.getContact(uid); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { final var fcResp = cb.findContact(nm); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { contact = BwContact.makeContact(); contact.setCn(nm); contact.setLink(altrep); cb.addContact(contact); } else { contact.setCn(nm); contact.setLink(altrep); } chg.addValue(pi, contact); break; case CREATED: /* ------------------- Created -------------------- */ if (chg.changed(pi, ev.getCreated(), pval)) { ev.setCreated(pval); } break; case DESCRIPTION: /* ------------------- Description -------------------- */ if (chg.changed(pi, ev.getDescription(), pval)) { ev.setDescription(pval); } break; case DTEND: /* ------------------- DtEnd -------------------- */ break; case DTSTAMP: /* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval); break; case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE: /* -------------------- Due ------------------------ */ break; case DURATION: /* ------------------- Duration -------------------- */ break; case EXDATE: /* ------------------- ExDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case EXRULE: /* ------------------- ExRule -------------------- */ chg.addValue(pi, pval); break; case FREEBUSY: /* ------------------- freebusy -------------------- */ final FreeBusy fbusy = (FreeBusy)prop; final PeriodList perpl = fbusy.getPeriods(); final Parameter par = IcalUtil.getParameter(fbusy, "FBTYPE"); final int fbtype; if (par == null) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY)) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY_TENTATIVE)) { fbtype = BwFreeBusyComponent.typeBusyTentative; } else if (par.equals(FbType.BUSY_UNAVAILABLE)) { fbtype = BwFreeBusyComponent.typeBusyUnavailable; } else if (par.equals(FbType.FREE)) { fbtype = BwFreeBusyComponent.typeFree; } else { if (logger.debug()) { logger.debug("Unsupported parameter " + par.getName()); } return Response.notOk(resp, failed, "Unsupported parameter " + par.getName()); } final BwFreeBusyComponent fbc = new BwFreeBusyComponent(); fbc.setType(fbtype); for (final Period per : perpl) { fbc.addPeriod(per); } ev.addFreeBusyPeriod(fbc); break; case GEO: /* ------------------- Geo -------------------- */ final Geo g = (Geo)prop; final BwGeo geo = new BwGeo(g.getLatitude(), g.getLongitude()); if (chg.changed(pi, ev.getGeo(), geo)) { ev.setGeo(geo); } break; case LAST_MODIFIED: /* ------------------- LastModified -------------------- */ if (chg.changed(pi, ev.getLastmod(), pval)) { ev.setLastmod(pval); } break; case LOCATION: /* ------------------- Location -------------------- */ BwLocation loc = null; //String uid = getUidPar(prop); /* At the moment Mozilla lightning is broken and this leads to all * sorts of problems. if (uid != null) { loc = cb.getLocation(uid); } */ lang = IcalUtil.getLang(prop); BwString addr = null; if (pval != null) { if (loc == null) { addr = new BwString(lang, pval); final var fcResp = cb.findLocation(addr); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { loc = fcResp.getEntity(); } } if (loc == null) { loc = BwLocation.makeLocation(); loc.setAddress(addr); cb.addLocation(loc); } } final BwLocation evloc = ev.getLocation(); if (chg.changed(pi, evloc, loc)) { // CHGTBL - this only shows that it's a different location object ev.setLocation(loc); } else if ((loc != null) && (evloc != null)) { // See if the value is changed final String evval = evloc.getAddress().getValue(); final String inval = loc.getAddress().getValue(); if (!evval.equals(inval)) { chg.changed(pi, evval, inval); evloc.getAddress().setValue(inval); } } break; case ORGANIZER: /* ------------------- Organizer -------------------- */ final BwOrganizer org = IcalUtil.getOrganizer(cb, (Organizer)prop); final BwOrganizer evorg = ev.getOrganizer(); final BwOrganizer evorgCopy; if (evorg == null) { evorgCopy = null; } else { evorgCopy = (BwOrganizer)evorg.clone(); } if (chg.changed(pi, evorgCopy, org)) { if (evorg == null) { ev.setOrganizer(org); } else { evorg.update(org); } } break; case PERCENT_COMPLETE: /* ------------------- PercentComplete -------------------- */ Integer ival = ((PercentComplete)prop).getPercentage(); if (chg.changed(pi, ev.getPercentComplete(), ival)) { ev.setPercentComplete(ival); } break; case POLL_MODE: /* ------------------- Poll mode -------------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollMode(), sval)) { ev.setPollMode(sval); } break; case POLL_PROPERTIES: /* ------------------- Poll properties ---------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollProperties(), sval)) { ev.setPollProperties(sval); } break; case POLL_WINNER: /* ------------------- Poll winner -------------------- */ ival = ((PollWinner)prop).getPollwinner(); if (chg.changed(pi, ev.getPollWinner(), ival)) { ev.setPollWinner(ival); } break; case PRIORITY: /* ------------------- Priority -------------------- */ ival = ((Priority)prop).getLevel(); if (chg.changed(pi, ev.getPriority(), ival)) { ev.setPriority(ival); } break; case RDATE: /* ------------------- RDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case RECURRENCE_ID: /* ------------------- RecurrenceID -------------------- */ // Done above break; case RELATED_TO: /* ------------------- RelatedTo -------------------- */ final RelatedTo irelto = (RelatedTo)prop; final BwRelatedTo relto = new BwRelatedTo(); final String parval = IcalUtil.getParameterVal(irelto, "RELTYPE"); if (parval != null) { relto.setRelType(parval); } relto.setValue(irelto.getValue()); if (chg.changed(pi, ev.getRelatedTo(), relto)) { ev.setRelatedTo(relto); } break; case REQUEST_STATUS: /* ------------------- RequestStatus -------------------- */ final BwRequestStatus rs = BwRequestStatus .fromRequestStatus((RequestStatus)prop); chg.addValue(pi, rs); break; case RESOURCES: /* ------------------- Resources -------------------- */ final TextList rl = ((Resources)prop).getResources(); if (rl != null) { /* Got some resources */ lang = IcalUtil.getLang(prop); for (final String s: rl) { final BwString rsrc = new BwString(lang, s); chg.addValue(pi, rsrc); } } break; case RRULE: /* ------------------- RRule -------------------- */ chg.addValue(pi, pval); break; case SEQUENCE: /* ------------------- Sequence -------------------- */ final int seq = ((Sequence)prop).getSequenceNo(); if (seq != ev.getSequence()) { chg.changed(pi, ev.getSequence(), seq); ev.setSequence(seq); } break; case STATUS: /* ------------------- Status -------------------- */ if (chg.changed(pi, ev.getStatus(), pval)) { ev.setStatus(pval); } break; case SUMMARY: /* ------------------- Summary -------------------- */ if (chg.changed(pi, ev.getSummary(), pval)) { ev.setSummary(pval); } break; case TRANSP: /* ------------------- Transp -------------------- */ if (chg.changed(pi, ev.getPeruserTransparency( cb.getPrincipal() .getPrincipalRef()), pval)) { final BwXproperty pu = ev.setPeruserTransparency( cb.getPrincipal().getPrincipalRef(), pval); if (pu != null) { chg.addValue(PropertyInfoIndex.XPROP, pu); } } break; case UID: /* ------------------- Uid -------------------- */ /* We did this above */ break; case URL: /* ------------------- Url -------------------- */ if (chg.changed(pi, ev.getLink(), pval)) { ev.setLink(pval); } break; case XPROP: /* ------------------------- x-property --------------------------- */ final String name = prop.getName(); if (name.equalsIgnoreCase(BwXproperty.bedeworkCost)) { if (chg.changed(PropertyInfoIndex.COST, ev.getCost(), pval)) { ev.setCost(pval); } break; } if (name.equalsIgnoreCase(BwXproperty.xBedeworkCategories)) { if (checkCategory(cb, chg, ev, null, pval)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkLocation)) { if (checkLocation(cb, chg, ev, prop)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkContact)) { if (checkContact(cb, chg, ev, null, pval)) { break; } } /* See if this is an x-category that can be converted to a real category */ final XProperty xp = (XProperty)prop; chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(name, xp.getParameters() .toString(), pval)); break; default: if (logger.debug()) { logger.debug("Unsupported property with index " + pi + "; class " + prop.getClass() + " and value " + pval); } } } /* =================== Process sub-components =============== */ final ComponentList<Component> subComps; if (val instanceof ComponentContainer) { subComps = ((ComponentContainer<Component>)val).getComponents(); } else { subComps = null; } final Set<Integer> pids; if (vpoll) { pids = new TreeSet<>(); final BwEvent vp = evinfo.getEvent(); if (!Util.isEmpty(vp.getPollItems())) { vp.clearPollItems(); } } else { pids = null; } if (!Util.isEmpty(subComps)) { for (final var subComp: subComps) { if (subComp instanceof Available) { if (!(val instanceof VAvailability)) { return Response.error(resp, "AVAILABLE only valid in VAVAILABLE"); } final var avlResp = processAvailable(cb, cal, ical, (VAvailability)val, (Available)subComp, evinfo); if (!avlResp.isOk()) { return Response.fromResponse(resp, avlResp); } continue; } if (subComp instanceof Participant) { if (vpoll) { final var vresp = processVoter(cb, (VPoll)val, (Participant)subComp, evinfo, chg, mergeAttendees); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Participant object"); continue; } if (subComp instanceof VResource) { logger.warn("Unimplemented VResource object"); continue; } if (subComp instanceof VLocation) { logger.warn("Unimplemented VLocation object"); continue; } if (subComp instanceof VAlarm) { final var aresp = VAlarmUtil.processAlarm(cb, val, (VAlarm)subComp, ev, currentPrincipal, chg); if (!aresp.isOk()) { return Response.fromResponse(resp, aresp); } continue; } if (vpoll && (event || task)) { final var vresp = processCandidate((VPoll)val, subComp, evinfo, pids, chg); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Component object: " + subComp); } } /* Fix up timestamps. */ if (ev.getCreated() == null) { if (ev.getLastmod() != null) { ev.setCreated(ev.getLastmod()); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); } else { ev.updateDtstamp(); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } } if (ev.getLastmod() == null) { // created cannot be null now ev.setLastmod(ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } processTimezones(ev, ical, chg); /* Remove any recipients and originator */ if (ev.getRecipients() != null) { ev.getRecipients().clear(); } ev.setOriginator(null); if (hasXparams.value) { /* Save a text copy of the entire event as an x-property */ final Component valCopy = val.copy(); /* Remove potentially large values */ final Description desp = valCopy.getProperty(Property.DESCRIPTION); if (desp != null) { desp.setValue(null); } final Attach attachp = valCopy.getProperty(Property.ATTACH); // Don't store the entire attachment - we just need the parameters. if (attachp != null) { final Value v = attachp.getParameter(Parameter.VALUE); if (v != null) { attachp.setValue(String.valueOf(attachp.getValue().hashCode())); } } chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(BwXproperty.bedeworkIcal, null, valCopy.toString())); } chg.processChanges(ev, true, false); ev.setRecurring(ev.isRecurringEntity()); if (logger.debug()) { logger.debug(chg.toString()); logger.debug(ev.toString()); } if (masterEI != null) { // Just return notfound as this event is on its override list return Response.notFound(resp); } resp.setEntity(evinfo); return resp; } catch (final Throwable t) { if (logger.debug()) { logger.error(t); } return Response.error(resp, t); } }
7,893
1
// We'll need this later.
public static GetEntityResponse<EventInfo> toEvent( final IcalCallback cb, final BwCalendar cal, final Icalendar ical, final Component val, final boolean mergeAttendees) { final var resp = new GetEntityResponse<EventInfo>(); if (val == null) { return Response.notOk(resp, failed, "No component supplied"); } String currentPrincipal = null; final BwPrincipal principal = cb.getPrincipal(); if (principal != null) { currentPrincipal = principal.getPrincipalRef(); } final Holder<Boolean> hasXparams = new Holder<>(Boolean.FALSE); final int methodType = ical.getMethodType(); String attUri = null; if (mergeAttendees) { // We'll need this later. attUri = cb.getCaladdr(cb.getPrincipal().getPrincipalRef()); } final String colPath; if (cal == null) { colPath = null; } else { colPath = cal.getPath(); } try { final PropertyList<Property> pl = val.getProperties(); boolean vpoll = false; boolean event = false; boolean task = false; if (pl == null) { // Empty component return Response.notOk(resp, failed, "Empty component"); } final int entityType; if (val instanceof VEvent) { entityType = IcalDefs.entityTypeEvent; event = true; } else if (val instanceof VToDo) { entityType = IcalDefs.entityTypeTodo; task = true; } else if (val instanceof VJournal) { entityType = IcalDefs.entityTypeJournal; } else if (val instanceof VFreeBusy) { entityType = IcalDefs.entityTypeFreeAndBusy; } else if (val instanceof VAvailability) { entityType = IcalDefs.entityTypeVavailability; } else if (val instanceof Available) { entityType = IcalDefs.entityTypeAvailable; } else if (val instanceof VPoll) { entityType = IcalDefs.entityTypeVpoll; vpoll = true; } else { return Response.error(resp, "org.bedework.invalid.component.type: " + val.getName()); } // Get the guid from the component String guid = null; final Uid uidp = pl.getProperty(Property.UID); if (uidp != null) { testXparams(uidp, hasXparams); guid = uidp.getValue(); } if (guid == null) { /* XXX A guid is required - but are there devices out there without a * guid - and if so how do we handle it? */ return Response.notOk(resp, failed, CalFacadeException.noGuid); } /* See if we have a recurrence id */ BwDateTime ridObj = null; String rid = null; TimeZone ridTz = null; final RecurrenceId ridp = pl.getProperty(Property.RECURRENCE_ID); if (ridp != null) { testXparams(ridp, hasXparams); ridObj = BwDateTime.makeBwDateTime(ridp); if (ridObj.getRange() != null) { /* XXX What do I do with it? */ logger.warn("TRANS-TO_EVENT: Got a recurrence id range"); } rid = ridObj.getDate(); } EventInfo masterEI = null; EventInfo evinfo = null; final BwEvent ev; /* If we have a recurrence id see if we already have the master (we should * get a master + all its overrides). * * If so find the override and use the annnotation or if no override, * make one. * * If no override retrieve the event, add it to our table and then locate the * annotation. * * If there is no annotation, create one. * * It's possible we have been sent 'detached' instances of a recurring * event. This may happen if we are invited to one or more instances of a * meeting. In this case we try to retrieve the master and if it doesn't * exist we manufacture one. We consider such an instance an update to * that instance only and leave the others alone. */ /* We need this in a couple of places */ final DtStart dtStart = pl.getProperty(Property.DTSTART); /* if (rid != null) { // See if we have a new master event. If so create a proxy to that event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI == null) { masterEI = makeNewEvent(cb, chg, entityType, guid, cal); BwEvent e = masterEI.getEvent(); // XXX This seems bogus DtStart mdtStart; String bogusDate = "19980118T230000"; if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + "Z"); } else if (dtStart.getTimeZone() == null) { mdtStart = new DtStart(bogusDate); } else { mdtStart = new DtStart(bogusDate + "Z", dtStart.getTimeZone()); } setDates(e, mdtStart, null, null, chg); e.setRecurring(true); e.addRdate(ridObj); e.setSuppressed(true); ical.addComponent(masterEI); } if (masterEI != null) { evinfo = masterEI.findOverride(rid); } } */ /* If this is a recurrence instance see if we can find the master We only need this because the master may follow the overrides. */ if (rid != null) { // See if we have a new master event. If so create a proxy to this event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI != null) { evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; } } if ((evinfo == null) && (cal != null) && (cal.getCalType() != BwCalendar.calTypeInbox) && (cal.getCalType() != BwCalendar.calTypePendingInbox) && (cal.getCalType() != BwCalendar.calTypeOutbox)) { if (logger.debug()) { logger.debug("TRANS-TO_EVENT: try to fetch event with guid=" + guid); } final GetEntitiesResponse<EventInfo> eisResp = cb.getEvent(colPath, guid); if (eisResp.isError()) { return Response.fromResponse(resp, eisResp); } final var eis = eisResp.getEntities(); if (!Util.isEmpty(eis)) { if (eis.size() > 1) { // DORECUR - wrong again return Response.notOk(resp, failed, "More than one event returned for guid."); } evinfo = eis.iterator().next(); } if (logger.debug()) { if (evinfo != null) { logger.debug("TRANS-TO_EVENT: fetched event with guid"); } else { logger.debug("TRANS-TO_EVENT: did not find event with guid"); } } if (evinfo != null) { if (rid != null) { // We just retrieved it's master masterEI = evinfo; masterEI.setInstanceOnly(true); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; ical.addComponent(masterEI); } else if (methodType == ScheduleMethods.methodTypeCancel) { // This should never have an rid for cancel of entire event. evinfo.setInstanceOnly(evinfo.getEvent().getSuppressed()); } else { // Presumably sent an update for the entire event. No longer suppressed master evinfo.getEvent().setSuppressed(false); } } else if (rid != null) { /* Manufacture a master for the instance */ masterEI = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); final BwEvent e = masterEI.getEvent(); // XXX This seems bogus final DtStart mdtStart; final String bogusDate = "19980118"; final String bogusTime = "T230000"; // Base dtstart on the recurrence id. final boolean isDateType = ridObj.getDateType(); if (isDateType) { mdtStart = new DtStart(new Date(bogusDate)); } else if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + bogusTime + "Z"); } else if (ridObj.getTzid() == null) { mdtStart = new DtStart(bogusDate + bogusTime); } else { mdtStart = new DtStart(bogusDate + bogusTime, Timezones.getTz(ridObj.getTzid())); } IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), masterEI, mdtStart, null, null); e.setRecurring(true); // e.addRdate(ridObj); final var sum = (Summary)pl.getProperty(Property.SUMMARY); e.setSummary(sum.getValue()); e.setSuppressed(true); ical.addComponent(masterEI); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; masterEI.setInstanceOnly(rid != null); } } if (evinfo == null) { evinfo = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); } else if (evinfo.getEvent().getEntityType() != entityType) { return Response.notOk(resp, failed, "org.bedework.mismatched.entity.type: " + val); } final ChangeTable chg = evinfo.getChangeset( cb.getPrincipal().getPrincipalRef()); if (rid != null) { final String evrid = evinfo.getEvent().getRecurrenceId(); if ((evrid == null) || (!evrid.equals(rid))) { logger. warn("Mismatched rid ev=" + evrid + " expected " + rid); chg.changed(PropertyInfoIndex.RECURRENCE_ID, evrid, rid); // XXX spurious??? } if (masterEI.getEvent().getSuppressed()) { masterEI.getEvent().addRdate(ridObj); } } ev = evinfo.getEvent(); ev.setScheduleMethod(methodType); DtEnd dtEnd = null; if (entityType == IcalDefs.entityTypeTodo) { final Due due = pl.getProperty(Property.DUE); if (due != null ) { dtEnd = new DtEnd(due.getParameters(), due.getValue()); } } else { dtEnd = pl.getProperty(Property.DTEND); } final Duration duration = pl.getProperty(Property.DURATION); IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), evinfo, dtStart, dtEnd, duration); for (final Property prop: pl) { testXparams(prop, hasXparams); //debug("ical prop " + prop.getClass().getName()); String pval = prop.getValue(); if ((pval != null) && (pval.length() == 0)) { pval = null; } final PropertyInfoIndex pi; if (prop instanceof XProperty) { pi = PropertyInfoIndex.XPROP; } else { pi = PropertyInfoIndex.fromName(prop.getName()); } if (pi == null) { logger.debug("Unknown property with name " + prop.getName() + " class " + prop.getClass() + " and value " + pval); continue; } chg.present(pi); switch (pi) { case ACCEPT_RESPONSE: /* ------------------- Accept Response -------------------- */ String sval = prop.getValue(); if (chg.changed(pi, ev.getPollAcceptResponse(), sval)) { ev.setPollAcceptResponse(sval); } break; case ATTACH: /* ------------------- Attachment -------------------- */ chg.addValue(pi, IcalUtil.getAttachment((Attach)prop)); break; case ATTENDEE: /* ------------------- Attendee -------------------- */ if (methodType == ScheduleMethods.methodTypePublish) { if (cb.getStrictness() == IcalCallback.conformanceStrict) { return Response.notOk(resp, failed, CalFacadeException.attendeesInPublish); } //if (cb.getStrictness() == IcalCallback.conformanceWarn) { // warn("Had attendees for PUBLISH"); //} } final Attendee attPr = (Attendee)prop; if (evinfo.getNewEvent() || !mergeAttendees) { chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { final String pUri = cb.getCaladdr(attPr.getValue()); if (pUri.equals(attUri)) { /* Only update for our own attendee * We're doing a PUT and this must be the attendee updating their * partstat. We don't allow them to change other attendees * whatever the PUT content says. */ chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { // Use the value we currently have boolean found = false; for (final BwAttendee att: ev.getAttendees()) { if (pUri.equals(att.getAttendeeUri())) { chg.addValue(pi, att.clone()); found = true; break; } } if (!found) { // An added attendee final BwAttendee att = IcalUtil .getAttendee(cb, attPr); att.setPartstat(IcalDefs.partstatValNeedsAction); chg.addValue(pi, att); } } } break; case BUSYTYPE: final int ibt = BwEvent.fromBusyTypeString(pval); if (chg.changed(pi, ev.getBusyType(), ibt)) { ev.setBusyType(ibt); } break; case CATEGORIES: /* ------------------- Categories -------------------- */ final Categories cats = (Categories)prop; final TextList cl = cats.getCategories(); String lang = IcalUtil.getLang(cats); if (cl != null) { /* Got some categories */ for (final String wd: cl) { if (wd == null) { continue; } final BwString key = new BwString(lang, wd); final var fcResp = cb.findCategory(key); final BwCategory cat; if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isNotFound()) { cat = BwCategory.makeCategory(); cat.setWord(key); cb.addCategory(cat); } else { cat = fcResp.getEntity(); } chg.addValue(pi, cat); } } break; case CLASS: /* ------------------- Class -------------------- */ if (chg.changed(pi, ev.getClassification(), pval)) { ev.setClassification(pval); } break; case COMMENT: /* ------------------- Comment -------------------- */ chg.addValue(pi, new BwString(null, pval)); break; case COMPLETED: /* ------------------- Completed -------------------- */ if (chg.changed(pi, ev.getCompleted(), pval)) { ev.setCompleted(pval); } break; case CONCEPT: /* ------------------- Concept -------------------- */ final Concept c = (Concept)prop; final String cval = c.getValue(); if (cval != null) { /* Got a concept */ chg.addValue(PropertyInfoIndex.XPROP, BwXproperty.makeIcalProperty("CONCEPT", null, cval)); } break; case CONTACT: /* ------------------- Contact -------------------- */ final String altrep = getAltRepPar(prop); lang = IcalUtil.getLang(prop); final String uid = getUidPar(prop); final BwString nm = new BwString(lang, pval); BwContact contact = null; if (uid != null) { final var fcResp = cb.getContact(uid); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { final var fcResp = cb.findContact(nm); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { contact = BwContact.makeContact(); contact.setCn(nm); contact.setLink(altrep); cb.addContact(contact); } else { contact.setCn(nm); contact.setLink(altrep); } chg.addValue(pi, contact); break; case CREATED: /* ------------------- Created -------------------- */ if (chg.changed(pi, ev.getCreated(), pval)) { ev.setCreated(pval); } break; case DESCRIPTION: /* ------------------- Description -------------------- */ if (chg.changed(pi, ev.getDescription(), pval)) { ev.setDescription(pval); } break; case DTEND: /* ------------------- DtEnd -------------------- */ break; case DTSTAMP: /* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval); break; case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE: /* -------------------- Due ------------------------ */ break; case DURATION: /* ------------------- Duration -------------------- */ break; case EXDATE: /* ------------------- ExDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case EXRULE: /* ------------------- ExRule -------------------- */ chg.addValue(pi, pval); break; case FREEBUSY: /* ------------------- freebusy -------------------- */ final FreeBusy fbusy = (FreeBusy)prop; final PeriodList perpl = fbusy.getPeriods(); final Parameter par = IcalUtil.getParameter(fbusy, "FBTYPE"); final int fbtype; if (par == null) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY)) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY_TENTATIVE)) { fbtype = BwFreeBusyComponent.typeBusyTentative; } else if (par.equals(FbType.BUSY_UNAVAILABLE)) { fbtype = BwFreeBusyComponent.typeBusyUnavailable; } else if (par.equals(FbType.FREE)) { fbtype = BwFreeBusyComponent.typeFree; } else { if (logger.debug()) { logger.debug("Unsupported parameter " + par.getName()); } return Response.notOk(resp, failed, "Unsupported parameter " + par.getName()); } final BwFreeBusyComponent fbc = new BwFreeBusyComponent(); fbc.setType(fbtype); for (final Period per : perpl) { fbc.addPeriod(per); } ev.addFreeBusyPeriod(fbc); break; case GEO: /* ------------------- Geo -------------------- */ final Geo g = (Geo)prop; final BwGeo geo = new BwGeo(g.getLatitude(), g.getLongitude()); if (chg.changed(pi, ev.getGeo(), geo)) { ev.setGeo(geo); } break; case LAST_MODIFIED: /* ------------------- LastModified -------------------- */ if (chg.changed(pi, ev.getLastmod(), pval)) { ev.setLastmod(pval); } break; case LOCATION: /* ------------------- Location -------------------- */ BwLocation loc = null; //String uid = getUidPar(prop); /* At the moment Mozilla lightning is broken and this leads to all * sorts of problems. if (uid != null) { loc = cb.getLocation(uid); } */ lang = IcalUtil.getLang(prop); BwString addr = null; if (pval != null) { if (loc == null) { addr = new BwString(lang, pval); final var fcResp = cb.findLocation(addr); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { loc = fcResp.getEntity(); } } if (loc == null) { loc = BwLocation.makeLocation(); loc.setAddress(addr); cb.addLocation(loc); } } final BwLocation evloc = ev.getLocation(); if (chg.changed(pi, evloc, loc)) { // CHGTBL - this only shows that it's a different location object ev.setLocation(loc); } else if ((loc != null) && (evloc != null)) { // See if the value is changed final String evval = evloc.getAddress().getValue(); final String inval = loc.getAddress().getValue(); if (!evval.equals(inval)) { chg.changed(pi, evval, inval); evloc.getAddress().setValue(inval); } } break; case ORGANIZER: /* ------------------- Organizer -------------------- */ final BwOrganizer org = IcalUtil.getOrganizer(cb, (Organizer)prop); final BwOrganizer evorg = ev.getOrganizer(); final BwOrganizer evorgCopy; if (evorg == null) { evorgCopy = null; } else { evorgCopy = (BwOrganizer)evorg.clone(); } if (chg.changed(pi, evorgCopy, org)) { if (evorg == null) { ev.setOrganizer(org); } else { evorg.update(org); } } break; case PERCENT_COMPLETE: /* ------------------- PercentComplete -------------------- */ Integer ival = ((PercentComplete)prop).getPercentage(); if (chg.changed(pi, ev.getPercentComplete(), ival)) { ev.setPercentComplete(ival); } break; case POLL_MODE: /* ------------------- Poll mode -------------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollMode(), sval)) { ev.setPollMode(sval); } break; case POLL_PROPERTIES: /* ------------------- Poll properties ---------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollProperties(), sval)) { ev.setPollProperties(sval); } break; case POLL_WINNER: /* ------------------- Poll winner -------------------- */ ival = ((PollWinner)prop).getPollwinner(); if (chg.changed(pi, ev.getPollWinner(), ival)) { ev.setPollWinner(ival); } break; case PRIORITY: /* ------------------- Priority -------------------- */ ival = ((Priority)prop).getLevel(); if (chg.changed(pi, ev.getPriority(), ival)) { ev.setPriority(ival); } break; case RDATE: /* ------------------- RDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case RECURRENCE_ID: /* ------------------- RecurrenceID -------------------- */ // Done above break; case RELATED_TO: /* ------------------- RelatedTo -------------------- */ final RelatedTo irelto = (RelatedTo)prop; final BwRelatedTo relto = new BwRelatedTo(); final String parval = IcalUtil.getParameterVal(irelto, "RELTYPE"); if (parval != null) { relto.setRelType(parval); } relto.setValue(irelto.getValue()); if (chg.changed(pi, ev.getRelatedTo(), relto)) { ev.setRelatedTo(relto); } break; case REQUEST_STATUS: /* ------------------- RequestStatus -------------------- */ final BwRequestStatus rs = BwRequestStatus .fromRequestStatus((RequestStatus)prop); chg.addValue(pi, rs); break; case RESOURCES: /* ------------------- Resources -------------------- */ final TextList rl = ((Resources)prop).getResources(); if (rl != null) { /* Got some resources */ lang = IcalUtil.getLang(prop); for (final String s: rl) { final BwString rsrc = new BwString(lang, s); chg.addValue(pi, rsrc); } } break; case RRULE: /* ------------------- RRule -------------------- */ chg.addValue(pi, pval); break; case SEQUENCE: /* ------------------- Sequence -------------------- */ final int seq = ((Sequence)prop).getSequenceNo(); if (seq != ev.getSequence()) { chg.changed(pi, ev.getSequence(), seq); ev.setSequence(seq); } break; case STATUS: /* ------------------- Status -------------------- */ if (chg.changed(pi, ev.getStatus(), pval)) { ev.setStatus(pval); } break; case SUMMARY: /* ------------------- Summary -------------------- */ if (chg.changed(pi, ev.getSummary(), pval)) { ev.setSummary(pval); } break; case TRANSP: /* ------------------- Transp -------------------- */ if (chg.changed(pi, ev.getPeruserTransparency( cb.getPrincipal() .getPrincipalRef()), pval)) { final BwXproperty pu = ev.setPeruserTransparency( cb.getPrincipal().getPrincipalRef(), pval); if (pu != null) { chg.addValue(PropertyInfoIndex.XPROP, pu); } } break; case UID: /* ------------------- Uid -------------------- */ /* We did this above */ break; case URL: /* ------------------- Url -------------------- */ if (chg.changed(pi, ev.getLink(), pval)) { ev.setLink(pval); } break; case XPROP: /* ------------------------- x-property --------------------------- */ final String name = prop.getName(); if (name.equalsIgnoreCase(BwXproperty.bedeworkCost)) { if (chg.changed(PropertyInfoIndex.COST, ev.getCost(), pval)) { ev.setCost(pval); } break; } if (name.equalsIgnoreCase(BwXproperty.xBedeworkCategories)) { if (checkCategory(cb, chg, ev, null, pval)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkLocation)) { if (checkLocation(cb, chg, ev, prop)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkContact)) { if (checkContact(cb, chg, ev, null, pval)) { break; } } /* See if this is an x-category that can be converted to a real category */ final XProperty xp = (XProperty)prop; chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(name, xp.getParameters() .toString(), pval)); break; default: if (logger.debug()) { logger.debug("Unsupported property with index " + pi + "; class " + prop.getClass() + " and value " + pval); } } } /* =================== Process sub-components =============== */ final ComponentList<Component> subComps; if (val instanceof ComponentContainer) { subComps = ((ComponentContainer<Component>)val).getComponents(); } else { subComps = null; } final Set<Integer> pids; if (vpoll) { pids = new TreeSet<>(); final BwEvent vp = evinfo.getEvent(); if (!Util.isEmpty(vp.getPollItems())) { vp.clearPollItems(); } } else { pids = null; } if (!Util.isEmpty(subComps)) { for (final var subComp: subComps) { if (subComp instanceof Available) { if (!(val instanceof VAvailability)) { return Response.error(resp, "AVAILABLE only valid in VAVAILABLE"); } final var avlResp = processAvailable(cb, cal, ical, (VAvailability)val, (Available)subComp, evinfo); if (!avlResp.isOk()) { return Response.fromResponse(resp, avlResp); } continue; } if (subComp instanceof Participant) { if (vpoll) { final var vresp = processVoter(cb, (VPoll)val, (Participant)subComp, evinfo, chg, mergeAttendees); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Participant object"); continue; } if (subComp instanceof VResource) { logger.warn("Unimplemented VResource object"); continue; } if (subComp instanceof VLocation) { logger.warn("Unimplemented VLocation object"); continue; } if (subComp instanceof VAlarm) { final var aresp = VAlarmUtil.processAlarm(cb, val, (VAlarm)subComp, ev, currentPrincipal, chg); if (!aresp.isOk()) { return Response.fromResponse(resp, aresp); } continue; } if (vpoll && (event || task)) { final var vresp = processCandidate((VPoll)val, subComp, evinfo, pids, chg); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Component object: " + subComp); } } /* Fix up timestamps. */ if (ev.getCreated() == null) { if (ev.getLastmod() != null) { ev.setCreated(ev.getLastmod()); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); } else { ev.updateDtstamp(); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } } if (ev.getLastmod() == null) { // created cannot be null now ev.setLastmod(ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } processTimezones(ev, ical, chg); /* Remove any recipients and originator */ if (ev.getRecipients() != null) { ev.getRecipients().clear(); } ev.setOriginator(null); if (hasXparams.value) { /* Save a text copy of the entire event as an x-property */ final Component valCopy = val.copy(); /* Remove potentially large values */ final Description desp = valCopy.getProperty(Property.DESCRIPTION); if (desp != null) { desp.setValue(null); } final Attach attachp = valCopy.getProperty(Property.ATTACH); // Don't store the entire attachment - we just need the parameters. if (attachp != null) { final Value v = attachp.getParameter(Parameter.VALUE); if (v != null) { attachp.setValue(String.valueOf(attachp.getValue().hashCode())); } } chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(BwXproperty.bedeworkIcal, null, valCopy.toString())); } chg.processChanges(ev, true, false); ev.setRecurring(ev.isRecurringEntity()); if (logger.debug()) { logger.debug(chg.toString()); logger.debug(ev.toString()); } if (masterEI != null) { // Just return notfound as this event is on its override list return Response.notFound(resp); } resp.setEntity(evinfo); return resp; } catch (final Throwable t) { if (logger.debug()) { logger.error(t); } return Response.error(resp, t); } }
NONSATD
true
String attUri = null; if (mergeAttendees) { // We'll need this later. attUri = cb.getCaladdr(cb.getPrincipal().getPrincipalRef()); }
} String currentPrincipal = null; final BwPrincipal principal = cb.getPrincipal(); if (principal != null) { currentPrincipal = principal.getPrincipalRef(); } final Holder<Boolean> hasXparams = new Holder<>(Boolean.FALSE); final int methodType = ical.getMethodType(); String attUri = null; if (mergeAttendees) { // We'll need this later. attUri = cb.getCaladdr(cb.getPrincipal().getPrincipalRef()); } final String colPath; if (cal == null) { colPath = null; } else { colPath = cal.getPath(); } try { final PropertyList<Property> pl = val.getProperties();
public static GetEntityResponse<EventInfo> toEvent( final IcalCallback cb, final BwCalendar cal, final Icalendar ical, final Component val, final boolean mergeAttendees) { final var resp = new GetEntityResponse<EventInfo>(); if (val == null) { return Response.notOk(resp, failed, "No component supplied"); } String currentPrincipal = null; final BwPrincipal principal = cb.getPrincipal(); if (principal != null) { currentPrincipal = principal.getPrincipalRef(); } final Holder<Boolean> hasXparams = new Holder<>(Boolean.FALSE); final int methodType = ical.getMethodType(); String attUri = null; if (mergeAttendees) { // We'll need this later. attUri = cb.getCaladdr(cb.getPrincipal().getPrincipalRef()); } final String colPath; if (cal == null) { colPath = null; } else { colPath = cal.getPath(); } try { final PropertyList<Property> pl = val.getProperties(); boolean vpoll = false; boolean event = false; boolean task = false; if (pl == null) { // Empty component return Response.notOk(resp, failed, "Empty component"); } final int entityType; if (val instanceof VEvent) { entityType = IcalDefs.entityTypeEvent;
7,893
2
// Empty component
public static GetEntityResponse<EventInfo> toEvent( final IcalCallback cb, final BwCalendar cal, final Icalendar ical, final Component val, final boolean mergeAttendees) { final var resp = new GetEntityResponse<EventInfo>(); if (val == null) { return Response.notOk(resp, failed, "No component supplied"); } String currentPrincipal = null; final BwPrincipal principal = cb.getPrincipal(); if (principal != null) { currentPrincipal = principal.getPrincipalRef(); } final Holder<Boolean> hasXparams = new Holder<>(Boolean.FALSE); final int methodType = ical.getMethodType(); String attUri = null; if (mergeAttendees) { // We'll need this later. attUri = cb.getCaladdr(cb.getPrincipal().getPrincipalRef()); } final String colPath; if (cal == null) { colPath = null; } else { colPath = cal.getPath(); } try { final PropertyList<Property> pl = val.getProperties(); boolean vpoll = false; boolean event = false; boolean task = false; if (pl == null) { // Empty component return Response.notOk(resp, failed, "Empty component"); } final int entityType; if (val instanceof VEvent) { entityType = IcalDefs.entityTypeEvent; event = true; } else if (val instanceof VToDo) { entityType = IcalDefs.entityTypeTodo; task = true; } else if (val instanceof VJournal) { entityType = IcalDefs.entityTypeJournal; } else if (val instanceof VFreeBusy) { entityType = IcalDefs.entityTypeFreeAndBusy; } else if (val instanceof VAvailability) { entityType = IcalDefs.entityTypeVavailability; } else if (val instanceof Available) { entityType = IcalDefs.entityTypeAvailable; } else if (val instanceof VPoll) { entityType = IcalDefs.entityTypeVpoll; vpoll = true; } else { return Response.error(resp, "org.bedework.invalid.component.type: " + val.getName()); } // Get the guid from the component String guid = null; final Uid uidp = pl.getProperty(Property.UID); if (uidp != null) { testXparams(uidp, hasXparams); guid = uidp.getValue(); } if (guid == null) { /* XXX A guid is required - but are there devices out there without a * guid - and if so how do we handle it? */ return Response.notOk(resp, failed, CalFacadeException.noGuid); } /* See if we have a recurrence id */ BwDateTime ridObj = null; String rid = null; TimeZone ridTz = null; final RecurrenceId ridp = pl.getProperty(Property.RECURRENCE_ID); if (ridp != null) { testXparams(ridp, hasXparams); ridObj = BwDateTime.makeBwDateTime(ridp); if (ridObj.getRange() != null) { /* XXX What do I do with it? */ logger.warn("TRANS-TO_EVENT: Got a recurrence id range"); } rid = ridObj.getDate(); } EventInfo masterEI = null; EventInfo evinfo = null; final BwEvent ev; /* If we have a recurrence id see if we already have the master (we should * get a master + all its overrides). * * If so find the override and use the annnotation or if no override, * make one. * * If no override retrieve the event, add it to our table and then locate the * annotation. * * If there is no annotation, create one. * * It's possible we have been sent 'detached' instances of a recurring * event. This may happen if we are invited to one or more instances of a * meeting. In this case we try to retrieve the master and if it doesn't * exist we manufacture one. We consider such an instance an update to * that instance only and leave the others alone. */ /* We need this in a couple of places */ final DtStart dtStart = pl.getProperty(Property.DTSTART); /* if (rid != null) { // See if we have a new master event. If so create a proxy to that event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI == null) { masterEI = makeNewEvent(cb, chg, entityType, guid, cal); BwEvent e = masterEI.getEvent(); // XXX This seems bogus DtStart mdtStart; String bogusDate = "19980118T230000"; if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + "Z"); } else if (dtStart.getTimeZone() == null) { mdtStart = new DtStart(bogusDate); } else { mdtStart = new DtStart(bogusDate + "Z", dtStart.getTimeZone()); } setDates(e, mdtStart, null, null, chg); e.setRecurring(true); e.addRdate(ridObj); e.setSuppressed(true); ical.addComponent(masterEI); } if (masterEI != null) { evinfo = masterEI.findOverride(rid); } } */ /* If this is a recurrence instance see if we can find the master We only need this because the master may follow the overrides. */ if (rid != null) { // See if we have a new master event. If so create a proxy to this event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI != null) { evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; } } if ((evinfo == null) && (cal != null) && (cal.getCalType() != BwCalendar.calTypeInbox) && (cal.getCalType() != BwCalendar.calTypePendingInbox) && (cal.getCalType() != BwCalendar.calTypeOutbox)) { if (logger.debug()) { logger.debug("TRANS-TO_EVENT: try to fetch event with guid=" + guid); } final GetEntitiesResponse<EventInfo> eisResp = cb.getEvent(colPath, guid); if (eisResp.isError()) { return Response.fromResponse(resp, eisResp); } final var eis = eisResp.getEntities(); if (!Util.isEmpty(eis)) { if (eis.size() > 1) { // DORECUR - wrong again return Response.notOk(resp, failed, "More than one event returned for guid."); } evinfo = eis.iterator().next(); } if (logger.debug()) { if (evinfo != null) { logger.debug("TRANS-TO_EVENT: fetched event with guid"); } else { logger.debug("TRANS-TO_EVENT: did not find event with guid"); } } if (evinfo != null) { if (rid != null) { // We just retrieved it's master masterEI = evinfo; masterEI.setInstanceOnly(true); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; ical.addComponent(masterEI); } else if (methodType == ScheduleMethods.methodTypeCancel) { // This should never have an rid for cancel of entire event. evinfo.setInstanceOnly(evinfo.getEvent().getSuppressed()); } else { // Presumably sent an update for the entire event. No longer suppressed master evinfo.getEvent().setSuppressed(false); } } else if (rid != null) { /* Manufacture a master for the instance */ masterEI = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); final BwEvent e = masterEI.getEvent(); // XXX This seems bogus final DtStart mdtStart; final String bogusDate = "19980118"; final String bogusTime = "T230000"; // Base dtstart on the recurrence id. final boolean isDateType = ridObj.getDateType(); if (isDateType) { mdtStart = new DtStart(new Date(bogusDate)); } else if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + bogusTime + "Z"); } else if (ridObj.getTzid() == null) { mdtStart = new DtStart(bogusDate + bogusTime); } else { mdtStart = new DtStart(bogusDate + bogusTime, Timezones.getTz(ridObj.getTzid())); } IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), masterEI, mdtStart, null, null); e.setRecurring(true); // e.addRdate(ridObj); final var sum = (Summary)pl.getProperty(Property.SUMMARY); e.setSummary(sum.getValue()); e.setSuppressed(true); ical.addComponent(masterEI); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; masterEI.setInstanceOnly(rid != null); } } if (evinfo == null) { evinfo = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); } else if (evinfo.getEvent().getEntityType() != entityType) { return Response.notOk(resp, failed, "org.bedework.mismatched.entity.type: " + val); } final ChangeTable chg = evinfo.getChangeset( cb.getPrincipal().getPrincipalRef()); if (rid != null) { final String evrid = evinfo.getEvent().getRecurrenceId(); if ((evrid == null) || (!evrid.equals(rid))) { logger. warn("Mismatched rid ev=" + evrid + " expected " + rid); chg.changed(PropertyInfoIndex.RECURRENCE_ID, evrid, rid); // XXX spurious??? } if (masterEI.getEvent().getSuppressed()) { masterEI.getEvent().addRdate(ridObj); } } ev = evinfo.getEvent(); ev.setScheduleMethod(methodType); DtEnd dtEnd = null; if (entityType == IcalDefs.entityTypeTodo) { final Due due = pl.getProperty(Property.DUE); if (due != null ) { dtEnd = new DtEnd(due.getParameters(), due.getValue()); } } else { dtEnd = pl.getProperty(Property.DTEND); } final Duration duration = pl.getProperty(Property.DURATION); IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), evinfo, dtStart, dtEnd, duration); for (final Property prop: pl) { testXparams(prop, hasXparams); //debug("ical prop " + prop.getClass().getName()); String pval = prop.getValue(); if ((pval != null) && (pval.length() == 0)) { pval = null; } final PropertyInfoIndex pi; if (prop instanceof XProperty) { pi = PropertyInfoIndex.XPROP; } else { pi = PropertyInfoIndex.fromName(prop.getName()); } if (pi == null) { logger.debug("Unknown property with name " + prop.getName() + " class " + prop.getClass() + " and value " + pval); continue; } chg.present(pi); switch (pi) { case ACCEPT_RESPONSE: /* ------------------- Accept Response -------------------- */ String sval = prop.getValue(); if (chg.changed(pi, ev.getPollAcceptResponse(), sval)) { ev.setPollAcceptResponse(sval); } break; case ATTACH: /* ------------------- Attachment -------------------- */ chg.addValue(pi, IcalUtil.getAttachment((Attach)prop)); break; case ATTENDEE: /* ------------------- Attendee -------------------- */ if (methodType == ScheduleMethods.methodTypePublish) { if (cb.getStrictness() == IcalCallback.conformanceStrict) { return Response.notOk(resp, failed, CalFacadeException.attendeesInPublish); } //if (cb.getStrictness() == IcalCallback.conformanceWarn) { // warn("Had attendees for PUBLISH"); //} } final Attendee attPr = (Attendee)prop; if (evinfo.getNewEvent() || !mergeAttendees) { chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { final String pUri = cb.getCaladdr(attPr.getValue()); if (pUri.equals(attUri)) { /* Only update for our own attendee * We're doing a PUT and this must be the attendee updating their * partstat. We don't allow them to change other attendees * whatever the PUT content says. */ chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { // Use the value we currently have boolean found = false; for (final BwAttendee att: ev.getAttendees()) { if (pUri.equals(att.getAttendeeUri())) { chg.addValue(pi, att.clone()); found = true; break; } } if (!found) { // An added attendee final BwAttendee att = IcalUtil .getAttendee(cb, attPr); att.setPartstat(IcalDefs.partstatValNeedsAction); chg.addValue(pi, att); } } } break; case BUSYTYPE: final int ibt = BwEvent.fromBusyTypeString(pval); if (chg.changed(pi, ev.getBusyType(), ibt)) { ev.setBusyType(ibt); } break; case CATEGORIES: /* ------------------- Categories -------------------- */ final Categories cats = (Categories)prop; final TextList cl = cats.getCategories(); String lang = IcalUtil.getLang(cats); if (cl != null) { /* Got some categories */ for (final String wd: cl) { if (wd == null) { continue; } final BwString key = new BwString(lang, wd); final var fcResp = cb.findCategory(key); final BwCategory cat; if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isNotFound()) { cat = BwCategory.makeCategory(); cat.setWord(key); cb.addCategory(cat); } else { cat = fcResp.getEntity(); } chg.addValue(pi, cat); } } break; case CLASS: /* ------------------- Class -------------------- */ if (chg.changed(pi, ev.getClassification(), pval)) { ev.setClassification(pval); } break; case COMMENT: /* ------------------- Comment -------------------- */ chg.addValue(pi, new BwString(null, pval)); break; case COMPLETED: /* ------------------- Completed -------------------- */ if (chg.changed(pi, ev.getCompleted(), pval)) { ev.setCompleted(pval); } break; case CONCEPT: /* ------------------- Concept -------------------- */ final Concept c = (Concept)prop; final String cval = c.getValue(); if (cval != null) { /* Got a concept */ chg.addValue(PropertyInfoIndex.XPROP, BwXproperty.makeIcalProperty("CONCEPT", null, cval)); } break; case CONTACT: /* ------------------- Contact -------------------- */ final String altrep = getAltRepPar(prop); lang = IcalUtil.getLang(prop); final String uid = getUidPar(prop); final BwString nm = new BwString(lang, pval); BwContact contact = null; if (uid != null) { final var fcResp = cb.getContact(uid); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { final var fcResp = cb.findContact(nm); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { contact = BwContact.makeContact(); contact.setCn(nm); contact.setLink(altrep); cb.addContact(contact); } else { contact.setCn(nm); contact.setLink(altrep); } chg.addValue(pi, contact); break; case CREATED: /* ------------------- Created -------------------- */ if (chg.changed(pi, ev.getCreated(), pval)) { ev.setCreated(pval); } break; case DESCRIPTION: /* ------------------- Description -------------------- */ if (chg.changed(pi, ev.getDescription(), pval)) { ev.setDescription(pval); } break; case DTEND: /* ------------------- DtEnd -------------------- */ break; case DTSTAMP: /* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval); break; case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE: /* -------------------- Due ------------------------ */ break; case DURATION: /* ------------------- Duration -------------------- */ break; case EXDATE: /* ------------------- ExDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case EXRULE: /* ------------------- ExRule -------------------- */ chg.addValue(pi, pval); break; case FREEBUSY: /* ------------------- freebusy -------------------- */ final FreeBusy fbusy = (FreeBusy)prop; final PeriodList perpl = fbusy.getPeriods(); final Parameter par = IcalUtil.getParameter(fbusy, "FBTYPE"); final int fbtype; if (par == null) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY)) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY_TENTATIVE)) { fbtype = BwFreeBusyComponent.typeBusyTentative; } else if (par.equals(FbType.BUSY_UNAVAILABLE)) { fbtype = BwFreeBusyComponent.typeBusyUnavailable; } else if (par.equals(FbType.FREE)) { fbtype = BwFreeBusyComponent.typeFree; } else { if (logger.debug()) { logger.debug("Unsupported parameter " + par.getName()); } return Response.notOk(resp, failed, "Unsupported parameter " + par.getName()); } final BwFreeBusyComponent fbc = new BwFreeBusyComponent(); fbc.setType(fbtype); for (final Period per : perpl) { fbc.addPeriod(per); } ev.addFreeBusyPeriod(fbc); break; case GEO: /* ------------------- Geo -------------------- */ final Geo g = (Geo)prop; final BwGeo geo = new BwGeo(g.getLatitude(), g.getLongitude()); if (chg.changed(pi, ev.getGeo(), geo)) { ev.setGeo(geo); } break; case LAST_MODIFIED: /* ------------------- LastModified -------------------- */ if (chg.changed(pi, ev.getLastmod(), pval)) { ev.setLastmod(pval); } break; case LOCATION: /* ------------------- Location -------------------- */ BwLocation loc = null; //String uid = getUidPar(prop); /* At the moment Mozilla lightning is broken and this leads to all * sorts of problems. if (uid != null) { loc = cb.getLocation(uid); } */ lang = IcalUtil.getLang(prop); BwString addr = null; if (pval != null) { if (loc == null) { addr = new BwString(lang, pval); final var fcResp = cb.findLocation(addr); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { loc = fcResp.getEntity(); } } if (loc == null) { loc = BwLocation.makeLocation(); loc.setAddress(addr); cb.addLocation(loc); } } final BwLocation evloc = ev.getLocation(); if (chg.changed(pi, evloc, loc)) { // CHGTBL - this only shows that it's a different location object ev.setLocation(loc); } else if ((loc != null) && (evloc != null)) { // See if the value is changed final String evval = evloc.getAddress().getValue(); final String inval = loc.getAddress().getValue(); if (!evval.equals(inval)) { chg.changed(pi, evval, inval); evloc.getAddress().setValue(inval); } } break; case ORGANIZER: /* ------------------- Organizer -------------------- */ final BwOrganizer org = IcalUtil.getOrganizer(cb, (Organizer)prop); final BwOrganizer evorg = ev.getOrganizer(); final BwOrganizer evorgCopy; if (evorg == null) { evorgCopy = null; } else { evorgCopy = (BwOrganizer)evorg.clone(); } if (chg.changed(pi, evorgCopy, org)) { if (evorg == null) { ev.setOrganizer(org); } else { evorg.update(org); } } break; case PERCENT_COMPLETE: /* ------------------- PercentComplete -------------------- */ Integer ival = ((PercentComplete)prop).getPercentage(); if (chg.changed(pi, ev.getPercentComplete(), ival)) { ev.setPercentComplete(ival); } break; case POLL_MODE: /* ------------------- Poll mode -------------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollMode(), sval)) { ev.setPollMode(sval); } break; case POLL_PROPERTIES: /* ------------------- Poll properties ---------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollProperties(), sval)) { ev.setPollProperties(sval); } break; case POLL_WINNER: /* ------------------- Poll winner -------------------- */ ival = ((PollWinner)prop).getPollwinner(); if (chg.changed(pi, ev.getPollWinner(), ival)) { ev.setPollWinner(ival); } break; case PRIORITY: /* ------------------- Priority -------------------- */ ival = ((Priority)prop).getLevel(); if (chg.changed(pi, ev.getPriority(), ival)) { ev.setPriority(ival); } break; case RDATE: /* ------------------- RDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case RECURRENCE_ID: /* ------------------- RecurrenceID -------------------- */ // Done above break; case RELATED_TO: /* ------------------- RelatedTo -------------------- */ final RelatedTo irelto = (RelatedTo)prop; final BwRelatedTo relto = new BwRelatedTo(); final String parval = IcalUtil.getParameterVal(irelto, "RELTYPE"); if (parval != null) { relto.setRelType(parval); } relto.setValue(irelto.getValue()); if (chg.changed(pi, ev.getRelatedTo(), relto)) { ev.setRelatedTo(relto); } break; case REQUEST_STATUS: /* ------------------- RequestStatus -------------------- */ final BwRequestStatus rs = BwRequestStatus .fromRequestStatus((RequestStatus)prop); chg.addValue(pi, rs); break; case RESOURCES: /* ------------------- Resources -------------------- */ final TextList rl = ((Resources)prop).getResources(); if (rl != null) { /* Got some resources */ lang = IcalUtil.getLang(prop); for (final String s: rl) { final BwString rsrc = new BwString(lang, s); chg.addValue(pi, rsrc); } } break; case RRULE: /* ------------------- RRule -------------------- */ chg.addValue(pi, pval); break; case SEQUENCE: /* ------------------- Sequence -------------------- */ final int seq = ((Sequence)prop).getSequenceNo(); if (seq != ev.getSequence()) { chg.changed(pi, ev.getSequence(), seq); ev.setSequence(seq); } break; case STATUS: /* ------------------- Status -------------------- */ if (chg.changed(pi, ev.getStatus(), pval)) { ev.setStatus(pval); } break; case SUMMARY: /* ------------------- Summary -------------------- */ if (chg.changed(pi, ev.getSummary(), pval)) { ev.setSummary(pval); } break; case TRANSP: /* ------------------- Transp -------------------- */ if (chg.changed(pi, ev.getPeruserTransparency( cb.getPrincipal() .getPrincipalRef()), pval)) { final BwXproperty pu = ev.setPeruserTransparency( cb.getPrincipal().getPrincipalRef(), pval); if (pu != null) { chg.addValue(PropertyInfoIndex.XPROP, pu); } } break; case UID: /* ------------------- Uid -------------------- */ /* We did this above */ break; case URL: /* ------------------- Url -------------------- */ if (chg.changed(pi, ev.getLink(), pval)) { ev.setLink(pval); } break; case XPROP: /* ------------------------- x-property --------------------------- */ final String name = prop.getName(); if (name.equalsIgnoreCase(BwXproperty.bedeworkCost)) { if (chg.changed(PropertyInfoIndex.COST, ev.getCost(), pval)) { ev.setCost(pval); } break; } if (name.equalsIgnoreCase(BwXproperty.xBedeworkCategories)) { if (checkCategory(cb, chg, ev, null, pval)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkLocation)) { if (checkLocation(cb, chg, ev, prop)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkContact)) { if (checkContact(cb, chg, ev, null, pval)) { break; } } /* See if this is an x-category that can be converted to a real category */ final XProperty xp = (XProperty)prop; chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(name, xp.getParameters() .toString(), pval)); break; default: if (logger.debug()) { logger.debug("Unsupported property with index " + pi + "; class " + prop.getClass() + " and value " + pval); } } } /* =================== Process sub-components =============== */ final ComponentList<Component> subComps; if (val instanceof ComponentContainer) { subComps = ((ComponentContainer<Component>)val).getComponents(); } else { subComps = null; } final Set<Integer> pids; if (vpoll) { pids = new TreeSet<>(); final BwEvent vp = evinfo.getEvent(); if (!Util.isEmpty(vp.getPollItems())) { vp.clearPollItems(); } } else { pids = null; } if (!Util.isEmpty(subComps)) { for (final var subComp: subComps) { if (subComp instanceof Available) { if (!(val instanceof VAvailability)) { return Response.error(resp, "AVAILABLE only valid in VAVAILABLE"); } final var avlResp = processAvailable(cb, cal, ical, (VAvailability)val, (Available)subComp, evinfo); if (!avlResp.isOk()) { return Response.fromResponse(resp, avlResp); } continue; } if (subComp instanceof Participant) { if (vpoll) { final var vresp = processVoter(cb, (VPoll)val, (Participant)subComp, evinfo, chg, mergeAttendees); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Participant object"); continue; } if (subComp instanceof VResource) { logger.warn("Unimplemented VResource object"); continue; } if (subComp instanceof VLocation) { logger.warn("Unimplemented VLocation object"); continue; } if (subComp instanceof VAlarm) { final var aresp = VAlarmUtil.processAlarm(cb, val, (VAlarm)subComp, ev, currentPrincipal, chg); if (!aresp.isOk()) { return Response.fromResponse(resp, aresp); } continue; } if (vpoll && (event || task)) { final var vresp = processCandidate((VPoll)val, subComp, evinfo, pids, chg); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Component object: " + subComp); } } /* Fix up timestamps. */ if (ev.getCreated() == null) { if (ev.getLastmod() != null) { ev.setCreated(ev.getLastmod()); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); } else { ev.updateDtstamp(); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } } if (ev.getLastmod() == null) { // created cannot be null now ev.setLastmod(ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } processTimezones(ev, ical, chg); /* Remove any recipients and originator */ if (ev.getRecipients() != null) { ev.getRecipients().clear(); } ev.setOriginator(null); if (hasXparams.value) { /* Save a text copy of the entire event as an x-property */ final Component valCopy = val.copy(); /* Remove potentially large values */ final Description desp = valCopy.getProperty(Property.DESCRIPTION); if (desp != null) { desp.setValue(null); } final Attach attachp = valCopy.getProperty(Property.ATTACH); // Don't store the entire attachment - we just need the parameters. if (attachp != null) { final Value v = attachp.getParameter(Parameter.VALUE); if (v != null) { attachp.setValue(String.valueOf(attachp.getValue().hashCode())); } } chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(BwXproperty.bedeworkIcal, null, valCopy.toString())); } chg.processChanges(ev, true, false); ev.setRecurring(ev.isRecurringEntity()); if (logger.debug()) { logger.debug(chg.toString()); logger.debug(ev.toString()); } if (masterEI != null) { // Just return notfound as this event is on its override list return Response.notFound(resp); } resp.setEntity(evinfo); return resp; } catch (final Throwable t) { if (logger.debug()) { logger.error(t); } return Response.error(resp, t); } }
NONSATD
true
boolean task = false; if (pl == null) { // Empty component return Response.notOk(resp, failed, "Empty component"); }
colPath = null; } else { colPath = cal.getPath(); } try { final PropertyList<Property> pl = val.getProperties(); boolean vpoll = false; boolean event = false; boolean task = false; if (pl == null) { // Empty component return Response.notOk(resp, failed, "Empty component"); } final int entityType; if (val instanceof VEvent) { entityType = IcalDefs.entityTypeEvent; event = true; } else if (val instanceof VToDo) { entityType = IcalDefs.entityTypeTodo; task = true; } else if (val instanceof VJournal) {
} final Holder<Boolean> hasXparams = new Holder<>(Boolean.FALSE); final int methodType = ical.getMethodType(); String attUri = null; if (mergeAttendees) { // We'll need this later. attUri = cb.getCaladdr(cb.getPrincipal().getPrincipalRef()); } final String colPath; if (cal == null) { colPath = null; } else { colPath = cal.getPath(); } try { final PropertyList<Property> pl = val.getProperties(); boolean vpoll = false; boolean event = false; boolean task = false; if (pl == null) { // Empty component return Response.notOk(resp, failed, "Empty component"); } final int entityType; if (val instanceof VEvent) { entityType = IcalDefs.entityTypeEvent; event = true; } else if (val instanceof VToDo) { entityType = IcalDefs.entityTypeTodo; task = true; } else if (val instanceof VJournal) { entityType = IcalDefs.entityTypeJournal; } else if (val instanceof VFreeBusy) { entityType = IcalDefs.entityTypeFreeAndBusy; } else if (val instanceof VAvailability) { entityType = IcalDefs.entityTypeVavailability; } else if (val instanceof Available) { entityType = IcalDefs.entityTypeAvailable; } else if (val instanceof VPoll) { entityType = IcalDefs.entityTypeVpoll; vpoll = true;
7,893
3
// Get the guid from the component
public static GetEntityResponse<EventInfo> toEvent( final IcalCallback cb, final BwCalendar cal, final Icalendar ical, final Component val, final boolean mergeAttendees) { final var resp = new GetEntityResponse<EventInfo>(); if (val == null) { return Response.notOk(resp, failed, "No component supplied"); } String currentPrincipal = null; final BwPrincipal principal = cb.getPrincipal(); if (principal != null) { currentPrincipal = principal.getPrincipalRef(); } final Holder<Boolean> hasXparams = new Holder<>(Boolean.FALSE); final int methodType = ical.getMethodType(); String attUri = null; if (mergeAttendees) { // We'll need this later. attUri = cb.getCaladdr(cb.getPrincipal().getPrincipalRef()); } final String colPath; if (cal == null) { colPath = null; } else { colPath = cal.getPath(); } try { final PropertyList<Property> pl = val.getProperties(); boolean vpoll = false; boolean event = false; boolean task = false; if (pl == null) { // Empty component return Response.notOk(resp, failed, "Empty component"); } final int entityType; if (val instanceof VEvent) { entityType = IcalDefs.entityTypeEvent; event = true; } else if (val instanceof VToDo) { entityType = IcalDefs.entityTypeTodo; task = true; } else if (val instanceof VJournal) { entityType = IcalDefs.entityTypeJournal; } else if (val instanceof VFreeBusy) { entityType = IcalDefs.entityTypeFreeAndBusy; } else if (val instanceof VAvailability) { entityType = IcalDefs.entityTypeVavailability; } else if (val instanceof Available) { entityType = IcalDefs.entityTypeAvailable; } else if (val instanceof VPoll) { entityType = IcalDefs.entityTypeVpoll; vpoll = true; } else { return Response.error(resp, "org.bedework.invalid.component.type: " + val.getName()); } // Get the guid from the component String guid = null; final Uid uidp = pl.getProperty(Property.UID); if (uidp != null) { testXparams(uidp, hasXparams); guid = uidp.getValue(); } if (guid == null) { /* XXX A guid is required - but are there devices out there without a * guid - and if so how do we handle it? */ return Response.notOk(resp, failed, CalFacadeException.noGuid); } /* See if we have a recurrence id */ BwDateTime ridObj = null; String rid = null; TimeZone ridTz = null; final RecurrenceId ridp = pl.getProperty(Property.RECURRENCE_ID); if (ridp != null) { testXparams(ridp, hasXparams); ridObj = BwDateTime.makeBwDateTime(ridp); if (ridObj.getRange() != null) { /* XXX What do I do with it? */ logger.warn("TRANS-TO_EVENT: Got a recurrence id range"); } rid = ridObj.getDate(); } EventInfo masterEI = null; EventInfo evinfo = null; final BwEvent ev; /* If we have a recurrence id see if we already have the master (we should * get a master + all its overrides). * * If so find the override and use the annnotation or if no override, * make one. * * If no override retrieve the event, add it to our table and then locate the * annotation. * * If there is no annotation, create one. * * It's possible we have been sent 'detached' instances of a recurring * event. This may happen if we are invited to one or more instances of a * meeting. In this case we try to retrieve the master and if it doesn't * exist we manufacture one. We consider such an instance an update to * that instance only and leave the others alone. */ /* We need this in a couple of places */ final DtStart dtStart = pl.getProperty(Property.DTSTART); /* if (rid != null) { // See if we have a new master event. If so create a proxy to that event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI == null) { masterEI = makeNewEvent(cb, chg, entityType, guid, cal); BwEvent e = masterEI.getEvent(); // XXX This seems bogus DtStart mdtStart; String bogusDate = "19980118T230000"; if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + "Z"); } else if (dtStart.getTimeZone() == null) { mdtStart = new DtStart(bogusDate); } else { mdtStart = new DtStart(bogusDate + "Z", dtStart.getTimeZone()); } setDates(e, mdtStart, null, null, chg); e.setRecurring(true); e.addRdate(ridObj); e.setSuppressed(true); ical.addComponent(masterEI); } if (masterEI != null) { evinfo = masterEI.findOverride(rid); } } */ /* If this is a recurrence instance see if we can find the master We only need this because the master may follow the overrides. */ if (rid != null) { // See if we have a new master event. If so create a proxy to this event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI != null) { evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; } } if ((evinfo == null) && (cal != null) && (cal.getCalType() != BwCalendar.calTypeInbox) && (cal.getCalType() != BwCalendar.calTypePendingInbox) && (cal.getCalType() != BwCalendar.calTypeOutbox)) { if (logger.debug()) { logger.debug("TRANS-TO_EVENT: try to fetch event with guid=" + guid); } final GetEntitiesResponse<EventInfo> eisResp = cb.getEvent(colPath, guid); if (eisResp.isError()) { return Response.fromResponse(resp, eisResp); } final var eis = eisResp.getEntities(); if (!Util.isEmpty(eis)) { if (eis.size() > 1) { // DORECUR - wrong again return Response.notOk(resp, failed, "More than one event returned for guid."); } evinfo = eis.iterator().next(); } if (logger.debug()) { if (evinfo != null) { logger.debug("TRANS-TO_EVENT: fetched event with guid"); } else { logger.debug("TRANS-TO_EVENT: did not find event with guid"); } } if (evinfo != null) { if (rid != null) { // We just retrieved it's master masterEI = evinfo; masterEI.setInstanceOnly(true); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; ical.addComponent(masterEI); } else if (methodType == ScheduleMethods.methodTypeCancel) { // This should never have an rid for cancel of entire event. evinfo.setInstanceOnly(evinfo.getEvent().getSuppressed()); } else { // Presumably sent an update for the entire event. No longer suppressed master evinfo.getEvent().setSuppressed(false); } } else if (rid != null) { /* Manufacture a master for the instance */ masterEI = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); final BwEvent e = masterEI.getEvent(); // XXX This seems bogus final DtStart mdtStart; final String bogusDate = "19980118"; final String bogusTime = "T230000"; // Base dtstart on the recurrence id. final boolean isDateType = ridObj.getDateType(); if (isDateType) { mdtStart = new DtStart(new Date(bogusDate)); } else if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + bogusTime + "Z"); } else if (ridObj.getTzid() == null) { mdtStart = new DtStart(bogusDate + bogusTime); } else { mdtStart = new DtStart(bogusDate + bogusTime, Timezones.getTz(ridObj.getTzid())); } IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), masterEI, mdtStart, null, null); e.setRecurring(true); // e.addRdate(ridObj); final var sum = (Summary)pl.getProperty(Property.SUMMARY); e.setSummary(sum.getValue()); e.setSuppressed(true); ical.addComponent(masterEI); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; masterEI.setInstanceOnly(rid != null); } } if (evinfo == null) { evinfo = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); } else if (evinfo.getEvent().getEntityType() != entityType) { return Response.notOk(resp, failed, "org.bedework.mismatched.entity.type: " + val); } final ChangeTable chg = evinfo.getChangeset( cb.getPrincipal().getPrincipalRef()); if (rid != null) { final String evrid = evinfo.getEvent().getRecurrenceId(); if ((evrid == null) || (!evrid.equals(rid))) { logger. warn("Mismatched rid ev=" + evrid + " expected " + rid); chg.changed(PropertyInfoIndex.RECURRENCE_ID, evrid, rid); // XXX spurious??? } if (masterEI.getEvent().getSuppressed()) { masterEI.getEvent().addRdate(ridObj); } } ev = evinfo.getEvent(); ev.setScheduleMethod(methodType); DtEnd dtEnd = null; if (entityType == IcalDefs.entityTypeTodo) { final Due due = pl.getProperty(Property.DUE); if (due != null ) { dtEnd = new DtEnd(due.getParameters(), due.getValue()); } } else { dtEnd = pl.getProperty(Property.DTEND); } final Duration duration = pl.getProperty(Property.DURATION); IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), evinfo, dtStart, dtEnd, duration); for (final Property prop: pl) { testXparams(prop, hasXparams); //debug("ical prop " + prop.getClass().getName()); String pval = prop.getValue(); if ((pval != null) && (pval.length() == 0)) { pval = null; } final PropertyInfoIndex pi; if (prop instanceof XProperty) { pi = PropertyInfoIndex.XPROP; } else { pi = PropertyInfoIndex.fromName(prop.getName()); } if (pi == null) { logger.debug("Unknown property with name " + prop.getName() + " class " + prop.getClass() + " and value " + pval); continue; } chg.present(pi); switch (pi) { case ACCEPT_RESPONSE: /* ------------------- Accept Response -------------------- */ String sval = prop.getValue(); if (chg.changed(pi, ev.getPollAcceptResponse(), sval)) { ev.setPollAcceptResponse(sval); } break; case ATTACH: /* ------------------- Attachment -------------------- */ chg.addValue(pi, IcalUtil.getAttachment((Attach)prop)); break; case ATTENDEE: /* ------------------- Attendee -------------------- */ if (methodType == ScheduleMethods.methodTypePublish) { if (cb.getStrictness() == IcalCallback.conformanceStrict) { return Response.notOk(resp, failed, CalFacadeException.attendeesInPublish); } //if (cb.getStrictness() == IcalCallback.conformanceWarn) { // warn("Had attendees for PUBLISH"); //} } final Attendee attPr = (Attendee)prop; if (evinfo.getNewEvent() || !mergeAttendees) { chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { final String pUri = cb.getCaladdr(attPr.getValue()); if (pUri.equals(attUri)) { /* Only update for our own attendee * We're doing a PUT and this must be the attendee updating their * partstat. We don't allow them to change other attendees * whatever the PUT content says. */ chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { // Use the value we currently have boolean found = false; for (final BwAttendee att: ev.getAttendees()) { if (pUri.equals(att.getAttendeeUri())) { chg.addValue(pi, att.clone()); found = true; break; } } if (!found) { // An added attendee final BwAttendee att = IcalUtil .getAttendee(cb, attPr); att.setPartstat(IcalDefs.partstatValNeedsAction); chg.addValue(pi, att); } } } break; case BUSYTYPE: final int ibt = BwEvent.fromBusyTypeString(pval); if (chg.changed(pi, ev.getBusyType(), ibt)) { ev.setBusyType(ibt); } break; case CATEGORIES: /* ------------------- Categories -------------------- */ final Categories cats = (Categories)prop; final TextList cl = cats.getCategories(); String lang = IcalUtil.getLang(cats); if (cl != null) { /* Got some categories */ for (final String wd: cl) { if (wd == null) { continue; } final BwString key = new BwString(lang, wd); final var fcResp = cb.findCategory(key); final BwCategory cat; if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isNotFound()) { cat = BwCategory.makeCategory(); cat.setWord(key); cb.addCategory(cat); } else { cat = fcResp.getEntity(); } chg.addValue(pi, cat); } } break; case CLASS: /* ------------------- Class -------------------- */ if (chg.changed(pi, ev.getClassification(), pval)) { ev.setClassification(pval); } break; case COMMENT: /* ------------------- Comment -------------------- */ chg.addValue(pi, new BwString(null, pval)); break; case COMPLETED: /* ------------------- Completed -------------------- */ if (chg.changed(pi, ev.getCompleted(), pval)) { ev.setCompleted(pval); } break; case CONCEPT: /* ------------------- Concept -------------------- */ final Concept c = (Concept)prop; final String cval = c.getValue(); if (cval != null) { /* Got a concept */ chg.addValue(PropertyInfoIndex.XPROP, BwXproperty.makeIcalProperty("CONCEPT", null, cval)); } break; case CONTACT: /* ------------------- Contact -------------------- */ final String altrep = getAltRepPar(prop); lang = IcalUtil.getLang(prop); final String uid = getUidPar(prop); final BwString nm = new BwString(lang, pval); BwContact contact = null; if (uid != null) { final var fcResp = cb.getContact(uid); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { final var fcResp = cb.findContact(nm); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { contact = BwContact.makeContact(); contact.setCn(nm); contact.setLink(altrep); cb.addContact(contact); } else { contact.setCn(nm); contact.setLink(altrep); } chg.addValue(pi, contact); break; case CREATED: /* ------------------- Created -------------------- */ if (chg.changed(pi, ev.getCreated(), pval)) { ev.setCreated(pval); } break; case DESCRIPTION: /* ------------------- Description -------------------- */ if (chg.changed(pi, ev.getDescription(), pval)) { ev.setDescription(pval); } break; case DTEND: /* ------------------- DtEnd -------------------- */ break; case DTSTAMP: /* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval); break; case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE: /* -------------------- Due ------------------------ */ break; case DURATION: /* ------------------- Duration -------------------- */ break; case EXDATE: /* ------------------- ExDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case EXRULE: /* ------------------- ExRule -------------------- */ chg.addValue(pi, pval); break; case FREEBUSY: /* ------------------- freebusy -------------------- */ final FreeBusy fbusy = (FreeBusy)prop; final PeriodList perpl = fbusy.getPeriods(); final Parameter par = IcalUtil.getParameter(fbusy, "FBTYPE"); final int fbtype; if (par == null) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY)) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY_TENTATIVE)) { fbtype = BwFreeBusyComponent.typeBusyTentative; } else if (par.equals(FbType.BUSY_UNAVAILABLE)) { fbtype = BwFreeBusyComponent.typeBusyUnavailable; } else if (par.equals(FbType.FREE)) { fbtype = BwFreeBusyComponent.typeFree; } else { if (logger.debug()) { logger.debug("Unsupported parameter " + par.getName()); } return Response.notOk(resp, failed, "Unsupported parameter " + par.getName()); } final BwFreeBusyComponent fbc = new BwFreeBusyComponent(); fbc.setType(fbtype); for (final Period per : perpl) { fbc.addPeriod(per); } ev.addFreeBusyPeriod(fbc); break; case GEO: /* ------------------- Geo -------------------- */ final Geo g = (Geo)prop; final BwGeo geo = new BwGeo(g.getLatitude(), g.getLongitude()); if (chg.changed(pi, ev.getGeo(), geo)) { ev.setGeo(geo); } break; case LAST_MODIFIED: /* ------------------- LastModified -------------------- */ if (chg.changed(pi, ev.getLastmod(), pval)) { ev.setLastmod(pval); } break; case LOCATION: /* ------------------- Location -------------------- */ BwLocation loc = null; //String uid = getUidPar(prop); /* At the moment Mozilla lightning is broken and this leads to all * sorts of problems. if (uid != null) { loc = cb.getLocation(uid); } */ lang = IcalUtil.getLang(prop); BwString addr = null; if (pval != null) { if (loc == null) { addr = new BwString(lang, pval); final var fcResp = cb.findLocation(addr); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { loc = fcResp.getEntity(); } } if (loc == null) { loc = BwLocation.makeLocation(); loc.setAddress(addr); cb.addLocation(loc); } } final BwLocation evloc = ev.getLocation(); if (chg.changed(pi, evloc, loc)) { // CHGTBL - this only shows that it's a different location object ev.setLocation(loc); } else if ((loc != null) && (evloc != null)) { // See if the value is changed final String evval = evloc.getAddress().getValue(); final String inval = loc.getAddress().getValue(); if (!evval.equals(inval)) { chg.changed(pi, evval, inval); evloc.getAddress().setValue(inval); } } break; case ORGANIZER: /* ------------------- Organizer -------------------- */ final BwOrganizer org = IcalUtil.getOrganizer(cb, (Organizer)prop); final BwOrganizer evorg = ev.getOrganizer(); final BwOrganizer evorgCopy; if (evorg == null) { evorgCopy = null; } else { evorgCopy = (BwOrganizer)evorg.clone(); } if (chg.changed(pi, evorgCopy, org)) { if (evorg == null) { ev.setOrganizer(org); } else { evorg.update(org); } } break; case PERCENT_COMPLETE: /* ------------------- PercentComplete -------------------- */ Integer ival = ((PercentComplete)prop).getPercentage(); if (chg.changed(pi, ev.getPercentComplete(), ival)) { ev.setPercentComplete(ival); } break; case POLL_MODE: /* ------------------- Poll mode -------------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollMode(), sval)) { ev.setPollMode(sval); } break; case POLL_PROPERTIES: /* ------------------- Poll properties ---------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollProperties(), sval)) { ev.setPollProperties(sval); } break; case POLL_WINNER: /* ------------------- Poll winner -------------------- */ ival = ((PollWinner)prop).getPollwinner(); if (chg.changed(pi, ev.getPollWinner(), ival)) { ev.setPollWinner(ival); } break; case PRIORITY: /* ------------------- Priority -------------------- */ ival = ((Priority)prop).getLevel(); if (chg.changed(pi, ev.getPriority(), ival)) { ev.setPriority(ival); } break; case RDATE: /* ------------------- RDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case RECURRENCE_ID: /* ------------------- RecurrenceID -------------------- */ // Done above break; case RELATED_TO: /* ------------------- RelatedTo -------------------- */ final RelatedTo irelto = (RelatedTo)prop; final BwRelatedTo relto = new BwRelatedTo(); final String parval = IcalUtil.getParameterVal(irelto, "RELTYPE"); if (parval != null) { relto.setRelType(parval); } relto.setValue(irelto.getValue()); if (chg.changed(pi, ev.getRelatedTo(), relto)) { ev.setRelatedTo(relto); } break; case REQUEST_STATUS: /* ------------------- RequestStatus -------------------- */ final BwRequestStatus rs = BwRequestStatus .fromRequestStatus((RequestStatus)prop); chg.addValue(pi, rs); break; case RESOURCES: /* ------------------- Resources -------------------- */ final TextList rl = ((Resources)prop).getResources(); if (rl != null) { /* Got some resources */ lang = IcalUtil.getLang(prop); for (final String s: rl) { final BwString rsrc = new BwString(lang, s); chg.addValue(pi, rsrc); } } break; case RRULE: /* ------------------- RRule -------------------- */ chg.addValue(pi, pval); break; case SEQUENCE: /* ------------------- Sequence -------------------- */ final int seq = ((Sequence)prop).getSequenceNo(); if (seq != ev.getSequence()) { chg.changed(pi, ev.getSequence(), seq); ev.setSequence(seq); } break; case STATUS: /* ------------------- Status -------------------- */ if (chg.changed(pi, ev.getStatus(), pval)) { ev.setStatus(pval); } break; case SUMMARY: /* ------------------- Summary -------------------- */ if (chg.changed(pi, ev.getSummary(), pval)) { ev.setSummary(pval); } break; case TRANSP: /* ------------------- Transp -------------------- */ if (chg.changed(pi, ev.getPeruserTransparency( cb.getPrincipal() .getPrincipalRef()), pval)) { final BwXproperty pu = ev.setPeruserTransparency( cb.getPrincipal().getPrincipalRef(), pval); if (pu != null) { chg.addValue(PropertyInfoIndex.XPROP, pu); } } break; case UID: /* ------------------- Uid -------------------- */ /* We did this above */ break; case URL: /* ------------------- Url -------------------- */ if (chg.changed(pi, ev.getLink(), pval)) { ev.setLink(pval); } break; case XPROP: /* ------------------------- x-property --------------------------- */ final String name = prop.getName(); if (name.equalsIgnoreCase(BwXproperty.bedeworkCost)) { if (chg.changed(PropertyInfoIndex.COST, ev.getCost(), pval)) { ev.setCost(pval); } break; } if (name.equalsIgnoreCase(BwXproperty.xBedeworkCategories)) { if (checkCategory(cb, chg, ev, null, pval)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkLocation)) { if (checkLocation(cb, chg, ev, prop)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkContact)) { if (checkContact(cb, chg, ev, null, pval)) { break; } } /* See if this is an x-category that can be converted to a real category */ final XProperty xp = (XProperty)prop; chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(name, xp.getParameters() .toString(), pval)); break; default: if (logger.debug()) { logger.debug("Unsupported property with index " + pi + "; class " + prop.getClass() + " and value " + pval); } } } /* =================== Process sub-components =============== */ final ComponentList<Component> subComps; if (val instanceof ComponentContainer) { subComps = ((ComponentContainer<Component>)val).getComponents(); } else { subComps = null; } final Set<Integer> pids; if (vpoll) { pids = new TreeSet<>(); final BwEvent vp = evinfo.getEvent(); if (!Util.isEmpty(vp.getPollItems())) { vp.clearPollItems(); } } else { pids = null; } if (!Util.isEmpty(subComps)) { for (final var subComp: subComps) { if (subComp instanceof Available) { if (!(val instanceof VAvailability)) { return Response.error(resp, "AVAILABLE only valid in VAVAILABLE"); } final var avlResp = processAvailable(cb, cal, ical, (VAvailability)val, (Available)subComp, evinfo); if (!avlResp.isOk()) { return Response.fromResponse(resp, avlResp); } continue; } if (subComp instanceof Participant) { if (vpoll) { final var vresp = processVoter(cb, (VPoll)val, (Participant)subComp, evinfo, chg, mergeAttendees); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Participant object"); continue; } if (subComp instanceof VResource) { logger.warn("Unimplemented VResource object"); continue; } if (subComp instanceof VLocation) { logger.warn("Unimplemented VLocation object"); continue; } if (subComp instanceof VAlarm) { final var aresp = VAlarmUtil.processAlarm(cb, val, (VAlarm)subComp, ev, currentPrincipal, chg); if (!aresp.isOk()) { return Response.fromResponse(resp, aresp); } continue; } if (vpoll && (event || task)) { final var vresp = processCandidate((VPoll)val, subComp, evinfo, pids, chg); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Component object: " + subComp); } } /* Fix up timestamps. */ if (ev.getCreated() == null) { if (ev.getLastmod() != null) { ev.setCreated(ev.getLastmod()); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); } else { ev.updateDtstamp(); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } } if (ev.getLastmod() == null) { // created cannot be null now ev.setLastmod(ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } processTimezones(ev, ical, chg); /* Remove any recipients and originator */ if (ev.getRecipients() != null) { ev.getRecipients().clear(); } ev.setOriginator(null); if (hasXparams.value) { /* Save a text copy of the entire event as an x-property */ final Component valCopy = val.copy(); /* Remove potentially large values */ final Description desp = valCopy.getProperty(Property.DESCRIPTION); if (desp != null) { desp.setValue(null); } final Attach attachp = valCopy.getProperty(Property.ATTACH); // Don't store the entire attachment - we just need the parameters. if (attachp != null) { final Value v = attachp.getParameter(Parameter.VALUE); if (v != null) { attachp.setValue(String.valueOf(attachp.getValue().hashCode())); } } chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(BwXproperty.bedeworkIcal, null, valCopy.toString())); } chg.processChanges(ev, true, false); ev.setRecurring(ev.isRecurringEntity()); if (logger.debug()) { logger.debug(chg.toString()); logger.debug(ev.toString()); } if (masterEI != null) { // Just return notfound as this event is on its override list return Response.notFound(resp); } resp.setEntity(evinfo); return resp; } catch (final Throwable t) { if (logger.debug()) { logger.error(t); } return Response.error(resp, t); } }
NONSATD
true
val.getName()); } // Get the guid from the component String guid = null; final Uid uidp = pl.getProperty(Property.UID);
entityType = IcalDefs.entityTypeVavailability; } else if (val instanceof Available) { entityType = IcalDefs.entityTypeAvailable; } else if (val instanceof VPoll) { entityType = IcalDefs.entityTypeVpoll; vpoll = true; } else { return Response.error(resp, "org.bedework.invalid.component.type: " + val.getName()); } // Get the guid from the component String guid = null; final Uid uidp = pl.getProperty(Property.UID); if (uidp != null) { testXparams(uidp, hasXparams); guid = uidp.getValue(); } if (guid == null) { /* XXX A guid is required - but are there devices out there without a * guid - and if so how do we handle it? */
entityType = IcalDefs.entityTypeEvent; event = true; } else if (val instanceof VToDo) { entityType = IcalDefs.entityTypeTodo; task = true; } else if (val instanceof VJournal) { entityType = IcalDefs.entityTypeJournal; } else if (val instanceof VFreeBusy) { entityType = IcalDefs.entityTypeFreeAndBusy; } else if (val instanceof VAvailability) { entityType = IcalDefs.entityTypeVavailability; } else if (val instanceof Available) { entityType = IcalDefs.entityTypeAvailable; } else if (val instanceof VPoll) { entityType = IcalDefs.entityTypeVpoll; vpoll = true; } else { return Response.error(resp, "org.bedework.invalid.component.type: " + val.getName()); } // Get the guid from the component String guid = null; final Uid uidp = pl.getProperty(Property.UID); if (uidp != null) { testXparams(uidp, hasXparams); guid = uidp.getValue(); } if (guid == null) { /* XXX A guid is required - but are there devices out there without a * guid - and if so how do we handle it? */ return Response.notOk(resp, failed, CalFacadeException.noGuid); } /* See if we have a recurrence id */ BwDateTime ridObj = null; String rid = null; TimeZone ridTz = null; final RecurrenceId ridp = pl.getProperty(Property.RECURRENCE_ID); if (ridp != null) { testXparams(ridp, hasXparams); ridObj = BwDateTime.makeBwDateTime(ridp);
7,893
4
/* XXX A guid is required - but are there devices out there without a * guid - and if so how do we handle it? */
public static GetEntityResponse<EventInfo> toEvent( final IcalCallback cb, final BwCalendar cal, final Icalendar ical, final Component val, final boolean mergeAttendees) { final var resp = new GetEntityResponse<EventInfo>(); if (val == null) { return Response.notOk(resp, failed, "No component supplied"); } String currentPrincipal = null; final BwPrincipal principal = cb.getPrincipal(); if (principal != null) { currentPrincipal = principal.getPrincipalRef(); } final Holder<Boolean> hasXparams = new Holder<>(Boolean.FALSE); final int methodType = ical.getMethodType(); String attUri = null; if (mergeAttendees) { // We'll need this later. attUri = cb.getCaladdr(cb.getPrincipal().getPrincipalRef()); } final String colPath; if (cal == null) { colPath = null; } else { colPath = cal.getPath(); } try { final PropertyList<Property> pl = val.getProperties(); boolean vpoll = false; boolean event = false; boolean task = false; if (pl == null) { // Empty component return Response.notOk(resp, failed, "Empty component"); } final int entityType; if (val instanceof VEvent) { entityType = IcalDefs.entityTypeEvent; event = true; } else if (val instanceof VToDo) { entityType = IcalDefs.entityTypeTodo; task = true; } else if (val instanceof VJournal) { entityType = IcalDefs.entityTypeJournal; } else if (val instanceof VFreeBusy) { entityType = IcalDefs.entityTypeFreeAndBusy; } else if (val instanceof VAvailability) { entityType = IcalDefs.entityTypeVavailability; } else if (val instanceof Available) { entityType = IcalDefs.entityTypeAvailable; } else if (val instanceof VPoll) { entityType = IcalDefs.entityTypeVpoll; vpoll = true; } else { return Response.error(resp, "org.bedework.invalid.component.type: " + val.getName()); } // Get the guid from the component String guid = null; final Uid uidp = pl.getProperty(Property.UID); if (uidp != null) { testXparams(uidp, hasXparams); guid = uidp.getValue(); } if (guid == null) { /* XXX A guid is required - but are there devices out there without a * guid - and if so how do we handle it? */ return Response.notOk(resp, failed, CalFacadeException.noGuid); } /* See if we have a recurrence id */ BwDateTime ridObj = null; String rid = null; TimeZone ridTz = null; final RecurrenceId ridp = pl.getProperty(Property.RECURRENCE_ID); if (ridp != null) { testXparams(ridp, hasXparams); ridObj = BwDateTime.makeBwDateTime(ridp); if (ridObj.getRange() != null) { /* XXX What do I do with it? */ logger.warn("TRANS-TO_EVENT: Got a recurrence id range"); } rid = ridObj.getDate(); } EventInfo masterEI = null; EventInfo evinfo = null; final BwEvent ev; /* If we have a recurrence id see if we already have the master (we should * get a master + all its overrides). * * If so find the override and use the annnotation or if no override, * make one. * * If no override retrieve the event, add it to our table and then locate the * annotation. * * If there is no annotation, create one. * * It's possible we have been sent 'detached' instances of a recurring * event. This may happen if we are invited to one or more instances of a * meeting. In this case we try to retrieve the master and if it doesn't * exist we manufacture one. We consider such an instance an update to * that instance only and leave the others alone. */ /* We need this in a couple of places */ final DtStart dtStart = pl.getProperty(Property.DTSTART); /* if (rid != null) { // See if we have a new master event. If so create a proxy to that event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI == null) { masterEI = makeNewEvent(cb, chg, entityType, guid, cal); BwEvent e = masterEI.getEvent(); // XXX This seems bogus DtStart mdtStart; String bogusDate = "19980118T230000"; if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + "Z"); } else if (dtStart.getTimeZone() == null) { mdtStart = new DtStart(bogusDate); } else { mdtStart = new DtStart(bogusDate + "Z", dtStart.getTimeZone()); } setDates(e, mdtStart, null, null, chg); e.setRecurring(true); e.addRdate(ridObj); e.setSuppressed(true); ical.addComponent(masterEI); } if (masterEI != null) { evinfo = masterEI.findOverride(rid); } } */ /* If this is a recurrence instance see if we can find the master We only need this because the master may follow the overrides. */ if (rid != null) { // See if we have a new master event. If so create a proxy to this event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI != null) { evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; } } if ((evinfo == null) && (cal != null) && (cal.getCalType() != BwCalendar.calTypeInbox) && (cal.getCalType() != BwCalendar.calTypePendingInbox) && (cal.getCalType() != BwCalendar.calTypeOutbox)) { if (logger.debug()) { logger.debug("TRANS-TO_EVENT: try to fetch event with guid=" + guid); } final GetEntitiesResponse<EventInfo> eisResp = cb.getEvent(colPath, guid); if (eisResp.isError()) { return Response.fromResponse(resp, eisResp); } final var eis = eisResp.getEntities(); if (!Util.isEmpty(eis)) { if (eis.size() > 1) { // DORECUR - wrong again return Response.notOk(resp, failed, "More than one event returned for guid."); } evinfo = eis.iterator().next(); } if (logger.debug()) { if (evinfo != null) { logger.debug("TRANS-TO_EVENT: fetched event with guid"); } else { logger.debug("TRANS-TO_EVENT: did not find event with guid"); } } if (evinfo != null) { if (rid != null) { // We just retrieved it's master masterEI = evinfo; masterEI.setInstanceOnly(true); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; ical.addComponent(masterEI); } else if (methodType == ScheduleMethods.methodTypeCancel) { // This should never have an rid for cancel of entire event. evinfo.setInstanceOnly(evinfo.getEvent().getSuppressed()); } else { // Presumably sent an update for the entire event. No longer suppressed master evinfo.getEvent().setSuppressed(false); } } else if (rid != null) { /* Manufacture a master for the instance */ masterEI = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); final BwEvent e = masterEI.getEvent(); // XXX This seems bogus final DtStart mdtStart; final String bogusDate = "19980118"; final String bogusTime = "T230000"; // Base dtstart on the recurrence id. final boolean isDateType = ridObj.getDateType(); if (isDateType) { mdtStart = new DtStart(new Date(bogusDate)); } else if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + bogusTime + "Z"); } else if (ridObj.getTzid() == null) { mdtStart = new DtStart(bogusDate + bogusTime); } else { mdtStart = new DtStart(bogusDate + bogusTime, Timezones.getTz(ridObj.getTzid())); } IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), masterEI, mdtStart, null, null); e.setRecurring(true); // e.addRdate(ridObj); final var sum = (Summary)pl.getProperty(Property.SUMMARY); e.setSummary(sum.getValue()); e.setSuppressed(true); ical.addComponent(masterEI); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; masterEI.setInstanceOnly(rid != null); } } if (evinfo == null) { evinfo = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); } else if (evinfo.getEvent().getEntityType() != entityType) { return Response.notOk(resp, failed, "org.bedework.mismatched.entity.type: " + val); } final ChangeTable chg = evinfo.getChangeset( cb.getPrincipal().getPrincipalRef()); if (rid != null) { final String evrid = evinfo.getEvent().getRecurrenceId(); if ((evrid == null) || (!evrid.equals(rid))) { logger. warn("Mismatched rid ev=" + evrid + " expected " + rid); chg.changed(PropertyInfoIndex.RECURRENCE_ID, evrid, rid); // XXX spurious??? } if (masterEI.getEvent().getSuppressed()) { masterEI.getEvent().addRdate(ridObj); } } ev = evinfo.getEvent(); ev.setScheduleMethod(methodType); DtEnd dtEnd = null; if (entityType == IcalDefs.entityTypeTodo) { final Due due = pl.getProperty(Property.DUE); if (due != null ) { dtEnd = new DtEnd(due.getParameters(), due.getValue()); } } else { dtEnd = pl.getProperty(Property.DTEND); } final Duration duration = pl.getProperty(Property.DURATION); IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), evinfo, dtStart, dtEnd, duration); for (final Property prop: pl) { testXparams(prop, hasXparams); //debug("ical prop " + prop.getClass().getName()); String pval = prop.getValue(); if ((pval != null) && (pval.length() == 0)) { pval = null; } final PropertyInfoIndex pi; if (prop instanceof XProperty) { pi = PropertyInfoIndex.XPROP; } else { pi = PropertyInfoIndex.fromName(prop.getName()); } if (pi == null) { logger.debug("Unknown property with name " + prop.getName() + " class " + prop.getClass() + " and value " + pval); continue; } chg.present(pi); switch (pi) { case ACCEPT_RESPONSE: /* ------------------- Accept Response -------------------- */ String sval = prop.getValue(); if (chg.changed(pi, ev.getPollAcceptResponse(), sval)) { ev.setPollAcceptResponse(sval); } break; case ATTACH: /* ------------------- Attachment -------------------- */ chg.addValue(pi, IcalUtil.getAttachment((Attach)prop)); break; case ATTENDEE: /* ------------------- Attendee -------------------- */ if (methodType == ScheduleMethods.methodTypePublish) { if (cb.getStrictness() == IcalCallback.conformanceStrict) { return Response.notOk(resp, failed, CalFacadeException.attendeesInPublish); } //if (cb.getStrictness() == IcalCallback.conformanceWarn) { // warn("Had attendees for PUBLISH"); //} } final Attendee attPr = (Attendee)prop; if (evinfo.getNewEvent() || !mergeAttendees) { chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { final String pUri = cb.getCaladdr(attPr.getValue()); if (pUri.equals(attUri)) { /* Only update for our own attendee * We're doing a PUT and this must be the attendee updating their * partstat. We don't allow them to change other attendees * whatever the PUT content says. */ chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { // Use the value we currently have boolean found = false; for (final BwAttendee att: ev.getAttendees()) { if (pUri.equals(att.getAttendeeUri())) { chg.addValue(pi, att.clone()); found = true; break; } } if (!found) { // An added attendee final BwAttendee att = IcalUtil .getAttendee(cb, attPr); att.setPartstat(IcalDefs.partstatValNeedsAction); chg.addValue(pi, att); } } } break; case BUSYTYPE: final int ibt = BwEvent.fromBusyTypeString(pval); if (chg.changed(pi, ev.getBusyType(), ibt)) { ev.setBusyType(ibt); } break; case CATEGORIES: /* ------------------- Categories -------------------- */ final Categories cats = (Categories)prop; final TextList cl = cats.getCategories(); String lang = IcalUtil.getLang(cats); if (cl != null) { /* Got some categories */ for (final String wd: cl) { if (wd == null) { continue; } final BwString key = new BwString(lang, wd); final var fcResp = cb.findCategory(key); final BwCategory cat; if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isNotFound()) { cat = BwCategory.makeCategory(); cat.setWord(key); cb.addCategory(cat); } else { cat = fcResp.getEntity(); } chg.addValue(pi, cat); } } break; case CLASS: /* ------------------- Class -------------------- */ if (chg.changed(pi, ev.getClassification(), pval)) { ev.setClassification(pval); } break; case COMMENT: /* ------------------- Comment -------------------- */ chg.addValue(pi, new BwString(null, pval)); break; case COMPLETED: /* ------------------- Completed -------------------- */ if (chg.changed(pi, ev.getCompleted(), pval)) { ev.setCompleted(pval); } break; case CONCEPT: /* ------------------- Concept -------------------- */ final Concept c = (Concept)prop; final String cval = c.getValue(); if (cval != null) { /* Got a concept */ chg.addValue(PropertyInfoIndex.XPROP, BwXproperty.makeIcalProperty("CONCEPT", null, cval)); } break; case CONTACT: /* ------------------- Contact -------------------- */ final String altrep = getAltRepPar(prop); lang = IcalUtil.getLang(prop); final String uid = getUidPar(prop); final BwString nm = new BwString(lang, pval); BwContact contact = null; if (uid != null) { final var fcResp = cb.getContact(uid); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { final var fcResp = cb.findContact(nm); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { contact = BwContact.makeContact(); contact.setCn(nm); contact.setLink(altrep); cb.addContact(contact); } else { contact.setCn(nm); contact.setLink(altrep); } chg.addValue(pi, contact); break; case CREATED: /* ------------------- Created -------------------- */ if (chg.changed(pi, ev.getCreated(), pval)) { ev.setCreated(pval); } break; case DESCRIPTION: /* ------------------- Description -------------------- */ if (chg.changed(pi, ev.getDescription(), pval)) { ev.setDescription(pval); } break; case DTEND: /* ------------------- DtEnd -------------------- */ break; case DTSTAMP: /* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval); break; case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE: /* -------------------- Due ------------------------ */ break; case DURATION: /* ------------------- Duration -------------------- */ break; case EXDATE: /* ------------------- ExDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case EXRULE: /* ------------------- ExRule -------------------- */ chg.addValue(pi, pval); break; case FREEBUSY: /* ------------------- freebusy -------------------- */ final FreeBusy fbusy = (FreeBusy)prop; final PeriodList perpl = fbusy.getPeriods(); final Parameter par = IcalUtil.getParameter(fbusy, "FBTYPE"); final int fbtype; if (par == null) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY)) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY_TENTATIVE)) { fbtype = BwFreeBusyComponent.typeBusyTentative; } else if (par.equals(FbType.BUSY_UNAVAILABLE)) { fbtype = BwFreeBusyComponent.typeBusyUnavailable; } else if (par.equals(FbType.FREE)) { fbtype = BwFreeBusyComponent.typeFree; } else { if (logger.debug()) { logger.debug("Unsupported parameter " + par.getName()); } return Response.notOk(resp, failed, "Unsupported parameter " + par.getName()); } final BwFreeBusyComponent fbc = new BwFreeBusyComponent(); fbc.setType(fbtype); for (final Period per : perpl) { fbc.addPeriod(per); } ev.addFreeBusyPeriod(fbc); break; case GEO: /* ------------------- Geo -------------------- */ final Geo g = (Geo)prop; final BwGeo geo = new BwGeo(g.getLatitude(), g.getLongitude()); if (chg.changed(pi, ev.getGeo(), geo)) { ev.setGeo(geo); } break; case LAST_MODIFIED: /* ------------------- LastModified -------------------- */ if (chg.changed(pi, ev.getLastmod(), pval)) { ev.setLastmod(pval); } break; case LOCATION: /* ------------------- Location -------------------- */ BwLocation loc = null; //String uid = getUidPar(prop); /* At the moment Mozilla lightning is broken and this leads to all * sorts of problems. if (uid != null) { loc = cb.getLocation(uid); } */ lang = IcalUtil.getLang(prop); BwString addr = null; if (pval != null) { if (loc == null) { addr = new BwString(lang, pval); final var fcResp = cb.findLocation(addr); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { loc = fcResp.getEntity(); } } if (loc == null) { loc = BwLocation.makeLocation(); loc.setAddress(addr); cb.addLocation(loc); } } final BwLocation evloc = ev.getLocation(); if (chg.changed(pi, evloc, loc)) { // CHGTBL - this only shows that it's a different location object ev.setLocation(loc); } else if ((loc != null) && (evloc != null)) { // See if the value is changed final String evval = evloc.getAddress().getValue(); final String inval = loc.getAddress().getValue(); if (!evval.equals(inval)) { chg.changed(pi, evval, inval); evloc.getAddress().setValue(inval); } } break; case ORGANIZER: /* ------------------- Organizer -------------------- */ final BwOrganizer org = IcalUtil.getOrganizer(cb, (Organizer)prop); final BwOrganizer evorg = ev.getOrganizer(); final BwOrganizer evorgCopy; if (evorg == null) { evorgCopy = null; } else { evorgCopy = (BwOrganizer)evorg.clone(); } if (chg.changed(pi, evorgCopy, org)) { if (evorg == null) { ev.setOrganizer(org); } else { evorg.update(org); } } break; case PERCENT_COMPLETE: /* ------------------- PercentComplete -------------------- */ Integer ival = ((PercentComplete)prop).getPercentage(); if (chg.changed(pi, ev.getPercentComplete(), ival)) { ev.setPercentComplete(ival); } break; case POLL_MODE: /* ------------------- Poll mode -------------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollMode(), sval)) { ev.setPollMode(sval); } break; case POLL_PROPERTIES: /* ------------------- Poll properties ---------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollProperties(), sval)) { ev.setPollProperties(sval); } break; case POLL_WINNER: /* ------------------- Poll winner -------------------- */ ival = ((PollWinner)prop).getPollwinner(); if (chg.changed(pi, ev.getPollWinner(), ival)) { ev.setPollWinner(ival); } break; case PRIORITY: /* ------------------- Priority -------------------- */ ival = ((Priority)prop).getLevel(); if (chg.changed(pi, ev.getPriority(), ival)) { ev.setPriority(ival); } break; case RDATE: /* ------------------- RDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case RECURRENCE_ID: /* ------------------- RecurrenceID -------------------- */ // Done above break; case RELATED_TO: /* ------------------- RelatedTo -------------------- */ final RelatedTo irelto = (RelatedTo)prop; final BwRelatedTo relto = new BwRelatedTo(); final String parval = IcalUtil.getParameterVal(irelto, "RELTYPE"); if (parval != null) { relto.setRelType(parval); } relto.setValue(irelto.getValue()); if (chg.changed(pi, ev.getRelatedTo(), relto)) { ev.setRelatedTo(relto); } break; case REQUEST_STATUS: /* ------------------- RequestStatus -------------------- */ final BwRequestStatus rs = BwRequestStatus .fromRequestStatus((RequestStatus)prop); chg.addValue(pi, rs); break; case RESOURCES: /* ------------------- Resources -------------------- */ final TextList rl = ((Resources)prop).getResources(); if (rl != null) { /* Got some resources */ lang = IcalUtil.getLang(prop); for (final String s: rl) { final BwString rsrc = new BwString(lang, s); chg.addValue(pi, rsrc); } } break; case RRULE: /* ------------------- RRule -------------------- */ chg.addValue(pi, pval); break; case SEQUENCE: /* ------------------- Sequence -------------------- */ final int seq = ((Sequence)prop).getSequenceNo(); if (seq != ev.getSequence()) { chg.changed(pi, ev.getSequence(), seq); ev.setSequence(seq); } break; case STATUS: /* ------------------- Status -------------------- */ if (chg.changed(pi, ev.getStatus(), pval)) { ev.setStatus(pval); } break; case SUMMARY: /* ------------------- Summary -------------------- */ if (chg.changed(pi, ev.getSummary(), pval)) { ev.setSummary(pval); } break; case TRANSP: /* ------------------- Transp -------------------- */ if (chg.changed(pi, ev.getPeruserTransparency( cb.getPrincipal() .getPrincipalRef()), pval)) { final BwXproperty pu = ev.setPeruserTransparency( cb.getPrincipal().getPrincipalRef(), pval); if (pu != null) { chg.addValue(PropertyInfoIndex.XPROP, pu); } } break; case UID: /* ------------------- Uid -------------------- */ /* We did this above */ break; case URL: /* ------------------- Url -------------------- */ if (chg.changed(pi, ev.getLink(), pval)) { ev.setLink(pval); } break; case XPROP: /* ------------------------- x-property --------------------------- */ final String name = prop.getName(); if (name.equalsIgnoreCase(BwXproperty.bedeworkCost)) { if (chg.changed(PropertyInfoIndex.COST, ev.getCost(), pval)) { ev.setCost(pval); } break; } if (name.equalsIgnoreCase(BwXproperty.xBedeworkCategories)) { if (checkCategory(cb, chg, ev, null, pval)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkLocation)) { if (checkLocation(cb, chg, ev, prop)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkContact)) { if (checkContact(cb, chg, ev, null, pval)) { break; } } /* See if this is an x-category that can be converted to a real category */ final XProperty xp = (XProperty)prop; chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(name, xp.getParameters() .toString(), pval)); break; default: if (logger.debug()) { logger.debug("Unsupported property with index " + pi + "; class " + prop.getClass() + " and value " + pval); } } } /* =================== Process sub-components =============== */ final ComponentList<Component> subComps; if (val instanceof ComponentContainer) { subComps = ((ComponentContainer<Component>)val).getComponents(); } else { subComps = null; } final Set<Integer> pids; if (vpoll) { pids = new TreeSet<>(); final BwEvent vp = evinfo.getEvent(); if (!Util.isEmpty(vp.getPollItems())) { vp.clearPollItems(); } } else { pids = null; } if (!Util.isEmpty(subComps)) { for (final var subComp: subComps) { if (subComp instanceof Available) { if (!(val instanceof VAvailability)) { return Response.error(resp, "AVAILABLE only valid in VAVAILABLE"); } final var avlResp = processAvailable(cb, cal, ical, (VAvailability)val, (Available)subComp, evinfo); if (!avlResp.isOk()) { return Response.fromResponse(resp, avlResp); } continue; } if (subComp instanceof Participant) { if (vpoll) { final var vresp = processVoter(cb, (VPoll)val, (Participant)subComp, evinfo, chg, mergeAttendees); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Participant object"); continue; } if (subComp instanceof VResource) { logger.warn("Unimplemented VResource object"); continue; } if (subComp instanceof VLocation) { logger.warn("Unimplemented VLocation object"); continue; } if (subComp instanceof VAlarm) { final var aresp = VAlarmUtil.processAlarm(cb, val, (VAlarm)subComp, ev, currentPrincipal, chg); if (!aresp.isOk()) { return Response.fromResponse(resp, aresp); } continue; } if (vpoll && (event || task)) { final var vresp = processCandidate((VPoll)val, subComp, evinfo, pids, chg); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Component object: " + subComp); } } /* Fix up timestamps. */ if (ev.getCreated() == null) { if (ev.getLastmod() != null) { ev.setCreated(ev.getLastmod()); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); } else { ev.updateDtstamp(); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } } if (ev.getLastmod() == null) { // created cannot be null now ev.setLastmod(ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } processTimezones(ev, ical, chg); /* Remove any recipients and originator */ if (ev.getRecipients() != null) { ev.getRecipients().clear(); } ev.setOriginator(null); if (hasXparams.value) { /* Save a text copy of the entire event as an x-property */ final Component valCopy = val.copy(); /* Remove potentially large values */ final Description desp = valCopy.getProperty(Property.DESCRIPTION); if (desp != null) { desp.setValue(null); } final Attach attachp = valCopy.getProperty(Property.ATTACH); // Don't store the entire attachment - we just need the parameters. if (attachp != null) { final Value v = attachp.getParameter(Parameter.VALUE); if (v != null) { attachp.setValue(String.valueOf(attachp.getValue().hashCode())); } } chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(BwXproperty.bedeworkIcal, null, valCopy.toString())); } chg.processChanges(ev, true, false); ev.setRecurring(ev.isRecurringEntity()); if (logger.debug()) { logger.debug(chg.toString()); logger.debug(ev.toString()); } if (masterEI != null) { // Just return notfound as this event is on its override list return Response.notFound(resp); } resp.setEntity(evinfo); return resp; } catch (final Throwable t) { if (logger.debug()) { logger.error(t); } return Response.error(resp, t); } }
DEFECT
true
} if (guid == null) { /* XXX A guid is required - but are there devices out there without a * guid - and if so how do we handle it? */ return Response.notOk(resp, failed, CalFacadeException.noGuid); }
val.getName()); } // Get the guid from the component String guid = null; final Uid uidp = pl.getProperty(Property.UID); if (uidp != null) { testXparams(uidp, hasXparams); guid = uidp.getValue(); } if (guid == null) { /* XXX A guid is required - but are there devices out there without a * guid - and if so how do we handle it? */ return Response.notOk(resp, failed, CalFacadeException.noGuid); } /* See if we have a recurrence id */ BwDateTime ridObj = null; String rid = null; TimeZone ridTz = null; final RecurrenceId ridp = pl.getProperty(Property.RECURRENCE_ID); if (ridp != null) { testXparams(ridp, hasXparams); ridObj = BwDateTime.makeBwDateTime(ridp);
entityType = IcalDefs.entityTypeFreeAndBusy; } else if (val instanceof VAvailability) { entityType = IcalDefs.entityTypeVavailability; } else if (val instanceof Available) { entityType = IcalDefs.entityTypeAvailable; } else if (val instanceof VPoll) { entityType = IcalDefs.entityTypeVpoll; vpoll = true; } else { return Response.error(resp, "org.bedework.invalid.component.type: " + val.getName()); } // Get the guid from the component String guid = null; final Uid uidp = pl.getProperty(Property.UID); if (uidp != null) { testXparams(uidp, hasXparams); guid = uidp.getValue(); } if (guid == null) { /* XXX A guid is required - but are there devices out there without a * guid - and if so how do we handle it? */ return Response.notOk(resp, failed, CalFacadeException.noGuid); } /* See if we have a recurrence id */ BwDateTime ridObj = null; String rid = null; TimeZone ridTz = null; final RecurrenceId ridp = pl.getProperty(Property.RECURRENCE_ID); if (ridp != null) { testXparams(ridp, hasXparams); ridObj = BwDateTime.makeBwDateTime(ridp); if (ridObj.getRange() != null) { /* XXX What do I do with it? */ logger.warn("TRANS-TO_EVENT: Got a recurrence id range"); } rid = ridObj.getDate(); } EventInfo masterEI = null; EventInfo evinfo = null; final BwEvent ev; /* If we have a recurrence id see if we already have the master (we should
7,893
5
/* See if we have a recurrence id */
public static GetEntityResponse<EventInfo> toEvent( final IcalCallback cb, final BwCalendar cal, final Icalendar ical, final Component val, final boolean mergeAttendees) { final var resp = new GetEntityResponse<EventInfo>(); if (val == null) { return Response.notOk(resp, failed, "No component supplied"); } String currentPrincipal = null; final BwPrincipal principal = cb.getPrincipal(); if (principal != null) { currentPrincipal = principal.getPrincipalRef(); } final Holder<Boolean> hasXparams = new Holder<>(Boolean.FALSE); final int methodType = ical.getMethodType(); String attUri = null; if (mergeAttendees) { // We'll need this later. attUri = cb.getCaladdr(cb.getPrincipal().getPrincipalRef()); } final String colPath; if (cal == null) { colPath = null; } else { colPath = cal.getPath(); } try { final PropertyList<Property> pl = val.getProperties(); boolean vpoll = false; boolean event = false; boolean task = false; if (pl == null) { // Empty component return Response.notOk(resp, failed, "Empty component"); } final int entityType; if (val instanceof VEvent) { entityType = IcalDefs.entityTypeEvent; event = true; } else if (val instanceof VToDo) { entityType = IcalDefs.entityTypeTodo; task = true; } else if (val instanceof VJournal) { entityType = IcalDefs.entityTypeJournal; } else if (val instanceof VFreeBusy) { entityType = IcalDefs.entityTypeFreeAndBusy; } else if (val instanceof VAvailability) { entityType = IcalDefs.entityTypeVavailability; } else if (val instanceof Available) { entityType = IcalDefs.entityTypeAvailable; } else if (val instanceof VPoll) { entityType = IcalDefs.entityTypeVpoll; vpoll = true; } else { return Response.error(resp, "org.bedework.invalid.component.type: " + val.getName()); } // Get the guid from the component String guid = null; final Uid uidp = pl.getProperty(Property.UID); if (uidp != null) { testXparams(uidp, hasXparams); guid = uidp.getValue(); } if (guid == null) { /* XXX A guid is required - but are there devices out there without a * guid - and if so how do we handle it? */ return Response.notOk(resp, failed, CalFacadeException.noGuid); } /* See if we have a recurrence id */ BwDateTime ridObj = null; String rid = null; TimeZone ridTz = null; final RecurrenceId ridp = pl.getProperty(Property.RECURRENCE_ID); if (ridp != null) { testXparams(ridp, hasXparams); ridObj = BwDateTime.makeBwDateTime(ridp); if (ridObj.getRange() != null) { /* XXX What do I do with it? */ logger.warn("TRANS-TO_EVENT: Got a recurrence id range"); } rid = ridObj.getDate(); } EventInfo masterEI = null; EventInfo evinfo = null; final BwEvent ev; /* If we have a recurrence id see if we already have the master (we should * get a master + all its overrides). * * If so find the override and use the annnotation or if no override, * make one. * * If no override retrieve the event, add it to our table and then locate the * annotation. * * If there is no annotation, create one. * * It's possible we have been sent 'detached' instances of a recurring * event. This may happen if we are invited to one or more instances of a * meeting. In this case we try to retrieve the master and if it doesn't * exist we manufacture one. We consider such an instance an update to * that instance only and leave the others alone. */ /* We need this in a couple of places */ final DtStart dtStart = pl.getProperty(Property.DTSTART); /* if (rid != null) { // See if we have a new master event. If so create a proxy to that event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI == null) { masterEI = makeNewEvent(cb, chg, entityType, guid, cal); BwEvent e = masterEI.getEvent(); // XXX This seems bogus DtStart mdtStart; String bogusDate = "19980118T230000"; if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + "Z"); } else if (dtStart.getTimeZone() == null) { mdtStart = new DtStart(bogusDate); } else { mdtStart = new DtStart(bogusDate + "Z", dtStart.getTimeZone()); } setDates(e, mdtStart, null, null, chg); e.setRecurring(true); e.addRdate(ridObj); e.setSuppressed(true); ical.addComponent(masterEI); } if (masterEI != null) { evinfo = masterEI.findOverride(rid); } } */ /* If this is a recurrence instance see if we can find the master We only need this because the master may follow the overrides. */ if (rid != null) { // See if we have a new master event. If so create a proxy to this event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI != null) { evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; } } if ((evinfo == null) && (cal != null) && (cal.getCalType() != BwCalendar.calTypeInbox) && (cal.getCalType() != BwCalendar.calTypePendingInbox) && (cal.getCalType() != BwCalendar.calTypeOutbox)) { if (logger.debug()) { logger.debug("TRANS-TO_EVENT: try to fetch event with guid=" + guid); } final GetEntitiesResponse<EventInfo> eisResp = cb.getEvent(colPath, guid); if (eisResp.isError()) { return Response.fromResponse(resp, eisResp); } final var eis = eisResp.getEntities(); if (!Util.isEmpty(eis)) { if (eis.size() > 1) { // DORECUR - wrong again return Response.notOk(resp, failed, "More than one event returned for guid."); } evinfo = eis.iterator().next(); } if (logger.debug()) { if (evinfo != null) { logger.debug("TRANS-TO_EVENT: fetched event with guid"); } else { logger.debug("TRANS-TO_EVENT: did not find event with guid"); } } if (evinfo != null) { if (rid != null) { // We just retrieved it's master masterEI = evinfo; masterEI.setInstanceOnly(true); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; ical.addComponent(masterEI); } else if (methodType == ScheduleMethods.methodTypeCancel) { // This should never have an rid for cancel of entire event. evinfo.setInstanceOnly(evinfo.getEvent().getSuppressed()); } else { // Presumably sent an update for the entire event. No longer suppressed master evinfo.getEvent().setSuppressed(false); } } else if (rid != null) { /* Manufacture a master for the instance */ masterEI = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); final BwEvent e = masterEI.getEvent(); // XXX This seems bogus final DtStart mdtStart; final String bogusDate = "19980118"; final String bogusTime = "T230000"; // Base dtstart on the recurrence id. final boolean isDateType = ridObj.getDateType(); if (isDateType) { mdtStart = new DtStart(new Date(bogusDate)); } else if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + bogusTime + "Z"); } else if (ridObj.getTzid() == null) { mdtStart = new DtStart(bogusDate + bogusTime); } else { mdtStart = new DtStart(bogusDate + bogusTime, Timezones.getTz(ridObj.getTzid())); } IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), masterEI, mdtStart, null, null); e.setRecurring(true); // e.addRdate(ridObj); final var sum = (Summary)pl.getProperty(Property.SUMMARY); e.setSummary(sum.getValue()); e.setSuppressed(true); ical.addComponent(masterEI); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; masterEI.setInstanceOnly(rid != null); } } if (evinfo == null) { evinfo = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); } else if (evinfo.getEvent().getEntityType() != entityType) { return Response.notOk(resp, failed, "org.bedework.mismatched.entity.type: " + val); } final ChangeTable chg = evinfo.getChangeset( cb.getPrincipal().getPrincipalRef()); if (rid != null) { final String evrid = evinfo.getEvent().getRecurrenceId(); if ((evrid == null) || (!evrid.equals(rid))) { logger. warn("Mismatched rid ev=" + evrid + " expected " + rid); chg.changed(PropertyInfoIndex.RECURRENCE_ID, evrid, rid); // XXX spurious??? } if (masterEI.getEvent().getSuppressed()) { masterEI.getEvent().addRdate(ridObj); } } ev = evinfo.getEvent(); ev.setScheduleMethod(methodType); DtEnd dtEnd = null; if (entityType == IcalDefs.entityTypeTodo) { final Due due = pl.getProperty(Property.DUE); if (due != null ) { dtEnd = new DtEnd(due.getParameters(), due.getValue()); } } else { dtEnd = pl.getProperty(Property.DTEND); } final Duration duration = pl.getProperty(Property.DURATION); IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), evinfo, dtStart, dtEnd, duration); for (final Property prop: pl) { testXparams(prop, hasXparams); //debug("ical prop " + prop.getClass().getName()); String pval = prop.getValue(); if ((pval != null) && (pval.length() == 0)) { pval = null; } final PropertyInfoIndex pi; if (prop instanceof XProperty) { pi = PropertyInfoIndex.XPROP; } else { pi = PropertyInfoIndex.fromName(prop.getName()); } if (pi == null) { logger.debug("Unknown property with name " + prop.getName() + " class " + prop.getClass() + " and value " + pval); continue; } chg.present(pi); switch (pi) { case ACCEPT_RESPONSE: /* ------------------- Accept Response -------------------- */ String sval = prop.getValue(); if (chg.changed(pi, ev.getPollAcceptResponse(), sval)) { ev.setPollAcceptResponse(sval); } break; case ATTACH: /* ------------------- Attachment -------------------- */ chg.addValue(pi, IcalUtil.getAttachment((Attach)prop)); break; case ATTENDEE: /* ------------------- Attendee -------------------- */ if (methodType == ScheduleMethods.methodTypePublish) { if (cb.getStrictness() == IcalCallback.conformanceStrict) { return Response.notOk(resp, failed, CalFacadeException.attendeesInPublish); } //if (cb.getStrictness() == IcalCallback.conformanceWarn) { // warn("Had attendees for PUBLISH"); //} } final Attendee attPr = (Attendee)prop; if (evinfo.getNewEvent() || !mergeAttendees) { chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { final String pUri = cb.getCaladdr(attPr.getValue()); if (pUri.equals(attUri)) { /* Only update for our own attendee * We're doing a PUT and this must be the attendee updating their * partstat. We don't allow them to change other attendees * whatever the PUT content says. */ chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { // Use the value we currently have boolean found = false; for (final BwAttendee att: ev.getAttendees()) { if (pUri.equals(att.getAttendeeUri())) { chg.addValue(pi, att.clone()); found = true; break; } } if (!found) { // An added attendee final BwAttendee att = IcalUtil .getAttendee(cb, attPr); att.setPartstat(IcalDefs.partstatValNeedsAction); chg.addValue(pi, att); } } } break; case BUSYTYPE: final int ibt = BwEvent.fromBusyTypeString(pval); if (chg.changed(pi, ev.getBusyType(), ibt)) { ev.setBusyType(ibt); } break; case CATEGORIES: /* ------------------- Categories -------------------- */ final Categories cats = (Categories)prop; final TextList cl = cats.getCategories(); String lang = IcalUtil.getLang(cats); if (cl != null) { /* Got some categories */ for (final String wd: cl) { if (wd == null) { continue; } final BwString key = new BwString(lang, wd); final var fcResp = cb.findCategory(key); final BwCategory cat; if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isNotFound()) { cat = BwCategory.makeCategory(); cat.setWord(key); cb.addCategory(cat); } else { cat = fcResp.getEntity(); } chg.addValue(pi, cat); } } break; case CLASS: /* ------------------- Class -------------------- */ if (chg.changed(pi, ev.getClassification(), pval)) { ev.setClassification(pval); } break; case COMMENT: /* ------------------- Comment -------------------- */ chg.addValue(pi, new BwString(null, pval)); break; case COMPLETED: /* ------------------- Completed -------------------- */ if (chg.changed(pi, ev.getCompleted(), pval)) { ev.setCompleted(pval); } break; case CONCEPT: /* ------------------- Concept -------------------- */ final Concept c = (Concept)prop; final String cval = c.getValue(); if (cval != null) { /* Got a concept */ chg.addValue(PropertyInfoIndex.XPROP, BwXproperty.makeIcalProperty("CONCEPT", null, cval)); } break; case CONTACT: /* ------------------- Contact -------------------- */ final String altrep = getAltRepPar(prop); lang = IcalUtil.getLang(prop); final String uid = getUidPar(prop); final BwString nm = new BwString(lang, pval); BwContact contact = null; if (uid != null) { final var fcResp = cb.getContact(uid); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { final var fcResp = cb.findContact(nm); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { contact = BwContact.makeContact(); contact.setCn(nm); contact.setLink(altrep); cb.addContact(contact); } else { contact.setCn(nm); contact.setLink(altrep); } chg.addValue(pi, contact); break; case CREATED: /* ------------------- Created -------------------- */ if (chg.changed(pi, ev.getCreated(), pval)) { ev.setCreated(pval); } break; case DESCRIPTION: /* ------------------- Description -------------------- */ if (chg.changed(pi, ev.getDescription(), pval)) { ev.setDescription(pval); } break; case DTEND: /* ------------------- DtEnd -------------------- */ break; case DTSTAMP: /* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval); break; case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE: /* -------------------- Due ------------------------ */ break; case DURATION: /* ------------------- Duration -------------------- */ break; case EXDATE: /* ------------------- ExDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case EXRULE: /* ------------------- ExRule -------------------- */ chg.addValue(pi, pval); break; case FREEBUSY: /* ------------------- freebusy -------------------- */ final FreeBusy fbusy = (FreeBusy)prop; final PeriodList perpl = fbusy.getPeriods(); final Parameter par = IcalUtil.getParameter(fbusy, "FBTYPE"); final int fbtype; if (par == null) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY)) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY_TENTATIVE)) { fbtype = BwFreeBusyComponent.typeBusyTentative; } else if (par.equals(FbType.BUSY_UNAVAILABLE)) { fbtype = BwFreeBusyComponent.typeBusyUnavailable; } else if (par.equals(FbType.FREE)) { fbtype = BwFreeBusyComponent.typeFree; } else { if (logger.debug()) { logger.debug("Unsupported parameter " + par.getName()); } return Response.notOk(resp, failed, "Unsupported parameter " + par.getName()); } final BwFreeBusyComponent fbc = new BwFreeBusyComponent(); fbc.setType(fbtype); for (final Period per : perpl) { fbc.addPeriod(per); } ev.addFreeBusyPeriod(fbc); break; case GEO: /* ------------------- Geo -------------------- */ final Geo g = (Geo)prop; final BwGeo geo = new BwGeo(g.getLatitude(), g.getLongitude()); if (chg.changed(pi, ev.getGeo(), geo)) { ev.setGeo(geo); } break; case LAST_MODIFIED: /* ------------------- LastModified -------------------- */ if (chg.changed(pi, ev.getLastmod(), pval)) { ev.setLastmod(pval); } break; case LOCATION: /* ------------------- Location -------------------- */ BwLocation loc = null; //String uid = getUidPar(prop); /* At the moment Mozilla lightning is broken and this leads to all * sorts of problems. if (uid != null) { loc = cb.getLocation(uid); } */ lang = IcalUtil.getLang(prop); BwString addr = null; if (pval != null) { if (loc == null) { addr = new BwString(lang, pval); final var fcResp = cb.findLocation(addr); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { loc = fcResp.getEntity(); } } if (loc == null) { loc = BwLocation.makeLocation(); loc.setAddress(addr); cb.addLocation(loc); } } final BwLocation evloc = ev.getLocation(); if (chg.changed(pi, evloc, loc)) { // CHGTBL - this only shows that it's a different location object ev.setLocation(loc); } else if ((loc != null) && (evloc != null)) { // See if the value is changed final String evval = evloc.getAddress().getValue(); final String inval = loc.getAddress().getValue(); if (!evval.equals(inval)) { chg.changed(pi, evval, inval); evloc.getAddress().setValue(inval); } } break; case ORGANIZER: /* ------------------- Organizer -------------------- */ final BwOrganizer org = IcalUtil.getOrganizer(cb, (Organizer)prop); final BwOrganizer evorg = ev.getOrganizer(); final BwOrganizer evorgCopy; if (evorg == null) { evorgCopy = null; } else { evorgCopy = (BwOrganizer)evorg.clone(); } if (chg.changed(pi, evorgCopy, org)) { if (evorg == null) { ev.setOrganizer(org); } else { evorg.update(org); } } break; case PERCENT_COMPLETE: /* ------------------- PercentComplete -------------------- */ Integer ival = ((PercentComplete)prop).getPercentage(); if (chg.changed(pi, ev.getPercentComplete(), ival)) { ev.setPercentComplete(ival); } break; case POLL_MODE: /* ------------------- Poll mode -------------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollMode(), sval)) { ev.setPollMode(sval); } break; case POLL_PROPERTIES: /* ------------------- Poll properties ---------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollProperties(), sval)) { ev.setPollProperties(sval); } break; case POLL_WINNER: /* ------------------- Poll winner -------------------- */ ival = ((PollWinner)prop).getPollwinner(); if (chg.changed(pi, ev.getPollWinner(), ival)) { ev.setPollWinner(ival); } break; case PRIORITY: /* ------------------- Priority -------------------- */ ival = ((Priority)prop).getLevel(); if (chg.changed(pi, ev.getPriority(), ival)) { ev.setPriority(ival); } break; case RDATE: /* ------------------- RDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case RECURRENCE_ID: /* ------------------- RecurrenceID -------------------- */ // Done above break; case RELATED_TO: /* ------------------- RelatedTo -------------------- */ final RelatedTo irelto = (RelatedTo)prop; final BwRelatedTo relto = new BwRelatedTo(); final String parval = IcalUtil.getParameterVal(irelto, "RELTYPE"); if (parval != null) { relto.setRelType(parval); } relto.setValue(irelto.getValue()); if (chg.changed(pi, ev.getRelatedTo(), relto)) { ev.setRelatedTo(relto); } break; case REQUEST_STATUS: /* ------------------- RequestStatus -------------------- */ final BwRequestStatus rs = BwRequestStatus .fromRequestStatus((RequestStatus)prop); chg.addValue(pi, rs); break; case RESOURCES: /* ------------------- Resources -------------------- */ final TextList rl = ((Resources)prop).getResources(); if (rl != null) { /* Got some resources */ lang = IcalUtil.getLang(prop); for (final String s: rl) { final BwString rsrc = new BwString(lang, s); chg.addValue(pi, rsrc); } } break; case RRULE: /* ------------------- RRule -------------------- */ chg.addValue(pi, pval); break; case SEQUENCE: /* ------------------- Sequence -------------------- */ final int seq = ((Sequence)prop).getSequenceNo(); if (seq != ev.getSequence()) { chg.changed(pi, ev.getSequence(), seq); ev.setSequence(seq); } break; case STATUS: /* ------------------- Status -------------------- */ if (chg.changed(pi, ev.getStatus(), pval)) { ev.setStatus(pval); } break; case SUMMARY: /* ------------------- Summary -------------------- */ if (chg.changed(pi, ev.getSummary(), pval)) { ev.setSummary(pval); } break; case TRANSP: /* ------------------- Transp -------------------- */ if (chg.changed(pi, ev.getPeruserTransparency( cb.getPrincipal() .getPrincipalRef()), pval)) { final BwXproperty pu = ev.setPeruserTransparency( cb.getPrincipal().getPrincipalRef(), pval); if (pu != null) { chg.addValue(PropertyInfoIndex.XPROP, pu); } } break; case UID: /* ------------------- Uid -------------------- */ /* We did this above */ break; case URL: /* ------------------- Url -------------------- */ if (chg.changed(pi, ev.getLink(), pval)) { ev.setLink(pval); } break; case XPROP: /* ------------------------- x-property --------------------------- */ final String name = prop.getName(); if (name.equalsIgnoreCase(BwXproperty.bedeworkCost)) { if (chg.changed(PropertyInfoIndex.COST, ev.getCost(), pval)) { ev.setCost(pval); } break; } if (name.equalsIgnoreCase(BwXproperty.xBedeworkCategories)) { if (checkCategory(cb, chg, ev, null, pval)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkLocation)) { if (checkLocation(cb, chg, ev, prop)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkContact)) { if (checkContact(cb, chg, ev, null, pval)) { break; } } /* See if this is an x-category that can be converted to a real category */ final XProperty xp = (XProperty)prop; chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(name, xp.getParameters() .toString(), pval)); break; default: if (logger.debug()) { logger.debug("Unsupported property with index " + pi + "; class " + prop.getClass() + " and value " + pval); } } } /* =================== Process sub-components =============== */ final ComponentList<Component> subComps; if (val instanceof ComponentContainer) { subComps = ((ComponentContainer<Component>)val).getComponents(); } else { subComps = null; } final Set<Integer> pids; if (vpoll) { pids = new TreeSet<>(); final BwEvent vp = evinfo.getEvent(); if (!Util.isEmpty(vp.getPollItems())) { vp.clearPollItems(); } } else { pids = null; } if (!Util.isEmpty(subComps)) { for (final var subComp: subComps) { if (subComp instanceof Available) { if (!(val instanceof VAvailability)) { return Response.error(resp, "AVAILABLE only valid in VAVAILABLE"); } final var avlResp = processAvailable(cb, cal, ical, (VAvailability)val, (Available)subComp, evinfo); if (!avlResp.isOk()) { return Response.fromResponse(resp, avlResp); } continue; } if (subComp instanceof Participant) { if (vpoll) { final var vresp = processVoter(cb, (VPoll)val, (Participant)subComp, evinfo, chg, mergeAttendees); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Participant object"); continue; } if (subComp instanceof VResource) { logger.warn("Unimplemented VResource object"); continue; } if (subComp instanceof VLocation) { logger.warn("Unimplemented VLocation object"); continue; } if (subComp instanceof VAlarm) { final var aresp = VAlarmUtil.processAlarm(cb, val, (VAlarm)subComp, ev, currentPrincipal, chg); if (!aresp.isOk()) { return Response.fromResponse(resp, aresp); } continue; } if (vpoll && (event || task)) { final var vresp = processCandidate((VPoll)val, subComp, evinfo, pids, chg); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Component object: " + subComp); } } /* Fix up timestamps. */ if (ev.getCreated() == null) { if (ev.getLastmod() != null) { ev.setCreated(ev.getLastmod()); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); } else { ev.updateDtstamp(); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } } if (ev.getLastmod() == null) { // created cannot be null now ev.setLastmod(ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } processTimezones(ev, ical, chg); /* Remove any recipients and originator */ if (ev.getRecipients() != null) { ev.getRecipients().clear(); } ev.setOriginator(null); if (hasXparams.value) { /* Save a text copy of the entire event as an x-property */ final Component valCopy = val.copy(); /* Remove potentially large values */ final Description desp = valCopy.getProperty(Property.DESCRIPTION); if (desp != null) { desp.setValue(null); } final Attach attachp = valCopy.getProperty(Property.ATTACH); // Don't store the entire attachment - we just need the parameters. if (attachp != null) { final Value v = attachp.getParameter(Parameter.VALUE); if (v != null) { attachp.setValue(String.valueOf(attachp.getValue().hashCode())); } } chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(BwXproperty.bedeworkIcal, null, valCopy.toString())); } chg.processChanges(ev, true, false); ev.setRecurring(ev.isRecurringEntity()); if (logger.debug()) { logger.debug(chg.toString()); logger.debug(ev.toString()); } if (masterEI != null) { // Just return notfound as this event is on its override list return Response.notFound(resp); } resp.setEntity(evinfo); return resp; } catch (final Throwable t) { if (logger.debug()) { logger.error(t); } return Response.error(resp, t); } }
NONSATD
true
return Response.notOk(resp, failed, CalFacadeException.noGuid); } /* See if we have a recurrence id */ BwDateTime ridObj = null; String rid = null;
if (uidp != null) { testXparams(uidp, hasXparams); guid = uidp.getValue(); } if (guid == null) { /* XXX A guid is required - but are there devices out there without a * guid - and if so how do we handle it? */ return Response.notOk(resp, failed, CalFacadeException.noGuid); } /* See if we have a recurrence id */ BwDateTime ridObj = null; String rid = null; TimeZone ridTz = null; final RecurrenceId ridp = pl.getProperty(Property.RECURRENCE_ID); if (ridp != null) { testXparams(ridp, hasXparams); ridObj = BwDateTime.makeBwDateTime(ridp); if (ridObj.getRange() != null) { /* XXX What do I do with it? */ logger.warn("TRANS-TO_EVENT: Got a recurrence id range");
} else if (val instanceof VPoll) { entityType = IcalDefs.entityTypeVpoll; vpoll = true; } else { return Response.error(resp, "org.bedework.invalid.component.type: " + val.getName()); } // Get the guid from the component String guid = null; final Uid uidp = pl.getProperty(Property.UID); if (uidp != null) { testXparams(uidp, hasXparams); guid = uidp.getValue(); } if (guid == null) { /* XXX A guid is required - but are there devices out there without a * guid - and if so how do we handle it? */ return Response.notOk(resp, failed, CalFacadeException.noGuid); } /* See if we have a recurrence id */ BwDateTime ridObj = null; String rid = null; TimeZone ridTz = null; final RecurrenceId ridp = pl.getProperty(Property.RECURRENCE_ID); if (ridp != null) { testXparams(ridp, hasXparams); ridObj = BwDateTime.makeBwDateTime(ridp); if (ridObj.getRange() != null) { /* XXX What do I do with it? */ logger.warn("TRANS-TO_EVENT: Got a recurrence id range"); } rid = ridObj.getDate(); } EventInfo masterEI = null; EventInfo evinfo = null; final BwEvent ev; /* If we have a recurrence id see if we already have the master (we should * get a master + all its overrides). * * If so find the override and use the annnotation or if no override,
7,893
6
/* XXX What do I do with it? */
public static GetEntityResponse<EventInfo> toEvent( final IcalCallback cb, final BwCalendar cal, final Icalendar ical, final Component val, final boolean mergeAttendees) { final var resp = new GetEntityResponse<EventInfo>(); if (val == null) { return Response.notOk(resp, failed, "No component supplied"); } String currentPrincipal = null; final BwPrincipal principal = cb.getPrincipal(); if (principal != null) { currentPrincipal = principal.getPrincipalRef(); } final Holder<Boolean> hasXparams = new Holder<>(Boolean.FALSE); final int methodType = ical.getMethodType(); String attUri = null; if (mergeAttendees) { // We'll need this later. attUri = cb.getCaladdr(cb.getPrincipal().getPrincipalRef()); } final String colPath; if (cal == null) { colPath = null; } else { colPath = cal.getPath(); } try { final PropertyList<Property> pl = val.getProperties(); boolean vpoll = false; boolean event = false; boolean task = false; if (pl == null) { // Empty component return Response.notOk(resp, failed, "Empty component"); } final int entityType; if (val instanceof VEvent) { entityType = IcalDefs.entityTypeEvent; event = true; } else if (val instanceof VToDo) { entityType = IcalDefs.entityTypeTodo; task = true; } else if (val instanceof VJournal) { entityType = IcalDefs.entityTypeJournal; } else if (val instanceof VFreeBusy) { entityType = IcalDefs.entityTypeFreeAndBusy; } else if (val instanceof VAvailability) { entityType = IcalDefs.entityTypeVavailability; } else if (val instanceof Available) { entityType = IcalDefs.entityTypeAvailable; } else if (val instanceof VPoll) { entityType = IcalDefs.entityTypeVpoll; vpoll = true; } else { return Response.error(resp, "org.bedework.invalid.component.type: " + val.getName()); } // Get the guid from the component String guid = null; final Uid uidp = pl.getProperty(Property.UID); if (uidp != null) { testXparams(uidp, hasXparams); guid = uidp.getValue(); } if (guid == null) { /* XXX A guid is required - but are there devices out there without a * guid - and if so how do we handle it? */ return Response.notOk(resp, failed, CalFacadeException.noGuid); } /* See if we have a recurrence id */ BwDateTime ridObj = null; String rid = null; TimeZone ridTz = null; final RecurrenceId ridp = pl.getProperty(Property.RECURRENCE_ID); if (ridp != null) { testXparams(ridp, hasXparams); ridObj = BwDateTime.makeBwDateTime(ridp); if (ridObj.getRange() != null) { /* XXX What do I do with it? */ logger.warn("TRANS-TO_EVENT: Got a recurrence id range"); } rid = ridObj.getDate(); } EventInfo masterEI = null; EventInfo evinfo = null; final BwEvent ev; /* If we have a recurrence id see if we already have the master (we should * get a master + all its overrides). * * If so find the override and use the annnotation or if no override, * make one. * * If no override retrieve the event, add it to our table and then locate the * annotation. * * If there is no annotation, create one. * * It's possible we have been sent 'detached' instances of a recurring * event. This may happen if we are invited to one or more instances of a * meeting. In this case we try to retrieve the master and if it doesn't * exist we manufacture one. We consider such an instance an update to * that instance only and leave the others alone. */ /* We need this in a couple of places */ final DtStart dtStart = pl.getProperty(Property.DTSTART); /* if (rid != null) { // See if we have a new master event. If so create a proxy to that event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI == null) { masterEI = makeNewEvent(cb, chg, entityType, guid, cal); BwEvent e = masterEI.getEvent(); // XXX This seems bogus DtStart mdtStart; String bogusDate = "19980118T230000"; if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + "Z"); } else if (dtStart.getTimeZone() == null) { mdtStart = new DtStart(bogusDate); } else { mdtStart = new DtStart(bogusDate + "Z", dtStart.getTimeZone()); } setDates(e, mdtStart, null, null, chg); e.setRecurring(true); e.addRdate(ridObj); e.setSuppressed(true); ical.addComponent(masterEI); } if (masterEI != null) { evinfo = masterEI.findOverride(rid); } } */ /* If this is a recurrence instance see if we can find the master We only need this because the master may follow the overrides. */ if (rid != null) { // See if we have a new master event. If so create a proxy to this event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI != null) { evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; } } if ((evinfo == null) && (cal != null) && (cal.getCalType() != BwCalendar.calTypeInbox) && (cal.getCalType() != BwCalendar.calTypePendingInbox) && (cal.getCalType() != BwCalendar.calTypeOutbox)) { if (logger.debug()) { logger.debug("TRANS-TO_EVENT: try to fetch event with guid=" + guid); } final GetEntitiesResponse<EventInfo> eisResp = cb.getEvent(colPath, guid); if (eisResp.isError()) { return Response.fromResponse(resp, eisResp); } final var eis = eisResp.getEntities(); if (!Util.isEmpty(eis)) { if (eis.size() > 1) { // DORECUR - wrong again return Response.notOk(resp, failed, "More than one event returned for guid."); } evinfo = eis.iterator().next(); } if (logger.debug()) { if (evinfo != null) { logger.debug("TRANS-TO_EVENT: fetched event with guid"); } else { logger.debug("TRANS-TO_EVENT: did not find event with guid"); } } if (evinfo != null) { if (rid != null) { // We just retrieved it's master masterEI = evinfo; masterEI.setInstanceOnly(true); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; ical.addComponent(masterEI); } else if (methodType == ScheduleMethods.methodTypeCancel) { // This should never have an rid for cancel of entire event. evinfo.setInstanceOnly(evinfo.getEvent().getSuppressed()); } else { // Presumably sent an update for the entire event. No longer suppressed master evinfo.getEvent().setSuppressed(false); } } else if (rid != null) { /* Manufacture a master for the instance */ masterEI = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); final BwEvent e = masterEI.getEvent(); // XXX This seems bogus final DtStart mdtStart; final String bogusDate = "19980118"; final String bogusTime = "T230000"; // Base dtstart on the recurrence id. final boolean isDateType = ridObj.getDateType(); if (isDateType) { mdtStart = new DtStart(new Date(bogusDate)); } else if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + bogusTime + "Z"); } else if (ridObj.getTzid() == null) { mdtStart = new DtStart(bogusDate + bogusTime); } else { mdtStart = new DtStart(bogusDate + bogusTime, Timezones.getTz(ridObj.getTzid())); } IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), masterEI, mdtStart, null, null); e.setRecurring(true); // e.addRdate(ridObj); final var sum = (Summary)pl.getProperty(Property.SUMMARY); e.setSummary(sum.getValue()); e.setSuppressed(true); ical.addComponent(masterEI); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; masterEI.setInstanceOnly(rid != null); } } if (evinfo == null) { evinfo = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); } else if (evinfo.getEvent().getEntityType() != entityType) { return Response.notOk(resp, failed, "org.bedework.mismatched.entity.type: " + val); } final ChangeTable chg = evinfo.getChangeset( cb.getPrincipal().getPrincipalRef()); if (rid != null) { final String evrid = evinfo.getEvent().getRecurrenceId(); if ((evrid == null) || (!evrid.equals(rid))) { logger. warn("Mismatched rid ev=" + evrid + " expected " + rid); chg.changed(PropertyInfoIndex.RECURRENCE_ID, evrid, rid); // XXX spurious??? } if (masterEI.getEvent().getSuppressed()) { masterEI.getEvent().addRdate(ridObj); } } ev = evinfo.getEvent(); ev.setScheduleMethod(methodType); DtEnd dtEnd = null; if (entityType == IcalDefs.entityTypeTodo) { final Due due = pl.getProperty(Property.DUE); if (due != null ) { dtEnd = new DtEnd(due.getParameters(), due.getValue()); } } else { dtEnd = pl.getProperty(Property.DTEND); } final Duration duration = pl.getProperty(Property.DURATION); IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), evinfo, dtStart, dtEnd, duration); for (final Property prop: pl) { testXparams(prop, hasXparams); //debug("ical prop " + prop.getClass().getName()); String pval = prop.getValue(); if ((pval != null) && (pval.length() == 0)) { pval = null; } final PropertyInfoIndex pi; if (prop instanceof XProperty) { pi = PropertyInfoIndex.XPROP; } else { pi = PropertyInfoIndex.fromName(prop.getName()); } if (pi == null) { logger.debug("Unknown property with name " + prop.getName() + " class " + prop.getClass() + " and value " + pval); continue; } chg.present(pi); switch (pi) { case ACCEPT_RESPONSE: /* ------------------- Accept Response -------------------- */ String sval = prop.getValue(); if (chg.changed(pi, ev.getPollAcceptResponse(), sval)) { ev.setPollAcceptResponse(sval); } break; case ATTACH: /* ------------------- Attachment -------------------- */ chg.addValue(pi, IcalUtil.getAttachment((Attach)prop)); break; case ATTENDEE: /* ------------------- Attendee -------------------- */ if (methodType == ScheduleMethods.methodTypePublish) { if (cb.getStrictness() == IcalCallback.conformanceStrict) { return Response.notOk(resp, failed, CalFacadeException.attendeesInPublish); } //if (cb.getStrictness() == IcalCallback.conformanceWarn) { // warn("Had attendees for PUBLISH"); //} } final Attendee attPr = (Attendee)prop; if (evinfo.getNewEvent() || !mergeAttendees) { chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { final String pUri = cb.getCaladdr(attPr.getValue()); if (pUri.equals(attUri)) { /* Only update for our own attendee * We're doing a PUT and this must be the attendee updating their * partstat. We don't allow them to change other attendees * whatever the PUT content says. */ chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { // Use the value we currently have boolean found = false; for (final BwAttendee att: ev.getAttendees()) { if (pUri.equals(att.getAttendeeUri())) { chg.addValue(pi, att.clone()); found = true; break; } } if (!found) { // An added attendee final BwAttendee att = IcalUtil .getAttendee(cb, attPr); att.setPartstat(IcalDefs.partstatValNeedsAction); chg.addValue(pi, att); } } } break; case BUSYTYPE: final int ibt = BwEvent.fromBusyTypeString(pval); if (chg.changed(pi, ev.getBusyType(), ibt)) { ev.setBusyType(ibt); } break; case CATEGORIES: /* ------------------- Categories -------------------- */ final Categories cats = (Categories)prop; final TextList cl = cats.getCategories(); String lang = IcalUtil.getLang(cats); if (cl != null) { /* Got some categories */ for (final String wd: cl) { if (wd == null) { continue; } final BwString key = new BwString(lang, wd); final var fcResp = cb.findCategory(key); final BwCategory cat; if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isNotFound()) { cat = BwCategory.makeCategory(); cat.setWord(key); cb.addCategory(cat); } else { cat = fcResp.getEntity(); } chg.addValue(pi, cat); } } break; case CLASS: /* ------------------- Class -------------------- */ if (chg.changed(pi, ev.getClassification(), pval)) { ev.setClassification(pval); } break; case COMMENT: /* ------------------- Comment -------------------- */ chg.addValue(pi, new BwString(null, pval)); break; case COMPLETED: /* ------------------- Completed -------------------- */ if (chg.changed(pi, ev.getCompleted(), pval)) { ev.setCompleted(pval); } break; case CONCEPT: /* ------------------- Concept -------------------- */ final Concept c = (Concept)prop; final String cval = c.getValue(); if (cval != null) { /* Got a concept */ chg.addValue(PropertyInfoIndex.XPROP, BwXproperty.makeIcalProperty("CONCEPT", null, cval)); } break; case CONTACT: /* ------------------- Contact -------------------- */ final String altrep = getAltRepPar(prop); lang = IcalUtil.getLang(prop); final String uid = getUidPar(prop); final BwString nm = new BwString(lang, pval); BwContact contact = null; if (uid != null) { final var fcResp = cb.getContact(uid); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { final var fcResp = cb.findContact(nm); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { contact = BwContact.makeContact(); contact.setCn(nm); contact.setLink(altrep); cb.addContact(contact); } else { contact.setCn(nm); contact.setLink(altrep); } chg.addValue(pi, contact); break; case CREATED: /* ------------------- Created -------------------- */ if (chg.changed(pi, ev.getCreated(), pval)) { ev.setCreated(pval); } break; case DESCRIPTION: /* ------------------- Description -------------------- */ if (chg.changed(pi, ev.getDescription(), pval)) { ev.setDescription(pval); } break; case DTEND: /* ------------------- DtEnd -------------------- */ break; case DTSTAMP: /* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval); break; case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE: /* -------------------- Due ------------------------ */ break; case DURATION: /* ------------------- Duration -------------------- */ break; case EXDATE: /* ------------------- ExDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case EXRULE: /* ------------------- ExRule -------------------- */ chg.addValue(pi, pval); break; case FREEBUSY: /* ------------------- freebusy -------------------- */ final FreeBusy fbusy = (FreeBusy)prop; final PeriodList perpl = fbusy.getPeriods(); final Parameter par = IcalUtil.getParameter(fbusy, "FBTYPE"); final int fbtype; if (par == null) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY)) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY_TENTATIVE)) { fbtype = BwFreeBusyComponent.typeBusyTentative; } else if (par.equals(FbType.BUSY_UNAVAILABLE)) { fbtype = BwFreeBusyComponent.typeBusyUnavailable; } else if (par.equals(FbType.FREE)) { fbtype = BwFreeBusyComponent.typeFree; } else { if (logger.debug()) { logger.debug("Unsupported parameter " + par.getName()); } return Response.notOk(resp, failed, "Unsupported parameter " + par.getName()); } final BwFreeBusyComponent fbc = new BwFreeBusyComponent(); fbc.setType(fbtype); for (final Period per : perpl) { fbc.addPeriod(per); } ev.addFreeBusyPeriod(fbc); break; case GEO: /* ------------------- Geo -------------------- */ final Geo g = (Geo)prop; final BwGeo geo = new BwGeo(g.getLatitude(), g.getLongitude()); if (chg.changed(pi, ev.getGeo(), geo)) { ev.setGeo(geo); } break; case LAST_MODIFIED: /* ------------------- LastModified -------------------- */ if (chg.changed(pi, ev.getLastmod(), pval)) { ev.setLastmod(pval); } break; case LOCATION: /* ------------------- Location -------------------- */ BwLocation loc = null; //String uid = getUidPar(prop); /* At the moment Mozilla lightning is broken and this leads to all * sorts of problems. if (uid != null) { loc = cb.getLocation(uid); } */ lang = IcalUtil.getLang(prop); BwString addr = null; if (pval != null) { if (loc == null) { addr = new BwString(lang, pval); final var fcResp = cb.findLocation(addr); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { loc = fcResp.getEntity(); } } if (loc == null) { loc = BwLocation.makeLocation(); loc.setAddress(addr); cb.addLocation(loc); } } final BwLocation evloc = ev.getLocation(); if (chg.changed(pi, evloc, loc)) { // CHGTBL - this only shows that it's a different location object ev.setLocation(loc); } else if ((loc != null) && (evloc != null)) { // See if the value is changed final String evval = evloc.getAddress().getValue(); final String inval = loc.getAddress().getValue(); if (!evval.equals(inval)) { chg.changed(pi, evval, inval); evloc.getAddress().setValue(inval); } } break; case ORGANIZER: /* ------------------- Organizer -------------------- */ final BwOrganizer org = IcalUtil.getOrganizer(cb, (Organizer)prop); final BwOrganizer evorg = ev.getOrganizer(); final BwOrganizer evorgCopy; if (evorg == null) { evorgCopy = null; } else { evorgCopy = (BwOrganizer)evorg.clone(); } if (chg.changed(pi, evorgCopy, org)) { if (evorg == null) { ev.setOrganizer(org); } else { evorg.update(org); } } break; case PERCENT_COMPLETE: /* ------------------- PercentComplete -------------------- */ Integer ival = ((PercentComplete)prop).getPercentage(); if (chg.changed(pi, ev.getPercentComplete(), ival)) { ev.setPercentComplete(ival); } break; case POLL_MODE: /* ------------------- Poll mode -------------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollMode(), sval)) { ev.setPollMode(sval); } break; case POLL_PROPERTIES: /* ------------------- Poll properties ---------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollProperties(), sval)) { ev.setPollProperties(sval); } break; case POLL_WINNER: /* ------------------- Poll winner -------------------- */ ival = ((PollWinner)prop).getPollwinner(); if (chg.changed(pi, ev.getPollWinner(), ival)) { ev.setPollWinner(ival); } break; case PRIORITY: /* ------------------- Priority -------------------- */ ival = ((Priority)prop).getLevel(); if (chg.changed(pi, ev.getPriority(), ival)) { ev.setPriority(ival); } break; case RDATE: /* ------------------- RDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case RECURRENCE_ID: /* ------------------- RecurrenceID -------------------- */ // Done above break; case RELATED_TO: /* ------------------- RelatedTo -------------------- */ final RelatedTo irelto = (RelatedTo)prop; final BwRelatedTo relto = new BwRelatedTo(); final String parval = IcalUtil.getParameterVal(irelto, "RELTYPE"); if (parval != null) { relto.setRelType(parval); } relto.setValue(irelto.getValue()); if (chg.changed(pi, ev.getRelatedTo(), relto)) { ev.setRelatedTo(relto); } break; case REQUEST_STATUS: /* ------------------- RequestStatus -------------------- */ final BwRequestStatus rs = BwRequestStatus .fromRequestStatus((RequestStatus)prop); chg.addValue(pi, rs); break; case RESOURCES: /* ------------------- Resources -------------------- */ final TextList rl = ((Resources)prop).getResources(); if (rl != null) { /* Got some resources */ lang = IcalUtil.getLang(prop); for (final String s: rl) { final BwString rsrc = new BwString(lang, s); chg.addValue(pi, rsrc); } } break; case RRULE: /* ------------------- RRule -------------------- */ chg.addValue(pi, pval); break; case SEQUENCE: /* ------------------- Sequence -------------------- */ final int seq = ((Sequence)prop).getSequenceNo(); if (seq != ev.getSequence()) { chg.changed(pi, ev.getSequence(), seq); ev.setSequence(seq); } break; case STATUS: /* ------------------- Status -------------------- */ if (chg.changed(pi, ev.getStatus(), pval)) { ev.setStatus(pval); } break; case SUMMARY: /* ------------------- Summary -------------------- */ if (chg.changed(pi, ev.getSummary(), pval)) { ev.setSummary(pval); } break; case TRANSP: /* ------------------- Transp -------------------- */ if (chg.changed(pi, ev.getPeruserTransparency( cb.getPrincipal() .getPrincipalRef()), pval)) { final BwXproperty pu = ev.setPeruserTransparency( cb.getPrincipal().getPrincipalRef(), pval); if (pu != null) { chg.addValue(PropertyInfoIndex.XPROP, pu); } } break; case UID: /* ------------------- Uid -------------------- */ /* We did this above */ break; case URL: /* ------------------- Url -------------------- */ if (chg.changed(pi, ev.getLink(), pval)) { ev.setLink(pval); } break; case XPROP: /* ------------------------- x-property --------------------------- */ final String name = prop.getName(); if (name.equalsIgnoreCase(BwXproperty.bedeworkCost)) { if (chg.changed(PropertyInfoIndex.COST, ev.getCost(), pval)) { ev.setCost(pval); } break; } if (name.equalsIgnoreCase(BwXproperty.xBedeworkCategories)) { if (checkCategory(cb, chg, ev, null, pval)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkLocation)) { if (checkLocation(cb, chg, ev, prop)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkContact)) { if (checkContact(cb, chg, ev, null, pval)) { break; } } /* See if this is an x-category that can be converted to a real category */ final XProperty xp = (XProperty)prop; chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(name, xp.getParameters() .toString(), pval)); break; default: if (logger.debug()) { logger.debug("Unsupported property with index " + pi + "; class " + prop.getClass() + " and value " + pval); } } } /* =================== Process sub-components =============== */ final ComponentList<Component> subComps; if (val instanceof ComponentContainer) { subComps = ((ComponentContainer<Component>)val).getComponents(); } else { subComps = null; } final Set<Integer> pids; if (vpoll) { pids = new TreeSet<>(); final BwEvent vp = evinfo.getEvent(); if (!Util.isEmpty(vp.getPollItems())) { vp.clearPollItems(); } } else { pids = null; } if (!Util.isEmpty(subComps)) { for (final var subComp: subComps) { if (subComp instanceof Available) { if (!(val instanceof VAvailability)) { return Response.error(resp, "AVAILABLE only valid in VAVAILABLE"); } final var avlResp = processAvailable(cb, cal, ical, (VAvailability)val, (Available)subComp, evinfo); if (!avlResp.isOk()) { return Response.fromResponse(resp, avlResp); } continue; } if (subComp instanceof Participant) { if (vpoll) { final var vresp = processVoter(cb, (VPoll)val, (Participant)subComp, evinfo, chg, mergeAttendees); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Participant object"); continue; } if (subComp instanceof VResource) { logger.warn("Unimplemented VResource object"); continue; } if (subComp instanceof VLocation) { logger.warn("Unimplemented VLocation object"); continue; } if (subComp instanceof VAlarm) { final var aresp = VAlarmUtil.processAlarm(cb, val, (VAlarm)subComp, ev, currentPrincipal, chg); if (!aresp.isOk()) { return Response.fromResponse(resp, aresp); } continue; } if (vpoll && (event || task)) { final var vresp = processCandidate((VPoll)val, subComp, evinfo, pids, chg); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Component object: " + subComp); } } /* Fix up timestamps. */ if (ev.getCreated() == null) { if (ev.getLastmod() != null) { ev.setCreated(ev.getLastmod()); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); } else { ev.updateDtstamp(); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } } if (ev.getLastmod() == null) { // created cannot be null now ev.setLastmod(ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } processTimezones(ev, ical, chg); /* Remove any recipients and originator */ if (ev.getRecipients() != null) { ev.getRecipients().clear(); } ev.setOriginator(null); if (hasXparams.value) { /* Save a text copy of the entire event as an x-property */ final Component valCopy = val.copy(); /* Remove potentially large values */ final Description desp = valCopy.getProperty(Property.DESCRIPTION); if (desp != null) { desp.setValue(null); } final Attach attachp = valCopy.getProperty(Property.ATTACH); // Don't store the entire attachment - we just need the parameters. if (attachp != null) { final Value v = attachp.getParameter(Parameter.VALUE); if (v != null) { attachp.setValue(String.valueOf(attachp.getValue().hashCode())); } } chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(BwXproperty.bedeworkIcal, null, valCopy.toString())); } chg.processChanges(ev, true, false); ev.setRecurring(ev.isRecurringEntity()); if (logger.debug()) { logger.debug(chg.toString()); logger.debug(ev.toString()); } if (masterEI != null) { // Just return notfound as this event is on its override list return Response.notFound(resp); } resp.setEntity(evinfo); return resp; } catch (final Throwable t) { if (logger.debug()) { logger.error(t); } return Response.error(resp, t); } }
DESIGN
true
ridObj = BwDateTime.makeBwDateTime(ridp); if (ridObj.getRange() != null) { /* XXX What do I do with it? */ logger.warn("TRANS-TO_EVENT: Got a recurrence id range"); }
} /* See if we have a recurrence id */ BwDateTime ridObj = null; String rid = null; TimeZone ridTz = null; final RecurrenceId ridp = pl.getProperty(Property.RECURRENCE_ID); if (ridp != null) { testXparams(ridp, hasXparams); ridObj = BwDateTime.makeBwDateTime(ridp); if (ridObj.getRange() != null) { /* XXX What do I do with it? */ logger.warn("TRANS-TO_EVENT: Got a recurrence id range"); } rid = ridObj.getDate(); } EventInfo masterEI = null; EventInfo evinfo = null; final BwEvent ev; /* If we have a recurrence id see if we already have the master (we should * get a master + all its overrides). *
final Uid uidp = pl.getProperty(Property.UID); if (uidp != null) { testXparams(uidp, hasXparams); guid = uidp.getValue(); } if (guid == null) { /* XXX A guid is required - but are there devices out there without a * guid - and if so how do we handle it? */ return Response.notOk(resp, failed, CalFacadeException.noGuid); } /* See if we have a recurrence id */ BwDateTime ridObj = null; String rid = null; TimeZone ridTz = null; final RecurrenceId ridp = pl.getProperty(Property.RECURRENCE_ID); if (ridp != null) { testXparams(ridp, hasXparams); ridObj = BwDateTime.makeBwDateTime(ridp); if (ridObj.getRange() != null) { /* XXX What do I do with it? */ logger.warn("TRANS-TO_EVENT: Got a recurrence id range"); } rid = ridObj.getDate(); } EventInfo masterEI = null; EventInfo evinfo = null; final BwEvent ev; /* If we have a recurrence id see if we already have the master (we should * get a master + all its overrides). * * If so find the override and use the annnotation or if no override, * make one. * * If no override retrieve the event, add it to our table and then locate the * annotation. * * If there is no annotation, create one. * * It's possible we have been sent 'detached' instances of a recurring * event. This may happen if we are invited to one or more instances of a
7,893
7
/* If we have a recurrence id see if we already have the master (we should * get a master + all its overrides). * * If so find the override and use the annnotation or if no override, * make one. * * If no override retrieve the event, add it to our table and then locate the * annotation. * * If there is no annotation, create one. * * It's possible we have been sent 'detached' instances of a recurring * event. This may happen if we are invited to one or more instances of a * meeting. In this case we try to retrieve the master and if it doesn't * exist we manufacture one. We consider such an instance an update to * that instance only and leave the others alone. */
public static GetEntityResponse<EventInfo> toEvent( final IcalCallback cb, final BwCalendar cal, final Icalendar ical, final Component val, final boolean mergeAttendees) { final var resp = new GetEntityResponse<EventInfo>(); if (val == null) { return Response.notOk(resp, failed, "No component supplied"); } String currentPrincipal = null; final BwPrincipal principal = cb.getPrincipal(); if (principal != null) { currentPrincipal = principal.getPrincipalRef(); } final Holder<Boolean> hasXparams = new Holder<>(Boolean.FALSE); final int methodType = ical.getMethodType(); String attUri = null; if (mergeAttendees) { // We'll need this later. attUri = cb.getCaladdr(cb.getPrincipal().getPrincipalRef()); } final String colPath; if (cal == null) { colPath = null; } else { colPath = cal.getPath(); } try { final PropertyList<Property> pl = val.getProperties(); boolean vpoll = false; boolean event = false; boolean task = false; if (pl == null) { // Empty component return Response.notOk(resp, failed, "Empty component"); } final int entityType; if (val instanceof VEvent) { entityType = IcalDefs.entityTypeEvent; event = true; } else if (val instanceof VToDo) { entityType = IcalDefs.entityTypeTodo; task = true; } else if (val instanceof VJournal) { entityType = IcalDefs.entityTypeJournal; } else if (val instanceof VFreeBusy) { entityType = IcalDefs.entityTypeFreeAndBusy; } else if (val instanceof VAvailability) { entityType = IcalDefs.entityTypeVavailability; } else if (val instanceof Available) { entityType = IcalDefs.entityTypeAvailable; } else if (val instanceof VPoll) { entityType = IcalDefs.entityTypeVpoll; vpoll = true; } else { return Response.error(resp, "org.bedework.invalid.component.type: " + val.getName()); } // Get the guid from the component String guid = null; final Uid uidp = pl.getProperty(Property.UID); if (uidp != null) { testXparams(uidp, hasXparams); guid = uidp.getValue(); } if (guid == null) { /* XXX A guid is required - but are there devices out there without a * guid - and if so how do we handle it? */ return Response.notOk(resp, failed, CalFacadeException.noGuid); } /* See if we have a recurrence id */ BwDateTime ridObj = null; String rid = null; TimeZone ridTz = null; final RecurrenceId ridp = pl.getProperty(Property.RECURRENCE_ID); if (ridp != null) { testXparams(ridp, hasXparams); ridObj = BwDateTime.makeBwDateTime(ridp); if (ridObj.getRange() != null) { /* XXX What do I do with it? */ logger.warn("TRANS-TO_EVENT: Got a recurrence id range"); } rid = ridObj.getDate(); } EventInfo masterEI = null; EventInfo evinfo = null; final BwEvent ev; /* If we have a recurrence id see if we already have the master (we should * get a master + all its overrides). * * If so find the override and use the annnotation or if no override, * make one. * * If no override retrieve the event, add it to our table and then locate the * annotation. * * If there is no annotation, create one. * * It's possible we have been sent 'detached' instances of a recurring * event. This may happen if we are invited to one or more instances of a * meeting. In this case we try to retrieve the master and if it doesn't * exist we manufacture one. We consider such an instance an update to * that instance only and leave the others alone. */ /* We need this in a couple of places */ final DtStart dtStart = pl.getProperty(Property.DTSTART); /* if (rid != null) { // See if we have a new master event. If so create a proxy to that event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI == null) { masterEI = makeNewEvent(cb, chg, entityType, guid, cal); BwEvent e = masterEI.getEvent(); // XXX This seems bogus DtStart mdtStart; String bogusDate = "19980118T230000"; if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + "Z"); } else if (dtStart.getTimeZone() == null) { mdtStart = new DtStart(bogusDate); } else { mdtStart = new DtStart(bogusDate + "Z", dtStart.getTimeZone()); } setDates(e, mdtStart, null, null, chg); e.setRecurring(true); e.addRdate(ridObj); e.setSuppressed(true); ical.addComponent(masterEI); } if (masterEI != null) { evinfo = masterEI.findOverride(rid); } } */ /* If this is a recurrence instance see if we can find the master We only need this because the master may follow the overrides. */ if (rid != null) { // See if we have a new master event. If so create a proxy to this event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI != null) { evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; } } if ((evinfo == null) && (cal != null) && (cal.getCalType() != BwCalendar.calTypeInbox) && (cal.getCalType() != BwCalendar.calTypePendingInbox) && (cal.getCalType() != BwCalendar.calTypeOutbox)) { if (logger.debug()) { logger.debug("TRANS-TO_EVENT: try to fetch event with guid=" + guid); } final GetEntitiesResponse<EventInfo> eisResp = cb.getEvent(colPath, guid); if (eisResp.isError()) { return Response.fromResponse(resp, eisResp); } final var eis = eisResp.getEntities(); if (!Util.isEmpty(eis)) { if (eis.size() > 1) { // DORECUR - wrong again return Response.notOk(resp, failed, "More than one event returned for guid."); } evinfo = eis.iterator().next(); } if (logger.debug()) { if (evinfo != null) { logger.debug("TRANS-TO_EVENT: fetched event with guid"); } else { logger.debug("TRANS-TO_EVENT: did not find event with guid"); } } if (evinfo != null) { if (rid != null) { // We just retrieved it's master masterEI = evinfo; masterEI.setInstanceOnly(true); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; ical.addComponent(masterEI); } else if (methodType == ScheduleMethods.methodTypeCancel) { // This should never have an rid for cancel of entire event. evinfo.setInstanceOnly(evinfo.getEvent().getSuppressed()); } else { // Presumably sent an update for the entire event. No longer suppressed master evinfo.getEvent().setSuppressed(false); } } else if (rid != null) { /* Manufacture a master for the instance */ masterEI = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); final BwEvent e = masterEI.getEvent(); // XXX This seems bogus final DtStart mdtStart; final String bogusDate = "19980118"; final String bogusTime = "T230000"; // Base dtstart on the recurrence id. final boolean isDateType = ridObj.getDateType(); if (isDateType) { mdtStart = new DtStart(new Date(bogusDate)); } else if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + bogusTime + "Z"); } else if (ridObj.getTzid() == null) { mdtStart = new DtStart(bogusDate + bogusTime); } else { mdtStart = new DtStart(bogusDate + bogusTime, Timezones.getTz(ridObj.getTzid())); } IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), masterEI, mdtStart, null, null); e.setRecurring(true); // e.addRdate(ridObj); final var sum = (Summary)pl.getProperty(Property.SUMMARY); e.setSummary(sum.getValue()); e.setSuppressed(true); ical.addComponent(masterEI); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; masterEI.setInstanceOnly(rid != null); } } if (evinfo == null) { evinfo = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); } else if (evinfo.getEvent().getEntityType() != entityType) { return Response.notOk(resp, failed, "org.bedework.mismatched.entity.type: " + val); } final ChangeTable chg = evinfo.getChangeset( cb.getPrincipal().getPrincipalRef()); if (rid != null) { final String evrid = evinfo.getEvent().getRecurrenceId(); if ((evrid == null) || (!evrid.equals(rid))) { logger. warn("Mismatched rid ev=" + evrid + " expected " + rid); chg.changed(PropertyInfoIndex.RECURRENCE_ID, evrid, rid); // XXX spurious??? } if (masterEI.getEvent().getSuppressed()) { masterEI.getEvent().addRdate(ridObj); } } ev = evinfo.getEvent(); ev.setScheduleMethod(methodType); DtEnd dtEnd = null; if (entityType == IcalDefs.entityTypeTodo) { final Due due = pl.getProperty(Property.DUE); if (due != null ) { dtEnd = new DtEnd(due.getParameters(), due.getValue()); } } else { dtEnd = pl.getProperty(Property.DTEND); } final Duration duration = pl.getProperty(Property.DURATION); IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), evinfo, dtStart, dtEnd, duration); for (final Property prop: pl) { testXparams(prop, hasXparams); //debug("ical prop " + prop.getClass().getName()); String pval = prop.getValue(); if ((pval != null) && (pval.length() == 0)) { pval = null; } final PropertyInfoIndex pi; if (prop instanceof XProperty) { pi = PropertyInfoIndex.XPROP; } else { pi = PropertyInfoIndex.fromName(prop.getName()); } if (pi == null) { logger.debug("Unknown property with name " + prop.getName() + " class " + prop.getClass() + " and value " + pval); continue; } chg.present(pi); switch (pi) { case ACCEPT_RESPONSE: /* ------------------- Accept Response -------------------- */ String sval = prop.getValue(); if (chg.changed(pi, ev.getPollAcceptResponse(), sval)) { ev.setPollAcceptResponse(sval); } break; case ATTACH: /* ------------------- Attachment -------------------- */ chg.addValue(pi, IcalUtil.getAttachment((Attach)prop)); break; case ATTENDEE: /* ------------------- Attendee -------------------- */ if (methodType == ScheduleMethods.methodTypePublish) { if (cb.getStrictness() == IcalCallback.conformanceStrict) { return Response.notOk(resp, failed, CalFacadeException.attendeesInPublish); } //if (cb.getStrictness() == IcalCallback.conformanceWarn) { // warn("Had attendees for PUBLISH"); //} } final Attendee attPr = (Attendee)prop; if (evinfo.getNewEvent() || !mergeAttendees) { chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { final String pUri = cb.getCaladdr(attPr.getValue()); if (pUri.equals(attUri)) { /* Only update for our own attendee * We're doing a PUT and this must be the attendee updating their * partstat. We don't allow them to change other attendees * whatever the PUT content says. */ chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { // Use the value we currently have boolean found = false; for (final BwAttendee att: ev.getAttendees()) { if (pUri.equals(att.getAttendeeUri())) { chg.addValue(pi, att.clone()); found = true; break; } } if (!found) { // An added attendee final BwAttendee att = IcalUtil .getAttendee(cb, attPr); att.setPartstat(IcalDefs.partstatValNeedsAction); chg.addValue(pi, att); } } } break; case BUSYTYPE: final int ibt = BwEvent.fromBusyTypeString(pval); if (chg.changed(pi, ev.getBusyType(), ibt)) { ev.setBusyType(ibt); } break; case CATEGORIES: /* ------------------- Categories -------------------- */ final Categories cats = (Categories)prop; final TextList cl = cats.getCategories(); String lang = IcalUtil.getLang(cats); if (cl != null) { /* Got some categories */ for (final String wd: cl) { if (wd == null) { continue; } final BwString key = new BwString(lang, wd); final var fcResp = cb.findCategory(key); final BwCategory cat; if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isNotFound()) { cat = BwCategory.makeCategory(); cat.setWord(key); cb.addCategory(cat); } else { cat = fcResp.getEntity(); } chg.addValue(pi, cat); } } break; case CLASS: /* ------------------- Class -------------------- */ if (chg.changed(pi, ev.getClassification(), pval)) { ev.setClassification(pval); } break; case COMMENT: /* ------------------- Comment -------------------- */ chg.addValue(pi, new BwString(null, pval)); break; case COMPLETED: /* ------------------- Completed -------------------- */ if (chg.changed(pi, ev.getCompleted(), pval)) { ev.setCompleted(pval); } break; case CONCEPT: /* ------------------- Concept -------------------- */ final Concept c = (Concept)prop; final String cval = c.getValue(); if (cval != null) { /* Got a concept */ chg.addValue(PropertyInfoIndex.XPROP, BwXproperty.makeIcalProperty("CONCEPT", null, cval)); } break; case CONTACT: /* ------------------- Contact -------------------- */ final String altrep = getAltRepPar(prop); lang = IcalUtil.getLang(prop); final String uid = getUidPar(prop); final BwString nm = new BwString(lang, pval); BwContact contact = null; if (uid != null) { final var fcResp = cb.getContact(uid); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { final var fcResp = cb.findContact(nm); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { contact = BwContact.makeContact(); contact.setCn(nm); contact.setLink(altrep); cb.addContact(contact); } else { contact.setCn(nm); contact.setLink(altrep); } chg.addValue(pi, contact); break; case CREATED: /* ------------------- Created -------------------- */ if (chg.changed(pi, ev.getCreated(), pval)) { ev.setCreated(pval); } break; case DESCRIPTION: /* ------------------- Description -------------------- */ if (chg.changed(pi, ev.getDescription(), pval)) { ev.setDescription(pval); } break; case DTEND: /* ------------------- DtEnd -------------------- */ break; case DTSTAMP: /* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval); break; case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE: /* -------------------- Due ------------------------ */ break; case DURATION: /* ------------------- Duration -------------------- */ break; case EXDATE: /* ------------------- ExDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case EXRULE: /* ------------------- ExRule -------------------- */ chg.addValue(pi, pval); break; case FREEBUSY: /* ------------------- freebusy -------------------- */ final FreeBusy fbusy = (FreeBusy)prop; final PeriodList perpl = fbusy.getPeriods(); final Parameter par = IcalUtil.getParameter(fbusy, "FBTYPE"); final int fbtype; if (par == null) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY)) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY_TENTATIVE)) { fbtype = BwFreeBusyComponent.typeBusyTentative; } else if (par.equals(FbType.BUSY_UNAVAILABLE)) { fbtype = BwFreeBusyComponent.typeBusyUnavailable; } else if (par.equals(FbType.FREE)) { fbtype = BwFreeBusyComponent.typeFree; } else { if (logger.debug()) { logger.debug("Unsupported parameter " + par.getName()); } return Response.notOk(resp, failed, "Unsupported parameter " + par.getName()); } final BwFreeBusyComponent fbc = new BwFreeBusyComponent(); fbc.setType(fbtype); for (final Period per : perpl) { fbc.addPeriod(per); } ev.addFreeBusyPeriod(fbc); break; case GEO: /* ------------------- Geo -------------------- */ final Geo g = (Geo)prop; final BwGeo geo = new BwGeo(g.getLatitude(), g.getLongitude()); if (chg.changed(pi, ev.getGeo(), geo)) { ev.setGeo(geo); } break; case LAST_MODIFIED: /* ------------------- LastModified -------------------- */ if (chg.changed(pi, ev.getLastmod(), pval)) { ev.setLastmod(pval); } break; case LOCATION: /* ------------------- Location -------------------- */ BwLocation loc = null; //String uid = getUidPar(prop); /* At the moment Mozilla lightning is broken and this leads to all * sorts of problems. if (uid != null) { loc = cb.getLocation(uid); } */ lang = IcalUtil.getLang(prop); BwString addr = null; if (pval != null) { if (loc == null) { addr = new BwString(lang, pval); final var fcResp = cb.findLocation(addr); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { loc = fcResp.getEntity(); } } if (loc == null) { loc = BwLocation.makeLocation(); loc.setAddress(addr); cb.addLocation(loc); } } final BwLocation evloc = ev.getLocation(); if (chg.changed(pi, evloc, loc)) { // CHGTBL - this only shows that it's a different location object ev.setLocation(loc); } else if ((loc != null) && (evloc != null)) { // See if the value is changed final String evval = evloc.getAddress().getValue(); final String inval = loc.getAddress().getValue(); if (!evval.equals(inval)) { chg.changed(pi, evval, inval); evloc.getAddress().setValue(inval); } } break; case ORGANIZER: /* ------------------- Organizer -------------------- */ final BwOrganizer org = IcalUtil.getOrganizer(cb, (Organizer)prop); final BwOrganizer evorg = ev.getOrganizer(); final BwOrganizer evorgCopy; if (evorg == null) { evorgCopy = null; } else { evorgCopy = (BwOrganizer)evorg.clone(); } if (chg.changed(pi, evorgCopy, org)) { if (evorg == null) { ev.setOrganizer(org); } else { evorg.update(org); } } break; case PERCENT_COMPLETE: /* ------------------- PercentComplete -------------------- */ Integer ival = ((PercentComplete)prop).getPercentage(); if (chg.changed(pi, ev.getPercentComplete(), ival)) { ev.setPercentComplete(ival); } break; case POLL_MODE: /* ------------------- Poll mode -------------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollMode(), sval)) { ev.setPollMode(sval); } break; case POLL_PROPERTIES: /* ------------------- Poll properties ---------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollProperties(), sval)) { ev.setPollProperties(sval); } break; case POLL_WINNER: /* ------------------- Poll winner -------------------- */ ival = ((PollWinner)prop).getPollwinner(); if (chg.changed(pi, ev.getPollWinner(), ival)) { ev.setPollWinner(ival); } break; case PRIORITY: /* ------------------- Priority -------------------- */ ival = ((Priority)prop).getLevel(); if (chg.changed(pi, ev.getPriority(), ival)) { ev.setPriority(ival); } break; case RDATE: /* ------------------- RDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case RECURRENCE_ID: /* ------------------- RecurrenceID -------------------- */ // Done above break; case RELATED_TO: /* ------------------- RelatedTo -------------------- */ final RelatedTo irelto = (RelatedTo)prop; final BwRelatedTo relto = new BwRelatedTo(); final String parval = IcalUtil.getParameterVal(irelto, "RELTYPE"); if (parval != null) { relto.setRelType(parval); } relto.setValue(irelto.getValue()); if (chg.changed(pi, ev.getRelatedTo(), relto)) { ev.setRelatedTo(relto); } break; case REQUEST_STATUS: /* ------------------- RequestStatus -------------------- */ final BwRequestStatus rs = BwRequestStatus .fromRequestStatus((RequestStatus)prop); chg.addValue(pi, rs); break; case RESOURCES: /* ------------------- Resources -------------------- */ final TextList rl = ((Resources)prop).getResources(); if (rl != null) { /* Got some resources */ lang = IcalUtil.getLang(prop); for (final String s: rl) { final BwString rsrc = new BwString(lang, s); chg.addValue(pi, rsrc); } } break; case RRULE: /* ------------------- RRule -------------------- */ chg.addValue(pi, pval); break; case SEQUENCE: /* ------------------- Sequence -------------------- */ final int seq = ((Sequence)prop).getSequenceNo(); if (seq != ev.getSequence()) { chg.changed(pi, ev.getSequence(), seq); ev.setSequence(seq); } break; case STATUS: /* ------------------- Status -------------------- */ if (chg.changed(pi, ev.getStatus(), pval)) { ev.setStatus(pval); } break; case SUMMARY: /* ------------------- Summary -------------------- */ if (chg.changed(pi, ev.getSummary(), pval)) { ev.setSummary(pval); } break; case TRANSP: /* ------------------- Transp -------------------- */ if (chg.changed(pi, ev.getPeruserTransparency( cb.getPrincipal() .getPrincipalRef()), pval)) { final BwXproperty pu = ev.setPeruserTransparency( cb.getPrincipal().getPrincipalRef(), pval); if (pu != null) { chg.addValue(PropertyInfoIndex.XPROP, pu); } } break; case UID: /* ------------------- Uid -------------------- */ /* We did this above */ break; case URL: /* ------------------- Url -------------------- */ if (chg.changed(pi, ev.getLink(), pval)) { ev.setLink(pval); } break; case XPROP: /* ------------------------- x-property --------------------------- */ final String name = prop.getName(); if (name.equalsIgnoreCase(BwXproperty.bedeworkCost)) { if (chg.changed(PropertyInfoIndex.COST, ev.getCost(), pval)) { ev.setCost(pval); } break; } if (name.equalsIgnoreCase(BwXproperty.xBedeworkCategories)) { if (checkCategory(cb, chg, ev, null, pval)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkLocation)) { if (checkLocation(cb, chg, ev, prop)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkContact)) { if (checkContact(cb, chg, ev, null, pval)) { break; } } /* See if this is an x-category that can be converted to a real category */ final XProperty xp = (XProperty)prop; chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(name, xp.getParameters() .toString(), pval)); break; default: if (logger.debug()) { logger.debug("Unsupported property with index " + pi + "; class " + prop.getClass() + " and value " + pval); } } } /* =================== Process sub-components =============== */ final ComponentList<Component> subComps; if (val instanceof ComponentContainer) { subComps = ((ComponentContainer<Component>)val).getComponents(); } else { subComps = null; } final Set<Integer> pids; if (vpoll) { pids = new TreeSet<>(); final BwEvent vp = evinfo.getEvent(); if (!Util.isEmpty(vp.getPollItems())) { vp.clearPollItems(); } } else { pids = null; } if (!Util.isEmpty(subComps)) { for (final var subComp: subComps) { if (subComp instanceof Available) { if (!(val instanceof VAvailability)) { return Response.error(resp, "AVAILABLE only valid in VAVAILABLE"); } final var avlResp = processAvailable(cb, cal, ical, (VAvailability)val, (Available)subComp, evinfo); if (!avlResp.isOk()) { return Response.fromResponse(resp, avlResp); } continue; } if (subComp instanceof Participant) { if (vpoll) { final var vresp = processVoter(cb, (VPoll)val, (Participant)subComp, evinfo, chg, mergeAttendees); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Participant object"); continue; } if (subComp instanceof VResource) { logger.warn("Unimplemented VResource object"); continue; } if (subComp instanceof VLocation) { logger.warn("Unimplemented VLocation object"); continue; } if (subComp instanceof VAlarm) { final var aresp = VAlarmUtil.processAlarm(cb, val, (VAlarm)subComp, ev, currentPrincipal, chg); if (!aresp.isOk()) { return Response.fromResponse(resp, aresp); } continue; } if (vpoll && (event || task)) { final var vresp = processCandidate((VPoll)val, subComp, evinfo, pids, chg); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Component object: " + subComp); } } /* Fix up timestamps. */ if (ev.getCreated() == null) { if (ev.getLastmod() != null) { ev.setCreated(ev.getLastmod()); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); } else { ev.updateDtstamp(); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } } if (ev.getLastmod() == null) { // created cannot be null now ev.setLastmod(ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } processTimezones(ev, ical, chg); /* Remove any recipients and originator */ if (ev.getRecipients() != null) { ev.getRecipients().clear(); } ev.setOriginator(null); if (hasXparams.value) { /* Save a text copy of the entire event as an x-property */ final Component valCopy = val.copy(); /* Remove potentially large values */ final Description desp = valCopy.getProperty(Property.DESCRIPTION); if (desp != null) { desp.setValue(null); } final Attach attachp = valCopy.getProperty(Property.ATTACH); // Don't store the entire attachment - we just need the parameters. if (attachp != null) { final Value v = attachp.getParameter(Parameter.VALUE); if (v != null) { attachp.setValue(String.valueOf(attachp.getValue().hashCode())); } } chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(BwXproperty.bedeworkIcal, null, valCopy.toString())); } chg.processChanges(ev, true, false); ev.setRecurring(ev.isRecurringEntity()); if (logger.debug()) { logger.debug(chg.toString()); logger.debug(ev.toString()); } if (masterEI != null) { // Just return notfound as this event is on its override list return Response.notFound(resp); } resp.setEntity(evinfo); return resp; } catch (final Throwable t) { if (logger.debug()) { logger.error(t); } return Response.error(resp, t); } }
NONSATD
true
EventInfo evinfo = null; final BwEvent ev; /* If we have a recurrence id see if we already have the master (we should * get a master + all its overrides). * * If so find the override and use the annnotation or if no override, * make one. * * If no override retrieve the event, add it to our table and then locate the * annotation. * * If there is no annotation, create one. * * It's possible we have been sent 'detached' instances of a recurring * event. This may happen if we are invited to one or more instances of a * meeting. In this case we try to retrieve the master and if it doesn't * exist we manufacture one. We consider such an instance an update to * that instance only and leave the others alone. */ /* We need this in a couple of places */ final DtStart dtStart = pl.getProperty(Property.DTSTART);
ridObj = BwDateTime.makeBwDateTime(ridp); if (ridObj.getRange() != null) { /* XXX What do I do with it? */ logger.warn("TRANS-TO_EVENT: Got a recurrence id range"); } rid = ridObj.getDate(); } EventInfo masterEI = null; EventInfo evinfo = null; final BwEvent ev; /* If we have a recurrence id see if we already have the master (we should * get a master + all its overrides). * * If so find the override and use the annnotation or if no override, * make one. * * If no override retrieve the event, add it to our table and then locate the * annotation. * * If there is no annotation, create one. * * It's possible we have been sent 'detached' instances of a recurring * event. This may happen if we are invited to one or more instances of a * meeting. In this case we try to retrieve the master and if it doesn't * exist we manufacture one. We consider such an instance an update to * that instance only and leave the others alone. */ /* We need this in a couple of places */ final DtStart dtStart = pl.getProperty(Property.DTSTART); /* if (rid != null) { // See if we have a new master event. If so create a proxy to that event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI == null) { masterEI = makeNewEvent(cb, chg, entityType, guid, cal); BwEvent e = masterEI.getEvent(); // XXX This seems bogus
*/ return Response.notOk(resp, failed, CalFacadeException.noGuid); } /* See if we have a recurrence id */ BwDateTime ridObj = null; String rid = null; TimeZone ridTz = null; final RecurrenceId ridp = pl.getProperty(Property.RECURRENCE_ID); if (ridp != null) { testXparams(ridp, hasXparams); ridObj = BwDateTime.makeBwDateTime(ridp); if (ridObj.getRange() != null) { /* XXX What do I do with it? */ logger.warn("TRANS-TO_EVENT: Got a recurrence id range"); } rid = ridObj.getDate(); } EventInfo masterEI = null; EventInfo evinfo = null; final BwEvent ev; /* If we have a recurrence id see if we already have the master (we should * get a master + all its overrides). * * If so find the override and use the annnotation or if no override, * make one. * * If no override retrieve the event, add it to our table and then locate the * annotation. * * If there is no annotation, create one. * * It's possible we have been sent 'detached' instances of a recurring * event. This may happen if we are invited to one or more instances of a * meeting. In this case we try to retrieve the master and if it doesn't * exist we manufacture one. We consider such an instance an update to * that instance only and leave the others alone. */ /* We need this in a couple of places */ final DtStart dtStart = pl.getProperty(Property.DTSTART); /* if (rid != null) { // See if we have a new master event. If so create a proxy to that event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI == null) { masterEI = makeNewEvent(cb, chg, entityType, guid, cal); BwEvent e = masterEI.getEvent(); // XXX This seems bogus DtStart mdtStart; String bogusDate = "19980118T230000"; if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + "Z"); } else if (dtStart.getTimeZone() == null) { mdtStart = new DtStart(bogusDate); } else { mdtStart = new DtStart(bogusDate + "Z", dtStart.getTimeZone()); } setDates(e, mdtStart, null, null, chg);
7,893
8
/* We need this in a couple of places */
public static GetEntityResponse<EventInfo> toEvent( final IcalCallback cb, final BwCalendar cal, final Icalendar ical, final Component val, final boolean mergeAttendees) { final var resp = new GetEntityResponse<EventInfo>(); if (val == null) { return Response.notOk(resp, failed, "No component supplied"); } String currentPrincipal = null; final BwPrincipal principal = cb.getPrincipal(); if (principal != null) { currentPrincipal = principal.getPrincipalRef(); } final Holder<Boolean> hasXparams = new Holder<>(Boolean.FALSE); final int methodType = ical.getMethodType(); String attUri = null; if (mergeAttendees) { // We'll need this later. attUri = cb.getCaladdr(cb.getPrincipal().getPrincipalRef()); } final String colPath; if (cal == null) { colPath = null; } else { colPath = cal.getPath(); } try { final PropertyList<Property> pl = val.getProperties(); boolean vpoll = false; boolean event = false; boolean task = false; if (pl == null) { // Empty component return Response.notOk(resp, failed, "Empty component"); } final int entityType; if (val instanceof VEvent) { entityType = IcalDefs.entityTypeEvent; event = true; } else if (val instanceof VToDo) { entityType = IcalDefs.entityTypeTodo; task = true; } else if (val instanceof VJournal) { entityType = IcalDefs.entityTypeJournal; } else if (val instanceof VFreeBusy) { entityType = IcalDefs.entityTypeFreeAndBusy; } else if (val instanceof VAvailability) { entityType = IcalDefs.entityTypeVavailability; } else if (val instanceof Available) { entityType = IcalDefs.entityTypeAvailable; } else if (val instanceof VPoll) { entityType = IcalDefs.entityTypeVpoll; vpoll = true; } else { return Response.error(resp, "org.bedework.invalid.component.type: " + val.getName()); } // Get the guid from the component String guid = null; final Uid uidp = pl.getProperty(Property.UID); if (uidp != null) { testXparams(uidp, hasXparams); guid = uidp.getValue(); } if (guid == null) { /* XXX A guid is required - but are there devices out there without a * guid - and if so how do we handle it? */ return Response.notOk(resp, failed, CalFacadeException.noGuid); } /* See if we have a recurrence id */ BwDateTime ridObj = null; String rid = null; TimeZone ridTz = null; final RecurrenceId ridp = pl.getProperty(Property.RECURRENCE_ID); if (ridp != null) { testXparams(ridp, hasXparams); ridObj = BwDateTime.makeBwDateTime(ridp); if (ridObj.getRange() != null) { /* XXX What do I do with it? */ logger.warn("TRANS-TO_EVENT: Got a recurrence id range"); } rid = ridObj.getDate(); } EventInfo masterEI = null; EventInfo evinfo = null; final BwEvent ev; /* If we have a recurrence id see if we already have the master (we should * get a master + all its overrides). * * If so find the override and use the annnotation or if no override, * make one. * * If no override retrieve the event, add it to our table and then locate the * annotation. * * If there is no annotation, create one. * * It's possible we have been sent 'detached' instances of a recurring * event. This may happen if we are invited to one or more instances of a * meeting. In this case we try to retrieve the master and if it doesn't * exist we manufacture one. We consider such an instance an update to * that instance only and leave the others alone. */ /* We need this in a couple of places */ final DtStart dtStart = pl.getProperty(Property.DTSTART); /* if (rid != null) { // See if we have a new master event. If so create a proxy to that event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI == null) { masterEI = makeNewEvent(cb, chg, entityType, guid, cal); BwEvent e = masterEI.getEvent(); // XXX This seems bogus DtStart mdtStart; String bogusDate = "19980118T230000"; if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + "Z"); } else if (dtStart.getTimeZone() == null) { mdtStart = new DtStart(bogusDate); } else { mdtStart = new DtStart(bogusDate + "Z", dtStart.getTimeZone()); } setDates(e, mdtStart, null, null, chg); e.setRecurring(true); e.addRdate(ridObj); e.setSuppressed(true); ical.addComponent(masterEI); } if (masterEI != null) { evinfo = masterEI.findOverride(rid); } } */ /* If this is a recurrence instance see if we can find the master We only need this because the master may follow the overrides. */ if (rid != null) { // See if we have a new master event. If so create a proxy to this event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI != null) { evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; } } if ((evinfo == null) && (cal != null) && (cal.getCalType() != BwCalendar.calTypeInbox) && (cal.getCalType() != BwCalendar.calTypePendingInbox) && (cal.getCalType() != BwCalendar.calTypeOutbox)) { if (logger.debug()) { logger.debug("TRANS-TO_EVENT: try to fetch event with guid=" + guid); } final GetEntitiesResponse<EventInfo> eisResp = cb.getEvent(colPath, guid); if (eisResp.isError()) { return Response.fromResponse(resp, eisResp); } final var eis = eisResp.getEntities(); if (!Util.isEmpty(eis)) { if (eis.size() > 1) { // DORECUR - wrong again return Response.notOk(resp, failed, "More than one event returned for guid."); } evinfo = eis.iterator().next(); } if (logger.debug()) { if (evinfo != null) { logger.debug("TRANS-TO_EVENT: fetched event with guid"); } else { logger.debug("TRANS-TO_EVENT: did not find event with guid"); } } if (evinfo != null) { if (rid != null) { // We just retrieved it's master masterEI = evinfo; masterEI.setInstanceOnly(true); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; ical.addComponent(masterEI); } else if (methodType == ScheduleMethods.methodTypeCancel) { // This should never have an rid for cancel of entire event. evinfo.setInstanceOnly(evinfo.getEvent().getSuppressed()); } else { // Presumably sent an update for the entire event. No longer suppressed master evinfo.getEvent().setSuppressed(false); } } else if (rid != null) { /* Manufacture a master for the instance */ masterEI = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); final BwEvent e = masterEI.getEvent(); // XXX This seems bogus final DtStart mdtStart; final String bogusDate = "19980118"; final String bogusTime = "T230000"; // Base dtstart on the recurrence id. final boolean isDateType = ridObj.getDateType(); if (isDateType) { mdtStart = new DtStart(new Date(bogusDate)); } else if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + bogusTime + "Z"); } else if (ridObj.getTzid() == null) { mdtStart = new DtStart(bogusDate + bogusTime); } else { mdtStart = new DtStart(bogusDate + bogusTime, Timezones.getTz(ridObj.getTzid())); } IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), masterEI, mdtStart, null, null); e.setRecurring(true); // e.addRdate(ridObj); final var sum = (Summary)pl.getProperty(Property.SUMMARY); e.setSummary(sum.getValue()); e.setSuppressed(true); ical.addComponent(masterEI); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; masterEI.setInstanceOnly(rid != null); } } if (evinfo == null) { evinfo = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); } else if (evinfo.getEvent().getEntityType() != entityType) { return Response.notOk(resp, failed, "org.bedework.mismatched.entity.type: " + val); } final ChangeTable chg = evinfo.getChangeset( cb.getPrincipal().getPrincipalRef()); if (rid != null) { final String evrid = evinfo.getEvent().getRecurrenceId(); if ((evrid == null) || (!evrid.equals(rid))) { logger. warn("Mismatched rid ev=" + evrid + " expected " + rid); chg.changed(PropertyInfoIndex.RECURRENCE_ID, evrid, rid); // XXX spurious??? } if (masterEI.getEvent().getSuppressed()) { masterEI.getEvent().addRdate(ridObj); } } ev = evinfo.getEvent(); ev.setScheduleMethod(methodType); DtEnd dtEnd = null; if (entityType == IcalDefs.entityTypeTodo) { final Due due = pl.getProperty(Property.DUE); if (due != null ) { dtEnd = new DtEnd(due.getParameters(), due.getValue()); } } else { dtEnd = pl.getProperty(Property.DTEND); } final Duration duration = pl.getProperty(Property.DURATION); IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), evinfo, dtStart, dtEnd, duration); for (final Property prop: pl) { testXparams(prop, hasXparams); //debug("ical prop " + prop.getClass().getName()); String pval = prop.getValue(); if ((pval != null) && (pval.length() == 0)) { pval = null; } final PropertyInfoIndex pi; if (prop instanceof XProperty) { pi = PropertyInfoIndex.XPROP; } else { pi = PropertyInfoIndex.fromName(prop.getName()); } if (pi == null) { logger.debug("Unknown property with name " + prop.getName() + " class " + prop.getClass() + " and value " + pval); continue; } chg.present(pi); switch (pi) { case ACCEPT_RESPONSE: /* ------------------- Accept Response -------------------- */ String sval = prop.getValue(); if (chg.changed(pi, ev.getPollAcceptResponse(), sval)) { ev.setPollAcceptResponse(sval); } break; case ATTACH: /* ------------------- Attachment -------------------- */ chg.addValue(pi, IcalUtil.getAttachment((Attach)prop)); break; case ATTENDEE: /* ------------------- Attendee -------------------- */ if (methodType == ScheduleMethods.methodTypePublish) { if (cb.getStrictness() == IcalCallback.conformanceStrict) { return Response.notOk(resp, failed, CalFacadeException.attendeesInPublish); } //if (cb.getStrictness() == IcalCallback.conformanceWarn) { // warn("Had attendees for PUBLISH"); //} } final Attendee attPr = (Attendee)prop; if (evinfo.getNewEvent() || !mergeAttendees) { chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { final String pUri = cb.getCaladdr(attPr.getValue()); if (pUri.equals(attUri)) { /* Only update for our own attendee * We're doing a PUT and this must be the attendee updating their * partstat. We don't allow them to change other attendees * whatever the PUT content says. */ chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { // Use the value we currently have boolean found = false; for (final BwAttendee att: ev.getAttendees()) { if (pUri.equals(att.getAttendeeUri())) { chg.addValue(pi, att.clone()); found = true; break; } } if (!found) { // An added attendee final BwAttendee att = IcalUtil .getAttendee(cb, attPr); att.setPartstat(IcalDefs.partstatValNeedsAction); chg.addValue(pi, att); } } } break; case BUSYTYPE: final int ibt = BwEvent.fromBusyTypeString(pval); if (chg.changed(pi, ev.getBusyType(), ibt)) { ev.setBusyType(ibt); } break; case CATEGORIES: /* ------------------- Categories -------------------- */ final Categories cats = (Categories)prop; final TextList cl = cats.getCategories(); String lang = IcalUtil.getLang(cats); if (cl != null) { /* Got some categories */ for (final String wd: cl) { if (wd == null) { continue; } final BwString key = new BwString(lang, wd); final var fcResp = cb.findCategory(key); final BwCategory cat; if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isNotFound()) { cat = BwCategory.makeCategory(); cat.setWord(key); cb.addCategory(cat); } else { cat = fcResp.getEntity(); } chg.addValue(pi, cat); } } break; case CLASS: /* ------------------- Class -------------------- */ if (chg.changed(pi, ev.getClassification(), pval)) { ev.setClassification(pval); } break; case COMMENT: /* ------------------- Comment -------------------- */ chg.addValue(pi, new BwString(null, pval)); break; case COMPLETED: /* ------------------- Completed -------------------- */ if (chg.changed(pi, ev.getCompleted(), pval)) { ev.setCompleted(pval); } break; case CONCEPT: /* ------------------- Concept -------------------- */ final Concept c = (Concept)prop; final String cval = c.getValue(); if (cval != null) { /* Got a concept */ chg.addValue(PropertyInfoIndex.XPROP, BwXproperty.makeIcalProperty("CONCEPT", null, cval)); } break; case CONTACT: /* ------------------- Contact -------------------- */ final String altrep = getAltRepPar(prop); lang = IcalUtil.getLang(prop); final String uid = getUidPar(prop); final BwString nm = new BwString(lang, pval); BwContact contact = null; if (uid != null) { final var fcResp = cb.getContact(uid); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { final var fcResp = cb.findContact(nm); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { contact = BwContact.makeContact(); contact.setCn(nm); contact.setLink(altrep); cb.addContact(contact); } else { contact.setCn(nm); contact.setLink(altrep); } chg.addValue(pi, contact); break; case CREATED: /* ------------------- Created -------------------- */ if (chg.changed(pi, ev.getCreated(), pval)) { ev.setCreated(pval); } break; case DESCRIPTION: /* ------------------- Description -------------------- */ if (chg.changed(pi, ev.getDescription(), pval)) { ev.setDescription(pval); } break; case DTEND: /* ------------------- DtEnd -------------------- */ break; case DTSTAMP: /* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval); break; case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE: /* -------------------- Due ------------------------ */ break; case DURATION: /* ------------------- Duration -------------------- */ break; case EXDATE: /* ------------------- ExDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case EXRULE: /* ------------------- ExRule -------------------- */ chg.addValue(pi, pval); break; case FREEBUSY: /* ------------------- freebusy -------------------- */ final FreeBusy fbusy = (FreeBusy)prop; final PeriodList perpl = fbusy.getPeriods(); final Parameter par = IcalUtil.getParameter(fbusy, "FBTYPE"); final int fbtype; if (par == null) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY)) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY_TENTATIVE)) { fbtype = BwFreeBusyComponent.typeBusyTentative; } else if (par.equals(FbType.BUSY_UNAVAILABLE)) { fbtype = BwFreeBusyComponent.typeBusyUnavailable; } else if (par.equals(FbType.FREE)) { fbtype = BwFreeBusyComponent.typeFree; } else { if (logger.debug()) { logger.debug("Unsupported parameter " + par.getName()); } return Response.notOk(resp, failed, "Unsupported parameter " + par.getName()); } final BwFreeBusyComponent fbc = new BwFreeBusyComponent(); fbc.setType(fbtype); for (final Period per : perpl) { fbc.addPeriod(per); } ev.addFreeBusyPeriod(fbc); break; case GEO: /* ------------------- Geo -------------------- */ final Geo g = (Geo)prop; final BwGeo geo = new BwGeo(g.getLatitude(), g.getLongitude()); if (chg.changed(pi, ev.getGeo(), geo)) { ev.setGeo(geo); } break; case LAST_MODIFIED: /* ------------------- LastModified -------------------- */ if (chg.changed(pi, ev.getLastmod(), pval)) { ev.setLastmod(pval); } break; case LOCATION: /* ------------------- Location -------------------- */ BwLocation loc = null; //String uid = getUidPar(prop); /* At the moment Mozilla lightning is broken and this leads to all * sorts of problems. if (uid != null) { loc = cb.getLocation(uid); } */ lang = IcalUtil.getLang(prop); BwString addr = null; if (pval != null) { if (loc == null) { addr = new BwString(lang, pval); final var fcResp = cb.findLocation(addr); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { loc = fcResp.getEntity(); } } if (loc == null) { loc = BwLocation.makeLocation(); loc.setAddress(addr); cb.addLocation(loc); } } final BwLocation evloc = ev.getLocation(); if (chg.changed(pi, evloc, loc)) { // CHGTBL - this only shows that it's a different location object ev.setLocation(loc); } else if ((loc != null) && (evloc != null)) { // See if the value is changed final String evval = evloc.getAddress().getValue(); final String inval = loc.getAddress().getValue(); if (!evval.equals(inval)) { chg.changed(pi, evval, inval); evloc.getAddress().setValue(inval); } } break; case ORGANIZER: /* ------------------- Organizer -------------------- */ final BwOrganizer org = IcalUtil.getOrganizer(cb, (Organizer)prop); final BwOrganizer evorg = ev.getOrganizer(); final BwOrganizer evorgCopy; if (evorg == null) { evorgCopy = null; } else { evorgCopy = (BwOrganizer)evorg.clone(); } if (chg.changed(pi, evorgCopy, org)) { if (evorg == null) { ev.setOrganizer(org); } else { evorg.update(org); } } break; case PERCENT_COMPLETE: /* ------------------- PercentComplete -------------------- */ Integer ival = ((PercentComplete)prop).getPercentage(); if (chg.changed(pi, ev.getPercentComplete(), ival)) { ev.setPercentComplete(ival); } break; case POLL_MODE: /* ------------------- Poll mode -------------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollMode(), sval)) { ev.setPollMode(sval); } break; case POLL_PROPERTIES: /* ------------------- Poll properties ---------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollProperties(), sval)) { ev.setPollProperties(sval); } break; case POLL_WINNER: /* ------------------- Poll winner -------------------- */ ival = ((PollWinner)prop).getPollwinner(); if (chg.changed(pi, ev.getPollWinner(), ival)) { ev.setPollWinner(ival); } break; case PRIORITY: /* ------------------- Priority -------------------- */ ival = ((Priority)prop).getLevel(); if (chg.changed(pi, ev.getPriority(), ival)) { ev.setPriority(ival); } break; case RDATE: /* ------------------- RDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case RECURRENCE_ID: /* ------------------- RecurrenceID -------------------- */ // Done above break; case RELATED_TO: /* ------------------- RelatedTo -------------------- */ final RelatedTo irelto = (RelatedTo)prop; final BwRelatedTo relto = new BwRelatedTo(); final String parval = IcalUtil.getParameterVal(irelto, "RELTYPE"); if (parval != null) { relto.setRelType(parval); } relto.setValue(irelto.getValue()); if (chg.changed(pi, ev.getRelatedTo(), relto)) { ev.setRelatedTo(relto); } break; case REQUEST_STATUS: /* ------------------- RequestStatus -------------------- */ final BwRequestStatus rs = BwRequestStatus .fromRequestStatus((RequestStatus)prop); chg.addValue(pi, rs); break; case RESOURCES: /* ------------------- Resources -------------------- */ final TextList rl = ((Resources)prop).getResources(); if (rl != null) { /* Got some resources */ lang = IcalUtil.getLang(prop); for (final String s: rl) { final BwString rsrc = new BwString(lang, s); chg.addValue(pi, rsrc); } } break; case RRULE: /* ------------------- RRule -------------------- */ chg.addValue(pi, pval); break; case SEQUENCE: /* ------------------- Sequence -------------------- */ final int seq = ((Sequence)prop).getSequenceNo(); if (seq != ev.getSequence()) { chg.changed(pi, ev.getSequence(), seq); ev.setSequence(seq); } break; case STATUS: /* ------------------- Status -------------------- */ if (chg.changed(pi, ev.getStatus(), pval)) { ev.setStatus(pval); } break; case SUMMARY: /* ------------------- Summary -------------------- */ if (chg.changed(pi, ev.getSummary(), pval)) { ev.setSummary(pval); } break; case TRANSP: /* ------------------- Transp -------------------- */ if (chg.changed(pi, ev.getPeruserTransparency( cb.getPrincipal() .getPrincipalRef()), pval)) { final BwXproperty pu = ev.setPeruserTransparency( cb.getPrincipal().getPrincipalRef(), pval); if (pu != null) { chg.addValue(PropertyInfoIndex.XPROP, pu); } } break; case UID: /* ------------------- Uid -------------------- */ /* We did this above */ break; case URL: /* ------------------- Url -------------------- */ if (chg.changed(pi, ev.getLink(), pval)) { ev.setLink(pval); } break; case XPROP: /* ------------------------- x-property --------------------------- */ final String name = prop.getName(); if (name.equalsIgnoreCase(BwXproperty.bedeworkCost)) { if (chg.changed(PropertyInfoIndex.COST, ev.getCost(), pval)) { ev.setCost(pval); } break; } if (name.equalsIgnoreCase(BwXproperty.xBedeworkCategories)) { if (checkCategory(cb, chg, ev, null, pval)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkLocation)) { if (checkLocation(cb, chg, ev, prop)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkContact)) { if (checkContact(cb, chg, ev, null, pval)) { break; } } /* See if this is an x-category that can be converted to a real category */ final XProperty xp = (XProperty)prop; chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(name, xp.getParameters() .toString(), pval)); break; default: if (logger.debug()) { logger.debug("Unsupported property with index " + pi + "; class " + prop.getClass() + " and value " + pval); } } } /* =================== Process sub-components =============== */ final ComponentList<Component> subComps; if (val instanceof ComponentContainer) { subComps = ((ComponentContainer<Component>)val).getComponents(); } else { subComps = null; } final Set<Integer> pids; if (vpoll) { pids = new TreeSet<>(); final BwEvent vp = evinfo.getEvent(); if (!Util.isEmpty(vp.getPollItems())) { vp.clearPollItems(); } } else { pids = null; } if (!Util.isEmpty(subComps)) { for (final var subComp: subComps) { if (subComp instanceof Available) { if (!(val instanceof VAvailability)) { return Response.error(resp, "AVAILABLE only valid in VAVAILABLE"); } final var avlResp = processAvailable(cb, cal, ical, (VAvailability)val, (Available)subComp, evinfo); if (!avlResp.isOk()) { return Response.fromResponse(resp, avlResp); } continue; } if (subComp instanceof Participant) { if (vpoll) { final var vresp = processVoter(cb, (VPoll)val, (Participant)subComp, evinfo, chg, mergeAttendees); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Participant object"); continue; } if (subComp instanceof VResource) { logger.warn("Unimplemented VResource object"); continue; } if (subComp instanceof VLocation) { logger.warn("Unimplemented VLocation object"); continue; } if (subComp instanceof VAlarm) { final var aresp = VAlarmUtil.processAlarm(cb, val, (VAlarm)subComp, ev, currentPrincipal, chg); if (!aresp.isOk()) { return Response.fromResponse(resp, aresp); } continue; } if (vpoll && (event || task)) { final var vresp = processCandidate((VPoll)val, subComp, evinfo, pids, chg); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Component object: " + subComp); } } /* Fix up timestamps. */ if (ev.getCreated() == null) { if (ev.getLastmod() != null) { ev.setCreated(ev.getLastmod()); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); } else { ev.updateDtstamp(); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } } if (ev.getLastmod() == null) { // created cannot be null now ev.setLastmod(ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } processTimezones(ev, ical, chg); /* Remove any recipients and originator */ if (ev.getRecipients() != null) { ev.getRecipients().clear(); } ev.setOriginator(null); if (hasXparams.value) { /* Save a text copy of the entire event as an x-property */ final Component valCopy = val.copy(); /* Remove potentially large values */ final Description desp = valCopy.getProperty(Property.DESCRIPTION); if (desp != null) { desp.setValue(null); } final Attach attachp = valCopy.getProperty(Property.ATTACH); // Don't store the entire attachment - we just need the parameters. if (attachp != null) { final Value v = attachp.getParameter(Parameter.VALUE); if (v != null) { attachp.setValue(String.valueOf(attachp.getValue().hashCode())); } } chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(BwXproperty.bedeworkIcal, null, valCopy.toString())); } chg.processChanges(ev, true, false); ev.setRecurring(ev.isRecurringEntity()); if (logger.debug()) { logger.debug(chg.toString()); logger.debug(ev.toString()); } if (masterEI != null) { // Just return notfound as this event is on its override list return Response.notFound(resp); } resp.setEntity(evinfo); return resp; } catch (final Throwable t) { if (logger.debug()) { logger.error(t); } return Response.error(resp, t); } }
NONSATD
true
* that instance only and leave the others alone. */ /* We need this in a couple of places */ final DtStart dtStart = pl.getProperty(Property.DTSTART); /*
* annotation. * * If there is no annotation, create one. * * It's possible we have been sent 'detached' instances of a recurring * event. This may happen if we are invited to one or more instances of a * meeting. In this case we try to retrieve the master and if it doesn't * exist we manufacture one. We consider such an instance an update to * that instance only and leave the others alone. */ /* We need this in a couple of places */ final DtStart dtStart = pl.getProperty(Property.DTSTART); /* if (rid != null) { // See if we have a new master event. If so create a proxy to that event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI == null) { masterEI = makeNewEvent(cb, chg, entityType, guid, cal); BwEvent e = masterEI.getEvent(); // XXX This seems bogus DtStart mdtStart;
EventInfo masterEI = null; EventInfo evinfo = null; final BwEvent ev; /* If we have a recurrence id see if we already have the master (we should * get a master + all its overrides). * * If so find the override and use the annnotation or if no override, * make one. * * If no override retrieve the event, add it to our table and then locate the * annotation. * * If there is no annotation, create one. * * It's possible we have been sent 'detached' instances of a recurring * event. This may happen if we are invited to one or more instances of a * meeting. In this case we try to retrieve the master and if it doesn't * exist we manufacture one. We consider such an instance an update to * that instance only and leave the others alone. */ /* We need this in a couple of places */ final DtStart dtStart = pl.getProperty(Property.DTSTART); /* if (rid != null) { // See if we have a new master event. If so create a proxy to that event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI == null) { masterEI = makeNewEvent(cb, chg, entityType, guid, cal); BwEvent e = masterEI.getEvent(); // XXX This seems bogus DtStart mdtStart; String bogusDate = "19980118T230000"; if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + "Z"); } else if (dtStart.getTimeZone() == null) { mdtStart = new DtStart(bogusDate); } else { mdtStart = new DtStart(bogusDate + "Z", dtStart.getTimeZone()); } setDates(e, mdtStart, null, null, chg); e.setRecurring(true);
7,893
9
/* if (rid != null) { // See if we have a new master event. If so create a proxy to that event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI == null) { masterEI = makeNewEvent(cb, chg, entityType, guid, cal); BwEvent e = masterEI.getEvent(); // XXX This seems bogus DtStart mdtStart; String bogusDate = "19980118T230000"; if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + "Z"); } else if (dtStart.getTimeZone() == null) { mdtStart = new DtStart(bogusDate); } else { mdtStart = new DtStart(bogusDate + "Z", dtStart.getTimeZone()); } setDates(e, mdtStart, null, null, chg); e.setRecurring(true); e.addRdate(ridObj); e.setSuppressed(true); ical.addComponent(masterEI); } if (masterEI != null) { evinfo = masterEI.findOverride(rid); } } */
public static GetEntityResponse<EventInfo> toEvent( final IcalCallback cb, final BwCalendar cal, final Icalendar ical, final Component val, final boolean mergeAttendees) { final var resp = new GetEntityResponse<EventInfo>(); if (val == null) { return Response.notOk(resp, failed, "No component supplied"); } String currentPrincipal = null; final BwPrincipal principal = cb.getPrincipal(); if (principal != null) { currentPrincipal = principal.getPrincipalRef(); } final Holder<Boolean> hasXparams = new Holder<>(Boolean.FALSE); final int methodType = ical.getMethodType(); String attUri = null; if (mergeAttendees) { // We'll need this later. attUri = cb.getCaladdr(cb.getPrincipal().getPrincipalRef()); } final String colPath; if (cal == null) { colPath = null; } else { colPath = cal.getPath(); } try { final PropertyList<Property> pl = val.getProperties(); boolean vpoll = false; boolean event = false; boolean task = false; if (pl == null) { // Empty component return Response.notOk(resp, failed, "Empty component"); } final int entityType; if (val instanceof VEvent) { entityType = IcalDefs.entityTypeEvent; event = true; } else if (val instanceof VToDo) { entityType = IcalDefs.entityTypeTodo; task = true; } else if (val instanceof VJournal) { entityType = IcalDefs.entityTypeJournal; } else if (val instanceof VFreeBusy) { entityType = IcalDefs.entityTypeFreeAndBusy; } else if (val instanceof VAvailability) { entityType = IcalDefs.entityTypeVavailability; } else if (val instanceof Available) { entityType = IcalDefs.entityTypeAvailable; } else if (val instanceof VPoll) { entityType = IcalDefs.entityTypeVpoll; vpoll = true; } else { return Response.error(resp, "org.bedework.invalid.component.type: " + val.getName()); } // Get the guid from the component String guid = null; final Uid uidp = pl.getProperty(Property.UID); if (uidp != null) { testXparams(uidp, hasXparams); guid = uidp.getValue(); } if (guid == null) { /* XXX A guid is required - but are there devices out there without a * guid - and if so how do we handle it? */ return Response.notOk(resp, failed, CalFacadeException.noGuid); } /* See if we have a recurrence id */ BwDateTime ridObj = null; String rid = null; TimeZone ridTz = null; final RecurrenceId ridp = pl.getProperty(Property.RECURRENCE_ID); if (ridp != null) { testXparams(ridp, hasXparams); ridObj = BwDateTime.makeBwDateTime(ridp); if (ridObj.getRange() != null) { /* XXX What do I do with it? */ logger.warn("TRANS-TO_EVENT: Got a recurrence id range"); } rid = ridObj.getDate(); } EventInfo masterEI = null; EventInfo evinfo = null; final BwEvent ev; /* If we have a recurrence id see if we already have the master (we should * get a master + all its overrides). * * If so find the override and use the annnotation or if no override, * make one. * * If no override retrieve the event, add it to our table and then locate the * annotation. * * If there is no annotation, create one. * * It's possible we have been sent 'detached' instances of a recurring * event. This may happen if we are invited to one or more instances of a * meeting. In this case we try to retrieve the master and if it doesn't * exist we manufacture one. We consider such an instance an update to * that instance only and leave the others alone. */ /* We need this in a couple of places */ final DtStart dtStart = pl.getProperty(Property.DTSTART); /* if (rid != null) { // See if we have a new master event. If so create a proxy to that event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI == null) { masterEI = makeNewEvent(cb, chg, entityType, guid, cal); BwEvent e = masterEI.getEvent(); // XXX This seems bogus DtStart mdtStart; String bogusDate = "19980118T230000"; if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + "Z"); } else if (dtStart.getTimeZone() == null) { mdtStart = new DtStart(bogusDate); } else { mdtStart = new DtStart(bogusDate + "Z", dtStart.getTimeZone()); } setDates(e, mdtStart, null, null, chg); e.setRecurring(true); e.addRdate(ridObj); e.setSuppressed(true); ical.addComponent(masterEI); } if (masterEI != null) { evinfo = masterEI.findOverride(rid); } } */ /* If this is a recurrence instance see if we can find the master We only need this because the master may follow the overrides. */ if (rid != null) { // See if we have a new master event. If so create a proxy to this event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI != null) { evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; } } if ((evinfo == null) && (cal != null) && (cal.getCalType() != BwCalendar.calTypeInbox) && (cal.getCalType() != BwCalendar.calTypePendingInbox) && (cal.getCalType() != BwCalendar.calTypeOutbox)) { if (logger.debug()) { logger.debug("TRANS-TO_EVENT: try to fetch event with guid=" + guid); } final GetEntitiesResponse<EventInfo> eisResp = cb.getEvent(colPath, guid); if (eisResp.isError()) { return Response.fromResponse(resp, eisResp); } final var eis = eisResp.getEntities(); if (!Util.isEmpty(eis)) { if (eis.size() > 1) { // DORECUR - wrong again return Response.notOk(resp, failed, "More than one event returned for guid."); } evinfo = eis.iterator().next(); } if (logger.debug()) { if (evinfo != null) { logger.debug("TRANS-TO_EVENT: fetched event with guid"); } else { logger.debug("TRANS-TO_EVENT: did not find event with guid"); } } if (evinfo != null) { if (rid != null) { // We just retrieved it's master masterEI = evinfo; masterEI.setInstanceOnly(true); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; ical.addComponent(masterEI); } else if (methodType == ScheduleMethods.methodTypeCancel) { // This should never have an rid for cancel of entire event. evinfo.setInstanceOnly(evinfo.getEvent().getSuppressed()); } else { // Presumably sent an update for the entire event. No longer suppressed master evinfo.getEvent().setSuppressed(false); } } else if (rid != null) { /* Manufacture a master for the instance */ masterEI = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); final BwEvent e = masterEI.getEvent(); // XXX This seems bogus final DtStart mdtStart; final String bogusDate = "19980118"; final String bogusTime = "T230000"; // Base dtstart on the recurrence id. final boolean isDateType = ridObj.getDateType(); if (isDateType) { mdtStart = new DtStart(new Date(bogusDate)); } else if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + bogusTime + "Z"); } else if (ridObj.getTzid() == null) { mdtStart = new DtStart(bogusDate + bogusTime); } else { mdtStart = new DtStart(bogusDate + bogusTime, Timezones.getTz(ridObj.getTzid())); } IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), masterEI, mdtStart, null, null); e.setRecurring(true); // e.addRdate(ridObj); final var sum = (Summary)pl.getProperty(Property.SUMMARY); e.setSummary(sum.getValue()); e.setSuppressed(true); ical.addComponent(masterEI); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; masterEI.setInstanceOnly(rid != null); } } if (evinfo == null) { evinfo = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); } else if (evinfo.getEvent().getEntityType() != entityType) { return Response.notOk(resp, failed, "org.bedework.mismatched.entity.type: " + val); } final ChangeTable chg = evinfo.getChangeset( cb.getPrincipal().getPrincipalRef()); if (rid != null) { final String evrid = evinfo.getEvent().getRecurrenceId(); if ((evrid == null) || (!evrid.equals(rid))) { logger. warn("Mismatched rid ev=" + evrid + " expected " + rid); chg.changed(PropertyInfoIndex.RECURRENCE_ID, evrid, rid); // XXX spurious??? } if (masterEI.getEvent().getSuppressed()) { masterEI.getEvent().addRdate(ridObj); } } ev = evinfo.getEvent(); ev.setScheduleMethod(methodType); DtEnd dtEnd = null; if (entityType == IcalDefs.entityTypeTodo) { final Due due = pl.getProperty(Property.DUE); if (due != null ) { dtEnd = new DtEnd(due.getParameters(), due.getValue()); } } else { dtEnd = pl.getProperty(Property.DTEND); } final Duration duration = pl.getProperty(Property.DURATION); IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), evinfo, dtStart, dtEnd, duration); for (final Property prop: pl) { testXparams(prop, hasXparams); //debug("ical prop " + prop.getClass().getName()); String pval = prop.getValue(); if ((pval != null) && (pval.length() == 0)) { pval = null; } final PropertyInfoIndex pi; if (prop instanceof XProperty) { pi = PropertyInfoIndex.XPROP; } else { pi = PropertyInfoIndex.fromName(prop.getName()); } if (pi == null) { logger.debug("Unknown property with name " + prop.getName() + " class " + prop.getClass() + " and value " + pval); continue; } chg.present(pi); switch (pi) { case ACCEPT_RESPONSE: /* ------------------- Accept Response -------------------- */ String sval = prop.getValue(); if (chg.changed(pi, ev.getPollAcceptResponse(), sval)) { ev.setPollAcceptResponse(sval); } break; case ATTACH: /* ------------------- Attachment -------------------- */ chg.addValue(pi, IcalUtil.getAttachment((Attach)prop)); break; case ATTENDEE: /* ------------------- Attendee -------------------- */ if (methodType == ScheduleMethods.methodTypePublish) { if (cb.getStrictness() == IcalCallback.conformanceStrict) { return Response.notOk(resp, failed, CalFacadeException.attendeesInPublish); } //if (cb.getStrictness() == IcalCallback.conformanceWarn) { // warn("Had attendees for PUBLISH"); //} } final Attendee attPr = (Attendee)prop; if (evinfo.getNewEvent() || !mergeAttendees) { chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { final String pUri = cb.getCaladdr(attPr.getValue()); if (pUri.equals(attUri)) { /* Only update for our own attendee * We're doing a PUT and this must be the attendee updating their * partstat. We don't allow them to change other attendees * whatever the PUT content says. */ chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { // Use the value we currently have boolean found = false; for (final BwAttendee att: ev.getAttendees()) { if (pUri.equals(att.getAttendeeUri())) { chg.addValue(pi, att.clone()); found = true; break; } } if (!found) { // An added attendee final BwAttendee att = IcalUtil .getAttendee(cb, attPr); att.setPartstat(IcalDefs.partstatValNeedsAction); chg.addValue(pi, att); } } } break; case BUSYTYPE: final int ibt = BwEvent.fromBusyTypeString(pval); if (chg.changed(pi, ev.getBusyType(), ibt)) { ev.setBusyType(ibt); } break; case CATEGORIES: /* ------------------- Categories -------------------- */ final Categories cats = (Categories)prop; final TextList cl = cats.getCategories(); String lang = IcalUtil.getLang(cats); if (cl != null) { /* Got some categories */ for (final String wd: cl) { if (wd == null) { continue; } final BwString key = new BwString(lang, wd); final var fcResp = cb.findCategory(key); final BwCategory cat; if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isNotFound()) { cat = BwCategory.makeCategory(); cat.setWord(key); cb.addCategory(cat); } else { cat = fcResp.getEntity(); } chg.addValue(pi, cat); } } break; case CLASS: /* ------------------- Class -------------------- */ if (chg.changed(pi, ev.getClassification(), pval)) { ev.setClassification(pval); } break; case COMMENT: /* ------------------- Comment -------------------- */ chg.addValue(pi, new BwString(null, pval)); break; case COMPLETED: /* ------------------- Completed -------------------- */ if (chg.changed(pi, ev.getCompleted(), pval)) { ev.setCompleted(pval); } break; case CONCEPT: /* ------------------- Concept -------------------- */ final Concept c = (Concept)prop; final String cval = c.getValue(); if (cval != null) { /* Got a concept */ chg.addValue(PropertyInfoIndex.XPROP, BwXproperty.makeIcalProperty("CONCEPT", null, cval)); } break; case CONTACT: /* ------------------- Contact -------------------- */ final String altrep = getAltRepPar(prop); lang = IcalUtil.getLang(prop); final String uid = getUidPar(prop); final BwString nm = new BwString(lang, pval); BwContact contact = null; if (uid != null) { final var fcResp = cb.getContact(uid); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { final var fcResp = cb.findContact(nm); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { contact = BwContact.makeContact(); contact.setCn(nm); contact.setLink(altrep); cb.addContact(contact); } else { contact.setCn(nm); contact.setLink(altrep); } chg.addValue(pi, contact); break; case CREATED: /* ------------------- Created -------------------- */ if (chg.changed(pi, ev.getCreated(), pval)) { ev.setCreated(pval); } break; case DESCRIPTION: /* ------------------- Description -------------------- */ if (chg.changed(pi, ev.getDescription(), pval)) { ev.setDescription(pval); } break; case DTEND: /* ------------------- DtEnd -------------------- */ break; case DTSTAMP: /* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval); break; case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE: /* -------------------- Due ------------------------ */ break; case DURATION: /* ------------------- Duration -------------------- */ break; case EXDATE: /* ------------------- ExDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case EXRULE: /* ------------------- ExRule -------------------- */ chg.addValue(pi, pval); break; case FREEBUSY: /* ------------------- freebusy -------------------- */ final FreeBusy fbusy = (FreeBusy)prop; final PeriodList perpl = fbusy.getPeriods(); final Parameter par = IcalUtil.getParameter(fbusy, "FBTYPE"); final int fbtype; if (par == null) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY)) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY_TENTATIVE)) { fbtype = BwFreeBusyComponent.typeBusyTentative; } else if (par.equals(FbType.BUSY_UNAVAILABLE)) { fbtype = BwFreeBusyComponent.typeBusyUnavailable; } else if (par.equals(FbType.FREE)) { fbtype = BwFreeBusyComponent.typeFree; } else { if (logger.debug()) { logger.debug("Unsupported parameter " + par.getName()); } return Response.notOk(resp, failed, "Unsupported parameter " + par.getName()); } final BwFreeBusyComponent fbc = new BwFreeBusyComponent(); fbc.setType(fbtype); for (final Period per : perpl) { fbc.addPeriod(per); } ev.addFreeBusyPeriod(fbc); break; case GEO: /* ------------------- Geo -------------------- */ final Geo g = (Geo)prop; final BwGeo geo = new BwGeo(g.getLatitude(), g.getLongitude()); if (chg.changed(pi, ev.getGeo(), geo)) { ev.setGeo(geo); } break; case LAST_MODIFIED: /* ------------------- LastModified -------------------- */ if (chg.changed(pi, ev.getLastmod(), pval)) { ev.setLastmod(pval); } break; case LOCATION: /* ------------------- Location -------------------- */ BwLocation loc = null; //String uid = getUidPar(prop); /* At the moment Mozilla lightning is broken and this leads to all * sorts of problems. if (uid != null) { loc = cb.getLocation(uid); } */ lang = IcalUtil.getLang(prop); BwString addr = null; if (pval != null) { if (loc == null) { addr = new BwString(lang, pval); final var fcResp = cb.findLocation(addr); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { loc = fcResp.getEntity(); } } if (loc == null) { loc = BwLocation.makeLocation(); loc.setAddress(addr); cb.addLocation(loc); } } final BwLocation evloc = ev.getLocation(); if (chg.changed(pi, evloc, loc)) { // CHGTBL - this only shows that it's a different location object ev.setLocation(loc); } else if ((loc != null) && (evloc != null)) { // See if the value is changed final String evval = evloc.getAddress().getValue(); final String inval = loc.getAddress().getValue(); if (!evval.equals(inval)) { chg.changed(pi, evval, inval); evloc.getAddress().setValue(inval); } } break; case ORGANIZER: /* ------------------- Organizer -------------------- */ final BwOrganizer org = IcalUtil.getOrganizer(cb, (Organizer)prop); final BwOrganizer evorg = ev.getOrganizer(); final BwOrganizer evorgCopy; if (evorg == null) { evorgCopy = null; } else { evorgCopy = (BwOrganizer)evorg.clone(); } if (chg.changed(pi, evorgCopy, org)) { if (evorg == null) { ev.setOrganizer(org); } else { evorg.update(org); } } break; case PERCENT_COMPLETE: /* ------------------- PercentComplete -------------------- */ Integer ival = ((PercentComplete)prop).getPercentage(); if (chg.changed(pi, ev.getPercentComplete(), ival)) { ev.setPercentComplete(ival); } break; case POLL_MODE: /* ------------------- Poll mode -------------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollMode(), sval)) { ev.setPollMode(sval); } break; case POLL_PROPERTIES: /* ------------------- Poll properties ---------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollProperties(), sval)) { ev.setPollProperties(sval); } break; case POLL_WINNER: /* ------------------- Poll winner -------------------- */ ival = ((PollWinner)prop).getPollwinner(); if (chg.changed(pi, ev.getPollWinner(), ival)) { ev.setPollWinner(ival); } break; case PRIORITY: /* ------------------- Priority -------------------- */ ival = ((Priority)prop).getLevel(); if (chg.changed(pi, ev.getPriority(), ival)) { ev.setPriority(ival); } break; case RDATE: /* ------------------- RDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case RECURRENCE_ID: /* ------------------- RecurrenceID -------------------- */ // Done above break; case RELATED_TO: /* ------------------- RelatedTo -------------------- */ final RelatedTo irelto = (RelatedTo)prop; final BwRelatedTo relto = new BwRelatedTo(); final String parval = IcalUtil.getParameterVal(irelto, "RELTYPE"); if (parval != null) { relto.setRelType(parval); } relto.setValue(irelto.getValue()); if (chg.changed(pi, ev.getRelatedTo(), relto)) { ev.setRelatedTo(relto); } break; case REQUEST_STATUS: /* ------------------- RequestStatus -------------------- */ final BwRequestStatus rs = BwRequestStatus .fromRequestStatus((RequestStatus)prop); chg.addValue(pi, rs); break; case RESOURCES: /* ------------------- Resources -------------------- */ final TextList rl = ((Resources)prop).getResources(); if (rl != null) { /* Got some resources */ lang = IcalUtil.getLang(prop); for (final String s: rl) { final BwString rsrc = new BwString(lang, s); chg.addValue(pi, rsrc); } } break; case RRULE: /* ------------------- RRule -------------------- */ chg.addValue(pi, pval); break; case SEQUENCE: /* ------------------- Sequence -------------------- */ final int seq = ((Sequence)prop).getSequenceNo(); if (seq != ev.getSequence()) { chg.changed(pi, ev.getSequence(), seq); ev.setSequence(seq); } break; case STATUS: /* ------------------- Status -------------------- */ if (chg.changed(pi, ev.getStatus(), pval)) { ev.setStatus(pval); } break; case SUMMARY: /* ------------------- Summary -------------------- */ if (chg.changed(pi, ev.getSummary(), pval)) { ev.setSummary(pval); } break; case TRANSP: /* ------------------- Transp -------------------- */ if (chg.changed(pi, ev.getPeruserTransparency( cb.getPrincipal() .getPrincipalRef()), pval)) { final BwXproperty pu = ev.setPeruserTransparency( cb.getPrincipal().getPrincipalRef(), pval); if (pu != null) { chg.addValue(PropertyInfoIndex.XPROP, pu); } } break; case UID: /* ------------------- Uid -------------------- */ /* We did this above */ break; case URL: /* ------------------- Url -------------------- */ if (chg.changed(pi, ev.getLink(), pval)) { ev.setLink(pval); } break; case XPROP: /* ------------------------- x-property --------------------------- */ final String name = prop.getName(); if (name.equalsIgnoreCase(BwXproperty.bedeworkCost)) { if (chg.changed(PropertyInfoIndex.COST, ev.getCost(), pval)) { ev.setCost(pval); } break; } if (name.equalsIgnoreCase(BwXproperty.xBedeworkCategories)) { if (checkCategory(cb, chg, ev, null, pval)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkLocation)) { if (checkLocation(cb, chg, ev, prop)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkContact)) { if (checkContact(cb, chg, ev, null, pval)) { break; } } /* See if this is an x-category that can be converted to a real category */ final XProperty xp = (XProperty)prop; chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(name, xp.getParameters() .toString(), pval)); break; default: if (logger.debug()) { logger.debug("Unsupported property with index " + pi + "; class " + prop.getClass() + " and value " + pval); } } } /* =================== Process sub-components =============== */ final ComponentList<Component> subComps; if (val instanceof ComponentContainer) { subComps = ((ComponentContainer<Component>)val).getComponents(); } else { subComps = null; } final Set<Integer> pids; if (vpoll) { pids = new TreeSet<>(); final BwEvent vp = evinfo.getEvent(); if (!Util.isEmpty(vp.getPollItems())) { vp.clearPollItems(); } } else { pids = null; } if (!Util.isEmpty(subComps)) { for (final var subComp: subComps) { if (subComp instanceof Available) { if (!(val instanceof VAvailability)) { return Response.error(resp, "AVAILABLE only valid in VAVAILABLE"); } final var avlResp = processAvailable(cb, cal, ical, (VAvailability)val, (Available)subComp, evinfo); if (!avlResp.isOk()) { return Response.fromResponse(resp, avlResp); } continue; } if (subComp instanceof Participant) { if (vpoll) { final var vresp = processVoter(cb, (VPoll)val, (Participant)subComp, evinfo, chg, mergeAttendees); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Participant object"); continue; } if (subComp instanceof VResource) { logger.warn("Unimplemented VResource object"); continue; } if (subComp instanceof VLocation) { logger.warn("Unimplemented VLocation object"); continue; } if (subComp instanceof VAlarm) { final var aresp = VAlarmUtil.processAlarm(cb, val, (VAlarm)subComp, ev, currentPrincipal, chg); if (!aresp.isOk()) { return Response.fromResponse(resp, aresp); } continue; } if (vpoll && (event || task)) { final var vresp = processCandidate((VPoll)val, subComp, evinfo, pids, chg); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Component object: " + subComp); } } /* Fix up timestamps. */ if (ev.getCreated() == null) { if (ev.getLastmod() != null) { ev.setCreated(ev.getLastmod()); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); } else { ev.updateDtstamp(); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } } if (ev.getLastmod() == null) { // created cannot be null now ev.setLastmod(ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } processTimezones(ev, ical, chg); /* Remove any recipients and originator */ if (ev.getRecipients() != null) { ev.getRecipients().clear(); } ev.setOriginator(null); if (hasXparams.value) { /* Save a text copy of the entire event as an x-property */ final Component valCopy = val.copy(); /* Remove potentially large values */ final Description desp = valCopy.getProperty(Property.DESCRIPTION); if (desp != null) { desp.setValue(null); } final Attach attachp = valCopy.getProperty(Property.ATTACH); // Don't store the entire attachment - we just need the parameters. if (attachp != null) { final Value v = attachp.getParameter(Parameter.VALUE); if (v != null) { attachp.setValue(String.valueOf(attachp.getValue().hashCode())); } } chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(BwXproperty.bedeworkIcal, null, valCopy.toString())); } chg.processChanges(ev, true, false); ev.setRecurring(ev.isRecurringEntity()); if (logger.debug()) { logger.debug(chg.toString()); logger.debug(ev.toString()); } if (masterEI != null) { // Just return notfound as this event is on its override list return Response.notFound(resp); } resp.setEntity(evinfo); return resp; } catch (final Throwable t) { if (logger.debug()) { logger.error(t); } return Response.error(resp, t); } }
NONSATD
true
} if (guid == null) { /* XXX A guid is required - but are there devices out there without a * guid - and if so how do we handle it? */ return Response.notOk(resp, failed, CalFacadeException.noGuid); } /* See if we have a recurrence id */ BwDateTime ridObj = null; String rid = null; TimeZone ridTz = null; final RecurrenceId ridp = pl.getProperty(Property.RECURRENCE_ID); if (ridp != null) { testXparams(ridp, hasXparams); ridObj = BwDateTime.makeBwDateTime(ridp); if (ridObj.getRange() != null) { /* XXX What do I do with it? */ logger.warn("TRANS-TO_EVENT: Got a recurrence id range"); } rid = ridObj.getDate(); } EventInfo masterEI = null; EventInfo evinfo = null; final BwEvent ev; /* If we have a recurrence id see if we already have the master (we should * get a master + all its overrides). * * If so find the override and use the annnotation or if no override, * make one. * * If no override retrieve the event, add it to our table and then locate the * annotation.
val.getName()); } // Get the guid from the component String guid = null; final Uid uidp = pl.getProperty(Property.UID); if (uidp != null) { testXparams(uidp, hasXparams); guid = uidp.getValue(); } if (guid == null) { /* XXX A guid is required - but are there devices out there without a * guid - and if so how do we handle it? */ return Response.notOk(resp, failed, CalFacadeException.noGuid); } /* See if we have a recurrence id */ BwDateTime ridObj = null; String rid = null; TimeZone ridTz = null; final RecurrenceId ridp = pl.getProperty(Property.RECURRENCE_ID); if (ridp != null) { testXparams(ridp, hasXparams); ridObj = BwDateTime.makeBwDateTime(ridp); if (ridObj.getRange() != null) { /* XXX What do I do with it? */ logger.warn("TRANS-TO_EVENT: Got a recurrence id range"); } rid = ridObj.getDate(); } EventInfo masterEI = null; EventInfo evinfo = null; final BwEvent ev; /* If we have a recurrence id see if we already have the master (we should * get a master + all its overrides). * * If so find the override and use the annnotation or if no override, * make one. * * If no override retrieve the event, add it to our table and then locate the * annotation. * * If there is no annotation, create one. * * It's possible we have been sent 'detached' instances of a recurring * event. This may happen if we are invited to one or more instances of a * meeting. In this case we try to retrieve the master and if it doesn't * exist we manufacture one. We consider such an instance an update to * that instance only and leave the others alone.
entityType = IcalDefs.entityTypeFreeAndBusy; } else if (val instanceof VAvailability) { entityType = IcalDefs.entityTypeVavailability; } else if (val instanceof Available) { entityType = IcalDefs.entityTypeAvailable; } else if (val instanceof VPoll) { entityType = IcalDefs.entityTypeVpoll; vpoll = true; } else { return Response.error(resp, "org.bedework.invalid.component.type: " + val.getName()); } // Get the guid from the component String guid = null; final Uid uidp = pl.getProperty(Property.UID); if (uidp != null) { testXparams(uidp, hasXparams); guid = uidp.getValue(); } if (guid == null) { /* XXX A guid is required - but are there devices out there without a * guid - and if so how do we handle it? */ return Response.notOk(resp, failed, CalFacadeException.noGuid); } /* See if we have a recurrence id */ BwDateTime ridObj = null; String rid = null; TimeZone ridTz = null; final RecurrenceId ridp = pl.getProperty(Property.RECURRENCE_ID); if (ridp != null) { testXparams(ridp, hasXparams); ridObj = BwDateTime.makeBwDateTime(ridp); if (ridObj.getRange() != null) { /* XXX What do I do with it? */ logger.warn("TRANS-TO_EVENT: Got a recurrence id range"); } rid = ridObj.getDate(); } EventInfo masterEI = null; EventInfo evinfo = null; final BwEvent ev; /* If we have a recurrence id see if we already have the master (we should * get a master + all its overrides). * * If so find the override and use the annnotation or if no override, * make one. * * If no override retrieve the event, add it to our table and then locate the * annotation. * * If there is no annotation, create one. * * It's possible we have been sent 'detached' instances of a recurring * event. This may happen if we are invited to one or more instances of a * meeting. In this case we try to retrieve the master and if it doesn't * exist we manufacture one. We consider such an instance an update to * that instance only and leave the others alone. */ /* We need this in a couple of places */ final DtStart dtStart = pl.getProperty(Property.DTSTART); /* if (rid != null) { // See if we have a new master event. If so create a proxy to that event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI == null) { masterEI = makeNewEvent(cb, chg, entityType, guid, cal); BwEvent e = masterEI.getEvent();
7,893
10
/* If this is a recurrence instance see if we can find the master We only need this because the master may follow the overrides. */
public static GetEntityResponse<EventInfo> toEvent( final IcalCallback cb, final BwCalendar cal, final Icalendar ical, final Component val, final boolean mergeAttendees) { final var resp = new GetEntityResponse<EventInfo>(); if (val == null) { return Response.notOk(resp, failed, "No component supplied"); } String currentPrincipal = null; final BwPrincipal principal = cb.getPrincipal(); if (principal != null) { currentPrincipal = principal.getPrincipalRef(); } final Holder<Boolean> hasXparams = new Holder<>(Boolean.FALSE); final int methodType = ical.getMethodType(); String attUri = null; if (mergeAttendees) { // We'll need this later. attUri = cb.getCaladdr(cb.getPrincipal().getPrincipalRef()); } final String colPath; if (cal == null) { colPath = null; } else { colPath = cal.getPath(); } try { final PropertyList<Property> pl = val.getProperties(); boolean vpoll = false; boolean event = false; boolean task = false; if (pl == null) { // Empty component return Response.notOk(resp, failed, "Empty component"); } final int entityType; if (val instanceof VEvent) { entityType = IcalDefs.entityTypeEvent; event = true; } else if (val instanceof VToDo) { entityType = IcalDefs.entityTypeTodo; task = true; } else if (val instanceof VJournal) { entityType = IcalDefs.entityTypeJournal; } else if (val instanceof VFreeBusy) { entityType = IcalDefs.entityTypeFreeAndBusy; } else if (val instanceof VAvailability) { entityType = IcalDefs.entityTypeVavailability; } else if (val instanceof Available) { entityType = IcalDefs.entityTypeAvailable; } else if (val instanceof VPoll) { entityType = IcalDefs.entityTypeVpoll; vpoll = true; } else { return Response.error(resp, "org.bedework.invalid.component.type: " + val.getName()); } // Get the guid from the component String guid = null; final Uid uidp = pl.getProperty(Property.UID); if (uidp != null) { testXparams(uidp, hasXparams); guid = uidp.getValue(); } if (guid == null) { /* XXX A guid is required - but are there devices out there without a * guid - and if so how do we handle it? */ return Response.notOk(resp, failed, CalFacadeException.noGuid); } /* See if we have a recurrence id */ BwDateTime ridObj = null; String rid = null; TimeZone ridTz = null; final RecurrenceId ridp = pl.getProperty(Property.RECURRENCE_ID); if (ridp != null) { testXparams(ridp, hasXparams); ridObj = BwDateTime.makeBwDateTime(ridp); if (ridObj.getRange() != null) { /* XXX What do I do with it? */ logger.warn("TRANS-TO_EVENT: Got a recurrence id range"); } rid = ridObj.getDate(); } EventInfo masterEI = null; EventInfo evinfo = null; final BwEvent ev; /* If we have a recurrence id see if we already have the master (we should * get a master + all its overrides). * * If so find the override and use the annnotation or if no override, * make one. * * If no override retrieve the event, add it to our table and then locate the * annotation. * * If there is no annotation, create one. * * It's possible we have been sent 'detached' instances of a recurring * event. This may happen if we are invited to one or more instances of a * meeting. In this case we try to retrieve the master and if it doesn't * exist we manufacture one. We consider such an instance an update to * that instance only and leave the others alone. */ /* We need this in a couple of places */ final DtStart dtStart = pl.getProperty(Property.DTSTART); /* if (rid != null) { // See if we have a new master event. If so create a proxy to that event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI == null) { masterEI = makeNewEvent(cb, chg, entityType, guid, cal); BwEvent e = masterEI.getEvent(); // XXX This seems bogus DtStart mdtStart; String bogusDate = "19980118T230000"; if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + "Z"); } else if (dtStart.getTimeZone() == null) { mdtStart = new DtStart(bogusDate); } else { mdtStart = new DtStart(bogusDate + "Z", dtStart.getTimeZone()); } setDates(e, mdtStart, null, null, chg); e.setRecurring(true); e.addRdate(ridObj); e.setSuppressed(true); ical.addComponent(masterEI); } if (masterEI != null) { evinfo = masterEI.findOverride(rid); } } */ /* If this is a recurrence instance see if we can find the master We only need this because the master may follow the overrides. */ if (rid != null) { // See if we have a new master event. If so create a proxy to this event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI != null) { evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; } } if ((evinfo == null) && (cal != null) && (cal.getCalType() != BwCalendar.calTypeInbox) && (cal.getCalType() != BwCalendar.calTypePendingInbox) && (cal.getCalType() != BwCalendar.calTypeOutbox)) { if (logger.debug()) { logger.debug("TRANS-TO_EVENT: try to fetch event with guid=" + guid); } final GetEntitiesResponse<EventInfo> eisResp = cb.getEvent(colPath, guid); if (eisResp.isError()) { return Response.fromResponse(resp, eisResp); } final var eis = eisResp.getEntities(); if (!Util.isEmpty(eis)) { if (eis.size() > 1) { // DORECUR - wrong again return Response.notOk(resp, failed, "More than one event returned for guid."); } evinfo = eis.iterator().next(); } if (logger.debug()) { if (evinfo != null) { logger.debug("TRANS-TO_EVENT: fetched event with guid"); } else { logger.debug("TRANS-TO_EVENT: did not find event with guid"); } } if (evinfo != null) { if (rid != null) { // We just retrieved it's master masterEI = evinfo; masterEI.setInstanceOnly(true); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; ical.addComponent(masterEI); } else if (methodType == ScheduleMethods.methodTypeCancel) { // This should never have an rid for cancel of entire event. evinfo.setInstanceOnly(evinfo.getEvent().getSuppressed()); } else { // Presumably sent an update for the entire event. No longer suppressed master evinfo.getEvent().setSuppressed(false); } } else if (rid != null) { /* Manufacture a master for the instance */ masterEI = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); final BwEvent e = masterEI.getEvent(); // XXX This seems bogus final DtStart mdtStart; final String bogusDate = "19980118"; final String bogusTime = "T230000"; // Base dtstart on the recurrence id. final boolean isDateType = ridObj.getDateType(); if (isDateType) { mdtStart = new DtStart(new Date(bogusDate)); } else if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + bogusTime + "Z"); } else if (ridObj.getTzid() == null) { mdtStart = new DtStart(bogusDate + bogusTime); } else { mdtStart = new DtStart(bogusDate + bogusTime, Timezones.getTz(ridObj.getTzid())); } IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), masterEI, mdtStart, null, null); e.setRecurring(true); // e.addRdate(ridObj); final var sum = (Summary)pl.getProperty(Property.SUMMARY); e.setSummary(sum.getValue()); e.setSuppressed(true); ical.addComponent(masterEI); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; masterEI.setInstanceOnly(rid != null); } } if (evinfo == null) { evinfo = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); } else if (evinfo.getEvent().getEntityType() != entityType) { return Response.notOk(resp, failed, "org.bedework.mismatched.entity.type: " + val); } final ChangeTable chg = evinfo.getChangeset( cb.getPrincipal().getPrincipalRef()); if (rid != null) { final String evrid = evinfo.getEvent().getRecurrenceId(); if ((evrid == null) || (!evrid.equals(rid))) { logger. warn("Mismatched rid ev=" + evrid + " expected " + rid); chg.changed(PropertyInfoIndex.RECURRENCE_ID, evrid, rid); // XXX spurious??? } if (masterEI.getEvent().getSuppressed()) { masterEI.getEvent().addRdate(ridObj); } } ev = evinfo.getEvent(); ev.setScheduleMethod(methodType); DtEnd dtEnd = null; if (entityType == IcalDefs.entityTypeTodo) { final Due due = pl.getProperty(Property.DUE); if (due != null ) { dtEnd = new DtEnd(due.getParameters(), due.getValue()); } } else { dtEnd = pl.getProperty(Property.DTEND); } final Duration duration = pl.getProperty(Property.DURATION); IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), evinfo, dtStart, dtEnd, duration); for (final Property prop: pl) { testXparams(prop, hasXparams); //debug("ical prop " + prop.getClass().getName()); String pval = prop.getValue(); if ((pval != null) && (pval.length() == 0)) { pval = null; } final PropertyInfoIndex pi; if (prop instanceof XProperty) { pi = PropertyInfoIndex.XPROP; } else { pi = PropertyInfoIndex.fromName(prop.getName()); } if (pi == null) { logger.debug("Unknown property with name " + prop.getName() + " class " + prop.getClass() + " and value " + pval); continue; } chg.present(pi); switch (pi) { case ACCEPT_RESPONSE: /* ------------------- Accept Response -------------------- */ String sval = prop.getValue(); if (chg.changed(pi, ev.getPollAcceptResponse(), sval)) { ev.setPollAcceptResponse(sval); } break; case ATTACH: /* ------------------- Attachment -------------------- */ chg.addValue(pi, IcalUtil.getAttachment((Attach)prop)); break; case ATTENDEE: /* ------------------- Attendee -------------------- */ if (methodType == ScheduleMethods.methodTypePublish) { if (cb.getStrictness() == IcalCallback.conformanceStrict) { return Response.notOk(resp, failed, CalFacadeException.attendeesInPublish); } //if (cb.getStrictness() == IcalCallback.conformanceWarn) { // warn("Had attendees for PUBLISH"); //} } final Attendee attPr = (Attendee)prop; if (evinfo.getNewEvent() || !mergeAttendees) { chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { final String pUri = cb.getCaladdr(attPr.getValue()); if (pUri.equals(attUri)) { /* Only update for our own attendee * We're doing a PUT and this must be the attendee updating their * partstat. We don't allow them to change other attendees * whatever the PUT content says. */ chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { // Use the value we currently have boolean found = false; for (final BwAttendee att: ev.getAttendees()) { if (pUri.equals(att.getAttendeeUri())) { chg.addValue(pi, att.clone()); found = true; break; } } if (!found) { // An added attendee final BwAttendee att = IcalUtil .getAttendee(cb, attPr); att.setPartstat(IcalDefs.partstatValNeedsAction); chg.addValue(pi, att); } } } break; case BUSYTYPE: final int ibt = BwEvent.fromBusyTypeString(pval); if (chg.changed(pi, ev.getBusyType(), ibt)) { ev.setBusyType(ibt); } break; case CATEGORIES: /* ------------------- Categories -------------------- */ final Categories cats = (Categories)prop; final TextList cl = cats.getCategories(); String lang = IcalUtil.getLang(cats); if (cl != null) { /* Got some categories */ for (final String wd: cl) { if (wd == null) { continue; } final BwString key = new BwString(lang, wd); final var fcResp = cb.findCategory(key); final BwCategory cat; if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isNotFound()) { cat = BwCategory.makeCategory(); cat.setWord(key); cb.addCategory(cat); } else { cat = fcResp.getEntity(); } chg.addValue(pi, cat); } } break; case CLASS: /* ------------------- Class -------------------- */ if (chg.changed(pi, ev.getClassification(), pval)) { ev.setClassification(pval); } break; case COMMENT: /* ------------------- Comment -------------------- */ chg.addValue(pi, new BwString(null, pval)); break; case COMPLETED: /* ------------------- Completed -------------------- */ if (chg.changed(pi, ev.getCompleted(), pval)) { ev.setCompleted(pval); } break; case CONCEPT: /* ------------------- Concept -------------------- */ final Concept c = (Concept)prop; final String cval = c.getValue(); if (cval != null) { /* Got a concept */ chg.addValue(PropertyInfoIndex.XPROP, BwXproperty.makeIcalProperty("CONCEPT", null, cval)); } break; case CONTACT: /* ------------------- Contact -------------------- */ final String altrep = getAltRepPar(prop); lang = IcalUtil.getLang(prop); final String uid = getUidPar(prop); final BwString nm = new BwString(lang, pval); BwContact contact = null; if (uid != null) { final var fcResp = cb.getContact(uid); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { final var fcResp = cb.findContact(nm); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { contact = BwContact.makeContact(); contact.setCn(nm); contact.setLink(altrep); cb.addContact(contact); } else { contact.setCn(nm); contact.setLink(altrep); } chg.addValue(pi, contact); break; case CREATED: /* ------------------- Created -------------------- */ if (chg.changed(pi, ev.getCreated(), pval)) { ev.setCreated(pval); } break; case DESCRIPTION: /* ------------------- Description -------------------- */ if (chg.changed(pi, ev.getDescription(), pval)) { ev.setDescription(pval); } break; case DTEND: /* ------------------- DtEnd -------------------- */ break; case DTSTAMP: /* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval); break; case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE: /* -------------------- Due ------------------------ */ break; case DURATION: /* ------------------- Duration -------------------- */ break; case EXDATE: /* ------------------- ExDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case EXRULE: /* ------------------- ExRule -------------------- */ chg.addValue(pi, pval); break; case FREEBUSY: /* ------------------- freebusy -------------------- */ final FreeBusy fbusy = (FreeBusy)prop; final PeriodList perpl = fbusy.getPeriods(); final Parameter par = IcalUtil.getParameter(fbusy, "FBTYPE"); final int fbtype; if (par == null) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY)) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY_TENTATIVE)) { fbtype = BwFreeBusyComponent.typeBusyTentative; } else if (par.equals(FbType.BUSY_UNAVAILABLE)) { fbtype = BwFreeBusyComponent.typeBusyUnavailable; } else if (par.equals(FbType.FREE)) { fbtype = BwFreeBusyComponent.typeFree; } else { if (logger.debug()) { logger.debug("Unsupported parameter " + par.getName()); } return Response.notOk(resp, failed, "Unsupported parameter " + par.getName()); } final BwFreeBusyComponent fbc = new BwFreeBusyComponent(); fbc.setType(fbtype); for (final Period per : perpl) { fbc.addPeriod(per); } ev.addFreeBusyPeriod(fbc); break; case GEO: /* ------------------- Geo -------------------- */ final Geo g = (Geo)prop; final BwGeo geo = new BwGeo(g.getLatitude(), g.getLongitude()); if (chg.changed(pi, ev.getGeo(), geo)) { ev.setGeo(geo); } break; case LAST_MODIFIED: /* ------------------- LastModified -------------------- */ if (chg.changed(pi, ev.getLastmod(), pval)) { ev.setLastmod(pval); } break; case LOCATION: /* ------------------- Location -------------------- */ BwLocation loc = null; //String uid = getUidPar(prop); /* At the moment Mozilla lightning is broken and this leads to all * sorts of problems. if (uid != null) { loc = cb.getLocation(uid); } */ lang = IcalUtil.getLang(prop); BwString addr = null; if (pval != null) { if (loc == null) { addr = new BwString(lang, pval); final var fcResp = cb.findLocation(addr); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { loc = fcResp.getEntity(); } } if (loc == null) { loc = BwLocation.makeLocation(); loc.setAddress(addr); cb.addLocation(loc); } } final BwLocation evloc = ev.getLocation(); if (chg.changed(pi, evloc, loc)) { // CHGTBL - this only shows that it's a different location object ev.setLocation(loc); } else if ((loc != null) && (evloc != null)) { // See if the value is changed final String evval = evloc.getAddress().getValue(); final String inval = loc.getAddress().getValue(); if (!evval.equals(inval)) { chg.changed(pi, evval, inval); evloc.getAddress().setValue(inval); } } break; case ORGANIZER: /* ------------------- Organizer -------------------- */ final BwOrganizer org = IcalUtil.getOrganizer(cb, (Organizer)prop); final BwOrganizer evorg = ev.getOrganizer(); final BwOrganizer evorgCopy; if (evorg == null) { evorgCopy = null; } else { evorgCopy = (BwOrganizer)evorg.clone(); } if (chg.changed(pi, evorgCopy, org)) { if (evorg == null) { ev.setOrganizer(org); } else { evorg.update(org); } } break; case PERCENT_COMPLETE: /* ------------------- PercentComplete -------------------- */ Integer ival = ((PercentComplete)prop).getPercentage(); if (chg.changed(pi, ev.getPercentComplete(), ival)) { ev.setPercentComplete(ival); } break; case POLL_MODE: /* ------------------- Poll mode -------------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollMode(), sval)) { ev.setPollMode(sval); } break; case POLL_PROPERTIES: /* ------------------- Poll properties ---------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollProperties(), sval)) { ev.setPollProperties(sval); } break; case POLL_WINNER: /* ------------------- Poll winner -------------------- */ ival = ((PollWinner)prop).getPollwinner(); if (chg.changed(pi, ev.getPollWinner(), ival)) { ev.setPollWinner(ival); } break; case PRIORITY: /* ------------------- Priority -------------------- */ ival = ((Priority)prop).getLevel(); if (chg.changed(pi, ev.getPriority(), ival)) { ev.setPriority(ival); } break; case RDATE: /* ------------------- RDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case RECURRENCE_ID: /* ------------------- RecurrenceID -------------------- */ // Done above break; case RELATED_TO: /* ------------------- RelatedTo -------------------- */ final RelatedTo irelto = (RelatedTo)prop; final BwRelatedTo relto = new BwRelatedTo(); final String parval = IcalUtil.getParameterVal(irelto, "RELTYPE"); if (parval != null) { relto.setRelType(parval); } relto.setValue(irelto.getValue()); if (chg.changed(pi, ev.getRelatedTo(), relto)) { ev.setRelatedTo(relto); } break; case REQUEST_STATUS: /* ------------------- RequestStatus -------------------- */ final BwRequestStatus rs = BwRequestStatus .fromRequestStatus((RequestStatus)prop); chg.addValue(pi, rs); break; case RESOURCES: /* ------------------- Resources -------------------- */ final TextList rl = ((Resources)prop).getResources(); if (rl != null) { /* Got some resources */ lang = IcalUtil.getLang(prop); for (final String s: rl) { final BwString rsrc = new BwString(lang, s); chg.addValue(pi, rsrc); } } break; case RRULE: /* ------------------- RRule -------------------- */ chg.addValue(pi, pval); break; case SEQUENCE: /* ------------------- Sequence -------------------- */ final int seq = ((Sequence)prop).getSequenceNo(); if (seq != ev.getSequence()) { chg.changed(pi, ev.getSequence(), seq); ev.setSequence(seq); } break; case STATUS: /* ------------------- Status -------------------- */ if (chg.changed(pi, ev.getStatus(), pval)) { ev.setStatus(pval); } break; case SUMMARY: /* ------------------- Summary -------------------- */ if (chg.changed(pi, ev.getSummary(), pval)) { ev.setSummary(pval); } break; case TRANSP: /* ------------------- Transp -------------------- */ if (chg.changed(pi, ev.getPeruserTransparency( cb.getPrincipal() .getPrincipalRef()), pval)) { final BwXproperty pu = ev.setPeruserTransparency( cb.getPrincipal().getPrincipalRef(), pval); if (pu != null) { chg.addValue(PropertyInfoIndex.XPROP, pu); } } break; case UID: /* ------------------- Uid -------------------- */ /* We did this above */ break; case URL: /* ------------------- Url -------------------- */ if (chg.changed(pi, ev.getLink(), pval)) { ev.setLink(pval); } break; case XPROP: /* ------------------------- x-property --------------------------- */ final String name = prop.getName(); if (name.equalsIgnoreCase(BwXproperty.bedeworkCost)) { if (chg.changed(PropertyInfoIndex.COST, ev.getCost(), pval)) { ev.setCost(pval); } break; } if (name.equalsIgnoreCase(BwXproperty.xBedeworkCategories)) { if (checkCategory(cb, chg, ev, null, pval)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkLocation)) { if (checkLocation(cb, chg, ev, prop)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkContact)) { if (checkContact(cb, chg, ev, null, pval)) { break; } } /* See if this is an x-category that can be converted to a real category */ final XProperty xp = (XProperty)prop; chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(name, xp.getParameters() .toString(), pval)); break; default: if (logger.debug()) { logger.debug("Unsupported property with index " + pi + "; class " + prop.getClass() + " and value " + pval); } } } /* =================== Process sub-components =============== */ final ComponentList<Component> subComps; if (val instanceof ComponentContainer) { subComps = ((ComponentContainer<Component>)val).getComponents(); } else { subComps = null; } final Set<Integer> pids; if (vpoll) { pids = new TreeSet<>(); final BwEvent vp = evinfo.getEvent(); if (!Util.isEmpty(vp.getPollItems())) { vp.clearPollItems(); } } else { pids = null; } if (!Util.isEmpty(subComps)) { for (final var subComp: subComps) { if (subComp instanceof Available) { if (!(val instanceof VAvailability)) { return Response.error(resp, "AVAILABLE only valid in VAVAILABLE"); } final var avlResp = processAvailable(cb, cal, ical, (VAvailability)val, (Available)subComp, evinfo); if (!avlResp.isOk()) { return Response.fromResponse(resp, avlResp); } continue; } if (subComp instanceof Participant) { if (vpoll) { final var vresp = processVoter(cb, (VPoll)val, (Participant)subComp, evinfo, chg, mergeAttendees); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Participant object"); continue; } if (subComp instanceof VResource) { logger.warn("Unimplemented VResource object"); continue; } if (subComp instanceof VLocation) { logger.warn("Unimplemented VLocation object"); continue; } if (subComp instanceof VAlarm) { final var aresp = VAlarmUtil.processAlarm(cb, val, (VAlarm)subComp, ev, currentPrincipal, chg); if (!aresp.isOk()) { return Response.fromResponse(resp, aresp); } continue; } if (vpoll && (event || task)) { final var vresp = processCandidate((VPoll)val, subComp, evinfo, pids, chg); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Component object: " + subComp); } } /* Fix up timestamps. */ if (ev.getCreated() == null) { if (ev.getLastmod() != null) { ev.setCreated(ev.getLastmod()); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); } else { ev.updateDtstamp(); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } } if (ev.getLastmod() == null) { // created cannot be null now ev.setLastmod(ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } processTimezones(ev, ical, chg); /* Remove any recipients and originator */ if (ev.getRecipients() != null) { ev.getRecipients().clear(); } ev.setOriginator(null); if (hasXparams.value) { /* Save a text copy of the entire event as an x-property */ final Component valCopy = val.copy(); /* Remove potentially large values */ final Description desp = valCopy.getProperty(Property.DESCRIPTION); if (desp != null) { desp.setValue(null); } final Attach attachp = valCopy.getProperty(Property.ATTACH); // Don't store the entire attachment - we just need the parameters. if (attachp != null) { final Value v = attachp.getParameter(Parameter.VALUE); if (v != null) { attachp.setValue(String.valueOf(attachp.getValue().hashCode())); } } chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(BwXproperty.bedeworkIcal, null, valCopy.toString())); } chg.processChanges(ev, true, false); ev.setRecurring(ev.isRecurringEntity()); if (logger.debug()) { logger.debug(chg.toString()); logger.debug(ev.toString()); } if (masterEI != null) { // Just return notfound as this event is on its override list return Response.notFound(resp); } resp.setEntity(evinfo); return resp; } catch (final Throwable t) { if (logger.debug()) { logger.error(t); } return Response.error(resp, t); } }
NONSATD
true
} */ /* If this is a recurrence instance see if we can find the master We only need this because the master may follow the overrides. */ if (rid != null) { // See if we have a new master event. If so create a proxy to this event.
e.setRecurring(true); e.addRdate(ridObj); e.setSuppressed(true); ical.addComponent(masterEI); } if (masterEI != null) { evinfo = masterEI.findOverride(rid); } } */ /* If this is a recurrence instance see if we can find the master We only need this because the master may follow the overrides. */ if (rid != null) { // See if we have a new master event. If so create a proxy to this event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI != null) { evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; } } if ((evinfo == null) && (cal != null) &&
DtStart mdtStart; String bogusDate = "19980118T230000"; if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + "Z"); } else if (dtStart.getTimeZone() == null) { mdtStart = new DtStart(bogusDate); } else { mdtStart = new DtStart(bogusDate + "Z", dtStart.getTimeZone()); } setDates(e, mdtStart, null, null, chg); e.setRecurring(true); e.addRdate(ridObj); e.setSuppressed(true); ical.addComponent(masterEI); } if (masterEI != null) { evinfo = masterEI.findOverride(rid); } } */ /* If this is a recurrence instance see if we can find the master We only need this because the master may follow the overrides. */ if (rid != null) { // See if we have a new master event. If so create a proxy to this event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI != null) { evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; } } if ((evinfo == null) && (cal != null) && (cal.getCalType() != BwCalendar.calTypeInbox) && (cal.getCalType() != BwCalendar.calTypePendingInbox) && (cal.getCalType() != BwCalendar.calTypeOutbox)) { if (logger.debug()) { logger.debug("TRANS-TO_EVENT: try to fetch event with guid=" + guid); } final GetEntitiesResponse<EventInfo> eisResp = cb.getEvent(colPath, guid); if (eisResp.isError()) { return Response.fromResponse(resp, eisResp);
7,893
11
// See if we have a new master event. If so create a proxy to this event.
public static GetEntityResponse<EventInfo> toEvent( final IcalCallback cb, final BwCalendar cal, final Icalendar ical, final Component val, final boolean mergeAttendees) { final var resp = new GetEntityResponse<EventInfo>(); if (val == null) { return Response.notOk(resp, failed, "No component supplied"); } String currentPrincipal = null; final BwPrincipal principal = cb.getPrincipal(); if (principal != null) { currentPrincipal = principal.getPrincipalRef(); } final Holder<Boolean> hasXparams = new Holder<>(Boolean.FALSE); final int methodType = ical.getMethodType(); String attUri = null; if (mergeAttendees) { // We'll need this later. attUri = cb.getCaladdr(cb.getPrincipal().getPrincipalRef()); } final String colPath; if (cal == null) { colPath = null; } else { colPath = cal.getPath(); } try { final PropertyList<Property> pl = val.getProperties(); boolean vpoll = false; boolean event = false; boolean task = false; if (pl == null) { // Empty component return Response.notOk(resp, failed, "Empty component"); } final int entityType; if (val instanceof VEvent) { entityType = IcalDefs.entityTypeEvent; event = true; } else if (val instanceof VToDo) { entityType = IcalDefs.entityTypeTodo; task = true; } else if (val instanceof VJournal) { entityType = IcalDefs.entityTypeJournal; } else if (val instanceof VFreeBusy) { entityType = IcalDefs.entityTypeFreeAndBusy; } else if (val instanceof VAvailability) { entityType = IcalDefs.entityTypeVavailability; } else if (val instanceof Available) { entityType = IcalDefs.entityTypeAvailable; } else if (val instanceof VPoll) { entityType = IcalDefs.entityTypeVpoll; vpoll = true; } else { return Response.error(resp, "org.bedework.invalid.component.type: " + val.getName()); } // Get the guid from the component String guid = null; final Uid uidp = pl.getProperty(Property.UID); if (uidp != null) { testXparams(uidp, hasXparams); guid = uidp.getValue(); } if (guid == null) { /* XXX A guid is required - but are there devices out there without a * guid - and if so how do we handle it? */ return Response.notOk(resp, failed, CalFacadeException.noGuid); } /* See if we have a recurrence id */ BwDateTime ridObj = null; String rid = null; TimeZone ridTz = null; final RecurrenceId ridp = pl.getProperty(Property.RECURRENCE_ID); if (ridp != null) { testXparams(ridp, hasXparams); ridObj = BwDateTime.makeBwDateTime(ridp); if (ridObj.getRange() != null) { /* XXX What do I do with it? */ logger.warn("TRANS-TO_EVENT: Got a recurrence id range"); } rid = ridObj.getDate(); } EventInfo masterEI = null; EventInfo evinfo = null; final BwEvent ev; /* If we have a recurrence id see if we already have the master (we should * get a master + all its overrides). * * If so find the override and use the annnotation or if no override, * make one. * * If no override retrieve the event, add it to our table and then locate the * annotation. * * If there is no annotation, create one. * * It's possible we have been sent 'detached' instances of a recurring * event. This may happen if we are invited to one or more instances of a * meeting. In this case we try to retrieve the master and if it doesn't * exist we manufacture one. We consider such an instance an update to * that instance only and leave the others alone. */ /* We need this in a couple of places */ final DtStart dtStart = pl.getProperty(Property.DTSTART); /* if (rid != null) { // See if we have a new master event. If so create a proxy to that event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI == null) { masterEI = makeNewEvent(cb, chg, entityType, guid, cal); BwEvent e = masterEI.getEvent(); // XXX This seems bogus DtStart mdtStart; String bogusDate = "19980118T230000"; if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + "Z"); } else if (dtStart.getTimeZone() == null) { mdtStart = new DtStart(bogusDate); } else { mdtStart = new DtStart(bogusDate + "Z", dtStart.getTimeZone()); } setDates(e, mdtStart, null, null, chg); e.setRecurring(true); e.addRdate(ridObj); e.setSuppressed(true); ical.addComponent(masterEI); } if (masterEI != null) { evinfo = masterEI.findOverride(rid); } } */ /* If this is a recurrence instance see if we can find the master We only need this because the master may follow the overrides. */ if (rid != null) { // See if we have a new master event. If so create a proxy to this event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI != null) { evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; } } if ((evinfo == null) && (cal != null) && (cal.getCalType() != BwCalendar.calTypeInbox) && (cal.getCalType() != BwCalendar.calTypePendingInbox) && (cal.getCalType() != BwCalendar.calTypeOutbox)) { if (logger.debug()) { logger.debug("TRANS-TO_EVENT: try to fetch event with guid=" + guid); } final GetEntitiesResponse<EventInfo> eisResp = cb.getEvent(colPath, guid); if (eisResp.isError()) { return Response.fromResponse(resp, eisResp); } final var eis = eisResp.getEntities(); if (!Util.isEmpty(eis)) { if (eis.size() > 1) { // DORECUR - wrong again return Response.notOk(resp, failed, "More than one event returned for guid."); } evinfo = eis.iterator().next(); } if (logger.debug()) { if (evinfo != null) { logger.debug("TRANS-TO_EVENT: fetched event with guid"); } else { logger.debug("TRANS-TO_EVENT: did not find event with guid"); } } if (evinfo != null) { if (rid != null) { // We just retrieved it's master masterEI = evinfo; masterEI.setInstanceOnly(true); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; ical.addComponent(masterEI); } else if (methodType == ScheduleMethods.methodTypeCancel) { // This should never have an rid for cancel of entire event. evinfo.setInstanceOnly(evinfo.getEvent().getSuppressed()); } else { // Presumably sent an update for the entire event. No longer suppressed master evinfo.getEvent().setSuppressed(false); } } else if (rid != null) { /* Manufacture a master for the instance */ masterEI = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); final BwEvent e = masterEI.getEvent(); // XXX This seems bogus final DtStart mdtStart; final String bogusDate = "19980118"; final String bogusTime = "T230000"; // Base dtstart on the recurrence id. final boolean isDateType = ridObj.getDateType(); if (isDateType) { mdtStart = new DtStart(new Date(bogusDate)); } else if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + bogusTime + "Z"); } else if (ridObj.getTzid() == null) { mdtStart = new DtStart(bogusDate + bogusTime); } else { mdtStart = new DtStart(bogusDate + bogusTime, Timezones.getTz(ridObj.getTzid())); } IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), masterEI, mdtStart, null, null); e.setRecurring(true); // e.addRdate(ridObj); final var sum = (Summary)pl.getProperty(Property.SUMMARY); e.setSummary(sum.getValue()); e.setSuppressed(true); ical.addComponent(masterEI); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; masterEI.setInstanceOnly(rid != null); } } if (evinfo == null) { evinfo = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); } else if (evinfo.getEvent().getEntityType() != entityType) { return Response.notOk(resp, failed, "org.bedework.mismatched.entity.type: " + val); } final ChangeTable chg = evinfo.getChangeset( cb.getPrincipal().getPrincipalRef()); if (rid != null) { final String evrid = evinfo.getEvent().getRecurrenceId(); if ((evrid == null) || (!evrid.equals(rid))) { logger. warn("Mismatched rid ev=" + evrid + " expected " + rid); chg.changed(PropertyInfoIndex.RECURRENCE_ID, evrid, rid); // XXX spurious??? } if (masterEI.getEvent().getSuppressed()) { masterEI.getEvent().addRdate(ridObj); } } ev = evinfo.getEvent(); ev.setScheduleMethod(methodType); DtEnd dtEnd = null; if (entityType == IcalDefs.entityTypeTodo) { final Due due = pl.getProperty(Property.DUE); if (due != null ) { dtEnd = new DtEnd(due.getParameters(), due.getValue()); } } else { dtEnd = pl.getProperty(Property.DTEND); } final Duration duration = pl.getProperty(Property.DURATION); IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), evinfo, dtStart, dtEnd, duration); for (final Property prop: pl) { testXparams(prop, hasXparams); //debug("ical prop " + prop.getClass().getName()); String pval = prop.getValue(); if ((pval != null) && (pval.length() == 0)) { pval = null; } final PropertyInfoIndex pi; if (prop instanceof XProperty) { pi = PropertyInfoIndex.XPROP; } else { pi = PropertyInfoIndex.fromName(prop.getName()); } if (pi == null) { logger.debug("Unknown property with name " + prop.getName() + " class " + prop.getClass() + " and value " + pval); continue; } chg.present(pi); switch (pi) { case ACCEPT_RESPONSE: /* ------------------- Accept Response -------------------- */ String sval = prop.getValue(); if (chg.changed(pi, ev.getPollAcceptResponse(), sval)) { ev.setPollAcceptResponse(sval); } break; case ATTACH: /* ------------------- Attachment -------------------- */ chg.addValue(pi, IcalUtil.getAttachment((Attach)prop)); break; case ATTENDEE: /* ------------------- Attendee -------------------- */ if (methodType == ScheduleMethods.methodTypePublish) { if (cb.getStrictness() == IcalCallback.conformanceStrict) { return Response.notOk(resp, failed, CalFacadeException.attendeesInPublish); } //if (cb.getStrictness() == IcalCallback.conformanceWarn) { // warn("Had attendees for PUBLISH"); //} } final Attendee attPr = (Attendee)prop; if (evinfo.getNewEvent() || !mergeAttendees) { chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { final String pUri = cb.getCaladdr(attPr.getValue()); if (pUri.equals(attUri)) { /* Only update for our own attendee * We're doing a PUT and this must be the attendee updating their * partstat. We don't allow them to change other attendees * whatever the PUT content says. */ chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { // Use the value we currently have boolean found = false; for (final BwAttendee att: ev.getAttendees()) { if (pUri.equals(att.getAttendeeUri())) { chg.addValue(pi, att.clone()); found = true; break; } } if (!found) { // An added attendee final BwAttendee att = IcalUtil .getAttendee(cb, attPr); att.setPartstat(IcalDefs.partstatValNeedsAction); chg.addValue(pi, att); } } } break; case BUSYTYPE: final int ibt = BwEvent.fromBusyTypeString(pval); if (chg.changed(pi, ev.getBusyType(), ibt)) { ev.setBusyType(ibt); } break; case CATEGORIES: /* ------------------- Categories -------------------- */ final Categories cats = (Categories)prop; final TextList cl = cats.getCategories(); String lang = IcalUtil.getLang(cats); if (cl != null) { /* Got some categories */ for (final String wd: cl) { if (wd == null) { continue; } final BwString key = new BwString(lang, wd); final var fcResp = cb.findCategory(key); final BwCategory cat; if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isNotFound()) { cat = BwCategory.makeCategory(); cat.setWord(key); cb.addCategory(cat); } else { cat = fcResp.getEntity(); } chg.addValue(pi, cat); } } break; case CLASS: /* ------------------- Class -------------------- */ if (chg.changed(pi, ev.getClassification(), pval)) { ev.setClassification(pval); } break; case COMMENT: /* ------------------- Comment -------------------- */ chg.addValue(pi, new BwString(null, pval)); break; case COMPLETED: /* ------------------- Completed -------------------- */ if (chg.changed(pi, ev.getCompleted(), pval)) { ev.setCompleted(pval); } break; case CONCEPT: /* ------------------- Concept -------------------- */ final Concept c = (Concept)prop; final String cval = c.getValue(); if (cval != null) { /* Got a concept */ chg.addValue(PropertyInfoIndex.XPROP, BwXproperty.makeIcalProperty("CONCEPT", null, cval)); } break; case CONTACT: /* ------------------- Contact -------------------- */ final String altrep = getAltRepPar(prop); lang = IcalUtil.getLang(prop); final String uid = getUidPar(prop); final BwString nm = new BwString(lang, pval); BwContact contact = null; if (uid != null) { final var fcResp = cb.getContact(uid); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { final var fcResp = cb.findContact(nm); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { contact = BwContact.makeContact(); contact.setCn(nm); contact.setLink(altrep); cb.addContact(contact); } else { contact.setCn(nm); contact.setLink(altrep); } chg.addValue(pi, contact); break; case CREATED: /* ------------------- Created -------------------- */ if (chg.changed(pi, ev.getCreated(), pval)) { ev.setCreated(pval); } break; case DESCRIPTION: /* ------------------- Description -------------------- */ if (chg.changed(pi, ev.getDescription(), pval)) { ev.setDescription(pval); } break; case DTEND: /* ------------------- DtEnd -------------------- */ break; case DTSTAMP: /* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval); break; case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE: /* -------------------- Due ------------------------ */ break; case DURATION: /* ------------------- Duration -------------------- */ break; case EXDATE: /* ------------------- ExDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case EXRULE: /* ------------------- ExRule -------------------- */ chg.addValue(pi, pval); break; case FREEBUSY: /* ------------------- freebusy -------------------- */ final FreeBusy fbusy = (FreeBusy)prop; final PeriodList perpl = fbusy.getPeriods(); final Parameter par = IcalUtil.getParameter(fbusy, "FBTYPE"); final int fbtype; if (par == null) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY)) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY_TENTATIVE)) { fbtype = BwFreeBusyComponent.typeBusyTentative; } else if (par.equals(FbType.BUSY_UNAVAILABLE)) { fbtype = BwFreeBusyComponent.typeBusyUnavailable; } else if (par.equals(FbType.FREE)) { fbtype = BwFreeBusyComponent.typeFree; } else { if (logger.debug()) { logger.debug("Unsupported parameter " + par.getName()); } return Response.notOk(resp, failed, "Unsupported parameter " + par.getName()); } final BwFreeBusyComponent fbc = new BwFreeBusyComponent(); fbc.setType(fbtype); for (final Period per : perpl) { fbc.addPeriod(per); } ev.addFreeBusyPeriod(fbc); break; case GEO: /* ------------------- Geo -------------------- */ final Geo g = (Geo)prop; final BwGeo geo = new BwGeo(g.getLatitude(), g.getLongitude()); if (chg.changed(pi, ev.getGeo(), geo)) { ev.setGeo(geo); } break; case LAST_MODIFIED: /* ------------------- LastModified -------------------- */ if (chg.changed(pi, ev.getLastmod(), pval)) { ev.setLastmod(pval); } break; case LOCATION: /* ------------------- Location -------------------- */ BwLocation loc = null; //String uid = getUidPar(prop); /* At the moment Mozilla lightning is broken and this leads to all * sorts of problems. if (uid != null) { loc = cb.getLocation(uid); } */ lang = IcalUtil.getLang(prop); BwString addr = null; if (pval != null) { if (loc == null) { addr = new BwString(lang, pval); final var fcResp = cb.findLocation(addr); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { loc = fcResp.getEntity(); } } if (loc == null) { loc = BwLocation.makeLocation(); loc.setAddress(addr); cb.addLocation(loc); } } final BwLocation evloc = ev.getLocation(); if (chg.changed(pi, evloc, loc)) { // CHGTBL - this only shows that it's a different location object ev.setLocation(loc); } else if ((loc != null) && (evloc != null)) { // See if the value is changed final String evval = evloc.getAddress().getValue(); final String inval = loc.getAddress().getValue(); if (!evval.equals(inval)) { chg.changed(pi, evval, inval); evloc.getAddress().setValue(inval); } } break; case ORGANIZER: /* ------------------- Organizer -------------------- */ final BwOrganizer org = IcalUtil.getOrganizer(cb, (Organizer)prop); final BwOrganizer evorg = ev.getOrganizer(); final BwOrganizer evorgCopy; if (evorg == null) { evorgCopy = null; } else { evorgCopy = (BwOrganizer)evorg.clone(); } if (chg.changed(pi, evorgCopy, org)) { if (evorg == null) { ev.setOrganizer(org); } else { evorg.update(org); } } break; case PERCENT_COMPLETE: /* ------------------- PercentComplete -------------------- */ Integer ival = ((PercentComplete)prop).getPercentage(); if (chg.changed(pi, ev.getPercentComplete(), ival)) { ev.setPercentComplete(ival); } break; case POLL_MODE: /* ------------------- Poll mode -------------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollMode(), sval)) { ev.setPollMode(sval); } break; case POLL_PROPERTIES: /* ------------------- Poll properties ---------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollProperties(), sval)) { ev.setPollProperties(sval); } break; case POLL_WINNER: /* ------------------- Poll winner -------------------- */ ival = ((PollWinner)prop).getPollwinner(); if (chg.changed(pi, ev.getPollWinner(), ival)) { ev.setPollWinner(ival); } break; case PRIORITY: /* ------------------- Priority -------------------- */ ival = ((Priority)prop).getLevel(); if (chg.changed(pi, ev.getPriority(), ival)) { ev.setPriority(ival); } break; case RDATE: /* ------------------- RDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case RECURRENCE_ID: /* ------------------- RecurrenceID -------------------- */ // Done above break; case RELATED_TO: /* ------------------- RelatedTo -------------------- */ final RelatedTo irelto = (RelatedTo)prop; final BwRelatedTo relto = new BwRelatedTo(); final String parval = IcalUtil.getParameterVal(irelto, "RELTYPE"); if (parval != null) { relto.setRelType(parval); } relto.setValue(irelto.getValue()); if (chg.changed(pi, ev.getRelatedTo(), relto)) { ev.setRelatedTo(relto); } break; case REQUEST_STATUS: /* ------------------- RequestStatus -------------------- */ final BwRequestStatus rs = BwRequestStatus .fromRequestStatus((RequestStatus)prop); chg.addValue(pi, rs); break; case RESOURCES: /* ------------------- Resources -------------------- */ final TextList rl = ((Resources)prop).getResources(); if (rl != null) { /* Got some resources */ lang = IcalUtil.getLang(prop); for (final String s: rl) { final BwString rsrc = new BwString(lang, s); chg.addValue(pi, rsrc); } } break; case RRULE: /* ------------------- RRule -------------------- */ chg.addValue(pi, pval); break; case SEQUENCE: /* ------------------- Sequence -------------------- */ final int seq = ((Sequence)prop).getSequenceNo(); if (seq != ev.getSequence()) { chg.changed(pi, ev.getSequence(), seq); ev.setSequence(seq); } break; case STATUS: /* ------------------- Status -------------------- */ if (chg.changed(pi, ev.getStatus(), pval)) { ev.setStatus(pval); } break; case SUMMARY: /* ------------------- Summary -------------------- */ if (chg.changed(pi, ev.getSummary(), pval)) { ev.setSummary(pval); } break; case TRANSP: /* ------------------- Transp -------------------- */ if (chg.changed(pi, ev.getPeruserTransparency( cb.getPrincipal() .getPrincipalRef()), pval)) { final BwXproperty pu = ev.setPeruserTransparency( cb.getPrincipal().getPrincipalRef(), pval); if (pu != null) { chg.addValue(PropertyInfoIndex.XPROP, pu); } } break; case UID: /* ------------------- Uid -------------------- */ /* We did this above */ break; case URL: /* ------------------- Url -------------------- */ if (chg.changed(pi, ev.getLink(), pval)) { ev.setLink(pval); } break; case XPROP: /* ------------------------- x-property --------------------------- */ final String name = prop.getName(); if (name.equalsIgnoreCase(BwXproperty.bedeworkCost)) { if (chg.changed(PropertyInfoIndex.COST, ev.getCost(), pval)) { ev.setCost(pval); } break; } if (name.equalsIgnoreCase(BwXproperty.xBedeworkCategories)) { if (checkCategory(cb, chg, ev, null, pval)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkLocation)) { if (checkLocation(cb, chg, ev, prop)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkContact)) { if (checkContact(cb, chg, ev, null, pval)) { break; } } /* See if this is an x-category that can be converted to a real category */ final XProperty xp = (XProperty)prop; chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(name, xp.getParameters() .toString(), pval)); break; default: if (logger.debug()) { logger.debug("Unsupported property with index " + pi + "; class " + prop.getClass() + " and value " + pval); } } } /* =================== Process sub-components =============== */ final ComponentList<Component> subComps; if (val instanceof ComponentContainer) { subComps = ((ComponentContainer<Component>)val).getComponents(); } else { subComps = null; } final Set<Integer> pids; if (vpoll) { pids = new TreeSet<>(); final BwEvent vp = evinfo.getEvent(); if (!Util.isEmpty(vp.getPollItems())) { vp.clearPollItems(); } } else { pids = null; } if (!Util.isEmpty(subComps)) { for (final var subComp: subComps) { if (subComp instanceof Available) { if (!(val instanceof VAvailability)) { return Response.error(resp, "AVAILABLE only valid in VAVAILABLE"); } final var avlResp = processAvailable(cb, cal, ical, (VAvailability)val, (Available)subComp, evinfo); if (!avlResp.isOk()) { return Response.fromResponse(resp, avlResp); } continue; } if (subComp instanceof Participant) { if (vpoll) { final var vresp = processVoter(cb, (VPoll)val, (Participant)subComp, evinfo, chg, mergeAttendees); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Participant object"); continue; } if (subComp instanceof VResource) { logger.warn("Unimplemented VResource object"); continue; } if (subComp instanceof VLocation) { logger.warn("Unimplemented VLocation object"); continue; } if (subComp instanceof VAlarm) { final var aresp = VAlarmUtil.processAlarm(cb, val, (VAlarm)subComp, ev, currentPrincipal, chg); if (!aresp.isOk()) { return Response.fromResponse(resp, aresp); } continue; } if (vpoll && (event || task)) { final var vresp = processCandidate((VPoll)val, subComp, evinfo, pids, chg); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Component object: " + subComp); } } /* Fix up timestamps. */ if (ev.getCreated() == null) { if (ev.getLastmod() != null) { ev.setCreated(ev.getLastmod()); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); } else { ev.updateDtstamp(); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } } if (ev.getLastmod() == null) { // created cannot be null now ev.setLastmod(ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } processTimezones(ev, ical, chg); /* Remove any recipients and originator */ if (ev.getRecipients() != null) { ev.getRecipients().clear(); } ev.setOriginator(null); if (hasXparams.value) { /* Save a text copy of the entire event as an x-property */ final Component valCopy = val.copy(); /* Remove potentially large values */ final Description desp = valCopy.getProperty(Property.DESCRIPTION); if (desp != null) { desp.setValue(null); } final Attach attachp = valCopy.getProperty(Property.ATTACH); // Don't store the entire attachment - we just need the parameters. if (attachp != null) { final Value v = attachp.getParameter(Parameter.VALUE); if (v != null) { attachp.setValue(String.valueOf(attachp.getValue().hashCode())); } } chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(BwXproperty.bedeworkIcal, null, valCopy.toString())); } chg.processChanges(ev, true, false); ev.setRecurring(ev.isRecurringEntity()); if (logger.debug()) { logger.debug(chg.toString()); logger.debug(ev.toString()); } if (masterEI != null) { // Just return notfound as this event is on its override list return Response.notFound(resp); } resp.setEntity(evinfo); return resp; } catch (final Throwable t) { if (logger.debug()) { logger.error(t); } return Response.error(resp, t); } }
NONSATD
true
*/ if (rid != null) { // See if we have a new master event. If so create a proxy to this event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI != null) {
} if (masterEI != null) { evinfo = masterEI.findOverride(rid); } } */ /* If this is a recurrence instance see if we can find the master We only need this because the master may follow the overrides. */ if (rid != null) { // See if we have a new master event. If so create a proxy to this event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI != null) { evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; } } if ((evinfo == null) && (cal != null) && (cal.getCalType() != BwCalendar.calTypeInbox) && (cal.getCalType() != BwCalendar.calTypePendingInbox) &&
} else if (dtStart.getTimeZone() == null) { mdtStart = new DtStart(bogusDate); } else { mdtStart = new DtStart(bogusDate + "Z", dtStart.getTimeZone()); } setDates(e, mdtStart, null, null, chg); e.setRecurring(true); e.addRdate(ridObj); e.setSuppressed(true); ical.addComponent(masterEI); } if (masterEI != null) { evinfo = masterEI.findOverride(rid); } } */ /* If this is a recurrence instance see if we can find the master We only need this because the master may follow the overrides. */ if (rid != null) { // See if we have a new master event. If so create a proxy to this event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI != null) { evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; } } if ((evinfo == null) && (cal != null) && (cal.getCalType() != BwCalendar.calTypeInbox) && (cal.getCalType() != BwCalendar.calTypePendingInbox) && (cal.getCalType() != BwCalendar.calTypeOutbox)) { if (logger.debug()) { logger.debug("TRANS-TO_EVENT: try to fetch event with guid=" + guid); } final GetEntitiesResponse<EventInfo> eisResp = cb.getEvent(colPath, guid); if (eisResp.isError()) { return Response.fromResponse(resp, eisResp); } final var eis = eisResp.getEntities();
7,893
12
// DORECUR - wrong again
public static GetEntityResponse<EventInfo> toEvent( final IcalCallback cb, final BwCalendar cal, final Icalendar ical, final Component val, final boolean mergeAttendees) { final var resp = new GetEntityResponse<EventInfo>(); if (val == null) { return Response.notOk(resp, failed, "No component supplied"); } String currentPrincipal = null; final BwPrincipal principal = cb.getPrincipal(); if (principal != null) { currentPrincipal = principal.getPrincipalRef(); } final Holder<Boolean> hasXparams = new Holder<>(Boolean.FALSE); final int methodType = ical.getMethodType(); String attUri = null; if (mergeAttendees) { // We'll need this later. attUri = cb.getCaladdr(cb.getPrincipal().getPrincipalRef()); } final String colPath; if (cal == null) { colPath = null; } else { colPath = cal.getPath(); } try { final PropertyList<Property> pl = val.getProperties(); boolean vpoll = false; boolean event = false; boolean task = false; if (pl == null) { // Empty component return Response.notOk(resp, failed, "Empty component"); } final int entityType; if (val instanceof VEvent) { entityType = IcalDefs.entityTypeEvent; event = true; } else if (val instanceof VToDo) { entityType = IcalDefs.entityTypeTodo; task = true; } else if (val instanceof VJournal) { entityType = IcalDefs.entityTypeJournal; } else if (val instanceof VFreeBusy) { entityType = IcalDefs.entityTypeFreeAndBusy; } else if (val instanceof VAvailability) { entityType = IcalDefs.entityTypeVavailability; } else if (val instanceof Available) { entityType = IcalDefs.entityTypeAvailable; } else if (val instanceof VPoll) { entityType = IcalDefs.entityTypeVpoll; vpoll = true; } else { return Response.error(resp, "org.bedework.invalid.component.type: " + val.getName()); } // Get the guid from the component String guid = null; final Uid uidp = pl.getProperty(Property.UID); if (uidp != null) { testXparams(uidp, hasXparams); guid = uidp.getValue(); } if (guid == null) { /* XXX A guid is required - but are there devices out there without a * guid - and if so how do we handle it? */ return Response.notOk(resp, failed, CalFacadeException.noGuid); } /* See if we have a recurrence id */ BwDateTime ridObj = null; String rid = null; TimeZone ridTz = null; final RecurrenceId ridp = pl.getProperty(Property.RECURRENCE_ID); if (ridp != null) { testXparams(ridp, hasXparams); ridObj = BwDateTime.makeBwDateTime(ridp); if (ridObj.getRange() != null) { /* XXX What do I do with it? */ logger.warn("TRANS-TO_EVENT: Got a recurrence id range"); } rid = ridObj.getDate(); } EventInfo masterEI = null; EventInfo evinfo = null; final BwEvent ev; /* If we have a recurrence id see if we already have the master (we should * get a master + all its overrides). * * If so find the override and use the annnotation or if no override, * make one. * * If no override retrieve the event, add it to our table and then locate the * annotation. * * If there is no annotation, create one. * * It's possible we have been sent 'detached' instances of a recurring * event. This may happen if we are invited to one or more instances of a * meeting. In this case we try to retrieve the master and if it doesn't * exist we manufacture one. We consider such an instance an update to * that instance only and leave the others alone. */ /* We need this in a couple of places */ final DtStart dtStart = pl.getProperty(Property.DTSTART); /* if (rid != null) { // See if we have a new master event. If so create a proxy to that event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI == null) { masterEI = makeNewEvent(cb, chg, entityType, guid, cal); BwEvent e = masterEI.getEvent(); // XXX This seems bogus DtStart mdtStart; String bogusDate = "19980118T230000"; if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + "Z"); } else if (dtStart.getTimeZone() == null) { mdtStart = new DtStart(bogusDate); } else { mdtStart = new DtStart(bogusDate + "Z", dtStart.getTimeZone()); } setDates(e, mdtStart, null, null, chg); e.setRecurring(true); e.addRdate(ridObj); e.setSuppressed(true); ical.addComponent(masterEI); } if (masterEI != null) { evinfo = masterEI.findOverride(rid); } } */ /* If this is a recurrence instance see if we can find the master We only need this because the master may follow the overrides. */ if (rid != null) { // See if we have a new master event. If so create a proxy to this event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI != null) { evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; } } if ((evinfo == null) && (cal != null) && (cal.getCalType() != BwCalendar.calTypeInbox) && (cal.getCalType() != BwCalendar.calTypePendingInbox) && (cal.getCalType() != BwCalendar.calTypeOutbox)) { if (logger.debug()) { logger.debug("TRANS-TO_EVENT: try to fetch event with guid=" + guid); } final GetEntitiesResponse<EventInfo> eisResp = cb.getEvent(colPath, guid); if (eisResp.isError()) { return Response.fromResponse(resp, eisResp); } final var eis = eisResp.getEntities(); if (!Util.isEmpty(eis)) { if (eis.size() > 1) { // DORECUR - wrong again return Response.notOk(resp, failed, "More than one event returned for guid."); } evinfo = eis.iterator().next(); } if (logger.debug()) { if (evinfo != null) { logger.debug("TRANS-TO_EVENT: fetched event with guid"); } else { logger.debug("TRANS-TO_EVENT: did not find event with guid"); } } if (evinfo != null) { if (rid != null) { // We just retrieved it's master masterEI = evinfo; masterEI.setInstanceOnly(true); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; ical.addComponent(masterEI); } else if (methodType == ScheduleMethods.methodTypeCancel) { // This should never have an rid for cancel of entire event. evinfo.setInstanceOnly(evinfo.getEvent().getSuppressed()); } else { // Presumably sent an update for the entire event. No longer suppressed master evinfo.getEvent().setSuppressed(false); } } else if (rid != null) { /* Manufacture a master for the instance */ masterEI = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); final BwEvent e = masterEI.getEvent(); // XXX This seems bogus final DtStart mdtStart; final String bogusDate = "19980118"; final String bogusTime = "T230000"; // Base dtstart on the recurrence id. final boolean isDateType = ridObj.getDateType(); if (isDateType) { mdtStart = new DtStart(new Date(bogusDate)); } else if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + bogusTime + "Z"); } else if (ridObj.getTzid() == null) { mdtStart = new DtStart(bogusDate + bogusTime); } else { mdtStart = new DtStart(bogusDate + bogusTime, Timezones.getTz(ridObj.getTzid())); } IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), masterEI, mdtStart, null, null); e.setRecurring(true); // e.addRdate(ridObj); final var sum = (Summary)pl.getProperty(Property.SUMMARY); e.setSummary(sum.getValue()); e.setSuppressed(true); ical.addComponent(masterEI); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; masterEI.setInstanceOnly(rid != null); } } if (evinfo == null) { evinfo = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); } else if (evinfo.getEvent().getEntityType() != entityType) { return Response.notOk(resp, failed, "org.bedework.mismatched.entity.type: " + val); } final ChangeTable chg = evinfo.getChangeset( cb.getPrincipal().getPrincipalRef()); if (rid != null) { final String evrid = evinfo.getEvent().getRecurrenceId(); if ((evrid == null) || (!evrid.equals(rid))) { logger. warn("Mismatched rid ev=" + evrid + " expected " + rid); chg.changed(PropertyInfoIndex.RECURRENCE_ID, evrid, rid); // XXX spurious??? } if (masterEI.getEvent().getSuppressed()) { masterEI.getEvent().addRdate(ridObj); } } ev = evinfo.getEvent(); ev.setScheduleMethod(methodType); DtEnd dtEnd = null; if (entityType == IcalDefs.entityTypeTodo) { final Due due = pl.getProperty(Property.DUE); if (due != null ) { dtEnd = new DtEnd(due.getParameters(), due.getValue()); } } else { dtEnd = pl.getProperty(Property.DTEND); } final Duration duration = pl.getProperty(Property.DURATION); IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), evinfo, dtStart, dtEnd, duration); for (final Property prop: pl) { testXparams(prop, hasXparams); //debug("ical prop " + prop.getClass().getName()); String pval = prop.getValue(); if ((pval != null) && (pval.length() == 0)) { pval = null; } final PropertyInfoIndex pi; if (prop instanceof XProperty) { pi = PropertyInfoIndex.XPROP; } else { pi = PropertyInfoIndex.fromName(prop.getName()); } if (pi == null) { logger.debug("Unknown property with name " + prop.getName() + " class " + prop.getClass() + " and value " + pval); continue; } chg.present(pi); switch (pi) { case ACCEPT_RESPONSE: /* ------------------- Accept Response -------------------- */ String sval = prop.getValue(); if (chg.changed(pi, ev.getPollAcceptResponse(), sval)) { ev.setPollAcceptResponse(sval); } break; case ATTACH: /* ------------------- Attachment -------------------- */ chg.addValue(pi, IcalUtil.getAttachment((Attach)prop)); break; case ATTENDEE: /* ------------------- Attendee -------------------- */ if (methodType == ScheduleMethods.methodTypePublish) { if (cb.getStrictness() == IcalCallback.conformanceStrict) { return Response.notOk(resp, failed, CalFacadeException.attendeesInPublish); } //if (cb.getStrictness() == IcalCallback.conformanceWarn) { // warn("Had attendees for PUBLISH"); //} } final Attendee attPr = (Attendee)prop; if (evinfo.getNewEvent() || !mergeAttendees) { chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { final String pUri = cb.getCaladdr(attPr.getValue()); if (pUri.equals(attUri)) { /* Only update for our own attendee * We're doing a PUT and this must be the attendee updating their * partstat. We don't allow them to change other attendees * whatever the PUT content says. */ chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { // Use the value we currently have boolean found = false; for (final BwAttendee att: ev.getAttendees()) { if (pUri.equals(att.getAttendeeUri())) { chg.addValue(pi, att.clone()); found = true; break; } } if (!found) { // An added attendee final BwAttendee att = IcalUtil .getAttendee(cb, attPr); att.setPartstat(IcalDefs.partstatValNeedsAction); chg.addValue(pi, att); } } } break; case BUSYTYPE: final int ibt = BwEvent.fromBusyTypeString(pval); if (chg.changed(pi, ev.getBusyType(), ibt)) { ev.setBusyType(ibt); } break; case CATEGORIES: /* ------------------- Categories -------------------- */ final Categories cats = (Categories)prop; final TextList cl = cats.getCategories(); String lang = IcalUtil.getLang(cats); if (cl != null) { /* Got some categories */ for (final String wd: cl) { if (wd == null) { continue; } final BwString key = new BwString(lang, wd); final var fcResp = cb.findCategory(key); final BwCategory cat; if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isNotFound()) { cat = BwCategory.makeCategory(); cat.setWord(key); cb.addCategory(cat); } else { cat = fcResp.getEntity(); } chg.addValue(pi, cat); } } break; case CLASS: /* ------------------- Class -------------------- */ if (chg.changed(pi, ev.getClassification(), pval)) { ev.setClassification(pval); } break; case COMMENT: /* ------------------- Comment -------------------- */ chg.addValue(pi, new BwString(null, pval)); break; case COMPLETED: /* ------------------- Completed -------------------- */ if (chg.changed(pi, ev.getCompleted(), pval)) { ev.setCompleted(pval); } break; case CONCEPT: /* ------------------- Concept -------------------- */ final Concept c = (Concept)prop; final String cval = c.getValue(); if (cval != null) { /* Got a concept */ chg.addValue(PropertyInfoIndex.XPROP, BwXproperty.makeIcalProperty("CONCEPT", null, cval)); } break; case CONTACT: /* ------------------- Contact -------------------- */ final String altrep = getAltRepPar(prop); lang = IcalUtil.getLang(prop); final String uid = getUidPar(prop); final BwString nm = new BwString(lang, pval); BwContact contact = null; if (uid != null) { final var fcResp = cb.getContact(uid); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { final var fcResp = cb.findContact(nm); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { contact = BwContact.makeContact(); contact.setCn(nm); contact.setLink(altrep); cb.addContact(contact); } else { contact.setCn(nm); contact.setLink(altrep); } chg.addValue(pi, contact); break; case CREATED: /* ------------------- Created -------------------- */ if (chg.changed(pi, ev.getCreated(), pval)) { ev.setCreated(pval); } break; case DESCRIPTION: /* ------------------- Description -------------------- */ if (chg.changed(pi, ev.getDescription(), pval)) { ev.setDescription(pval); } break; case DTEND: /* ------------------- DtEnd -------------------- */ break; case DTSTAMP: /* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval); break; case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE: /* -------------------- Due ------------------------ */ break; case DURATION: /* ------------------- Duration -------------------- */ break; case EXDATE: /* ------------------- ExDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case EXRULE: /* ------------------- ExRule -------------------- */ chg.addValue(pi, pval); break; case FREEBUSY: /* ------------------- freebusy -------------------- */ final FreeBusy fbusy = (FreeBusy)prop; final PeriodList perpl = fbusy.getPeriods(); final Parameter par = IcalUtil.getParameter(fbusy, "FBTYPE"); final int fbtype; if (par == null) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY)) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY_TENTATIVE)) { fbtype = BwFreeBusyComponent.typeBusyTentative; } else if (par.equals(FbType.BUSY_UNAVAILABLE)) { fbtype = BwFreeBusyComponent.typeBusyUnavailable; } else if (par.equals(FbType.FREE)) { fbtype = BwFreeBusyComponent.typeFree; } else { if (logger.debug()) { logger.debug("Unsupported parameter " + par.getName()); } return Response.notOk(resp, failed, "Unsupported parameter " + par.getName()); } final BwFreeBusyComponent fbc = new BwFreeBusyComponent(); fbc.setType(fbtype); for (final Period per : perpl) { fbc.addPeriod(per); } ev.addFreeBusyPeriod(fbc); break; case GEO: /* ------------------- Geo -------------------- */ final Geo g = (Geo)prop; final BwGeo geo = new BwGeo(g.getLatitude(), g.getLongitude()); if (chg.changed(pi, ev.getGeo(), geo)) { ev.setGeo(geo); } break; case LAST_MODIFIED: /* ------------------- LastModified -------------------- */ if (chg.changed(pi, ev.getLastmod(), pval)) { ev.setLastmod(pval); } break; case LOCATION: /* ------------------- Location -------------------- */ BwLocation loc = null; //String uid = getUidPar(prop); /* At the moment Mozilla lightning is broken and this leads to all * sorts of problems. if (uid != null) { loc = cb.getLocation(uid); } */ lang = IcalUtil.getLang(prop); BwString addr = null; if (pval != null) { if (loc == null) { addr = new BwString(lang, pval); final var fcResp = cb.findLocation(addr); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { loc = fcResp.getEntity(); } } if (loc == null) { loc = BwLocation.makeLocation(); loc.setAddress(addr); cb.addLocation(loc); } } final BwLocation evloc = ev.getLocation(); if (chg.changed(pi, evloc, loc)) { // CHGTBL - this only shows that it's a different location object ev.setLocation(loc); } else if ((loc != null) && (evloc != null)) { // See if the value is changed final String evval = evloc.getAddress().getValue(); final String inval = loc.getAddress().getValue(); if (!evval.equals(inval)) { chg.changed(pi, evval, inval); evloc.getAddress().setValue(inval); } } break; case ORGANIZER: /* ------------------- Organizer -------------------- */ final BwOrganizer org = IcalUtil.getOrganizer(cb, (Organizer)prop); final BwOrganizer evorg = ev.getOrganizer(); final BwOrganizer evorgCopy; if (evorg == null) { evorgCopy = null; } else { evorgCopy = (BwOrganizer)evorg.clone(); } if (chg.changed(pi, evorgCopy, org)) { if (evorg == null) { ev.setOrganizer(org); } else { evorg.update(org); } } break; case PERCENT_COMPLETE: /* ------------------- PercentComplete -------------------- */ Integer ival = ((PercentComplete)prop).getPercentage(); if (chg.changed(pi, ev.getPercentComplete(), ival)) { ev.setPercentComplete(ival); } break; case POLL_MODE: /* ------------------- Poll mode -------------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollMode(), sval)) { ev.setPollMode(sval); } break; case POLL_PROPERTIES: /* ------------------- Poll properties ---------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollProperties(), sval)) { ev.setPollProperties(sval); } break; case POLL_WINNER: /* ------------------- Poll winner -------------------- */ ival = ((PollWinner)prop).getPollwinner(); if (chg.changed(pi, ev.getPollWinner(), ival)) { ev.setPollWinner(ival); } break; case PRIORITY: /* ------------------- Priority -------------------- */ ival = ((Priority)prop).getLevel(); if (chg.changed(pi, ev.getPriority(), ival)) { ev.setPriority(ival); } break; case RDATE: /* ------------------- RDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case RECURRENCE_ID: /* ------------------- RecurrenceID -------------------- */ // Done above break; case RELATED_TO: /* ------------------- RelatedTo -------------------- */ final RelatedTo irelto = (RelatedTo)prop; final BwRelatedTo relto = new BwRelatedTo(); final String parval = IcalUtil.getParameterVal(irelto, "RELTYPE"); if (parval != null) { relto.setRelType(parval); } relto.setValue(irelto.getValue()); if (chg.changed(pi, ev.getRelatedTo(), relto)) { ev.setRelatedTo(relto); } break; case REQUEST_STATUS: /* ------------------- RequestStatus -------------------- */ final BwRequestStatus rs = BwRequestStatus .fromRequestStatus((RequestStatus)prop); chg.addValue(pi, rs); break; case RESOURCES: /* ------------------- Resources -------------------- */ final TextList rl = ((Resources)prop).getResources(); if (rl != null) { /* Got some resources */ lang = IcalUtil.getLang(prop); for (final String s: rl) { final BwString rsrc = new BwString(lang, s); chg.addValue(pi, rsrc); } } break; case RRULE: /* ------------------- RRule -------------------- */ chg.addValue(pi, pval); break; case SEQUENCE: /* ------------------- Sequence -------------------- */ final int seq = ((Sequence)prop).getSequenceNo(); if (seq != ev.getSequence()) { chg.changed(pi, ev.getSequence(), seq); ev.setSequence(seq); } break; case STATUS: /* ------------------- Status -------------------- */ if (chg.changed(pi, ev.getStatus(), pval)) { ev.setStatus(pval); } break; case SUMMARY: /* ------------------- Summary -------------------- */ if (chg.changed(pi, ev.getSummary(), pval)) { ev.setSummary(pval); } break; case TRANSP: /* ------------------- Transp -------------------- */ if (chg.changed(pi, ev.getPeruserTransparency( cb.getPrincipal() .getPrincipalRef()), pval)) { final BwXproperty pu = ev.setPeruserTransparency( cb.getPrincipal().getPrincipalRef(), pval); if (pu != null) { chg.addValue(PropertyInfoIndex.XPROP, pu); } } break; case UID: /* ------------------- Uid -------------------- */ /* We did this above */ break; case URL: /* ------------------- Url -------------------- */ if (chg.changed(pi, ev.getLink(), pval)) { ev.setLink(pval); } break; case XPROP: /* ------------------------- x-property --------------------------- */ final String name = prop.getName(); if (name.equalsIgnoreCase(BwXproperty.bedeworkCost)) { if (chg.changed(PropertyInfoIndex.COST, ev.getCost(), pval)) { ev.setCost(pval); } break; } if (name.equalsIgnoreCase(BwXproperty.xBedeworkCategories)) { if (checkCategory(cb, chg, ev, null, pval)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkLocation)) { if (checkLocation(cb, chg, ev, prop)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkContact)) { if (checkContact(cb, chg, ev, null, pval)) { break; } } /* See if this is an x-category that can be converted to a real category */ final XProperty xp = (XProperty)prop; chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(name, xp.getParameters() .toString(), pval)); break; default: if (logger.debug()) { logger.debug("Unsupported property with index " + pi + "; class " + prop.getClass() + " and value " + pval); } } } /* =================== Process sub-components =============== */ final ComponentList<Component> subComps; if (val instanceof ComponentContainer) { subComps = ((ComponentContainer<Component>)val).getComponents(); } else { subComps = null; } final Set<Integer> pids; if (vpoll) { pids = new TreeSet<>(); final BwEvent vp = evinfo.getEvent(); if (!Util.isEmpty(vp.getPollItems())) { vp.clearPollItems(); } } else { pids = null; } if (!Util.isEmpty(subComps)) { for (final var subComp: subComps) { if (subComp instanceof Available) { if (!(val instanceof VAvailability)) { return Response.error(resp, "AVAILABLE only valid in VAVAILABLE"); } final var avlResp = processAvailable(cb, cal, ical, (VAvailability)val, (Available)subComp, evinfo); if (!avlResp.isOk()) { return Response.fromResponse(resp, avlResp); } continue; } if (subComp instanceof Participant) { if (vpoll) { final var vresp = processVoter(cb, (VPoll)val, (Participant)subComp, evinfo, chg, mergeAttendees); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Participant object"); continue; } if (subComp instanceof VResource) { logger.warn("Unimplemented VResource object"); continue; } if (subComp instanceof VLocation) { logger.warn("Unimplemented VLocation object"); continue; } if (subComp instanceof VAlarm) { final var aresp = VAlarmUtil.processAlarm(cb, val, (VAlarm)subComp, ev, currentPrincipal, chg); if (!aresp.isOk()) { return Response.fromResponse(resp, aresp); } continue; } if (vpoll && (event || task)) { final var vresp = processCandidate((VPoll)val, subComp, evinfo, pids, chg); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Component object: " + subComp); } } /* Fix up timestamps. */ if (ev.getCreated() == null) { if (ev.getLastmod() != null) { ev.setCreated(ev.getLastmod()); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); } else { ev.updateDtstamp(); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } } if (ev.getLastmod() == null) { // created cannot be null now ev.setLastmod(ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } processTimezones(ev, ical, chg); /* Remove any recipients and originator */ if (ev.getRecipients() != null) { ev.getRecipients().clear(); } ev.setOriginator(null); if (hasXparams.value) { /* Save a text copy of the entire event as an x-property */ final Component valCopy = val.copy(); /* Remove potentially large values */ final Description desp = valCopy.getProperty(Property.DESCRIPTION); if (desp != null) { desp.setValue(null); } final Attach attachp = valCopy.getProperty(Property.ATTACH); // Don't store the entire attachment - we just need the parameters. if (attachp != null) { final Value v = attachp.getParameter(Parameter.VALUE); if (v != null) { attachp.setValue(String.valueOf(attachp.getValue().hashCode())); } } chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(BwXproperty.bedeworkIcal, null, valCopy.toString())); } chg.processChanges(ev, true, false); ev.setRecurring(ev.isRecurringEntity()); if (logger.debug()) { logger.debug(chg.toString()); logger.debug(ev.toString()); } if (masterEI != null) { // Just return notfound as this event is on its override list return Response.notFound(resp); } resp.setEntity(evinfo); return resp; } catch (final Throwable t) { if (logger.debug()) { logger.error(t); } return Response.error(resp, t); } }
NONSATD
true
if (!Util.isEmpty(eis)) { if (eis.size() > 1) { // DORECUR - wrong again return Response.notOk(resp, failed, "More than one event returned for guid.");
logger.debug("TRANS-TO_EVENT: try to fetch event with guid=" + guid); } final GetEntitiesResponse<EventInfo> eisResp = cb.getEvent(colPath, guid); if (eisResp.isError()) { return Response.fromResponse(resp, eisResp); } final var eis = eisResp.getEntities(); if (!Util.isEmpty(eis)) { if (eis.size() > 1) { // DORECUR - wrong again return Response.notOk(resp, failed, "More than one event returned for guid."); } evinfo = eis.iterator().next(); } if (logger.debug()) { if (evinfo != null) { logger.debug("TRANS-TO_EVENT: fetched event with guid"); } else { logger.debug("TRANS-TO_EVENT: did not find event with guid");
evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; } } if ((evinfo == null) && (cal != null) && (cal.getCalType() != BwCalendar.calTypeInbox) && (cal.getCalType() != BwCalendar.calTypePendingInbox) && (cal.getCalType() != BwCalendar.calTypeOutbox)) { if (logger.debug()) { logger.debug("TRANS-TO_EVENT: try to fetch event with guid=" + guid); } final GetEntitiesResponse<EventInfo> eisResp = cb.getEvent(colPath, guid); if (eisResp.isError()) { return Response.fromResponse(resp, eisResp); } final var eis = eisResp.getEntities(); if (!Util.isEmpty(eis)) { if (eis.size() > 1) { // DORECUR - wrong again return Response.notOk(resp, failed, "More than one event returned for guid."); } evinfo = eis.iterator().next(); } if (logger.debug()) { if (evinfo != null) { logger.debug("TRANS-TO_EVENT: fetched event with guid"); } else { logger.debug("TRANS-TO_EVENT: did not find event with guid"); } } if (evinfo != null) { if (rid != null) { // We just retrieved it's master masterEI = evinfo; masterEI.setInstanceOnly(true); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; ical.addComponent(masterEI);
7,893
13
// We just retrieved it's master
public static GetEntityResponse<EventInfo> toEvent( final IcalCallback cb, final BwCalendar cal, final Icalendar ical, final Component val, final boolean mergeAttendees) { final var resp = new GetEntityResponse<EventInfo>(); if (val == null) { return Response.notOk(resp, failed, "No component supplied"); } String currentPrincipal = null; final BwPrincipal principal = cb.getPrincipal(); if (principal != null) { currentPrincipal = principal.getPrincipalRef(); } final Holder<Boolean> hasXparams = new Holder<>(Boolean.FALSE); final int methodType = ical.getMethodType(); String attUri = null; if (mergeAttendees) { // We'll need this later. attUri = cb.getCaladdr(cb.getPrincipal().getPrincipalRef()); } final String colPath; if (cal == null) { colPath = null; } else { colPath = cal.getPath(); } try { final PropertyList<Property> pl = val.getProperties(); boolean vpoll = false; boolean event = false; boolean task = false; if (pl == null) { // Empty component return Response.notOk(resp, failed, "Empty component"); } final int entityType; if (val instanceof VEvent) { entityType = IcalDefs.entityTypeEvent; event = true; } else if (val instanceof VToDo) { entityType = IcalDefs.entityTypeTodo; task = true; } else if (val instanceof VJournal) { entityType = IcalDefs.entityTypeJournal; } else if (val instanceof VFreeBusy) { entityType = IcalDefs.entityTypeFreeAndBusy; } else if (val instanceof VAvailability) { entityType = IcalDefs.entityTypeVavailability; } else if (val instanceof Available) { entityType = IcalDefs.entityTypeAvailable; } else if (val instanceof VPoll) { entityType = IcalDefs.entityTypeVpoll; vpoll = true; } else { return Response.error(resp, "org.bedework.invalid.component.type: " + val.getName()); } // Get the guid from the component String guid = null; final Uid uidp = pl.getProperty(Property.UID); if (uidp != null) { testXparams(uidp, hasXparams); guid = uidp.getValue(); } if (guid == null) { /* XXX A guid is required - but are there devices out there without a * guid - and if so how do we handle it? */ return Response.notOk(resp, failed, CalFacadeException.noGuid); } /* See if we have a recurrence id */ BwDateTime ridObj = null; String rid = null; TimeZone ridTz = null; final RecurrenceId ridp = pl.getProperty(Property.RECURRENCE_ID); if (ridp != null) { testXparams(ridp, hasXparams); ridObj = BwDateTime.makeBwDateTime(ridp); if (ridObj.getRange() != null) { /* XXX What do I do with it? */ logger.warn("TRANS-TO_EVENT: Got a recurrence id range"); } rid = ridObj.getDate(); } EventInfo masterEI = null; EventInfo evinfo = null; final BwEvent ev; /* If we have a recurrence id see if we already have the master (we should * get a master + all its overrides). * * If so find the override and use the annnotation or if no override, * make one. * * If no override retrieve the event, add it to our table and then locate the * annotation. * * If there is no annotation, create one. * * It's possible we have been sent 'detached' instances of a recurring * event. This may happen if we are invited to one or more instances of a * meeting. In this case we try to retrieve the master and if it doesn't * exist we manufacture one. We consider such an instance an update to * that instance only and leave the others alone. */ /* We need this in a couple of places */ final DtStart dtStart = pl.getProperty(Property.DTSTART); /* if (rid != null) { // See if we have a new master event. If so create a proxy to that event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI == null) { masterEI = makeNewEvent(cb, chg, entityType, guid, cal); BwEvent e = masterEI.getEvent(); // XXX This seems bogus DtStart mdtStart; String bogusDate = "19980118T230000"; if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + "Z"); } else if (dtStart.getTimeZone() == null) { mdtStart = new DtStart(bogusDate); } else { mdtStart = new DtStart(bogusDate + "Z", dtStart.getTimeZone()); } setDates(e, mdtStart, null, null, chg); e.setRecurring(true); e.addRdate(ridObj); e.setSuppressed(true); ical.addComponent(masterEI); } if (masterEI != null) { evinfo = masterEI.findOverride(rid); } } */ /* If this is a recurrence instance see if we can find the master We only need this because the master may follow the overrides. */ if (rid != null) { // See if we have a new master event. If so create a proxy to this event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI != null) { evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; } } if ((evinfo == null) && (cal != null) && (cal.getCalType() != BwCalendar.calTypeInbox) && (cal.getCalType() != BwCalendar.calTypePendingInbox) && (cal.getCalType() != BwCalendar.calTypeOutbox)) { if (logger.debug()) { logger.debug("TRANS-TO_EVENT: try to fetch event with guid=" + guid); } final GetEntitiesResponse<EventInfo> eisResp = cb.getEvent(colPath, guid); if (eisResp.isError()) { return Response.fromResponse(resp, eisResp); } final var eis = eisResp.getEntities(); if (!Util.isEmpty(eis)) { if (eis.size() > 1) { // DORECUR - wrong again return Response.notOk(resp, failed, "More than one event returned for guid."); } evinfo = eis.iterator().next(); } if (logger.debug()) { if (evinfo != null) { logger.debug("TRANS-TO_EVENT: fetched event with guid"); } else { logger.debug("TRANS-TO_EVENT: did not find event with guid"); } } if (evinfo != null) { if (rid != null) { // We just retrieved it's master masterEI = evinfo; masterEI.setInstanceOnly(true); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; ical.addComponent(masterEI); } else if (methodType == ScheduleMethods.methodTypeCancel) { // This should never have an rid for cancel of entire event. evinfo.setInstanceOnly(evinfo.getEvent().getSuppressed()); } else { // Presumably sent an update for the entire event. No longer suppressed master evinfo.getEvent().setSuppressed(false); } } else if (rid != null) { /* Manufacture a master for the instance */ masterEI = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); final BwEvent e = masterEI.getEvent(); // XXX This seems bogus final DtStart mdtStart; final String bogusDate = "19980118"; final String bogusTime = "T230000"; // Base dtstart on the recurrence id. final boolean isDateType = ridObj.getDateType(); if (isDateType) { mdtStart = new DtStart(new Date(bogusDate)); } else if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + bogusTime + "Z"); } else if (ridObj.getTzid() == null) { mdtStart = new DtStart(bogusDate + bogusTime); } else { mdtStart = new DtStart(bogusDate + bogusTime, Timezones.getTz(ridObj.getTzid())); } IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), masterEI, mdtStart, null, null); e.setRecurring(true); // e.addRdate(ridObj); final var sum = (Summary)pl.getProperty(Property.SUMMARY); e.setSummary(sum.getValue()); e.setSuppressed(true); ical.addComponent(masterEI); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; masterEI.setInstanceOnly(rid != null); } } if (evinfo == null) { evinfo = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); } else if (evinfo.getEvent().getEntityType() != entityType) { return Response.notOk(resp, failed, "org.bedework.mismatched.entity.type: " + val); } final ChangeTable chg = evinfo.getChangeset( cb.getPrincipal().getPrincipalRef()); if (rid != null) { final String evrid = evinfo.getEvent().getRecurrenceId(); if ((evrid == null) || (!evrid.equals(rid))) { logger. warn("Mismatched rid ev=" + evrid + " expected " + rid); chg.changed(PropertyInfoIndex.RECURRENCE_ID, evrid, rid); // XXX spurious??? } if (masterEI.getEvent().getSuppressed()) { masterEI.getEvent().addRdate(ridObj); } } ev = evinfo.getEvent(); ev.setScheduleMethod(methodType); DtEnd dtEnd = null; if (entityType == IcalDefs.entityTypeTodo) { final Due due = pl.getProperty(Property.DUE); if (due != null ) { dtEnd = new DtEnd(due.getParameters(), due.getValue()); } } else { dtEnd = pl.getProperty(Property.DTEND); } final Duration duration = pl.getProperty(Property.DURATION); IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), evinfo, dtStart, dtEnd, duration); for (final Property prop: pl) { testXparams(prop, hasXparams); //debug("ical prop " + prop.getClass().getName()); String pval = prop.getValue(); if ((pval != null) && (pval.length() == 0)) { pval = null; } final PropertyInfoIndex pi; if (prop instanceof XProperty) { pi = PropertyInfoIndex.XPROP; } else { pi = PropertyInfoIndex.fromName(prop.getName()); } if (pi == null) { logger.debug("Unknown property with name " + prop.getName() + " class " + prop.getClass() + " and value " + pval); continue; } chg.present(pi); switch (pi) { case ACCEPT_RESPONSE: /* ------------------- Accept Response -------------------- */ String sval = prop.getValue(); if (chg.changed(pi, ev.getPollAcceptResponse(), sval)) { ev.setPollAcceptResponse(sval); } break; case ATTACH: /* ------------------- Attachment -------------------- */ chg.addValue(pi, IcalUtil.getAttachment((Attach)prop)); break; case ATTENDEE: /* ------------------- Attendee -------------------- */ if (methodType == ScheduleMethods.methodTypePublish) { if (cb.getStrictness() == IcalCallback.conformanceStrict) { return Response.notOk(resp, failed, CalFacadeException.attendeesInPublish); } //if (cb.getStrictness() == IcalCallback.conformanceWarn) { // warn("Had attendees for PUBLISH"); //} } final Attendee attPr = (Attendee)prop; if (evinfo.getNewEvent() || !mergeAttendees) { chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { final String pUri = cb.getCaladdr(attPr.getValue()); if (pUri.equals(attUri)) { /* Only update for our own attendee * We're doing a PUT and this must be the attendee updating their * partstat. We don't allow them to change other attendees * whatever the PUT content says. */ chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { // Use the value we currently have boolean found = false; for (final BwAttendee att: ev.getAttendees()) { if (pUri.equals(att.getAttendeeUri())) { chg.addValue(pi, att.clone()); found = true; break; } } if (!found) { // An added attendee final BwAttendee att = IcalUtil .getAttendee(cb, attPr); att.setPartstat(IcalDefs.partstatValNeedsAction); chg.addValue(pi, att); } } } break; case BUSYTYPE: final int ibt = BwEvent.fromBusyTypeString(pval); if (chg.changed(pi, ev.getBusyType(), ibt)) { ev.setBusyType(ibt); } break; case CATEGORIES: /* ------------------- Categories -------------------- */ final Categories cats = (Categories)prop; final TextList cl = cats.getCategories(); String lang = IcalUtil.getLang(cats); if (cl != null) { /* Got some categories */ for (final String wd: cl) { if (wd == null) { continue; } final BwString key = new BwString(lang, wd); final var fcResp = cb.findCategory(key); final BwCategory cat; if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isNotFound()) { cat = BwCategory.makeCategory(); cat.setWord(key); cb.addCategory(cat); } else { cat = fcResp.getEntity(); } chg.addValue(pi, cat); } } break; case CLASS: /* ------------------- Class -------------------- */ if (chg.changed(pi, ev.getClassification(), pval)) { ev.setClassification(pval); } break; case COMMENT: /* ------------------- Comment -------------------- */ chg.addValue(pi, new BwString(null, pval)); break; case COMPLETED: /* ------------------- Completed -------------------- */ if (chg.changed(pi, ev.getCompleted(), pval)) { ev.setCompleted(pval); } break; case CONCEPT: /* ------------------- Concept -------------------- */ final Concept c = (Concept)prop; final String cval = c.getValue(); if (cval != null) { /* Got a concept */ chg.addValue(PropertyInfoIndex.XPROP, BwXproperty.makeIcalProperty("CONCEPT", null, cval)); } break; case CONTACT: /* ------------------- Contact -------------------- */ final String altrep = getAltRepPar(prop); lang = IcalUtil.getLang(prop); final String uid = getUidPar(prop); final BwString nm = new BwString(lang, pval); BwContact contact = null; if (uid != null) { final var fcResp = cb.getContact(uid); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { final var fcResp = cb.findContact(nm); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { contact = BwContact.makeContact(); contact.setCn(nm); contact.setLink(altrep); cb.addContact(contact); } else { contact.setCn(nm); contact.setLink(altrep); } chg.addValue(pi, contact); break; case CREATED: /* ------------------- Created -------------------- */ if (chg.changed(pi, ev.getCreated(), pval)) { ev.setCreated(pval); } break; case DESCRIPTION: /* ------------------- Description -------------------- */ if (chg.changed(pi, ev.getDescription(), pval)) { ev.setDescription(pval); } break; case DTEND: /* ------------------- DtEnd -------------------- */ break; case DTSTAMP: /* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval); break; case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE: /* -------------------- Due ------------------------ */ break; case DURATION: /* ------------------- Duration -------------------- */ break; case EXDATE: /* ------------------- ExDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case EXRULE: /* ------------------- ExRule -------------------- */ chg.addValue(pi, pval); break; case FREEBUSY: /* ------------------- freebusy -------------------- */ final FreeBusy fbusy = (FreeBusy)prop; final PeriodList perpl = fbusy.getPeriods(); final Parameter par = IcalUtil.getParameter(fbusy, "FBTYPE"); final int fbtype; if (par == null) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY)) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY_TENTATIVE)) { fbtype = BwFreeBusyComponent.typeBusyTentative; } else if (par.equals(FbType.BUSY_UNAVAILABLE)) { fbtype = BwFreeBusyComponent.typeBusyUnavailable; } else if (par.equals(FbType.FREE)) { fbtype = BwFreeBusyComponent.typeFree; } else { if (logger.debug()) { logger.debug("Unsupported parameter " + par.getName()); } return Response.notOk(resp, failed, "Unsupported parameter " + par.getName()); } final BwFreeBusyComponent fbc = new BwFreeBusyComponent(); fbc.setType(fbtype); for (final Period per : perpl) { fbc.addPeriod(per); } ev.addFreeBusyPeriod(fbc); break; case GEO: /* ------------------- Geo -------------------- */ final Geo g = (Geo)prop; final BwGeo geo = new BwGeo(g.getLatitude(), g.getLongitude()); if (chg.changed(pi, ev.getGeo(), geo)) { ev.setGeo(geo); } break; case LAST_MODIFIED: /* ------------------- LastModified -------------------- */ if (chg.changed(pi, ev.getLastmod(), pval)) { ev.setLastmod(pval); } break; case LOCATION: /* ------------------- Location -------------------- */ BwLocation loc = null; //String uid = getUidPar(prop); /* At the moment Mozilla lightning is broken and this leads to all * sorts of problems. if (uid != null) { loc = cb.getLocation(uid); } */ lang = IcalUtil.getLang(prop); BwString addr = null; if (pval != null) { if (loc == null) { addr = new BwString(lang, pval); final var fcResp = cb.findLocation(addr); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { loc = fcResp.getEntity(); } } if (loc == null) { loc = BwLocation.makeLocation(); loc.setAddress(addr); cb.addLocation(loc); } } final BwLocation evloc = ev.getLocation(); if (chg.changed(pi, evloc, loc)) { // CHGTBL - this only shows that it's a different location object ev.setLocation(loc); } else if ((loc != null) && (evloc != null)) { // See if the value is changed final String evval = evloc.getAddress().getValue(); final String inval = loc.getAddress().getValue(); if (!evval.equals(inval)) { chg.changed(pi, evval, inval); evloc.getAddress().setValue(inval); } } break; case ORGANIZER: /* ------------------- Organizer -------------------- */ final BwOrganizer org = IcalUtil.getOrganizer(cb, (Organizer)prop); final BwOrganizer evorg = ev.getOrganizer(); final BwOrganizer evorgCopy; if (evorg == null) { evorgCopy = null; } else { evorgCopy = (BwOrganizer)evorg.clone(); } if (chg.changed(pi, evorgCopy, org)) { if (evorg == null) { ev.setOrganizer(org); } else { evorg.update(org); } } break; case PERCENT_COMPLETE: /* ------------------- PercentComplete -------------------- */ Integer ival = ((PercentComplete)prop).getPercentage(); if (chg.changed(pi, ev.getPercentComplete(), ival)) { ev.setPercentComplete(ival); } break; case POLL_MODE: /* ------------------- Poll mode -------------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollMode(), sval)) { ev.setPollMode(sval); } break; case POLL_PROPERTIES: /* ------------------- Poll properties ---------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollProperties(), sval)) { ev.setPollProperties(sval); } break; case POLL_WINNER: /* ------------------- Poll winner -------------------- */ ival = ((PollWinner)prop).getPollwinner(); if (chg.changed(pi, ev.getPollWinner(), ival)) { ev.setPollWinner(ival); } break; case PRIORITY: /* ------------------- Priority -------------------- */ ival = ((Priority)prop).getLevel(); if (chg.changed(pi, ev.getPriority(), ival)) { ev.setPriority(ival); } break; case RDATE: /* ------------------- RDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case RECURRENCE_ID: /* ------------------- RecurrenceID -------------------- */ // Done above break; case RELATED_TO: /* ------------------- RelatedTo -------------------- */ final RelatedTo irelto = (RelatedTo)prop; final BwRelatedTo relto = new BwRelatedTo(); final String parval = IcalUtil.getParameterVal(irelto, "RELTYPE"); if (parval != null) { relto.setRelType(parval); } relto.setValue(irelto.getValue()); if (chg.changed(pi, ev.getRelatedTo(), relto)) { ev.setRelatedTo(relto); } break; case REQUEST_STATUS: /* ------------------- RequestStatus -------------------- */ final BwRequestStatus rs = BwRequestStatus .fromRequestStatus((RequestStatus)prop); chg.addValue(pi, rs); break; case RESOURCES: /* ------------------- Resources -------------------- */ final TextList rl = ((Resources)prop).getResources(); if (rl != null) { /* Got some resources */ lang = IcalUtil.getLang(prop); for (final String s: rl) { final BwString rsrc = new BwString(lang, s); chg.addValue(pi, rsrc); } } break; case RRULE: /* ------------------- RRule -------------------- */ chg.addValue(pi, pval); break; case SEQUENCE: /* ------------------- Sequence -------------------- */ final int seq = ((Sequence)prop).getSequenceNo(); if (seq != ev.getSequence()) { chg.changed(pi, ev.getSequence(), seq); ev.setSequence(seq); } break; case STATUS: /* ------------------- Status -------------------- */ if (chg.changed(pi, ev.getStatus(), pval)) { ev.setStatus(pval); } break; case SUMMARY: /* ------------------- Summary -------------------- */ if (chg.changed(pi, ev.getSummary(), pval)) { ev.setSummary(pval); } break; case TRANSP: /* ------------------- Transp -------------------- */ if (chg.changed(pi, ev.getPeruserTransparency( cb.getPrincipal() .getPrincipalRef()), pval)) { final BwXproperty pu = ev.setPeruserTransparency( cb.getPrincipal().getPrincipalRef(), pval); if (pu != null) { chg.addValue(PropertyInfoIndex.XPROP, pu); } } break; case UID: /* ------------------- Uid -------------------- */ /* We did this above */ break; case URL: /* ------------------- Url -------------------- */ if (chg.changed(pi, ev.getLink(), pval)) { ev.setLink(pval); } break; case XPROP: /* ------------------------- x-property --------------------------- */ final String name = prop.getName(); if (name.equalsIgnoreCase(BwXproperty.bedeworkCost)) { if (chg.changed(PropertyInfoIndex.COST, ev.getCost(), pval)) { ev.setCost(pval); } break; } if (name.equalsIgnoreCase(BwXproperty.xBedeworkCategories)) { if (checkCategory(cb, chg, ev, null, pval)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkLocation)) { if (checkLocation(cb, chg, ev, prop)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkContact)) { if (checkContact(cb, chg, ev, null, pval)) { break; } } /* See if this is an x-category that can be converted to a real category */ final XProperty xp = (XProperty)prop; chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(name, xp.getParameters() .toString(), pval)); break; default: if (logger.debug()) { logger.debug("Unsupported property with index " + pi + "; class " + prop.getClass() + " and value " + pval); } } } /* =================== Process sub-components =============== */ final ComponentList<Component> subComps; if (val instanceof ComponentContainer) { subComps = ((ComponentContainer<Component>)val).getComponents(); } else { subComps = null; } final Set<Integer> pids; if (vpoll) { pids = new TreeSet<>(); final BwEvent vp = evinfo.getEvent(); if (!Util.isEmpty(vp.getPollItems())) { vp.clearPollItems(); } } else { pids = null; } if (!Util.isEmpty(subComps)) { for (final var subComp: subComps) { if (subComp instanceof Available) { if (!(val instanceof VAvailability)) { return Response.error(resp, "AVAILABLE only valid in VAVAILABLE"); } final var avlResp = processAvailable(cb, cal, ical, (VAvailability)val, (Available)subComp, evinfo); if (!avlResp.isOk()) { return Response.fromResponse(resp, avlResp); } continue; } if (subComp instanceof Participant) { if (vpoll) { final var vresp = processVoter(cb, (VPoll)val, (Participant)subComp, evinfo, chg, mergeAttendees); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Participant object"); continue; } if (subComp instanceof VResource) { logger.warn("Unimplemented VResource object"); continue; } if (subComp instanceof VLocation) { logger.warn("Unimplemented VLocation object"); continue; } if (subComp instanceof VAlarm) { final var aresp = VAlarmUtil.processAlarm(cb, val, (VAlarm)subComp, ev, currentPrincipal, chg); if (!aresp.isOk()) { return Response.fromResponse(resp, aresp); } continue; } if (vpoll && (event || task)) { final var vresp = processCandidate((VPoll)val, subComp, evinfo, pids, chg); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Component object: " + subComp); } } /* Fix up timestamps. */ if (ev.getCreated() == null) { if (ev.getLastmod() != null) { ev.setCreated(ev.getLastmod()); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); } else { ev.updateDtstamp(); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } } if (ev.getLastmod() == null) { // created cannot be null now ev.setLastmod(ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } processTimezones(ev, ical, chg); /* Remove any recipients and originator */ if (ev.getRecipients() != null) { ev.getRecipients().clear(); } ev.setOriginator(null); if (hasXparams.value) { /* Save a text copy of the entire event as an x-property */ final Component valCopy = val.copy(); /* Remove potentially large values */ final Description desp = valCopy.getProperty(Property.DESCRIPTION); if (desp != null) { desp.setValue(null); } final Attach attachp = valCopy.getProperty(Property.ATTACH); // Don't store the entire attachment - we just need the parameters. if (attachp != null) { final Value v = attachp.getParameter(Parameter.VALUE); if (v != null) { attachp.setValue(String.valueOf(attachp.getValue().hashCode())); } } chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(BwXproperty.bedeworkIcal, null, valCopy.toString())); } chg.processChanges(ev, true, false); ev.setRecurring(ev.isRecurringEntity()); if (logger.debug()) { logger.debug(chg.toString()); logger.debug(ev.toString()); } if (masterEI != null) { // Just return notfound as this event is on its override list return Response.notFound(resp); } resp.setEntity(evinfo); return resp; } catch (final Throwable t) { if (logger.debug()) { logger.error(t); } return Response.error(resp, t); } }
NONSATD
true
if (evinfo != null) { if (rid != null) { // We just retrieved it's master masterEI = evinfo; masterEI.setInstanceOnly(true);
} if (logger.debug()) { if (evinfo != null) { logger.debug("TRANS-TO_EVENT: fetched event with guid"); } else { logger.debug("TRANS-TO_EVENT: did not find event with guid"); } } if (evinfo != null) { if (rid != null) { // We just retrieved it's master masterEI = evinfo; masterEI.setInstanceOnly(true); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; ical.addComponent(masterEI); } else if (methodType == ScheduleMethods.methodTypeCancel) { // This should never have an rid for cancel of entire event. evinfo.setInstanceOnly(evinfo.getEvent().getSuppressed()); } else { // Presumably sent an update for the entire event. No longer suppressed master
return Response.fromResponse(resp, eisResp); } final var eis = eisResp.getEntities(); if (!Util.isEmpty(eis)) { if (eis.size() > 1) { // DORECUR - wrong again return Response.notOk(resp, failed, "More than one event returned for guid."); } evinfo = eis.iterator().next(); } if (logger.debug()) { if (evinfo != null) { logger.debug("TRANS-TO_EVENT: fetched event with guid"); } else { logger.debug("TRANS-TO_EVENT: did not find event with guid"); } } if (evinfo != null) { if (rid != null) { // We just retrieved it's master masterEI = evinfo; masterEI.setInstanceOnly(true); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; ical.addComponent(masterEI); } else if (methodType == ScheduleMethods.methodTypeCancel) { // This should never have an rid for cancel of entire event. evinfo.setInstanceOnly(evinfo.getEvent().getSuppressed()); } else { // Presumably sent an update for the entire event. No longer suppressed master evinfo.getEvent().setSuppressed(false); } } else if (rid != null) { /* Manufacture a master for the instance */ masterEI = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); final BwEvent e = masterEI.getEvent(); // XXX This seems bogus final DtStart mdtStart; final String bogusDate = "19980118"; final String bogusTime = "T230000";
7,893
14
// This should never have an rid for cancel of entire event.
public static GetEntityResponse<EventInfo> toEvent( final IcalCallback cb, final BwCalendar cal, final Icalendar ical, final Component val, final boolean mergeAttendees) { final var resp = new GetEntityResponse<EventInfo>(); if (val == null) { return Response.notOk(resp, failed, "No component supplied"); } String currentPrincipal = null; final BwPrincipal principal = cb.getPrincipal(); if (principal != null) { currentPrincipal = principal.getPrincipalRef(); } final Holder<Boolean> hasXparams = new Holder<>(Boolean.FALSE); final int methodType = ical.getMethodType(); String attUri = null; if (mergeAttendees) { // We'll need this later. attUri = cb.getCaladdr(cb.getPrincipal().getPrincipalRef()); } final String colPath; if (cal == null) { colPath = null; } else { colPath = cal.getPath(); } try { final PropertyList<Property> pl = val.getProperties(); boolean vpoll = false; boolean event = false; boolean task = false; if (pl == null) { // Empty component return Response.notOk(resp, failed, "Empty component"); } final int entityType; if (val instanceof VEvent) { entityType = IcalDefs.entityTypeEvent; event = true; } else if (val instanceof VToDo) { entityType = IcalDefs.entityTypeTodo; task = true; } else if (val instanceof VJournal) { entityType = IcalDefs.entityTypeJournal; } else if (val instanceof VFreeBusy) { entityType = IcalDefs.entityTypeFreeAndBusy; } else if (val instanceof VAvailability) { entityType = IcalDefs.entityTypeVavailability; } else if (val instanceof Available) { entityType = IcalDefs.entityTypeAvailable; } else if (val instanceof VPoll) { entityType = IcalDefs.entityTypeVpoll; vpoll = true; } else { return Response.error(resp, "org.bedework.invalid.component.type: " + val.getName()); } // Get the guid from the component String guid = null; final Uid uidp = pl.getProperty(Property.UID); if (uidp != null) { testXparams(uidp, hasXparams); guid = uidp.getValue(); } if (guid == null) { /* XXX A guid is required - but are there devices out there without a * guid - and if so how do we handle it? */ return Response.notOk(resp, failed, CalFacadeException.noGuid); } /* See if we have a recurrence id */ BwDateTime ridObj = null; String rid = null; TimeZone ridTz = null; final RecurrenceId ridp = pl.getProperty(Property.RECURRENCE_ID); if (ridp != null) { testXparams(ridp, hasXparams); ridObj = BwDateTime.makeBwDateTime(ridp); if (ridObj.getRange() != null) { /* XXX What do I do with it? */ logger.warn("TRANS-TO_EVENT: Got a recurrence id range"); } rid = ridObj.getDate(); } EventInfo masterEI = null; EventInfo evinfo = null; final BwEvent ev; /* If we have a recurrence id see if we already have the master (we should * get a master + all its overrides). * * If so find the override and use the annnotation or if no override, * make one. * * If no override retrieve the event, add it to our table and then locate the * annotation. * * If there is no annotation, create one. * * It's possible we have been sent 'detached' instances of a recurring * event. This may happen if we are invited to one or more instances of a * meeting. In this case we try to retrieve the master and if it doesn't * exist we manufacture one. We consider such an instance an update to * that instance only and leave the others alone. */ /* We need this in a couple of places */ final DtStart dtStart = pl.getProperty(Property.DTSTART); /* if (rid != null) { // See if we have a new master event. If so create a proxy to that event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI == null) { masterEI = makeNewEvent(cb, chg, entityType, guid, cal); BwEvent e = masterEI.getEvent(); // XXX This seems bogus DtStart mdtStart; String bogusDate = "19980118T230000"; if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + "Z"); } else if (dtStart.getTimeZone() == null) { mdtStart = new DtStart(bogusDate); } else { mdtStart = new DtStart(bogusDate + "Z", dtStart.getTimeZone()); } setDates(e, mdtStart, null, null, chg); e.setRecurring(true); e.addRdate(ridObj); e.setSuppressed(true); ical.addComponent(masterEI); } if (masterEI != null) { evinfo = masterEI.findOverride(rid); } } */ /* If this is a recurrence instance see if we can find the master We only need this because the master may follow the overrides. */ if (rid != null) { // See if we have a new master event. If so create a proxy to this event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI != null) { evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; } } if ((evinfo == null) && (cal != null) && (cal.getCalType() != BwCalendar.calTypeInbox) && (cal.getCalType() != BwCalendar.calTypePendingInbox) && (cal.getCalType() != BwCalendar.calTypeOutbox)) { if (logger.debug()) { logger.debug("TRANS-TO_EVENT: try to fetch event with guid=" + guid); } final GetEntitiesResponse<EventInfo> eisResp = cb.getEvent(colPath, guid); if (eisResp.isError()) { return Response.fromResponse(resp, eisResp); } final var eis = eisResp.getEntities(); if (!Util.isEmpty(eis)) { if (eis.size() > 1) { // DORECUR - wrong again return Response.notOk(resp, failed, "More than one event returned for guid."); } evinfo = eis.iterator().next(); } if (logger.debug()) { if (evinfo != null) { logger.debug("TRANS-TO_EVENT: fetched event with guid"); } else { logger.debug("TRANS-TO_EVENT: did not find event with guid"); } } if (evinfo != null) { if (rid != null) { // We just retrieved it's master masterEI = evinfo; masterEI.setInstanceOnly(true); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; ical.addComponent(masterEI); } else if (methodType == ScheduleMethods.methodTypeCancel) { // This should never have an rid for cancel of entire event. evinfo.setInstanceOnly(evinfo.getEvent().getSuppressed()); } else { // Presumably sent an update for the entire event. No longer suppressed master evinfo.getEvent().setSuppressed(false); } } else if (rid != null) { /* Manufacture a master for the instance */ masterEI = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); final BwEvent e = masterEI.getEvent(); // XXX This seems bogus final DtStart mdtStart; final String bogusDate = "19980118"; final String bogusTime = "T230000"; // Base dtstart on the recurrence id. final boolean isDateType = ridObj.getDateType(); if (isDateType) { mdtStart = new DtStart(new Date(bogusDate)); } else if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + bogusTime + "Z"); } else if (ridObj.getTzid() == null) { mdtStart = new DtStart(bogusDate + bogusTime); } else { mdtStart = new DtStart(bogusDate + bogusTime, Timezones.getTz(ridObj.getTzid())); } IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), masterEI, mdtStart, null, null); e.setRecurring(true); // e.addRdate(ridObj); final var sum = (Summary)pl.getProperty(Property.SUMMARY); e.setSummary(sum.getValue()); e.setSuppressed(true); ical.addComponent(masterEI); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; masterEI.setInstanceOnly(rid != null); } } if (evinfo == null) { evinfo = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); } else if (evinfo.getEvent().getEntityType() != entityType) { return Response.notOk(resp, failed, "org.bedework.mismatched.entity.type: " + val); } final ChangeTable chg = evinfo.getChangeset( cb.getPrincipal().getPrincipalRef()); if (rid != null) { final String evrid = evinfo.getEvent().getRecurrenceId(); if ((evrid == null) || (!evrid.equals(rid))) { logger. warn("Mismatched rid ev=" + evrid + " expected " + rid); chg.changed(PropertyInfoIndex.RECURRENCE_ID, evrid, rid); // XXX spurious??? } if (masterEI.getEvent().getSuppressed()) { masterEI.getEvent().addRdate(ridObj); } } ev = evinfo.getEvent(); ev.setScheduleMethod(methodType); DtEnd dtEnd = null; if (entityType == IcalDefs.entityTypeTodo) { final Due due = pl.getProperty(Property.DUE); if (due != null ) { dtEnd = new DtEnd(due.getParameters(), due.getValue()); } } else { dtEnd = pl.getProperty(Property.DTEND); } final Duration duration = pl.getProperty(Property.DURATION); IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), evinfo, dtStart, dtEnd, duration); for (final Property prop: pl) { testXparams(prop, hasXparams); //debug("ical prop " + prop.getClass().getName()); String pval = prop.getValue(); if ((pval != null) && (pval.length() == 0)) { pval = null; } final PropertyInfoIndex pi; if (prop instanceof XProperty) { pi = PropertyInfoIndex.XPROP; } else { pi = PropertyInfoIndex.fromName(prop.getName()); } if (pi == null) { logger.debug("Unknown property with name " + prop.getName() + " class " + prop.getClass() + " and value " + pval); continue; } chg.present(pi); switch (pi) { case ACCEPT_RESPONSE: /* ------------------- Accept Response -------------------- */ String sval = prop.getValue(); if (chg.changed(pi, ev.getPollAcceptResponse(), sval)) { ev.setPollAcceptResponse(sval); } break; case ATTACH: /* ------------------- Attachment -------------------- */ chg.addValue(pi, IcalUtil.getAttachment((Attach)prop)); break; case ATTENDEE: /* ------------------- Attendee -------------------- */ if (methodType == ScheduleMethods.methodTypePublish) { if (cb.getStrictness() == IcalCallback.conformanceStrict) { return Response.notOk(resp, failed, CalFacadeException.attendeesInPublish); } //if (cb.getStrictness() == IcalCallback.conformanceWarn) { // warn("Had attendees for PUBLISH"); //} } final Attendee attPr = (Attendee)prop; if (evinfo.getNewEvent() || !mergeAttendees) { chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { final String pUri = cb.getCaladdr(attPr.getValue()); if (pUri.equals(attUri)) { /* Only update for our own attendee * We're doing a PUT and this must be the attendee updating their * partstat. We don't allow them to change other attendees * whatever the PUT content says. */ chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { // Use the value we currently have boolean found = false; for (final BwAttendee att: ev.getAttendees()) { if (pUri.equals(att.getAttendeeUri())) { chg.addValue(pi, att.clone()); found = true; break; } } if (!found) { // An added attendee final BwAttendee att = IcalUtil .getAttendee(cb, attPr); att.setPartstat(IcalDefs.partstatValNeedsAction); chg.addValue(pi, att); } } } break; case BUSYTYPE: final int ibt = BwEvent.fromBusyTypeString(pval); if (chg.changed(pi, ev.getBusyType(), ibt)) { ev.setBusyType(ibt); } break; case CATEGORIES: /* ------------------- Categories -------------------- */ final Categories cats = (Categories)prop; final TextList cl = cats.getCategories(); String lang = IcalUtil.getLang(cats); if (cl != null) { /* Got some categories */ for (final String wd: cl) { if (wd == null) { continue; } final BwString key = new BwString(lang, wd); final var fcResp = cb.findCategory(key); final BwCategory cat; if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isNotFound()) { cat = BwCategory.makeCategory(); cat.setWord(key); cb.addCategory(cat); } else { cat = fcResp.getEntity(); } chg.addValue(pi, cat); } } break; case CLASS: /* ------------------- Class -------------------- */ if (chg.changed(pi, ev.getClassification(), pval)) { ev.setClassification(pval); } break; case COMMENT: /* ------------------- Comment -------------------- */ chg.addValue(pi, new BwString(null, pval)); break; case COMPLETED: /* ------------------- Completed -------------------- */ if (chg.changed(pi, ev.getCompleted(), pval)) { ev.setCompleted(pval); } break; case CONCEPT: /* ------------------- Concept -------------------- */ final Concept c = (Concept)prop; final String cval = c.getValue(); if (cval != null) { /* Got a concept */ chg.addValue(PropertyInfoIndex.XPROP, BwXproperty.makeIcalProperty("CONCEPT", null, cval)); } break; case CONTACT: /* ------------------- Contact -------------------- */ final String altrep = getAltRepPar(prop); lang = IcalUtil.getLang(prop); final String uid = getUidPar(prop); final BwString nm = new BwString(lang, pval); BwContact contact = null; if (uid != null) { final var fcResp = cb.getContact(uid); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { final var fcResp = cb.findContact(nm); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { contact = BwContact.makeContact(); contact.setCn(nm); contact.setLink(altrep); cb.addContact(contact); } else { contact.setCn(nm); contact.setLink(altrep); } chg.addValue(pi, contact); break; case CREATED: /* ------------------- Created -------------------- */ if (chg.changed(pi, ev.getCreated(), pval)) { ev.setCreated(pval); } break; case DESCRIPTION: /* ------------------- Description -------------------- */ if (chg.changed(pi, ev.getDescription(), pval)) { ev.setDescription(pval); } break; case DTEND: /* ------------------- DtEnd -------------------- */ break; case DTSTAMP: /* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval); break; case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE: /* -------------------- Due ------------------------ */ break; case DURATION: /* ------------------- Duration -------------------- */ break; case EXDATE: /* ------------------- ExDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case EXRULE: /* ------------------- ExRule -------------------- */ chg.addValue(pi, pval); break; case FREEBUSY: /* ------------------- freebusy -------------------- */ final FreeBusy fbusy = (FreeBusy)prop; final PeriodList perpl = fbusy.getPeriods(); final Parameter par = IcalUtil.getParameter(fbusy, "FBTYPE"); final int fbtype; if (par == null) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY)) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY_TENTATIVE)) { fbtype = BwFreeBusyComponent.typeBusyTentative; } else if (par.equals(FbType.BUSY_UNAVAILABLE)) { fbtype = BwFreeBusyComponent.typeBusyUnavailable; } else if (par.equals(FbType.FREE)) { fbtype = BwFreeBusyComponent.typeFree; } else { if (logger.debug()) { logger.debug("Unsupported parameter " + par.getName()); } return Response.notOk(resp, failed, "Unsupported parameter " + par.getName()); } final BwFreeBusyComponent fbc = new BwFreeBusyComponent(); fbc.setType(fbtype); for (final Period per : perpl) { fbc.addPeriod(per); } ev.addFreeBusyPeriod(fbc); break; case GEO: /* ------------------- Geo -------------------- */ final Geo g = (Geo)prop; final BwGeo geo = new BwGeo(g.getLatitude(), g.getLongitude()); if (chg.changed(pi, ev.getGeo(), geo)) { ev.setGeo(geo); } break; case LAST_MODIFIED: /* ------------------- LastModified -------------------- */ if (chg.changed(pi, ev.getLastmod(), pval)) { ev.setLastmod(pval); } break; case LOCATION: /* ------------------- Location -------------------- */ BwLocation loc = null; //String uid = getUidPar(prop); /* At the moment Mozilla lightning is broken and this leads to all * sorts of problems. if (uid != null) { loc = cb.getLocation(uid); } */ lang = IcalUtil.getLang(prop); BwString addr = null; if (pval != null) { if (loc == null) { addr = new BwString(lang, pval); final var fcResp = cb.findLocation(addr); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { loc = fcResp.getEntity(); } } if (loc == null) { loc = BwLocation.makeLocation(); loc.setAddress(addr); cb.addLocation(loc); } } final BwLocation evloc = ev.getLocation(); if (chg.changed(pi, evloc, loc)) { // CHGTBL - this only shows that it's a different location object ev.setLocation(loc); } else if ((loc != null) && (evloc != null)) { // See if the value is changed final String evval = evloc.getAddress().getValue(); final String inval = loc.getAddress().getValue(); if (!evval.equals(inval)) { chg.changed(pi, evval, inval); evloc.getAddress().setValue(inval); } } break; case ORGANIZER: /* ------------------- Organizer -------------------- */ final BwOrganizer org = IcalUtil.getOrganizer(cb, (Organizer)prop); final BwOrganizer evorg = ev.getOrganizer(); final BwOrganizer evorgCopy; if (evorg == null) { evorgCopy = null; } else { evorgCopy = (BwOrganizer)evorg.clone(); } if (chg.changed(pi, evorgCopy, org)) { if (evorg == null) { ev.setOrganizer(org); } else { evorg.update(org); } } break; case PERCENT_COMPLETE: /* ------------------- PercentComplete -------------------- */ Integer ival = ((PercentComplete)prop).getPercentage(); if (chg.changed(pi, ev.getPercentComplete(), ival)) { ev.setPercentComplete(ival); } break; case POLL_MODE: /* ------------------- Poll mode -------------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollMode(), sval)) { ev.setPollMode(sval); } break; case POLL_PROPERTIES: /* ------------------- Poll properties ---------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollProperties(), sval)) { ev.setPollProperties(sval); } break; case POLL_WINNER: /* ------------------- Poll winner -------------------- */ ival = ((PollWinner)prop).getPollwinner(); if (chg.changed(pi, ev.getPollWinner(), ival)) { ev.setPollWinner(ival); } break; case PRIORITY: /* ------------------- Priority -------------------- */ ival = ((Priority)prop).getLevel(); if (chg.changed(pi, ev.getPriority(), ival)) { ev.setPriority(ival); } break; case RDATE: /* ------------------- RDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case RECURRENCE_ID: /* ------------------- RecurrenceID -------------------- */ // Done above break; case RELATED_TO: /* ------------------- RelatedTo -------------------- */ final RelatedTo irelto = (RelatedTo)prop; final BwRelatedTo relto = new BwRelatedTo(); final String parval = IcalUtil.getParameterVal(irelto, "RELTYPE"); if (parval != null) { relto.setRelType(parval); } relto.setValue(irelto.getValue()); if (chg.changed(pi, ev.getRelatedTo(), relto)) { ev.setRelatedTo(relto); } break; case REQUEST_STATUS: /* ------------------- RequestStatus -------------------- */ final BwRequestStatus rs = BwRequestStatus .fromRequestStatus((RequestStatus)prop); chg.addValue(pi, rs); break; case RESOURCES: /* ------------------- Resources -------------------- */ final TextList rl = ((Resources)prop).getResources(); if (rl != null) { /* Got some resources */ lang = IcalUtil.getLang(prop); for (final String s: rl) { final BwString rsrc = new BwString(lang, s); chg.addValue(pi, rsrc); } } break; case RRULE: /* ------------------- RRule -------------------- */ chg.addValue(pi, pval); break; case SEQUENCE: /* ------------------- Sequence -------------------- */ final int seq = ((Sequence)prop).getSequenceNo(); if (seq != ev.getSequence()) { chg.changed(pi, ev.getSequence(), seq); ev.setSequence(seq); } break; case STATUS: /* ------------------- Status -------------------- */ if (chg.changed(pi, ev.getStatus(), pval)) { ev.setStatus(pval); } break; case SUMMARY: /* ------------------- Summary -------------------- */ if (chg.changed(pi, ev.getSummary(), pval)) { ev.setSummary(pval); } break; case TRANSP: /* ------------------- Transp -------------------- */ if (chg.changed(pi, ev.getPeruserTransparency( cb.getPrincipal() .getPrincipalRef()), pval)) { final BwXproperty pu = ev.setPeruserTransparency( cb.getPrincipal().getPrincipalRef(), pval); if (pu != null) { chg.addValue(PropertyInfoIndex.XPROP, pu); } } break; case UID: /* ------------------- Uid -------------------- */ /* We did this above */ break; case URL: /* ------------------- Url -------------------- */ if (chg.changed(pi, ev.getLink(), pval)) { ev.setLink(pval); } break; case XPROP: /* ------------------------- x-property --------------------------- */ final String name = prop.getName(); if (name.equalsIgnoreCase(BwXproperty.bedeworkCost)) { if (chg.changed(PropertyInfoIndex.COST, ev.getCost(), pval)) { ev.setCost(pval); } break; } if (name.equalsIgnoreCase(BwXproperty.xBedeworkCategories)) { if (checkCategory(cb, chg, ev, null, pval)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkLocation)) { if (checkLocation(cb, chg, ev, prop)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkContact)) { if (checkContact(cb, chg, ev, null, pval)) { break; } } /* See if this is an x-category that can be converted to a real category */ final XProperty xp = (XProperty)prop; chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(name, xp.getParameters() .toString(), pval)); break; default: if (logger.debug()) { logger.debug("Unsupported property with index " + pi + "; class " + prop.getClass() + " and value " + pval); } } } /* =================== Process sub-components =============== */ final ComponentList<Component> subComps; if (val instanceof ComponentContainer) { subComps = ((ComponentContainer<Component>)val).getComponents(); } else { subComps = null; } final Set<Integer> pids; if (vpoll) { pids = new TreeSet<>(); final BwEvent vp = evinfo.getEvent(); if (!Util.isEmpty(vp.getPollItems())) { vp.clearPollItems(); } } else { pids = null; } if (!Util.isEmpty(subComps)) { for (final var subComp: subComps) { if (subComp instanceof Available) { if (!(val instanceof VAvailability)) { return Response.error(resp, "AVAILABLE only valid in VAVAILABLE"); } final var avlResp = processAvailable(cb, cal, ical, (VAvailability)val, (Available)subComp, evinfo); if (!avlResp.isOk()) { return Response.fromResponse(resp, avlResp); } continue; } if (subComp instanceof Participant) { if (vpoll) { final var vresp = processVoter(cb, (VPoll)val, (Participant)subComp, evinfo, chg, mergeAttendees); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Participant object"); continue; } if (subComp instanceof VResource) { logger.warn("Unimplemented VResource object"); continue; } if (subComp instanceof VLocation) { logger.warn("Unimplemented VLocation object"); continue; } if (subComp instanceof VAlarm) { final var aresp = VAlarmUtil.processAlarm(cb, val, (VAlarm)subComp, ev, currentPrincipal, chg); if (!aresp.isOk()) { return Response.fromResponse(resp, aresp); } continue; } if (vpoll && (event || task)) { final var vresp = processCandidate((VPoll)val, subComp, evinfo, pids, chg); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Component object: " + subComp); } } /* Fix up timestamps. */ if (ev.getCreated() == null) { if (ev.getLastmod() != null) { ev.setCreated(ev.getLastmod()); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); } else { ev.updateDtstamp(); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } } if (ev.getLastmod() == null) { // created cannot be null now ev.setLastmod(ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } processTimezones(ev, ical, chg); /* Remove any recipients and originator */ if (ev.getRecipients() != null) { ev.getRecipients().clear(); } ev.setOriginator(null); if (hasXparams.value) { /* Save a text copy of the entire event as an x-property */ final Component valCopy = val.copy(); /* Remove potentially large values */ final Description desp = valCopy.getProperty(Property.DESCRIPTION); if (desp != null) { desp.setValue(null); } final Attach attachp = valCopy.getProperty(Property.ATTACH); // Don't store the entire attachment - we just need the parameters. if (attachp != null) { final Value v = attachp.getParameter(Parameter.VALUE); if (v != null) { attachp.setValue(String.valueOf(attachp.getValue().hashCode())); } } chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(BwXproperty.bedeworkIcal, null, valCopy.toString())); } chg.processChanges(ev, true, false); ev.setRecurring(ev.isRecurringEntity()); if (logger.debug()) { logger.debug(chg.toString()); logger.debug(ev.toString()); } if (masterEI != null) { // Just return notfound as this event is on its override list return Response.notFound(resp); } resp.setEntity(evinfo); return resp; } catch (final Throwable t) { if (logger.debug()) { logger.error(t); } return Response.error(resp, t); } }
NONSATD
true
ical.addComponent(masterEI); } else if (methodType == ScheduleMethods.methodTypeCancel) { // This should never have an rid for cancel of entire event. evinfo.setInstanceOnly(evinfo.getEvent().getSuppressed()); } else {
} if (evinfo != null) { if (rid != null) { // We just retrieved it's master masterEI = evinfo; masterEI.setInstanceOnly(true); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; ical.addComponent(masterEI); } else if (methodType == ScheduleMethods.methodTypeCancel) { // This should never have an rid for cancel of entire event. evinfo.setInstanceOnly(evinfo.getEvent().getSuppressed()); } else { // Presumably sent an update for the entire event. No longer suppressed master evinfo.getEvent().setSuppressed(false); } } else if (rid != null) { /* Manufacture a master for the instance */ masterEI = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); final BwEvent e = masterEI.getEvent(); // XXX This seems bogus
"More than one event returned for guid."); } evinfo = eis.iterator().next(); } if (logger.debug()) { if (evinfo != null) { logger.debug("TRANS-TO_EVENT: fetched event with guid"); } else { logger.debug("TRANS-TO_EVENT: did not find event with guid"); } } if (evinfo != null) { if (rid != null) { // We just retrieved it's master masterEI = evinfo; masterEI.setInstanceOnly(true); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; ical.addComponent(masterEI); } else if (methodType == ScheduleMethods.methodTypeCancel) { // This should never have an rid for cancel of entire event. evinfo.setInstanceOnly(evinfo.getEvent().getSuppressed()); } else { // Presumably sent an update for the entire event. No longer suppressed master evinfo.getEvent().setSuppressed(false); } } else if (rid != null) { /* Manufacture a master for the instance */ masterEI = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); final BwEvent e = masterEI.getEvent(); // XXX This seems bogus final DtStart mdtStart; final String bogusDate = "19980118"; final String bogusTime = "T230000"; // Base dtstart on the recurrence id. final boolean isDateType = ridObj.getDateType(); if (isDateType) { mdtStart = new DtStart(new Date(bogusDate)); } else if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + bogusTime + "Z"); } else if (ridObj.getTzid() == null) {
7,893
15
// Presumably sent an update for the entire event. No longer suppressed master
public static GetEntityResponse<EventInfo> toEvent( final IcalCallback cb, final BwCalendar cal, final Icalendar ical, final Component val, final boolean mergeAttendees) { final var resp = new GetEntityResponse<EventInfo>(); if (val == null) { return Response.notOk(resp, failed, "No component supplied"); } String currentPrincipal = null; final BwPrincipal principal = cb.getPrincipal(); if (principal != null) { currentPrincipal = principal.getPrincipalRef(); } final Holder<Boolean> hasXparams = new Holder<>(Boolean.FALSE); final int methodType = ical.getMethodType(); String attUri = null; if (mergeAttendees) { // We'll need this later. attUri = cb.getCaladdr(cb.getPrincipal().getPrincipalRef()); } final String colPath; if (cal == null) { colPath = null; } else { colPath = cal.getPath(); } try { final PropertyList<Property> pl = val.getProperties(); boolean vpoll = false; boolean event = false; boolean task = false; if (pl == null) { // Empty component return Response.notOk(resp, failed, "Empty component"); } final int entityType; if (val instanceof VEvent) { entityType = IcalDefs.entityTypeEvent; event = true; } else if (val instanceof VToDo) { entityType = IcalDefs.entityTypeTodo; task = true; } else if (val instanceof VJournal) { entityType = IcalDefs.entityTypeJournal; } else if (val instanceof VFreeBusy) { entityType = IcalDefs.entityTypeFreeAndBusy; } else if (val instanceof VAvailability) { entityType = IcalDefs.entityTypeVavailability; } else if (val instanceof Available) { entityType = IcalDefs.entityTypeAvailable; } else if (val instanceof VPoll) { entityType = IcalDefs.entityTypeVpoll; vpoll = true; } else { return Response.error(resp, "org.bedework.invalid.component.type: " + val.getName()); } // Get the guid from the component String guid = null; final Uid uidp = pl.getProperty(Property.UID); if (uidp != null) { testXparams(uidp, hasXparams); guid = uidp.getValue(); } if (guid == null) { /* XXX A guid is required - but are there devices out there without a * guid - and if so how do we handle it? */ return Response.notOk(resp, failed, CalFacadeException.noGuid); } /* See if we have a recurrence id */ BwDateTime ridObj = null; String rid = null; TimeZone ridTz = null; final RecurrenceId ridp = pl.getProperty(Property.RECURRENCE_ID); if (ridp != null) { testXparams(ridp, hasXparams); ridObj = BwDateTime.makeBwDateTime(ridp); if (ridObj.getRange() != null) { /* XXX What do I do with it? */ logger.warn("TRANS-TO_EVENT: Got a recurrence id range"); } rid = ridObj.getDate(); } EventInfo masterEI = null; EventInfo evinfo = null; final BwEvent ev; /* If we have a recurrence id see if we already have the master (we should * get a master + all its overrides). * * If so find the override and use the annnotation or if no override, * make one. * * If no override retrieve the event, add it to our table and then locate the * annotation. * * If there is no annotation, create one. * * It's possible we have been sent 'detached' instances of a recurring * event. This may happen if we are invited to one or more instances of a * meeting. In this case we try to retrieve the master and if it doesn't * exist we manufacture one. We consider such an instance an update to * that instance only and leave the others alone. */ /* We need this in a couple of places */ final DtStart dtStart = pl.getProperty(Property.DTSTART); /* if (rid != null) { // See if we have a new master event. If so create a proxy to that event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI == null) { masterEI = makeNewEvent(cb, chg, entityType, guid, cal); BwEvent e = masterEI.getEvent(); // XXX This seems bogus DtStart mdtStart; String bogusDate = "19980118T230000"; if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + "Z"); } else if (dtStart.getTimeZone() == null) { mdtStart = new DtStart(bogusDate); } else { mdtStart = new DtStart(bogusDate + "Z", dtStart.getTimeZone()); } setDates(e, mdtStart, null, null, chg); e.setRecurring(true); e.addRdate(ridObj); e.setSuppressed(true); ical.addComponent(masterEI); } if (masterEI != null) { evinfo = masterEI.findOverride(rid); } } */ /* If this is a recurrence instance see if we can find the master We only need this because the master may follow the overrides. */ if (rid != null) { // See if we have a new master event. If so create a proxy to this event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI != null) { evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; } } if ((evinfo == null) && (cal != null) && (cal.getCalType() != BwCalendar.calTypeInbox) && (cal.getCalType() != BwCalendar.calTypePendingInbox) && (cal.getCalType() != BwCalendar.calTypeOutbox)) { if (logger.debug()) { logger.debug("TRANS-TO_EVENT: try to fetch event with guid=" + guid); } final GetEntitiesResponse<EventInfo> eisResp = cb.getEvent(colPath, guid); if (eisResp.isError()) { return Response.fromResponse(resp, eisResp); } final var eis = eisResp.getEntities(); if (!Util.isEmpty(eis)) { if (eis.size() > 1) { // DORECUR - wrong again return Response.notOk(resp, failed, "More than one event returned for guid."); } evinfo = eis.iterator().next(); } if (logger.debug()) { if (evinfo != null) { logger.debug("TRANS-TO_EVENT: fetched event with guid"); } else { logger.debug("TRANS-TO_EVENT: did not find event with guid"); } } if (evinfo != null) { if (rid != null) { // We just retrieved it's master masterEI = evinfo; masterEI.setInstanceOnly(true); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; ical.addComponent(masterEI); } else if (methodType == ScheduleMethods.methodTypeCancel) { // This should never have an rid for cancel of entire event. evinfo.setInstanceOnly(evinfo.getEvent().getSuppressed()); } else { // Presumably sent an update for the entire event. No longer suppressed master evinfo.getEvent().setSuppressed(false); } } else if (rid != null) { /* Manufacture a master for the instance */ masterEI = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); final BwEvent e = masterEI.getEvent(); // XXX This seems bogus final DtStart mdtStart; final String bogusDate = "19980118"; final String bogusTime = "T230000"; // Base dtstart on the recurrence id. final boolean isDateType = ridObj.getDateType(); if (isDateType) { mdtStart = new DtStart(new Date(bogusDate)); } else if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + bogusTime + "Z"); } else if (ridObj.getTzid() == null) { mdtStart = new DtStart(bogusDate + bogusTime); } else { mdtStart = new DtStart(bogusDate + bogusTime, Timezones.getTz(ridObj.getTzid())); } IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), masterEI, mdtStart, null, null); e.setRecurring(true); // e.addRdate(ridObj); final var sum = (Summary)pl.getProperty(Property.SUMMARY); e.setSummary(sum.getValue()); e.setSuppressed(true); ical.addComponent(masterEI); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; masterEI.setInstanceOnly(rid != null); } } if (evinfo == null) { evinfo = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); } else if (evinfo.getEvent().getEntityType() != entityType) { return Response.notOk(resp, failed, "org.bedework.mismatched.entity.type: " + val); } final ChangeTable chg = evinfo.getChangeset( cb.getPrincipal().getPrincipalRef()); if (rid != null) { final String evrid = evinfo.getEvent().getRecurrenceId(); if ((evrid == null) || (!evrid.equals(rid))) { logger. warn("Mismatched rid ev=" + evrid + " expected " + rid); chg.changed(PropertyInfoIndex.RECURRENCE_ID, evrid, rid); // XXX spurious??? } if (masterEI.getEvent().getSuppressed()) { masterEI.getEvent().addRdate(ridObj); } } ev = evinfo.getEvent(); ev.setScheduleMethod(methodType); DtEnd dtEnd = null; if (entityType == IcalDefs.entityTypeTodo) { final Due due = pl.getProperty(Property.DUE); if (due != null ) { dtEnd = new DtEnd(due.getParameters(), due.getValue()); } } else { dtEnd = pl.getProperty(Property.DTEND); } final Duration duration = pl.getProperty(Property.DURATION); IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), evinfo, dtStart, dtEnd, duration); for (final Property prop: pl) { testXparams(prop, hasXparams); //debug("ical prop " + prop.getClass().getName()); String pval = prop.getValue(); if ((pval != null) && (pval.length() == 0)) { pval = null; } final PropertyInfoIndex pi; if (prop instanceof XProperty) { pi = PropertyInfoIndex.XPROP; } else { pi = PropertyInfoIndex.fromName(prop.getName()); } if (pi == null) { logger.debug("Unknown property with name " + prop.getName() + " class " + prop.getClass() + " and value " + pval); continue; } chg.present(pi); switch (pi) { case ACCEPT_RESPONSE: /* ------------------- Accept Response -------------------- */ String sval = prop.getValue(); if (chg.changed(pi, ev.getPollAcceptResponse(), sval)) { ev.setPollAcceptResponse(sval); } break; case ATTACH: /* ------------------- Attachment -------------------- */ chg.addValue(pi, IcalUtil.getAttachment((Attach)prop)); break; case ATTENDEE: /* ------------------- Attendee -------------------- */ if (methodType == ScheduleMethods.methodTypePublish) { if (cb.getStrictness() == IcalCallback.conformanceStrict) { return Response.notOk(resp, failed, CalFacadeException.attendeesInPublish); } //if (cb.getStrictness() == IcalCallback.conformanceWarn) { // warn("Had attendees for PUBLISH"); //} } final Attendee attPr = (Attendee)prop; if (evinfo.getNewEvent() || !mergeAttendees) { chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { final String pUri = cb.getCaladdr(attPr.getValue()); if (pUri.equals(attUri)) { /* Only update for our own attendee * We're doing a PUT and this must be the attendee updating their * partstat. We don't allow them to change other attendees * whatever the PUT content says. */ chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { // Use the value we currently have boolean found = false; for (final BwAttendee att: ev.getAttendees()) { if (pUri.equals(att.getAttendeeUri())) { chg.addValue(pi, att.clone()); found = true; break; } } if (!found) { // An added attendee final BwAttendee att = IcalUtil .getAttendee(cb, attPr); att.setPartstat(IcalDefs.partstatValNeedsAction); chg.addValue(pi, att); } } } break; case BUSYTYPE: final int ibt = BwEvent.fromBusyTypeString(pval); if (chg.changed(pi, ev.getBusyType(), ibt)) { ev.setBusyType(ibt); } break; case CATEGORIES: /* ------------------- Categories -------------------- */ final Categories cats = (Categories)prop; final TextList cl = cats.getCategories(); String lang = IcalUtil.getLang(cats); if (cl != null) { /* Got some categories */ for (final String wd: cl) { if (wd == null) { continue; } final BwString key = new BwString(lang, wd); final var fcResp = cb.findCategory(key); final BwCategory cat; if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isNotFound()) { cat = BwCategory.makeCategory(); cat.setWord(key); cb.addCategory(cat); } else { cat = fcResp.getEntity(); } chg.addValue(pi, cat); } } break; case CLASS: /* ------------------- Class -------------------- */ if (chg.changed(pi, ev.getClassification(), pval)) { ev.setClassification(pval); } break; case COMMENT: /* ------------------- Comment -------------------- */ chg.addValue(pi, new BwString(null, pval)); break; case COMPLETED: /* ------------------- Completed -------------------- */ if (chg.changed(pi, ev.getCompleted(), pval)) { ev.setCompleted(pval); } break; case CONCEPT: /* ------------------- Concept -------------------- */ final Concept c = (Concept)prop; final String cval = c.getValue(); if (cval != null) { /* Got a concept */ chg.addValue(PropertyInfoIndex.XPROP, BwXproperty.makeIcalProperty("CONCEPT", null, cval)); } break; case CONTACT: /* ------------------- Contact -------------------- */ final String altrep = getAltRepPar(prop); lang = IcalUtil.getLang(prop); final String uid = getUidPar(prop); final BwString nm = new BwString(lang, pval); BwContact contact = null; if (uid != null) { final var fcResp = cb.getContact(uid); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { final var fcResp = cb.findContact(nm); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { contact = BwContact.makeContact(); contact.setCn(nm); contact.setLink(altrep); cb.addContact(contact); } else { contact.setCn(nm); contact.setLink(altrep); } chg.addValue(pi, contact); break; case CREATED: /* ------------------- Created -------------------- */ if (chg.changed(pi, ev.getCreated(), pval)) { ev.setCreated(pval); } break; case DESCRIPTION: /* ------------------- Description -------------------- */ if (chg.changed(pi, ev.getDescription(), pval)) { ev.setDescription(pval); } break; case DTEND: /* ------------------- DtEnd -------------------- */ break; case DTSTAMP: /* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval); break; case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE: /* -------------------- Due ------------------------ */ break; case DURATION: /* ------------------- Duration -------------------- */ break; case EXDATE: /* ------------------- ExDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case EXRULE: /* ------------------- ExRule -------------------- */ chg.addValue(pi, pval); break; case FREEBUSY: /* ------------------- freebusy -------------------- */ final FreeBusy fbusy = (FreeBusy)prop; final PeriodList perpl = fbusy.getPeriods(); final Parameter par = IcalUtil.getParameter(fbusy, "FBTYPE"); final int fbtype; if (par == null) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY)) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY_TENTATIVE)) { fbtype = BwFreeBusyComponent.typeBusyTentative; } else if (par.equals(FbType.BUSY_UNAVAILABLE)) { fbtype = BwFreeBusyComponent.typeBusyUnavailable; } else if (par.equals(FbType.FREE)) { fbtype = BwFreeBusyComponent.typeFree; } else { if (logger.debug()) { logger.debug("Unsupported parameter " + par.getName()); } return Response.notOk(resp, failed, "Unsupported parameter " + par.getName()); } final BwFreeBusyComponent fbc = new BwFreeBusyComponent(); fbc.setType(fbtype); for (final Period per : perpl) { fbc.addPeriod(per); } ev.addFreeBusyPeriod(fbc); break; case GEO: /* ------------------- Geo -------------------- */ final Geo g = (Geo)prop; final BwGeo geo = new BwGeo(g.getLatitude(), g.getLongitude()); if (chg.changed(pi, ev.getGeo(), geo)) { ev.setGeo(geo); } break; case LAST_MODIFIED: /* ------------------- LastModified -------------------- */ if (chg.changed(pi, ev.getLastmod(), pval)) { ev.setLastmod(pval); } break; case LOCATION: /* ------------------- Location -------------------- */ BwLocation loc = null; //String uid = getUidPar(prop); /* At the moment Mozilla lightning is broken and this leads to all * sorts of problems. if (uid != null) { loc = cb.getLocation(uid); } */ lang = IcalUtil.getLang(prop); BwString addr = null; if (pval != null) { if (loc == null) { addr = new BwString(lang, pval); final var fcResp = cb.findLocation(addr); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { loc = fcResp.getEntity(); } } if (loc == null) { loc = BwLocation.makeLocation(); loc.setAddress(addr); cb.addLocation(loc); } } final BwLocation evloc = ev.getLocation(); if (chg.changed(pi, evloc, loc)) { // CHGTBL - this only shows that it's a different location object ev.setLocation(loc); } else if ((loc != null) && (evloc != null)) { // See if the value is changed final String evval = evloc.getAddress().getValue(); final String inval = loc.getAddress().getValue(); if (!evval.equals(inval)) { chg.changed(pi, evval, inval); evloc.getAddress().setValue(inval); } } break; case ORGANIZER: /* ------------------- Organizer -------------------- */ final BwOrganizer org = IcalUtil.getOrganizer(cb, (Organizer)prop); final BwOrganizer evorg = ev.getOrganizer(); final BwOrganizer evorgCopy; if (evorg == null) { evorgCopy = null; } else { evorgCopy = (BwOrganizer)evorg.clone(); } if (chg.changed(pi, evorgCopy, org)) { if (evorg == null) { ev.setOrganizer(org); } else { evorg.update(org); } } break; case PERCENT_COMPLETE: /* ------------------- PercentComplete -------------------- */ Integer ival = ((PercentComplete)prop).getPercentage(); if (chg.changed(pi, ev.getPercentComplete(), ival)) { ev.setPercentComplete(ival); } break; case POLL_MODE: /* ------------------- Poll mode -------------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollMode(), sval)) { ev.setPollMode(sval); } break; case POLL_PROPERTIES: /* ------------------- Poll properties ---------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollProperties(), sval)) { ev.setPollProperties(sval); } break; case POLL_WINNER: /* ------------------- Poll winner -------------------- */ ival = ((PollWinner)prop).getPollwinner(); if (chg.changed(pi, ev.getPollWinner(), ival)) { ev.setPollWinner(ival); } break; case PRIORITY: /* ------------------- Priority -------------------- */ ival = ((Priority)prop).getLevel(); if (chg.changed(pi, ev.getPriority(), ival)) { ev.setPriority(ival); } break; case RDATE: /* ------------------- RDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case RECURRENCE_ID: /* ------------------- RecurrenceID -------------------- */ // Done above break; case RELATED_TO: /* ------------------- RelatedTo -------------------- */ final RelatedTo irelto = (RelatedTo)prop; final BwRelatedTo relto = new BwRelatedTo(); final String parval = IcalUtil.getParameterVal(irelto, "RELTYPE"); if (parval != null) { relto.setRelType(parval); } relto.setValue(irelto.getValue()); if (chg.changed(pi, ev.getRelatedTo(), relto)) { ev.setRelatedTo(relto); } break; case REQUEST_STATUS: /* ------------------- RequestStatus -------------------- */ final BwRequestStatus rs = BwRequestStatus .fromRequestStatus((RequestStatus)prop); chg.addValue(pi, rs); break; case RESOURCES: /* ------------------- Resources -------------------- */ final TextList rl = ((Resources)prop).getResources(); if (rl != null) { /* Got some resources */ lang = IcalUtil.getLang(prop); for (final String s: rl) { final BwString rsrc = new BwString(lang, s); chg.addValue(pi, rsrc); } } break; case RRULE: /* ------------------- RRule -------------------- */ chg.addValue(pi, pval); break; case SEQUENCE: /* ------------------- Sequence -------------------- */ final int seq = ((Sequence)prop).getSequenceNo(); if (seq != ev.getSequence()) { chg.changed(pi, ev.getSequence(), seq); ev.setSequence(seq); } break; case STATUS: /* ------------------- Status -------------------- */ if (chg.changed(pi, ev.getStatus(), pval)) { ev.setStatus(pval); } break; case SUMMARY: /* ------------------- Summary -------------------- */ if (chg.changed(pi, ev.getSummary(), pval)) { ev.setSummary(pval); } break; case TRANSP: /* ------------------- Transp -------------------- */ if (chg.changed(pi, ev.getPeruserTransparency( cb.getPrincipal() .getPrincipalRef()), pval)) { final BwXproperty pu = ev.setPeruserTransparency( cb.getPrincipal().getPrincipalRef(), pval); if (pu != null) { chg.addValue(PropertyInfoIndex.XPROP, pu); } } break; case UID: /* ------------------- Uid -------------------- */ /* We did this above */ break; case URL: /* ------------------- Url -------------------- */ if (chg.changed(pi, ev.getLink(), pval)) { ev.setLink(pval); } break; case XPROP: /* ------------------------- x-property --------------------------- */ final String name = prop.getName(); if (name.equalsIgnoreCase(BwXproperty.bedeworkCost)) { if (chg.changed(PropertyInfoIndex.COST, ev.getCost(), pval)) { ev.setCost(pval); } break; } if (name.equalsIgnoreCase(BwXproperty.xBedeworkCategories)) { if (checkCategory(cb, chg, ev, null, pval)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkLocation)) { if (checkLocation(cb, chg, ev, prop)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkContact)) { if (checkContact(cb, chg, ev, null, pval)) { break; } } /* See if this is an x-category that can be converted to a real category */ final XProperty xp = (XProperty)prop; chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(name, xp.getParameters() .toString(), pval)); break; default: if (logger.debug()) { logger.debug("Unsupported property with index " + pi + "; class " + prop.getClass() + " and value " + pval); } } } /* =================== Process sub-components =============== */ final ComponentList<Component> subComps; if (val instanceof ComponentContainer) { subComps = ((ComponentContainer<Component>)val).getComponents(); } else { subComps = null; } final Set<Integer> pids; if (vpoll) { pids = new TreeSet<>(); final BwEvent vp = evinfo.getEvent(); if (!Util.isEmpty(vp.getPollItems())) { vp.clearPollItems(); } } else { pids = null; } if (!Util.isEmpty(subComps)) { for (final var subComp: subComps) { if (subComp instanceof Available) { if (!(val instanceof VAvailability)) { return Response.error(resp, "AVAILABLE only valid in VAVAILABLE"); } final var avlResp = processAvailable(cb, cal, ical, (VAvailability)val, (Available)subComp, evinfo); if (!avlResp.isOk()) { return Response.fromResponse(resp, avlResp); } continue; } if (subComp instanceof Participant) { if (vpoll) { final var vresp = processVoter(cb, (VPoll)val, (Participant)subComp, evinfo, chg, mergeAttendees); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Participant object"); continue; } if (subComp instanceof VResource) { logger.warn("Unimplemented VResource object"); continue; } if (subComp instanceof VLocation) { logger.warn("Unimplemented VLocation object"); continue; } if (subComp instanceof VAlarm) { final var aresp = VAlarmUtil.processAlarm(cb, val, (VAlarm)subComp, ev, currentPrincipal, chg); if (!aresp.isOk()) { return Response.fromResponse(resp, aresp); } continue; } if (vpoll && (event || task)) { final var vresp = processCandidate((VPoll)val, subComp, evinfo, pids, chg); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Component object: " + subComp); } } /* Fix up timestamps. */ if (ev.getCreated() == null) { if (ev.getLastmod() != null) { ev.setCreated(ev.getLastmod()); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); } else { ev.updateDtstamp(); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } } if (ev.getLastmod() == null) { // created cannot be null now ev.setLastmod(ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } processTimezones(ev, ical, chg); /* Remove any recipients and originator */ if (ev.getRecipients() != null) { ev.getRecipients().clear(); } ev.setOriginator(null); if (hasXparams.value) { /* Save a text copy of the entire event as an x-property */ final Component valCopy = val.copy(); /* Remove potentially large values */ final Description desp = valCopy.getProperty(Property.DESCRIPTION); if (desp != null) { desp.setValue(null); } final Attach attachp = valCopy.getProperty(Property.ATTACH); // Don't store the entire attachment - we just need the parameters. if (attachp != null) { final Value v = attachp.getParameter(Parameter.VALUE); if (v != null) { attachp.setValue(String.valueOf(attachp.getValue().hashCode())); } } chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(BwXproperty.bedeworkIcal, null, valCopy.toString())); } chg.processChanges(ev, true, false); ev.setRecurring(ev.isRecurringEntity()); if (logger.debug()) { logger.debug(chg.toString()); logger.debug(ev.toString()); } if (masterEI != null) { // Just return notfound as this event is on its override list return Response.notFound(resp); } resp.setEntity(evinfo); return resp; } catch (final Throwable t) { if (logger.debug()) { logger.error(t); } return Response.error(resp, t); } }
NONSATD
true
evinfo.setInstanceOnly(evinfo.getEvent().getSuppressed()); } else { // Presumably sent an update for the entire event. No longer suppressed master evinfo.getEvent().setSuppressed(false); }
// We just retrieved it's master masterEI = evinfo; masterEI.setInstanceOnly(true); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; ical.addComponent(masterEI); } else if (methodType == ScheduleMethods.methodTypeCancel) { // This should never have an rid for cancel of entire event. evinfo.setInstanceOnly(evinfo.getEvent().getSuppressed()); } else { // Presumably sent an update for the entire event. No longer suppressed master evinfo.getEvent().setSuppressed(false); } } else if (rid != null) { /* Manufacture a master for the instance */ masterEI = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); final BwEvent e = masterEI.getEvent(); // XXX This seems bogus final DtStart mdtStart; final String bogusDate = "19980118"; final String bogusTime = "T230000";
} if (logger.debug()) { if (evinfo != null) { logger.debug("TRANS-TO_EVENT: fetched event with guid"); } else { logger.debug("TRANS-TO_EVENT: did not find event with guid"); } } if (evinfo != null) { if (rid != null) { // We just retrieved it's master masterEI = evinfo; masterEI.setInstanceOnly(true); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; ical.addComponent(masterEI); } else if (methodType == ScheduleMethods.methodTypeCancel) { // This should never have an rid for cancel of entire event. evinfo.setInstanceOnly(evinfo.getEvent().getSuppressed()); } else { // Presumably sent an update for the entire event. No longer suppressed master evinfo.getEvent().setSuppressed(false); } } else if (rid != null) { /* Manufacture a master for the instance */ masterEI = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); final BwEvent e = masterEI.getEvent(); // XXX This seems bogus final DtStart mdtStart; final String bogusDate = "19980118"; final String bogusTime = "T230000"; // Base dtstart on the recurrence id. final boolean isDateType = ridObj.getDateType(); if (isDateType) { mdtStart = new DtStart(new Date(bogusDate)); } else if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + bogusTime + "Z"); } else if (ridObj.getTzid() == null) { mdtStart = new DtStart(bogusDate + bogusTime); } else { mdtStart = new DtStart(bogusDate + bogusTime,
7,893
16
/* Manufacture a master for the instance */
public static GetEntityResponse<EventInfo> toEvent( final IcalCallback cb, final BwCalendar cal, final Icalendar ical, final Component val, final boolean mergeAttendees) { final var resp = new GetEntityResponse<EventInfo>(); if (val == null) { return Response.notOk(resp, failed, "No component supplied"); } String currentPrincipal = null; final BwPrincipal principal = cb.getPrincipal(); if (principal != null) { currentPrincipal = principal.getPrincipalRef(); } final Holder<Boolean> hasXparams = new Holder<>(Boolean.FALSE); final int methodType = ical.getMethodType(); String attUri = null; if (mergeAttendees) { // We'll need this later. attUri = cb.getCaladdr(cb.getPrincipal().getPrincipalRef()); } final String colPath; if (cal == null) { colPath = null; } else { colPath = cal.getPath(); } try { final PropertyList<Property> pl = val.getProperties(); boolean vpoll = false; boolean event = false; boolean task = false; if (pl == null) { // Empty component return Response.notOk(resp, failed, "Empty component"); } final int entityType; if (val instanceof VEvent) { entityType = IcalDefs.entityTypeEvent; event = true; } else if (val instanceof VToDo) { entityType = IcalDefs.entityTypeTodo; task = true; } else if (val instanceof VJournal) { entityType = IcalDefs.entityTypeJournal; } else if (val instanceof VFreeBusy) { entityType = IcalDefs.entityTypeFreeAndBusy; } else if (val instanceof VAvailability) { entityType = IcalDefs.entityTypeVavailability; } else if (val instanceof Available) { entityType = IcalDefs.entityTypeAvailable; } else if (val instanceof VPoll) { entityType = IcalDefs.entityTypeVpoll; vpoll = true; } else { return Response.error(resp, "org.bedework.invalid.component.type: " + val.getName()); } // Get the guid from the component String guid = null; final Uid uidp = pl.getProperty(Property.UID); if (uidp != null) { testXparams(uidp, hasXparams); guid = uidp.getValue(); } if (guid == null) { /* XXX A guid is required - but are there devices out there without a * guid - and if so how do we handle it? */ return Response.notOk(resp, failed, CalFacadeException.noGuid); } /* See if we have a recurrence id */ BwDateTime ridObj = null; String rid = null; TimeZone ridTz = null; final RecurrenceId ridp = pl.getProperty(Property.RECURRENCE_ID); if (ridp != null) { testXparams(ridp, hasXparams); ridObj = BwDateTime.makeBwDateTime(ridp); if (ridObj.getRange() != null) { /* XXX What do I do with it? */ logger.warn("TRANS-TO_EVENT: Got a recurrence id range"); } rid = ridObj.getDate(); } EventInfo masterEI = null; EventInfo evinfo = null; final BwEvent ev; /* If we have a recurrence id see if we already have the master (we should * get a master + all its overrides). * * If so find the override and use the annnotation or if no override, * make one. * * If no override retrieve the event, add it to our table and then locate the * annotation. * * If there is no annotation, create one. * * It's possible we have been sent 'detached' instances of a recurring * event. This may happen if we are invited to one or more instances of a * meeting. In this case we try to retrieve the master and if it doesn't * exist we manufacture one. We consider such an instance an update to * that instance only and leave the others alone. */ /* We need this in a couple of places */ final DtStart dtStart = pl.getProperty(Property.DTSTART); /* if (rid != null) { // See if we have a new master event. If so create a proxy to that event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI == null) { masterEI = makeNewEvent(cb, chg, entityType, guid, cal); BwEvent e = masterEI.getEvent(); // XXX This seems bogus DtStart mdtStart; String bogusDate = "19980118T230000"; if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + "Z"); } else if (dtStart.getTimeZone() == null) { mdtStart = new DtStart(bogusDate); } else { mdtStart = new DtStart(bogusDate + "Z", dtStart.getTimeZone()); } setDates(e, mdtStart, null, null, chg); e.setRecurring(true); e.addRdate(ridObj); e.setSuppressed(true); ical.addComponent(masterEI); } if (masterEI != null) { evinfo = masterEI.findOverride(rid); } } */ /* If this is a recurrence instance see if we can find the master We only need this because the master may follow the overrides. */ if (rid != null) { // See if we have a new master event. If so create a proxy to this event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI != null) { evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; } } if ((evinfo == null) && (cal != null) && (cal.getCalType() != BwCalendar.calTypeInbox) && (cal.getCalType() != BwCalendar.calTypePendingInbox) && (cal.getCalType() != BwCalendar.calTypeOutbox)) { if (logger.debug()) { logger.debug("TRANS-TO_EVENT: try to fetch event with guid=" + guid); } final GetEntitiesResponse<EventInfo> eisResp = cb.getEvent(colPath, guid); if (eisResp.isError()) { return Response.fromResponse(resp, eisResp); } final var eis = eisResp.getEntities(); if (!Util.isEmpty(eis)) { if (eis.size() > 1) { // DORECUR - wrong again return Response.notOk(resp, failed, "More than one event returned for guid."); } evinfo = eis.iterator().next(); } if (logger.debug()) { if (evinfo != null) { logger.debug("TRANS-TO_EVENT: fetched event with guid"); } else { logger.debug("TRANS-TO_EVENT: did not find event with guid"); } } if (evinfo != null) { if (rid != null) { // We just retrieved it's master masterEI = evinfo; masterEI.setInstanceOnly(true); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; ical.addComponent(masterEI); } else if (methodType == ScheduleMethods.methodTypeCancel) { // This should never have an rid for cancel of entire event. evinfo.setInstanceOnly(evinfo.getEvent().getSuppressed()); } else { // Presumably sent an update for the entire event. No longer suppressed master evinfo.getEvent().setSuppressed(false); } } else if (rid != null) { /* Manufacture a master for the instance */ masterEI = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); final BwEvent e = masterEI.getEvent(); // XXX This seems bogus final DtStart mdtStart; final String bogusDate = "19980118"; final String bogusTime = "T230000"; // Base dtstart on the recurrence id. final boolean isDateType = ridObj.getDateType(); if (isDateType) { mdtStart = new DtStart(new Date(bogusDate)); } else if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + bogusTime + "Z"); } else if (ridObj.getTzid() == null) { mdtStart = new DtStart(bogusDate + bogusTime); } else { mdtStart = new DtStart(bogusDate + bogusTime, Timezones.getTz(ridObj.getTzid())); } IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), masterEI, mdtStart, null, null); e.setRecurring(true); // e.addRdate(ridObj); final var sum = (Summary)pl.getProperty(Property.SUMMARY); e.setSummary(sum.getValue()); e.setSuppressed(true); ical.addComponent(masterEI); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; masterEI.setInstanceOnly(rid != null); } } if (evinfo == null) { evinfo = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); } else if (evinfo.getEvent().getEntityType() != entityType) { return Response.notOk(resp, failed, "org.bedework.mismatched.entity.type: " + val); } final ChangeTable chg = evinfo.getChangeset( cb.getPrincipal().getPrincipalRef()); if (rid != null) { final String evrid = evinfo.getEvent().getRecurrenceId(); if ((evrid == null) || (!evrid.equals(rid))) { logger. warn("Mismatched rid ev=" + evrid + " expected " + rid); chg.changed(PropertyInfoIndex.RECURRENCE_ID, evrid, rid); // XXX spurious??? } if (masterEI.getEvent().getSuppressed()) { masterEI.getEvent().addRdate(ridObj); } } ev = evinfo.getEvent(); ev.setScheduleMethod(methodType); DtEnd dtEnd = null; if (entityType == IcalDefs.entityTypeTodo) { final Due due = pl.getProperty(Property.DUE); if (due != null ) { dtEnd = new DtEnd(due.getParameters(), due.getValue()); } } else { dtEnd = pl.getProperty(Property.DTEND); } final Duration duration = pl.getProperty(Property.DURATION); IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), evinfo, dtStart, dtEnd, duration); for (final Property prop: pl) { testXparams(prop, hasXparams); //debug("ical prop " + prop.getClass().getName()); String pval = prop.getValue(); if ((pval != null) && (pval.length() == 0)) { pval = null; } final PropertyInfoIndex pi; if (prop instanceof XProperty) { pi = PropertyInfoIndex.XPROP; } else { pi = PropertyInfoIndex.fromName(prop.getName()); } if (pi == null) { logger.debug("Unknown property with name " + prop.getName() + " class " + prop.getClass() + " and value " + pval); continue; } chg.present(pi); switch (pi) { case ACCEPT_RESPONSE: /* ------------------- Accept Response -------------------- */ String sval = prop.getValue(); if (chg.changed(pi, ev.getPollAcceptResponse(), sval)) { ev.setPollAcceptResponse(sval); } break; case ATTACH: /* ------------------- Attachment -------------------- */ chg.addValue(pi, IcalUtil.getAttachment((Attach)prop)); break; case ATTENDEE: /* ------------------- Attendee -------------------- */ if (methodType == ScheduleMethods.methodTypePublish) { if (cb.getStrictness() == IcalCallback.conformanceStrict) { return Response.notOk(resp, failed, CalFacadeException.attendeesInPublish); } //if (cb.getStrictness() == IcalCallback.conformanceWarn) { // warn("Had attendees for PUBLISH"); //} } final Attendee attPr = (Attendee)prop; if (evinfo.getNewEvent() || !mergeAttendees) { chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { final String pUri = cb.getCaladdr(attPr.getValue()); if (pUri.equals(attUri)) { /* Only update for our own attendee * We're doing a PUT and this must be the attendee updating their * partstat. We don't allow them to change other attendees * whatever the PUT content says. */ chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { // Use the value we currently have boolean found = false; for (final BwAttendee att: ev.getAttendees()) { if (pUri.equals(att.getAttendeeUri())) { chg.addValue(pi, att.clone()); found = true; break; } } if (!found) { // An added attendee final BwAttendee att = IcalUtil .getAttendee(cb, attPr); att.setPartstat(IcalDefs.partstatValNeedsAction); chg.addValue(pi, att); } } } break; case BUSYTYPE: final int ibt = BwEvent.fromBusyTypeString(pval); if (chg.changed(pi, ev.getBusyType(), ibt)) { ev.setBusyType(ibt); } break; case CATEGORIES: /* ------------------- Categories -------------------- */ final Categories cats = (Categories)prop; final TextList cl = cats.getCategories(); String lang = IcalUtil.getLang(cats); if (cl != null) { /* Got some categories */ for (final String wd: cl) { if (wd == null) { continue; } final BwString key = new BwString(lang, wd); final var fcResp = cb.findCategory(key); final BwCategory cat; if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isNotFound()) { cat = BwCategory.makeCategory(); cat.setWord(key); cb.addCategory(cat); } else { cat = fcResp.getEntity(); } chg.addValue(pi, cat); } } break; case CLASS: /* ------------------- Class -------------------- */ if (chg.changed(pi, ev.getClassification(), pval)) { ev.setClassification(pval); } break; case COMMENT: /* ------------------- Comment -------------------- */ chg.addValue(pi, new BwString(null, pval)); break; case COMPLETED: /* ------------------- Completed -------------------- */ if (chg.changed(pi, ev.getCompleted(), pval)) { ev.setCompleted(pval); } break; case CONCEPT: /* ------------------- Concept -------------------- */ final Concept c = (Concept)prop; final String cval = c.getValue(); if (cval != null) { /* Got a concept */ chg.addValue(PropertyInfoIndex.XPROP, BwXproperty.makeIcalProperty("CONCEPT", null, cval)); } break; case CONTACT: /* ------------------- Contact -------------------- */ final String altrep = getAltRepPar(prop); lang = IcalUtil.getLang(prop); final String uid = getUidPar(prop); final BwString nm = new BwString(lang, pval); BwContact contact = null; if (uid != null) { final var fcResp = cb.getContact(uid); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { final var fcResp = cb.findContact(nm); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { contact = BwContact.makeContact(); contact.setCn(nm); contact.setLink(altrep); cb.addContact(contact); } else { contact.setCn(nm); contact.setLink(altrep); } chg.addValue(pi, contact); break; case CREATED: /* ------------------- Created -------------------- */ if (chg.changed(pi, ev.getCreated(), pval)) { ev.setCreated(pval); } break; case DESCRIPTION: /* ------------------- Description -------------------- */ if (chg.changed(pi, ev.getDescription(), pval)) { ev.setDescription(pval); } break; case DTEND: /* ------------------- DtEnd -------------------- */ break; case DTSTAMP: /* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval); break; case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE: /* -------------------- Due ------------------------ */ break; case DURATION: /* ------------------- Duration -------------------- */ break; case EXDATE: /* ------------------- ExDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case EXRULE: /* ------------------- ExRule -------------------- */ chg.addValue(pi, pval); break; case FREEBUSY: /* ------------------- freebusy -------------------- */ final FreeBusy fbusy = (FreeBusy)prop; final PeriodList perpl = fbusy.getPeriods(); final Parameter par = IcalUtil.getParameter(fbusy, "FBTYPE"); final int fbtype; if (par == null) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY)) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY_TENTATIVE)) { fbtype = BwFreeBusyComponent.typeBusyTentative; } else if (par.equals(FbType.BUSY_UNAVAILABLE)) { fbtype = BwFreeBusyComponent.typeBusyUnavailable; } else if (par.equals(FbType.FREE)) { fbtype = BwFreeBusyComponent.typeFree; } else { if (logger.debug()) { logger.debug("Unsupported parameter " + par.getName()); } return Response.notOk(resp, failed, "Unsupported parameter " + par.getName()); } final BwFreeBusyComponent fbc = new BwFreeBusyComponent(); fbc.setType(fbtype); for (final Period per : perpl) { fbc.addPeriod(per); } ev.addFreeBusyPeriod(fbc); break; case GEO: /* ------------------- Geo -------------------- */ final Geo g = (Geo)prop; final BwGeo geo = new BwGeo(g.getLatitude(), g.getLongitude()); if (chg.changed(pi, ev.getGeo(), geo)) { ev.setGeo(geo); } break; case LAST_MODIFIED: /* ------------------- LastModified -------------------- */ if (chg.changed(pi, ev.getLastmod(), pval)) { ev.setLastmod(pval); } break; case LOCATION: /* ------------------- Location -------------------- */ BwLocation loc = null; //String uid = getUidPar(prop); /* At the moment Mozilla lightning is broken and this leads to all * sorts of problems. if (uid != null) { loc = cb.getLocation(uid); } */ lang = IcalUtil.getLang(prop); BwString addr = null; if (pval != null) { if (loc == null) { addr = new BwString(lang, pval); final var fcResp = cb.findLocation(addr); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { loc = fcResp.getEntity(); } } if (loc == null) { loc = BwLocation.makeLocation(); loc.setAddress(addr); cb.addLocation(loc); } } final BwLocation evloc = ev.getLocation(); if (chg.changed(pi, evloc, loc)) { // CHGTBL - this only shows that it's a different location object ev.setLocation(loc); } else if ((loc != null) && (evloc != null)) { // See if the value is changed final String evval = evloc.getAddress().getValue(); final String inval = loc.getAddress().getValue(); if (!evval.equals(inval)) { chg.changed(pi, evval, inval); evloc.getAddress().setValue(inval); } } break; case ORGANIZER: /* ------------------- Organizer -------------------- */ final BwOrganizer org = IcalUtil.getOrganizer(cb, (Organizer)prop); final BwOrganizer evorg = ev.getOrganizer(); final BwOrganizer evorgCopy; if (evorg == null) { evorgCopy = null; } else { evorgCopy = (BwOrganizer)evorg.clone(); } if (chg.changed(pi, evorgCopy, org)) { if (evorg == null) { ev.setOrganizer(org); } else { evorg.update(org); } } break; case PERCENT_COMPLETE: /* ------------------- PercentComplete -------------------- */ Integer ival = ((PercentComplete)prop).getPercentage(); if (chg.changed(pi, ev.getPercentComplete(), ival)) { ev.setPercentComplete(ival); } break; case POLL_MODE: /* ------------------- Poll mode -------------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollMode(), sval)) { ev.setPollMode(sval); } break; case POLL_PROPERTIES: /* ------------------- Poll properties ---------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollProperties(), sval)) { ev.setPollProperties(sval); } break; case POLL_WINNER: /* ------------------- Poll winner -------------------- */ ival = ((PollWinner)prop).getPollwinner(); if (chg.changed(pi, ev.getPollWinner(), ival)) { ev.setPollWinner(ival); } break; case PRIORITY: /* ------------------- Priority -------------------- */ ival = ((Priority)prop).getLevel(); if (chg.changed(pi, ev.getPriority(), ival)) { ev.setPriority(ival); } break; case RDATE: /* ------------------- RDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case RECURRENCE_ID: /* ------------------- RecurrenceID -------------------- */ // Done above break; case RELATED_TO: /* ------------------- RelatedTo -------------------- */ final RelatedTo irelto = (RelatedTo)prop; final BwRelatedTo relto = new BwRelatedTo(); final String parval = IcalUtil.getParameterVal(irelto, "RELTYPE"); if (parval != null) { relto.setRelType(parval); } relto.setValue(irelto.getValue()); if (chg.changed(pi, ev.getRelatedTo(), relto)) { ev.setRelatedTo(relto); } break; case REQUEST_STATUS: /* ------------------- RequestStatus -------------------- */ final BwRequestStatus rs = BwRequestStatus .fromRequestStatus((RequestStatus)prop); chg.addValue(pi, rs); break; case RESOURCES: /* ------------------- Resources -------------------- */ final TextList rl = ((Resources)prop).getResources(); if (rl != null) { /* Got some resources */ lang = IcalUtil.getLang(prop); for (final String s: rl) { final BwString rsrc = new BwString(lang, s); chg.addValue(pi, rsrc); } } break; case RRULE: /* ------------------- RRule -------------------- */ chg.addValue(pi, pval); break; case SEQUENCE: /* ------------------- Sequence -------------------- */ final int seq = ((Sequence)prop).getSequenceNo(); if (seq != ev.getSequence()) { chg.changed(pi, ev.getSequence(), seq); ev.setSequence(seq); } break; case STATUS: /* ------------------- Status -------------------- */ if (chg.changed(pi, ev.getStatus(), pval)) { ev.setStatus(pval); } break; case SUMMARY: /* ------------------- Summary -------------------- */ if (chg.changed(pi, ev.getSummary(), pval)) { ev.setSummary(pval); } break; case TRANSP: /* ------------------- Transp -------------------- */ if (chg.changed(pi, ev.getPeruserTransparency( cb.getPrincipal() .getPrincipalRef()), pval)) { final BwXproperty pu = ev.setPeruserTransparency( cb.getPrincipal().getPrincipalRef(), pval); if (pu != null) { chg.addValue(PropertyInfoIndex.XPROP, pu); } } break; case UID: /* ------------------- Uid -------------------- */ /* We did this above */ break; case URL: /* ------------------- Url -------------------- */ if (chg.changed(pi, ev.getLink(), pval)) { ev.setLink(pval); } break; case XPROP: /* ------------------------- x-property --------------------------- */ final String name = prop.getName(); if (name.equalsIgnoreCase(BwXproperty.bedeworkCost)) { if (chg.changed(PropertyInfoIndex.COST, ev.getCost(), pval)) { ev.setCost(pval); } break; } if (name.equalsIgnoreCase(BwXproperty.xBedeworkCategories)) { if (checkCategory(cb, chg, ev, null, pval)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkLocation)) { if (checkLocation(cb, chg, ev, prop)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkContact)) { if (checkContact(cb, chg, ev, null, pval)) { break; } } /* See if this is an x-category that can be converted to a real category */ final XProperty xp = (XProperty)prop; chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(name, xp.getParameters() .toString(), pval)); break; default: if (logger.debug()) { logger.debug("Unsupported property with index " + pi + "; class " + prop.getClass() + " and value " + pval); } } } /* =================== Process sub-components =============== */ final ComponentList<Component> subComps; if (val instanceof ComponentContainer) { subComps = ((ComponentContainer<Component>)val).getComponents(); } else { subComps = null; } final Set<Integer> pids; if (vpoll) { pids = new TreeSet<>(); final BwEvent vp = evinfo.getEvent(); if (!Util.isEmpty(vp.getPollItems())) { vp.clearPollItems(); } } else { pids = null; } if (!Util.isEmpty(subComps)) { for (final var subComp: subComps) { if (subComp instanceof Available) { if (!(val instanceof VAvailability)) { return Response.error(resp, "AVAILABLE only valid in VAVAILABLE"); } final var avlResp = processAvailable(cb, cal, ical, (VAvailability)val, (Available)subComp, evinfo); if (!avlResp.isOk()) { return Response.fromResponse(resp, avlResp); } continue; } if (subComp instanceof Participant) { if (vpoll) { final var vresp = processVoter(cb, (VPoll)val, (Participant)subComp, evinfo, chg, mergeAttendees); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Participant object"); continue; } if (subComp instanceof VResource) { logger.warn("Unimplemented VResource object"); continue; } if (subComp instanceof VLocation) { logger.warn("Unimplemented VLocation object"); continue; } if (subComp instanceof VAlarm) { final var aresp = VAlarmUtil.processAlarm(cb, val, (VAlarm)subComp, ev, currentPrincipal, chg); if (!aresp.isOk()) { return Response.fromResponse(resp, aresp); } continue; } if (vpoll && (event || task)) { final var vresp = processCandidate((VPoll)val, subComp, evinfo, pids, chg); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Component object: " + subComp); } } /* Fix up timestamps. */ if (ev.getCreated() == null) { if (ev.getLastmod() != null) { ev.setCreated(ev.getLastmod()); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); } else { ev.updateDtstamp(); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } } if (ev.getLastmod() == null) { // created cannot be null now ev.setLastmod(ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } processTimezones(ev, ical, chg); /* Remove any recipients and originator */ if (ev.getRecipients() != null) { ev.getRecipients().clear(); } ev.setOriginator(null); if (hasXparams.value) { /* Save a text copy of the entire event as an x-property */ final Component valCopy = val.copy(); /* Remove potentially large values */ final Description desp = valCopy.getProperty(Property.DESCRIPTION); if (desp != null) { desp.setValue(null); } final Attach attachp = valCopy.getProperty(Property.ATTACH); // Don't store the entire attachment - we just need the parameters. if (attachp != null) { final Value v = attachp.getParameter(Parameter.VALUE); if (v != null) { attachp.setValue(String.valueOf(attachp.getValue().hashCode())); } } chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(BwXproperty.bedeworkIcal, null, valCopy.toString())); } chg.processChanges(ev, true, false); ev.setRecurring(ev.isRecurringEntity()); if (logger.debug()) { logger.debug(chg.toString()); logger.debug(ev.toString()); } if (masterEI != null) { // Just return notfound as this event is on its override list return Response.notFound(resp); } resp.setEntity(evinfo); return resp; } catch (final Throwable t) { if (logger.debug()) { logger.error(t); } return Response.error(resp, t); } }
NONSATD
true
} } else if (rid != null) { /* Manufacture a master for the instance */ masterEI = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); final BwEvent e = masterEI.getEvent();
evinfo.recurrenceSeen = true; ical.addComponent(masterEI); } else if (methodType == ScheduleMethods.methodTypeCancel) { // This should never have an rid for cancel of entire event. evinfo.setInstanceOnly(evinfo.getEvent().getSuppressed()); } else { // Presumably sent an update for the entire event. No longer suppressed master evinfo.getEvent().setSuppressed(false); } } else if (rid != null) { /* Manufacture a master for the instance */ masterEI = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); final BwEvent e = masterEI.getEvent(); // XXX This seems bogus final DtStart mdtStart; final String bogusDate = "19980118"; final String bogusTime = "T230000"; // Base dtstart on the recurrence id. final boolean isDateType = ridObj.getDateType(); if (isDateType) { mdtStart = new DtStart(new Date(bogusDate));
} else { logger.debug("TRANS-TO_EVENT: did not find event with guid"); } } if (evinfo != null) { if (rid != null) { // We just retrieved it's master masterEI = evinfo; masterEI.setInstanceOnly(true); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; ical.addComponent(masterEI); } else if (methodType == ScheduleMethods.methodTypeCancel) { // This should never have an rid for cancel of entire event. evinfo.setInstanceOnly(evinfo.getEvent().getSuppressed()); } else { // Presumably sent an update for the entire event. No longer suppressed master evinfo.getEvent().setSuppressed(false); } } else if (rid != null) { /* Manufacture a master for the instance */ masterEI = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); final BwEvent e = masterEI.getEvent(); // XXX This seems bogus final DtStart mdtStart; final String bogusDate = "19980118"; final String bogusTime = "T230000"; // Base dtstart on the recurrence id. final boolean isDateType = ridObj.getDateType(); if (isDateType) { mdtStart = new DtStart(new Date(bogusDate)); } else if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + bogusTime + "Z"); } else if (ridObj.getTzid() == null) { mdtStart = new DtStart(bogusDate + bogusTime); } else { mdtStart = new DtStart(bogusDate + bogusTime, Timezones.getTz(ridObj.getTzid())); } IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), masterEI, mdtStart, null, null);
7,893
17
// XXX This seems bogus
public static GetEntityResponse<EventInfo> toEvent( final IcalCallback cb, final BwCalendar cal, final Icalendar ical, final Component val, final boolean mergeAttendees) { final var resp = new GetEntityResponse<EventInfo>(); if (val == null) { return Response.notOk(resp, failed, "No component supplied"); } String currentPrincipal = null; final BwPrincipal principal = cb.getPrincipal(); if (principal != null) { currentPrincipal = principal.getPrincipalRef(); } final Holder<Boolean> hasXparams = new Holder<>(Boolean.FALSE); final int methodType = ical.getMethodType(); String attUri = null; if (mergeAttendees) { // We'll need this later. attUri = cb.getCaladdr(cb.getPrincipal().getPrincipalRef()); } final String colPath; if (cal == null) { colPath = null; } else { colPath = cal.getPath(); } try { final PropertyList<Property> pl = val.getProperties(); boolean vpoll = false; boolean event = false; boolean task = false; if (pl == null) { // Empty component return Response.notOk(resp, failed, "Empty component"); } final int entityType; if (val instanceof VEvent) { entityType = IcalDefs.entityTypeEvent; event = true; } else if (val instanceof VToDo) { entityType = IcalDefs.entityTypeTodo; task = true; } else if (val instanceof VJournal) { entityType = IcalDefs.entityTypeJournal; } else if (val instanceof VFreeBusy) { entityType = IcalDefs.entityTypeFreeAndBusy; } else if (val instanceof VAvailability) { entityType = IcalDefs.entityTypeVavailability; } else if (val instanceof Available) { entityType = IcalDefs.entityTypeAvailable; } else if (val instanceof VPoll) { entityType = IcalDefs.entityTypeVpoll; vpoll = true; } else { return Response.error(resp, "org.bedework.invalid.component.type: " + val.getName()); } // Get the guid from the component String guid = null; final Uid uidp = pl.getProperty(Property.UID); if (uidp != null) { testXparams(uidp, hasXparams); guid = uidp.getValue(); } if (guid == null) { /* XXX A guid is required - but are there devices out there without a * guid - and if so how do we handle it? */ return Response.notOk(resp, failed, CalFacadeException.noGuid); } /* See if we have a recurrence id */ BwDateTime ridObj = null; String rid = null; TimeZone ridTz = null; final RecurrenceId ridp = pl.getProperty(Property.RECURRENCE_ID); if (ridp != null) { testXparams(ridp, hasXparams); ridObj = BwDateTime.makeBwDateTime(ridp); if (ridObj.getRange() != null) { /* XXX What do I do with it? */ logger.warn("TRANS-TO_EVENT: Got a recurrence id range"); } rid = ridObj.getDate(); } EventInfo masterEI = null; EventInfo evinfo = null; final BwEvent ev; /* If we have a recurrence id see if we already have the master (we should * get a master + all its overrides). * * If so find the override and use the annnotation or if no override, * make one. * * If no override retrieve the event, add it to our table and then locate the * annotation. * * If there is no annotation, create one. * * It's possible we have been sent 'detached' instances of a recurring * event. This may happen if we are invited to one or more instances of a * meeting. In this case we try to retrieve the master and if it doesn't * exist we manufacture one. We consider such an instance an update to * that instance only and leave the others alone. */ /* We need this in a couple of places */ final DtStart dtStart = pl.getProperty(Property.DTSTART); /* if (rid != null) { // See if we have a new master event. If so create a proxy to that event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI == null) { masterEI = makeNewEvent(cb, chg, entityType, guid, cal); BwEvent e = masterEI.getEvent(); // XXX This seems bogus DtStart mdtStart; String bogusDate = "19980118T230000"; if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + "Z"); } else if (dtStart.getTimeZone() == null) { mdtStart = new DtStart(bogusDate); } else { mdtStart = new DtStart(bogusDate + "Z", dtStart.getTimeZone()); } setDates(e, mdtStart, null, null, chg); e.setRecurring(true); e.addRdate(ridObj); e.setSuppressed(true); ical.addComponent(masterEI); } if (masterEI != null) { evinfo = masterEI.findOverride(rid); } } */ /* If this is a recurrence instance see if we can find the master We only need this because the master may follow the overrides. */ if (rid != null) { // See if we have a new master event. If so create a proxy to this event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI != null) { evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; } } if ((evinfo == null) && (cal != null) && (cal.getCalType() != BwCalendar.calTypeInbox) && (cal.getCalType() != BwCalendar.calTypePendingInbox) && (cal.getCalType() != BwCalendar.calTypeOutbox)) { if (logger.debug()) { logger.debug("TRANS-TO_EVENT: try to fetch event with guid=" + guid); } final GetEntitiesResponse<EventInfo> eisResp = cb.getEvent(colPath, guid); if (eisResp.isError()) { return Response.fromResponse(resp, eisResp); } final var eis = eisResp.getEntities(); if (!Util.isEmpty(eis)) { if (eis.size() > 1) { // DORECUR - wrong again return Response.notOk(resp, failed, "More than one event returned for guid."); } evinfo = eis.iterator().next(); } if (logger.debug()) { if (evinfo != null) { logger.debug("TRANS-TO_EVENT: fetched event with guid"); } else { logger.debug("TRANS-TO_EVENT: did not find event with guid"); } } if (evinfo != null) { if (rid != null) { // We just retrieved it's master masterEI = evinfo; masterEI.setInstanceOnly(true); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; ical.addComponent(masterEI); } else if (methodType == ScheduleMethods.methodTypeCancel) { // This should never have an rid for cancel of entire event. evinfo.setInstanceOnly(evinfo.getEvent().getSuppressed()); } else { // Presumably sent an update for the entire event. No longer suppressed master evinfo.getEvent().setSuppressed(false); } } else if (rid != null) { /* Manufacture a master for the instance */ masterEI = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); final BwEvent e = masterEI.getEvent(); // XXX This seems bogus final DtStart mdtStart; final String bogusDate = "19980118"; final String bogusTime = "T230000"; // Base dtstart on the recurrence id. final boolean isDateType = ridObj.getDateType(); if (isDateType) { mdtStart = new DtStart(new Date(bogusDate)); } else if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + bogusTime + "Z"); } else if (ridObj.getTzid() == null) { mdtStart = new DtStart(bogusDate + bogusTime); } else { mdtStart = new DtStart(bogusDate + bogusTime, Timezones.getTz(ridObj.getTzid())); } IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), masterEI, mdtStart, null, null); e.setRecurring(true); // e.addRdate(ridObj); final var sum = (Summary)pl.getProperty(Property.SUMMARY); e.setSummary(sum.getValue()); e.setSuppressed(true); ical.addComponent(masterEI); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; masterEI.setInstanceOnly(rid != null); } } if (evinfo == null) { evinfo = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); } else if (evinfo.getEvent().getEntityType() != entityType) { return Response.notOk(resp, failed, "org.bedework.mismatched.entity.type: " + val); } final ChangeTable chg = evinfo.getChangeset( cb.getPrincipal().getPrincipalRef()); if (rid != null) { final String evrid = evinfo.getEvent().getRecurrenceId(); if ((evrid == null) || (!evrid.equals(rid))) { logger. warn("Mismatched rid ev=" + evrid + " expected " + rid); chg.changed(PropertyInfoIndex.RECURRENCE_ID, evrid, rid); // XXX spurious??? } if (masterEI.getEvent().getSuppressed()) { masterEI.getEvent().addRdate(ridObj); } } ev = evinfo.getEvent(); ev.setScheduleMethod(methodType); DtEnd dtEnd = null; if (entityType == IcalDefs.entityTypeTodo) { final Due due = pl.getProperty(Property.DUE); if (due != null ) { dtEnd = new DtEnd(due.getParameters(), due.getValue()); } } else { dtEnd = pl.getProperty(Property.DTEND); } final Duration duration = pl.getProperty(Property.DURATION); IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), evinfo, dtStart, dtEnd, duration); for (final Property prop: pl) { testXparams(prop, hasXparams); //debug("ical prop " + prop.getClass().getName()); String pval = prop.getValue(); if ((pval != null) && (pval.length() == 0)) { pval = null; } final PropertyInfoIndex pi; if (prop instanceof XProperty) { pi = PropertyInfoIndex.XPROP; } else { pi = PropertyInfoIndex.fromName(prop.getName()); } if (pi == null) { logger.debug("Unknown property with name " + prop.getName() + " class " + prop.getClass() + " and value " + pval); continue; } chg.present(pi); switch (pi) { case ACCEPT_RESPONSE: /* ------------------- Accept Response -------------------- */ String sval = prop.getValue(); if (chg.changed(pi, ev.getPollAcceptResponse(), sval)) { ev.setPollAcceptResponse(sval); } break; case ATTACH: /* ------------------- Attachment -------------------- */ chg.addValue(pi, IcalUtil.getAttachment((Attach)prop)); break; case ATTENDEE: /* ------------------- Attendee -------------------- */ if (methodType == ScheduleMethods.methodTypePublish) { if (cb.getStrictness() == IcalCallback.conformanceStrict) { return Response.notOk(resp, failed, CalFacadeException.attendeesInPublish); } //if (cb.getStrictness() == IcalCallback.conformanceWarn) { // warn("Had attendees for PUBLISH"); //} } final Attendee attPr = (Attendee)prop; if (evinfo.getNewEvent() || !mergeAttendees) { chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { final String pUri = cb.getCaladdr(attPr.getValue()); if (pUri.equals(attUri)) { /* Only update for our own attendee * We're doing a PUT and this must be the attendee updating their * partstat. We don't allow them to change other attendees * whatever the PUT content says. */ chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { // Use the value we currently have boolean found = false; for (final BwAttendee att: ev.getAttendees()) { if (pUri.equals(att.getAttendeeUri())) { chg.addValue(pi, att.clone()); found = true; break; } } if (!found) { // An added attendee final BwAttendee att = IcalUtil .getAttendee(cb, attPr); att.setPartstat(IcalDefs.partstatValNeedsAction); chg.addValue(pi, att); } } } break; case BUSYTYPE: final int ibt = BwEvent.fromBusyTypeString(pval); if (chg.changed(pi, ev.getBusyType(), ibt)) { ev.setBusyType(ibt); } break; case CATEGORIES: /* ------------------- Categories -------------------- */ final Categories cats = (Categories)prop; final TextList cl = cats.getCategories(); String lang = IcalUtil.getLang(cats); if (cl != null) { /* Got some categories */ for (final String wd: cl) { if (wd == null) { continue; } final BwString key = new BwString(lang, wd); final var fcResp = cb.findCategory(key); final BwCategory cat; if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isNotFound()) { cat = BwCategory.makeCategory(); cat.setWord(key); cb.addCategory(cat); } else { cat = fcResp.getEntity(); } chg.addValue(pi, cat); } } break; case CLASS: /* ------------------- Class -------------------- */ if (chg.changed(pi, ev.getClassification(), pval)) { ev.setClassification(pval); } break; case COMMENT: /* ------------------- Comment -------------------- */ chg.addValue(pi, new BwString(null, pval)); break; case COMPLETED: /* ------------------- Completed -------------------- */ if (chg.changed(pi, ev.getCompleted(), pval)) { ev.setCompleted(pval); } break; case CONCEPT: /* ------------------- Concept -------------------- */ final Concept c = (Concept)prop; final String cval = c.getValue(); if (cval != null) { /* Got a concept */ chg.addValue(PropertyInfoIndex.XPROP, BwXproperty.makeIcalProperty("CONCEPT", null, cval)); } break; case CONTACT: /* ------------------- Contact -------------------- */ final String altrep = getAltRepPar(prop); lang = IcalUtil.getLang(prop); final String uid = getUidPar(prop); final BwString nm = new BwString(lang, pval); BwContact contact = null; if (uid != null) { final var fcResp = cb.getContact(uid); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { final var fcResp = cb.findContact(nm); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { contact = BwContact.makeContact(); contact.setCn(nm); contact.setLink(altrep); cb.addContact(contact); } else { contact.setCn(nm); contact.setLink(altrep); } chg.addValue(pi, contact); break; case CREATED: /* ------------------- Created -------------------- */ if (chg.changed(pi, ev.getCreated(), pval)) { ev.setCreated(pval); } break; case DESCRIPTION: /* ------------------- Description -------------------- */ if (chg.changed(pi, ev.getDescription(), pval)) { ev.setDescription(pval); } break; case DTEND: /* ------------------- DtEnd -------------------- */ break; case DTSTAMP: /* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval); break; case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE: /* -------------------- Due ------------------------ */ break; case DURATION: /* ------------------- Duration -------------------- */ break; case EXDATE: /* ------------------- ExDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case EXRULE: /* ------------------- ExRule -------------------- */ chg.addValue(pi, pval); break; case FREEBUSY: /* ------------------- freebusy -------------------- */ final FreeBusy fbusy = (FreeBusy)prop; final PeriodList perpl = fbusy.getPeriods(); final Parameter par = IcalUtil.getParameter(fbusy, "FBTYPE"); final int fbtype; if (par == null) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY)) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY_TENTATIVE)) { fbtype = BwFreeBusyComponent.typeBusyTentative; } else if (par.equals(FbType.BUSY_UNAVAILABLE)) { fbtype = BwFreeBusyComponent.typeBusyUnavailable; } else if (par.equals(FbType.FREE)) { fbtype = BwFreeBusyComponent.typeFree; } else { if (logger.debug()) { logger.debug("Unsupported parameter " + par.getName()); } return Response.notOk(resp, failed, "Unsupported parameter " + par.getName()); } final BwFreeBusyComponent fbc = new BwFreeBusyComponent(); fbc.setType(fbtype); for (final Period per : perpl) { fbc.addPeriod(per); } ev.addFreeBusyPeriod(fbc); break; case GEO: /* ------------------- Geo -------------------- */ final Geo g = (Geo)prop; final BwGeo geo = new BwGeo(g.getLatitude(), g.getLongitude()); if (chg.changed(pi, ev.getGeo(), geo)) { ev.setGeo(geo); } break; case LAST_MODIFIED: /* ------------------- LastModified -------------------- */ if (chg.changed(pi, ev.getLastmod(), pval)) { ev.setLastmod(pval); } break; case LOCATION: /* ------------------- Location -------------------- */ BwLocation loc = null; //String uid = getUidPar(prop); /* At the moment Mozilla lightning is broken and this leads to all * sorts of problems. if (uid != null) { loc = cb.getLocation(uid); } */ lang = IcalUtil.getLang(prop); BwString addr = null; if (pval != null) { if (loc == null) { addr = new BwString(lang, pval); final var fcResp = cb.findLocation(addr); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { loc = fcResp.getEntity(); } } if (loc == null) { loc = BwLocation.makeLocation(); loc.setAddress(addr); cb.addLocation(loc); } } final BwLocation evloc = ev.getLocation(); if (chg.changed(pi, evloc, loc)) { // CHGTBL - this only shows that it's a different location object ev.setLocation(loc); } else if ((loc != null) && (evloc != null)) { // See if the value is changed final String evval = evloc.getAddress().getValue(); final String inval = loc.getAddress().getValue(); if (!evval.equals(inval)) { chg.changed(pi, evval, inval); evloc.getAddress().setValue(inval); } } break; case ORGANIZER: /* ------------------- Organizer -------------------- */ final BwOrganizer org = IcalUtil.getOrganizer(cb, (Organizer)prop); final BwOrganizer evorg = ev.getOrganizer(); final BwOrganizer evorgCopy; if (evorg == null) { evorgCopy = null; } else { evorgCopy = (BwOrganizer)evorg.clone(); } if (chg.changed(pi, evorgCopy, org)) { if (evorg == null) { ev.setOrganizer(org); } else { evorg.update(org); } } break; case PERCENT_COMPLETE: /* ------------------- PercentComplete -------------------- */ Integer ival = ((PercentComplete)prop).getPercentage(); if (chg.changed(pi, ev.getPercentComplete(), ival)) { ev.setPercentComplete(ival); } break; case POLL_MODE: /* ------------------- Poll mode -------------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollMode(), sval)) { ev.setPollMode(sval); } break; case POLL_PROPERTIES: /* ------------------- Poll properties ---------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollProperties(), sval)) { ev.setPollProperties(sval); } break; case POLL_WINNER: /* ------------------- Poll winner -------------------- */ ival = ((PollWinner)prop).getPollwinner(); if (chg.changed(pi, ev.getPollWinner(), ival)) { ev.setPollWinner(ival); } break; case PRIORITY: /* ------------------- Priority -------------------- */ ival = ((Priority)prop).getLevel(); if (chg.changed(pi, ev.getPriority(), ival)) { ev.setPriority(ival); } break; case RDATE: /* ------------------- RDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case RECURRENCE_ID: /* ------------------- RecurrenceID -------------------- */ // Done above break; case RELATED_TO: /* ------------------- RelatedTo -------------------- */ final RelatedTo irelto = (RelatedTo)prop; final BwRelatedTo relto = new BwRelatedTo(); final String parval = IcalUtil.getParameterVal(irelto, "RELTYPE"); if (parval != null) { relto.setRelType(parval); } relto.setValue(irelto.getValue()); if (chg.changed(pi, ev.getRelatedTo(), relto)) { ev.setRelatedTo(relto); } break; case REQUEST_STATUS: /* ------------------- RequestStatus -------------------- */ final BwRequestStatus rs = BwRequestStatus .fromRequestStatus((RequestStatus)prop); chg.addValue(pi, rs); break; case RESOURCES: /* ------------------- Resources -------------------- */ final TextList rl = ((Resources)prop).getResources(); if (rl != null) { /* Got some resources */ lang = IcalUtil.getLang(prop); for (final String s: rl) { final BwString rsrc = new BwString(lang, s); chg.addValue(pi, rsrc); } } break; case RRULE: /* ------------------- RRule -------------------- */ chg.addValue(pi, pval); break; case SEQUENCE: /* ------------------- Sequence -------------------- */ final int seq = ((Sequence)prop).getSequenceNo(); if (seq != ev.getSequence()) { chg.changed(pi, ev.getSequence(), seq); ev.setSequence(seq); } break; case STATUS: /* ------------------- Status -------------------- */ if (chg.changed(pi, ev.getStatus(), pval)) { ev.setStatus(pval); } break; case SUMMARY: /* ------------------- Summary -------------------- */ if (chg.changed(pi, ev.getSummary(), pval)) { ev.setSummary(pval); } break; case TRANSP: /* ------------------- Transp -------------------- */ if (chg.changed(pi, ev.getPeruserTransparency( cb.getPrincipal() .getPrincipalRef()), pval)) { final BwXproperty pu = ev.setPeruserTransparency( cb.getPrincipal().getPrincipalRef(), pval); if (pu != null) { chg.addValue(PropertyInfoIndex.XPROP, pu); } } break; case UID: /* ------------------- Uid -------------------- */ /* We did this above */ break; case URL: /* ------------------- Url -------------------- */ if (chg.changed(pi, ev.getLink(), pval)) { ev.setLink(pval); } break; case XPROP: /* ------------------------- x-property --------------------------- */ final String name = prop.getName(); if (name.equalsIgnoreCase(BwXproperty.bedeworkCost)) { if (chg.changed(PropertyInfoIndex.COST, ev.getCost(), pval)) { ev.setCost(pval); } break; } if (name.equalsIgnoreCase(BwXproperty.xBedeworkCategories)) { if (checkCategory(cb, chg, ev, null, pval)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkLocation)) { if (checkLocation(cb, chg, ev, prop)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkContact)) { if (checkContact(cb, chg, ev, null, pval)) { break; } } /* See if this is an x-category that can be converted to a real category */ final XProperty xp = (XProperty)prop; chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(name, xp.getParameters() .toString(), pval)); break; default: if (logger.debug()) { logger.debug("Unsupported property with index " + pi + "; class " + prop.getClass() + " and value " + pval); } } } /* =================== Process sub-components =============== */ final ComponentList<Component> subComps; if (val instanceof ComponentContainer) { subComps = ((ComponentContainer<Component>)val).getComponents(); } else { subComps = null; } final Set<Integer> pids; if (vpoll) { pids = new TreeSet<>(); final BwEvent vp = evinfo.getEvent(); if (!Util.isEmpty(vp.getPollItems())) { vp.clearPollItems(); } } else { pids = null; } if (!Util.isEmpty(subComps)) { for (final var subComp: subComps) { if (subComp instanceof Available) { if (!(val instanceof VAvailability)) { return Response.error(resp, "AVAILABLE only valid in VAVAILABLE"); } final var avlResp = processAvailable(cb, cal, ical, (VAvailability)val, (Available)subComp, evinfo); if (!avlResp.isOk()) { return Response.fromResponse(resp, avlResp); } continue; } if (subComp instanceof Participant) { if (vpoll) { final var vresp = processVoter(cb, (VPoll)val, (Participant)subComp, evinfo, chg, mergeAttendees); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Participant object"); continue; } if (subComp instanceof VResource) { logger.warn("Unimplemented VResource object"); continue; } if (subComp instanceof VLocation) { logger.warn("Unimplemented VLocation object"); continue; } if (subComp instanceof VAlarm) { final var aresp = VAlarmUtil.processAlarm(cb, val, (VAlarm)subComp, ev, currentPrincipal, chg); if (!aresp.isOk()) { return Response.fromResponse(resp, aresp); } continue; } if (vpoll && (event || task)) { final var vresp = processCandidate((VPoll)val, subComp, evinfo, pids, chg); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Component object: " + subComp); } } /* Fix up timestamps. */ if (ev.getCreated() == null) { if (ev.getLastmod() != null) { ev.setCreated(ev.getLastmod()); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); } else { ev.updateDtstamp(); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } } if (ev.getLastmod() == null) { // created cannot be null now ev.setLastmod(ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } processTimezones(ev, ical, chg); /* Remove any recipients and originator */ if (ev.getRecipients() != null) { ev.getRecipients().clear(); } ev.setOriginator(null); if (hasXparams.value) { /* Save a text copy of the entire event as an x-property */ final Component valCopy = val.copy(); /* Remove potentially large values */ final Description desp = valCopy.getProperty(Property.DESCRIPTION); if (desp != null) { desp.setValue(null); } final Attach attachp = valCopy.getProperty(Property.ATTACH); // Don't store the entire attachment - we just need the parameters. if (attachp != null) { final Value v = attachp.getParameter(Parameter.VALUE); if (v != null) { attachp.setValue(String.valueOf(attachp.getValue().hashCode())); } } chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(BwXproperty.bedeworkIcal, null, valCopy.toString())); } chg.processChanges(ev, true, false); ev.setRecurring(ev.isRecurringEntity()); if (logger.debug()) { logger.debug(chg.toString()); logger.debug(ev.toString()); } if (masterEI != null) { // Just return notfound as this event is on its override list return Response.notFound(resp); } resp.setEntity(evinfo); return resp; } catch (final Throwable t) { if (logger.debug()) { logger.error(t); } return Response.error(resp, t); } }
DEFECT
true
masterEI = makeNewEvent(cb, chg, entityType, guid, cal); BwEvent e = masterEI.getEvent(); // XXX This seems bogus DtStart mdtStart; String bogusDate = "19980118T230000";
*/ /* We need this in a couple of places */ final DtStart dtStart = pl.getProperty(Property.DTSTART); /* if (rid != null) { // See if we have a new master event. If so create a proxy to that event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI == null) { masterEI = makeNewEvent(cb, chg, entityType, guid, cal); BwEvent e = masterEI.getEvent(); // XXX This seems bogus DtStart mdtStart; String bogusDate = "19980118T230000"; if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + "Z"); } else if (dtStart.getTimeZone() == null) { mdtStart = new DtStart(bogusDate); } else { mdtStart = new DtStart(bogusDate + "Z", dtStart.getTimeZone()); } setDates(e, mdtStart, null, null, chg);
* If no override retrieve the event, add it to our table and then locate the * annotation. * * If there is no annotation, create one. * * It's possible we have been sent 'detached' instances of a recurring * event. This may happen if we are invited to one or more instances of a * meeting. In this case we try to retrieve the master and if it doesn't * exist we manufacture one. We consider such an instance an update to * that instance only and leave the others alone. */ /* We need this in a couple of places */ final DtStart dtStart = pl.getProperty(Property.DTSTART); /* if (rid != null) { // See if we have a new master event. If so create a proxy to that event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI == null) { masterEI = makeNewEvent(cb, chg, entityType, guid, cal); BwEvent e = masterEI.getEvent(); // XXX This seems bogus DtStart mdtStart; String bogusDate = "19980118T230000"; if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + "Z"); } else if (dtStart.getTimeZone() == null) { mdtStart = new DtStart(bogusDate); } else { mdtStart = new DtStart(bogusDate + "Z", dtStart.getTimeZone()); } setDates(e, mdtStart, null, null, chg); e.setRecurring(true); e.addRdate(ridObj); e.setSuppressed(true); ical.addComponent(masterEI); } if (masterEI != null) { evinfo = masterEI.findOverride(rid); } } */
7,893
18
// Base dtstart on the recurrence id.
public static GetEntityResponse<EventInfo> toEvent( final IcalCallback cb, final BwCalendar cal, final Icalendar ical, final Component val, final boolean mergeAttendees) { final var resp = new GetEntityResponse<EventInfo>(); if (val == null) { return Response.notOk(resp, failed, "No component supplied"); } String currentPrincipal = null; final BwPrincipal principal = cb.getPrincipal(); if (principal != null) { currentPrincipal = principal.getPrincipalRef(); } final Holder<Boolean> hasXparams = new Holder<>(Boolean.FALSE); final int methodType = ical.getMethodType(); String attUri = null; if (mergeAttendees) { // We'll need this later. attUri = cb.getCaladdr(cb.getPrincipal().getPrincipalRef()); } final String colPath; if (cal == null) { colPath = null; } else { colPath = cal.getPath(); } try { final PropertyList<Property> pl = val.getProperties(); boolean vpoll = false; boolean event = false; boolean task = false; if (pl == null) { // Empty component return Response.notOk(resp, failed, "Empty component"); } final int entityType; if (val instanceof VEvent) { entityType = IcalDefs.entityTypeEvent; event = true; } else if (val instanceof VToDo) { entityType = IcalDefs.entityTypeTodo; task = true; } else if (val instanceof VJournal) { entityType = IcalDefs.entityTypeJournal; } else if (val instanceof VFreeBusy) { entityType = IcalDefs.entityTypeFreeAndBusy; } else if (val instanceof VAvailability) { entityType = IcalDefs.entityTypeVavailability; } else if (val instanceof Available) { entityType = IcalDefs.entityTypeAvailable; } else if (val instanceof VPoll) { entityType = IcalDefs.entityTypeVpoll; vpoll = true; } else { return Response.error(resp, "org.bedework.invalid.component.type: " + val.getName()); } // Get the guid from the component String guid = null; final Uid uidp = pl.getProperty(Property.UID); if (uidp != null) { testXparams(uidp, hasXparams); guid = uidp.getValue(); } if (guid == null) { /* XXX A guid is required - but are there devices out there without a * guid - and if so how do we handle it? */ return Response.notOk(resp, failed, CalFacadeException.noGuid); } /* See if we have a recurrence id */ BwDateTime ridObj = null; String rid = null; TimeZone ridTz = null; final RecurrenceId ridp = pl.getProperty(Property.RECURRENCE_ID); if (ridp != null) { testXparams(ridp, hasXparams); ridObj = BwDateTime.makeBwDateTime(ridp); if (ridObj.getRange() != null) { /* XXX What do I do with it? */ logger.warn("TRANS-TO_EVENT: Got a recurrence id range"); } rid = ridObj.getDate(); } EventInfo masterEI = null; EventInfo evinfo = null; final BwEvent ev; /* If we have a recurrence id see if we already have the master (we should * get a master + all its overrides). * * If so find the override and use the annnotation or if no override, * make one. * * If no override retrieve the event, add it to our table and then locate the * annotation. * * If there is no annotation, create one. * * It's possible we have been sent 'detached' instances of a recurring * event. This may happen if we are invited to one or more instances of a * meeting. In this case we try to retrieve the master and if it doesn't * exist we manufacture one. We consider such an instance an update to * that instance only and leave the others alone. */ /* We need this in a couple of places */ final DtStart dtStart = pl.getProperty(Property.DTSTART); /* if (rid != null) { // See if we have a new master event. If so create a proxy to that event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI == null) { masterEI = makeNewEvent(cb, chg, entityType, guid, cal); BwEvent e = masterEI.getEvent(); // XXX This seems bogus DtStart mdtStart; String bogusDate = "19980118T230000"; if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + "Z"); } else if (dtStart.getTimeZone() == null) { mdtStart = new DtStart(bogusDate); } else { mdtStart = new DtStart(bogusDate + "Z", dtStart.getTimeZone()); } setDates(e, mdtStart, null, null, chg); e.setRecurring(true); e.addRdate(ridObj); e.setSuppressed(true); ical.addComponent(masterEI); } if (masterEI != null) { evinfo = masterEI.findOverride(rid); } } */ /* If this is a recurrence instance see if we can find the master We only need this because the master may follow the overrides. */ if (rid != null) { // See if we have a new master event. If so create a proxy to this event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI != null) { evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; } } if ((evinfo == null) && (cal != null) && (cal.getCalType() != BwCalendar.calTypeInbox) && (cal.getCalType() != BwCalendar.calTypePendingInbox) && (cal.getCalType() != BwCalendar.calTypeOutbox)) { if (logger.debug()) { logger.debug("TRANS-TO_EVENT: try to fetch event with guid=" + guid); } final GetEntitiesResponse<EventInfo> eisResp = cb.getEvent(colPath, guid); if (eisResp.isError()) { return Response.fromResponse(resp, eisResp); } final var eis = eisResp.getEntities(); if (!Util.isEmpty(eis)) { if (eis.size() > 1) { // DORECUR - wrong again return Response.notOk(resp, failed, "More than one event returned for guid."); } evinfo = eis.iterator().next(); } if (logger.debug()) { if (evinfo != null) { logger.debug("TRANS-TO_EVENT: fetched event with guid"); } else { logger.debug("TRANS-TO_EVENT: did not find event with guid"); } } if (evinfo != null) { if (rid != null) { // We just retrieved it's master masterEI = evinfo; masterEI.setInstanceOnly(true); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; ical.addComponent(masterEI); } else if (methodType == ScheduleMethods.methodTypeCancel) { // This should never have an rid for cancel of entire event. evinfo.setInstanceOnly(evinfo.getEvent().getSuppressed()); } else { // Presumably sent an update for the entire event. No longer suppressed master evinfo.getEvent().setSuppressed(false); } } else if (rid != null) { /* Manufacture a master for the instance */ masterEI = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); final BwEvent e = masterEI.getEvent(); // XXX This seems bogus final DtStart mdtStart; final String bogusDate = "19980118"; final String bogusTime = "T230000"; // Base dtstart on the recurrence id. final boolean isDateType = ridObj.getDateType(); if (isDateType) { mdtStart = new DtStart(new Date(bogusDate)); } else if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + bogusTime + "Z"); } else if (ridObj.getTzid() == null) { mdtStart = new DtStart(bogusDate + bogusTime); } else { mdtStart = new DtStart(bogusDate + bogusTime, Timezones.getTz(ridObj.getTzid())); } IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), masterEI, mdtStart, null, null); e.setRecurring(true); // e.addRdate(ridObj); final var sum = (Summary)pl.getProperty(Property.SUMMARY); e.setSummary(sum.getValue()); e.setSuppressed(true); ical.addComponent(masterEI); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; masterEI.setInstanceOnly(rid != null); } } if (evinfo == null) { evinfo = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); } else if (evinfo.getEvent().getEntityType() != entityType) { return Response.notOk(resp, failed, "org.bedework.mismatched.entity.type: " + val); } final ChangeTable chg = evinfo.getChangeset( cb.getPrincipal().getPrincipalRef()); if (rid != null) { final String evrid = evinfo.getEvent().getRecurrenceId(); if ((evrid == null) || (!evrid.equals(rid))) { logger. warn("Mismatched rid ev=" + evrid + " expected " + rid); chg.changed(PropertyInfoIndex.RECURRENCE_ID, evrid, rid); // XXX spurious??? } if (masterEI.getEvent().getSuppressed()) { masterEI.getEvent().addRdate(ridObj); } } ev = evinfo.getEvent(); ev.setScheduleMethod(methodType); DtEnd dtEnd = null; if (entityType == IcalDefs.entityTypeTodo) { final Due due = pl.getProperty(Property.DUE); if (due != null ) { dtEnd = new DtEnd(due.getParameters(), due.getValue()); } } else { dtEnd = pl.getProperty(Property.DTEND); } final Duration duration = pl.getProperty(Property.DURATION); IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), evinfo, dtStart, dtEnd, duration); for (final Property prop: pl) { testXparams(prop, hasXparams); //debug("ical prop " + prop.getClass().getName()); String pval = prop.getValue(); if ((pval != null) && (pval.length() == 0)) { pval = null; } final PropertyInfoIndex pi; if (prop instanceof XProperty) { pi = PropertyInfoIndex.XPROP; } else { pi = PropertyInfoIndex.fromName(prop.getName()); } if (pi == null) { logger.debug("Unknown property with name " + prop.getName() + " class " + prop.getClass() + " and value " + pval); continue; } chg.present(pi); switch (pi) { case ACCEPT_RESPONSE: /* ------------------- Accept Response -------------------- */ String sval = prop.getValue(); if (chg.changed(pi, ev.getPollAcceptResponse(), sval)) { ev.setPollAcceptResponse(sval); } break; case ATTACH: /* ------------------- Attachment -------------------- */ chg.addValue(pi, IcalUtil.getAttachment((Attach)prop)); break; case ATTENDEE: /* ------------------- Attendee -------------------- */ if (methodType == ScheduleMethods.methodTypePublish) { if (cb.getStrictness() == IcalCallback.conformanceStrict) { return Response.notOk(resp, failed, CalFacadeException.attendeesInPublish); } //if (cb.getStrictness() == IcalCallback.conformanceWarn) { // warn("Had attendees for PUBLISH"); //} } final Attendee attPr = (Attendee)prop; if (evinfo.getNewEvent() || !mergeAttendees) { chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { final String pUri = cb.getCaladdr(attPr.getValue()); if (pUri.equals(attUri)) { /* Only update for our own attendee * We're doing a PUT and this must be the attendee updating their * partstat. We don't allow them to change other attendees * whatever the PUT content says. */ chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { // Use the value we currently have boolean found = false; for (final BwAttendee att: ev.getAttendees()) { if (pUri.equals(att.getAttendeeUri())) { chg.addValue(pi, att.clone()); found = true; break; } } if (!found) { // An added attendee final BwAttendee att = IcalUtil .getAttendee(cb, attPr); att.setPartstat(IcalDefs.partstatValNeedsAction); chg.addValue(pi, att); } } } break; case BUSYTYPE: final int ibt = BwEvent.fromBusyTypeString(pval); if (chg.changed(pi, ev.getBusyType(), ibt)) { ev.setBusyType(ibt); } break; case CATEGORIES: /* ------------------- Categories -------------------- */ final Categories cats = (Categories)prop; final TextList cl = cats.getCategories(); String lang = IcalUtil.getLang(cats); if (cl != null) { /* Got some categories */ for (final String wd: cl) { if (wd == null) { continue; } final BwString key = new BwString(lang, wd); final var fcResp = cb.findCategory(key); final BwCategory cat; if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isNotFound()) { cat = BwCategory.makeCategory(); cat.setWord(key); cb.addCategory(cat); } else { cat = fcResp.getEntity(); } chg.addValue(pi, cat); } } break; case CLASS: /* ------------------- Class -------------------- */ if (chg.changed(pi, ev.getClassification(), pval)) { ev.setClassification(pval); } break; case COMMENT: /* ------------------- Comment -------------------- */ chg.addValue(pi, new BwString(null, pval)); break; case COMPLETED: /* ------------------- Completed -------------------- */ if (chg.changed(pi, ev.getCompleted(), pval)) { ev.setCompleted(pval); } break; case CONCEPT: /* ------------------- Concept -------------------- */ final Concept c = (Concept)prop; final String cval = c.getValue(); if (cval != null) { /* Got a concept */ chg.addValue(PropertyInfoIndex.XPROP, BwXproperty.makeIcalProperty("CONCEPT", null, cval)); } break; case CONTACT: /* ------------------- Contact -------------------- */ final String altrep = getAltRepPar(prop); lang = IcalUtil.getLang(prop); final String uid = getUidPar(prop); final BwString nm = new BwString(lang, pval); BwContact contact = null; if (uid != null) { final var fcResp = cb.getContact(uid); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { final var fcResp = cb.findContact(nm); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { contact = BwContact.makeContact(); contact.setCn(nm); contact.setLink(altrep); cb.addContact(contact); } else { contact.setCn(nm); contact.setLink(altrep); } chg.addValue(pi, contact); break; case CREATED: /* ------------------- Created -------------------- */ if (chg.changed(pi, ev.getCreated(), pval)) { ev.setCreated(pval); } break; case DESCRIPTION: /* ------------------- Description -------------------- */ if (chg.changed(pi, ev.getDescription(), pval)) { ev.setDescription(pval); } break; case DTEND: /* ------------------- DtEnd -------------------- */ break; case DTSTAMP: /* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval); break; case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE: /* -------------------- Due ------------------------ */ break; case DURATION: /* ------------------- Duration -------------------- */ break; case EXDATE: /* ------------------- ExDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case EXRULE: /* ------------------- ExRule -------------------- */ chg.addValue(pi, pval); break; case FREEBUSY: /* ------------------- freebusy -------------------- */ final FreeBusy fbusy = (FreeBusy)prop; final PeriodList perpl = fbusy.getPeriods(); final Parameter par = IcalUtil.getParameter(fbusy, "FBTYPE"); final int fbtype; if (par == null) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY)) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY_TENTATIVE)) { fbtype = BwFreeBusyComponent.typeBusyTentative; } else if (par.equals(FbType.BUSY_UNAVAILABLE)) { fbtype = BwFreeBusyComponent.typeBusyUnavailable; } else if (par.equals(FbType.FREE)) { fbtype = BwFreeBusyComponent.typeFree; } else { if (logger.debug()) { logger.debug("Unsupported parameter " + par.getName()); } return Response.notOk(resp, failed, "Unsupported parameter " + par.getName()); } final BwFreeBusyComponent fbc = new BwFreeBusyComponent(); fbc.setType(fbtype); for (final Period per : perpl) { fbc.addPeriod(per); } ev.addFreeBusyPeriod(fbc); break; case GEO: /* ------------------- Geo -------------------- */ final Geo g = (Geo)prop; final BwGeo geo = new BwGeo(g.getLatitude(), g.getLongitude()); if (chg.changed(pi, ev.getGeo(), geo)) { ev.setGeo(geo); } break; case LAST_MODIFIED: /* ------------------- LastModified -------------------- */ if (chg.changed(pi, ev.getLastmod(), pval)) { ev.setLastmod(pval); } break; case LOCATION: /* ------------------- Location -------------------- */ BwLocation loc = null; //String uid = getUidPar(prop); /* At the moment Mozilla lightning is broken and this leads to all * sorts of problems. if (uid != null) { loc = cb.getLocation(uid); } */ lang = IcalUtil.getLang(prop); BwString addr = null; if (pval != null) { if (loc == null) { addr = new BwString(lang, pval); final var fcResp = cb.findLocation(addr); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { loc = fcResp.getEntity(); } } if (loc == null) { loc = BwLocation.makeLocation(); loc.setAddress(addr); cb.addLocation(loc); } } final BwLocation evloc = ev.getLocation(); if (chg.changed(pi, evloc, loc)) { // CHGTBL - this only shows that it's a different location object ev.setLocation(loc); } else if ((loc != null) && (evloc != null)) { // See if the value is changed final String evval = evloc.getAddress().getValue(); final String inval = loc.getAddress().getValue(); if (!evval.equals(inval)) { chg.changed(pi, evval, inval); evloc.getAddress().setValue(inval); } } break; case ORGANIZER: /* ------------------- Organizer -------------------- */ final BwOrganizer org = IcalUtil.getOrganizer(cb, (Organizer)prop); final BwOrganizer evorg = ev.getOrganizer(); final BwOrganizer evorgCopy; if (evorg == null) { evorgCopy = null; } else { evorgCopy = (BwOrganizer)evorg.clone(); } if (chg.changed(pi, evorgCopy, org)) { if (evorg == null) { ev.setOrganizer(org); } else { evorg.update(org); } } break; case PERCENT_COMPLETE: /* ------------------- PercentComplete -------------------- */ Integer ival = ((PercentComplete)prop).getPercentage(); if (chg.changed(pi, ev.getPercentComplete(), ival)) { ev.setPercentComplete(ival); } break; case POLL_MODE: /* ------------------- Poll mode -------------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollMode(), sval)) { ev.setPollMode(sval); } break; case POLL_PROPERTIES: /* ------------------- Poll properties ---------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollProperties(), sval)) { ev.setPollProperties(sval); } break; case POLL_WINNER: /* ------------------- Poll winner -------------------- */ ival = ((PollWinner)prop).getPollwinner(); if (chg.changed(pi, ev.getPollWinner(), ival)) { ev.setPollWinner(ival); } break; case PRIORITY: /* ------------------- Priority -------------------- */ ival = ((Priority)prop).getLevel(); if (chg.changed(pi, ev.getPriority(), ival)) { ev.setPriority(ival); } break; case RDATE: /* ------------------- RDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case RECURRENCE_ID: /* ------------------- RecurrenceID -------------------- */ // Done above break; case RELATED_TO: /* ------------------- RelatedTo -------------------- */ final RelatedTo irelto = (RelatedTo)prop; final BwRelatedTo relto = new BwRelatedTo(); final String parval = IcalUtil.getParameterVal(irelto, "RELTYPE"); if (parval != null) { relto.setRelType(parval); } relto.setValue(irelto.getValue()); if (chg.changed(pi, ev.getRelatedTo(), relto)) { ev.setRelatedTo(relto); } break; case REQUEST_STATUS: /* ------------------- RequestStatus -------------------- */ final BwRequestStatus rs = BwRequestStatus .fromRequestStatus((RequestStatus)prop); chg.addValue(pi, rs); break; case RESOURCES: /* ------------------- Resources -------------------- */ final TextList rl = ((Resources)prop).getResources(); if (rl != null) { /* Got some resources */ lang = IcalUtil.getLang(prop); for (final String s: rl) { final BwString rsrc = new BwString(lang, s); chg.addValue(pi, rsrc); } } break; case RRULE: /* ------------------- RRule -------------------- */ chg.addValue(pi, pval); break; case SEQUENCE: /* ------------------- Sequence -------------------- */ final int seq = ((Sequence)prop).getSequenceNo(); if (seq != ev.getSequence()) { chg.changed(pi, ev.getSequence(), seq); ev.setSequence(seq); } break; case STATUS: /* ------------------- Status -------------------- */ if (chg.changed(pi, ev.getStatus(), pval)) { ev.setStatus(pval); } break; case SUMMARY: /* ------------------- Summary -------------------- */ if (chg.changed(pi, ev.getSummary(), pval)) { ev.setSummary(pval); } break; case TRANSP: /* ------------------- Transp -------------------- */ if (chg.changed(pi, ev.getPeruserTransparency( cb.getPrincipal() .getPrincipalRef()), pval)) { final BwXproperty pu = ev.setPeruserTransparency( cb.getPrincipal().getPrincipalRef(), pval); if (pu != null) { chg.addValue(PropertyInfoIndex.XPROP, pu); } } break; case UID: /* ------------------- Uid -------------------- */ /* We did this above */ break; case URL: /* ------------------- Url -------------------- */ if (chg.changed(pi, ev.getLink(), pval)) { ev.setLink(pval); } break; case XPROP: /* ------------------------- x-property --------------------------- */ final String name = prop.getName(); if (name.equalsIgnoreCase(BwXproperty.bedeworkCost)) { if (chg.changed(PropertyInfoIndex.COST, ev.getCost(), pval)) { ev.setCost(pval); } break; } if (name.equalsIgnoreCase(BwXproperty.xBedeworkCategories)) { if (checkCategory(cb, chg, ev, null, pval)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkLocation)) { if (checkLocation(cb, chg, ev, prop)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkContact)) { if (checkContact(cb, chg, ev, null, pval)) { break; } } /* See if this is an x-category that can be converted to a real category */ final XProperty xp = (XProperty)prop; chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(name, xp.getParameters() .toString(), pval)); break; default: if (logger.debug()) { logger.debug("Unsupported property with index " + pi + "; class " + prop.getClass() + " and value " + pval); } } } /* =================== Process sub-components =============== */ final ComponentList<Component> subComps; if (val instanceof ComponentContainer) { subComps = ((ComponentContainer<Component>)val).getComponents(); } else { subComps = null; } final Set<Integer> pids; if (vpoll) { pids = new TreeSet<>(); final BwEvent vp = evinfo.getEvent(); if (!Util.isEmpty(vp.getPollItems())) { vp.clearPollItems(); } } else { pids = null; } if (!Util.isEmpty(subComps)) { for (final var subComp: subComps) { if (subComp instanceof Available) { if (!(val instanceof VAvailability)) { return Response.error(resp, "AVAILABLE only valid in VAVAILABLE"); } final var avlResp = processAvailable(cb, cal, ical, (VAvailability)val, (Available)subComp, evinfo); if (!avlResp.isOk()) { return Response.fromResponse(resp, avlResp); } continue; } if (subComp instanceof Participant) { if (vpoll) { final var vresp = processVoter(cb, (VPoll)val, (Participant)subComp, evinfo, chg, mergeAttendees); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Participant object"); continue; } if (subComp instanceof VResource) { logger.warn("Unimplemented VResource object"); continue; } if (subComp instanceof VLocation) { logger.warn("Unimplemented VLocation object"); continue; } if (subComp instanceof VAlarm) { final var aresp = VAlarmUtil.processAlarm(cb, val, (VAlarm)subComp, ev, currentPrincipal, chg); if (!aresp.isOk()) { return Response.fromResponse(resp, aresp); } continue; } if (vpoll && (event || task)) { final var vresp = processCandidate((VPoll)val, subComp, evinfo, pids, chg); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Component object: " + subComp); } } /* Fix up timestamps. */ if (ev.getCreated() == null) { if (ev.getLastmod() != null) { ev.setCreated(ev.getLastmod()); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); } else { ev.updateDtstamp(); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } } if (ev.getLastmod() == null) { // created cannot be null now ev.setLastmod(ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } processTimezones(ev, ical, chg); /* Remove any recipients and originator */ if (ev.getRecipients() != null) { ev.getRecipients().clear(); } ev.setOriginator(null); if (hasXparams.value) { /* Save a text copy of the entire event as an x-property */ final Component valCopy = val.copy(); /* Remove potentially large values */ final Description desp = valCopy.getProperty(Property.DESCRIPTION); if (desp != null) { desp.setValue(null); } final Attach attachp = valCopy.getProperty(Property.ATTACH); // Don't store the entire attachment - we just need the parameters. if (attachp != null) { final Value v = attachp.getParameter(Parameter.VALUE); if (v != null) { attachp.setValue(String.valueOf(attachp.getValue().hashCode())); } } chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(BwXproperty.bedeworkIcal, null, valCopy.toString())); } chg.processChanges(ev, true, false); ev.setRecurring(ev.isRecurringEntity()); if (logger.debug()) { logger.debug(chg.toString()); logger.debug(ev.toString()); } if (masterEI != null) { // Just return notfound as this event is on its override list return Response.notFound(resp); } resp.setEntity(evinfo); return resp; } catch (final Throwable t) { if (logger.debug()) { logger.error(t); } return Response.error(resp, t); } }
NONSATD
true
final String bogusDate = "19980118"; final String bogusTime = "T230000"; // Base dtstart on the recurrence id. final boolean isDateType = ridObj.getDateType(); if (isDateType) {
evinfo.getEvent().setSuppressed(false); } } else if (rid != null) { /* Manufacture a master for the instance */ masterEI = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); final BwEvent e = masterEI.getEvent(); // XXX This seems bogus final DtStart mdtStart; final String bogusDate = "19980118"; final String bogusTime = "T230000"; // Base dtstart on the recurrence id. final boolean isDateType = ridObj.getDateType(); if (isDateType) { mdtStart = new DtStart(new Date(bogusDate)); } else if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + bogusTime + "Z"); } else if (ridObj.getTzid() == null) { mdtStart = new DtStart(bogusDate + bogusTime); } else { mdtStart = new DtStart(bogusDate + bogusTime, Timezones.getTz(ridObj.getTzid()));
masterEI = evinfo; masterEI.setInstanceOnly(true); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; ical.addComponent(masterEI); } else if (methodType == ScheduleMethods.methodTypeCancel) { // This should never have an rid for cancel of entire event. evinfo.setInstanceOnly(evinfo.getEvent().getSuppressed()); } else { // Presumably sent an update for the entire event. No longer suppressed master evinfo.getEvent().setSuppressed(false); } } else if (rid != null) { /* Manufacture a master for the instance */ masterEI = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); final BwEvent e = masterEI.getEvent(); // XXX This seems bogus final DtStart mdtStart; final String bogusDate = "19980118"; final String bogusTime = "T230000"; // Base dtstart on the recurrence id. final boolean isDateType = ridObj.getDateType(); if (isDateType) { mdtStart = new DtStart(new Date(bogusDate)); } else if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + bogusTime + "Z"); } else if (ridObj.getTzid() == null) { mdtStart = new DtStart(bogusDate + bogusTime); } else { mdtStart = new DtStart(bogusDate + bogusTime, Timezones.getTz(ridObj.getTzid())); } IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), masterEI, mdtStart, null, null); e.setRecurring(true); // e.addRdate(ridObj); final var sum = (Summary)pl.getProperty(Property.SUMMARY); e.setSummary(sum.getValue()); e.setSuppressed(true); ical.addComponent(masterEI); evinfo = masterEI.findOverride(rid);
7,893
19
// e.addRdate(ridObj);
public static GetEntityResponse<EventInfo> toEvent( final IcalCallback cb, final BwCalendar cal, final Icalendar ical, final Component val, final boolean mergeAttendees) { final var resp = new GetEntityResponse<EventInfo>(); if (val == null) { return Response.notOk(resp, failed, "No component supplied"); } String currentPrincipal = null; final BwPrincipal principal = cb.getPrincipal(); if (principal != null) { currentPrincipal = principal.getPrincipalRef(); } final Holder<Boolean> hasXparams = new Holder<>(Boolean.FALSE); final int methodType = ical.getMethodType(); String attUri = null; if (mergeAttendees) { // We'll need this later. attUri = cb.getCaladdr(cb.getPrincipal().getPrincipalRef()); } final String colPath; if (cal == null) { colPath = null; } else { colPath = cal.getPath(); } try { final PropertyList<Property> pl = val.getProperties(); boolean vpoll = false; boolean event = false; boolean task = false; if (pl == null) { // Empty component return Response.notOk(resp, failed, "Empty component"); } final int entityType; if (val instanceof VEvent) { entityType = IcalDefs.entityTypeEvent; event = true; } else if (val instanceof VToDo) { entityType = IcalDefs.entityTypeTodo; task = true; } else if (val instanceof VJournal) { entityType = IcalDefs.entityTypeJournal; } else if (val instanceof VFreeBusy) { entityType = IcalDefs.entityTypeFreeAndBusy; } else if (val instanceof VAvailability) { entityType = IcalDefs.entityTypeVavailability; } else if (val instanceof Available) { entityType = IcalDefs.entityTypeAvailable; } else if (val instanceof VPoll) { entityType = IcalDefs.entityTypeVpoll; vpoll = true; } else { return Response.error(resp, "org.bedework.invalid.component.type: " + val.getName()); } // Get the guid from the component String guid = null; final Uid uidp = pl.getProperty(Property.UID); if (uidp != null) { testXparams(uidp, hasXparams); guid = uidp.getValue(); } if (guid == null) { /* XXX A guid is required - but are there devices out there without a * guid - and if so how do we handle it? */ return Response.notOk(resp, failed, CalFacadeException.noGuid); } /* See if we have a recurrence id */ BwDateTime ridObj = null; String rid = null; TimeZone ridTz = null; final RecurrenceId ridp = pl.getProperty(Property.RECURRENCE_ID); if (ridp != null) { testXparams(ridp, hasXparams); ridObj = BwDateTime.makeBwDateTime(ridp); if (ridObj.getRange() != null) { /* XXX What do I do with it? */ logger.warn("TRANS-TO_EVENT: Got a recurrence id range"); } rid = ridObj.getDate(); } EventInfo masterEI = null; EventInfo evinfo = null; final BwEvent ev; /* If we have a recurrence id see if we already have the master (we should * get a master + all its overrides). * * If so find the override and use the annnotation or if no override, * make one. * * If no override retrieve the event, add it to our table and then locate the * annotation. * * If there is no annotation, create one. * * It's possible we have been sent 'detached' instances of a recurring * event. This may happen if we are invited to one or more instances of a * meeting. In this case we try to retrieve the master and if it doesn't * exist we manufacture one. We consider such an instance an update to * that instance only and leave the others alone. */ /* We need this in a couple of places */ final DtStart dtStart = pl.getProperty(Property.DTSTART); /* if (rid != null) { // See if we have a new master event. If so create a proxy to that event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI == null) { masterEI = makeNewEvent(cb, chg, entityType, guid, cal); BwEvent e = masterEI.getEvent(); // XXX This seems bogus DtStart mdtStart; String bogusDate = "19980118T230000"; if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + "Z"); } else if (dtStart.getTimeZone() == null) { mdtStart = new DtStart(bogusDate); } else { mdtStart = new DtStart(bogusDate + "Z", dtStart.getTimeZone()); } setDates(e, mdtStart, null, null, chg); e.setRecurring(true); e.addRdate(ridObj); e.setSuppressed(true); ical.addComponent(masterEI); } if (masterEI != null) { evinfo = masterEI.findOverride(rid); } } */ /* If this is a recurrence instance see if we can find the master We only need this because the master may follow the overrides. */ if (rid != null) { // See if we have a new master event. If so create a proxy to this event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI != null) { evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; } } if ((evinfo == null) && (cal != null) && (cal.getCalType() != BwCalendar.calTypeInbox) && (cal.getCalType() != BwCalendar.calTypePendingInbox) && (cal.getCalType() != BwCalendar.calTypeOutbox)) { if (logger.debug()) { logger.debug("TRANS-TO_EVENT: try to fetch event with guid=" + guid); } final GetEntitiesResponse<EventInfo> eisResp = cb.getEvent(colPath, guid); if (eisResp.isError()) { return Response.fromResponse(resp, eisResp); } final var eis = eisResp.getEntities(); if (!Util.isEmpty(eis)) { if (eis.size() > 1) { // DORECUR - wrong again return Response.notOk(resp, failed, "More than one event returned for guid."); } evinfo = eis.iterator().next(); } if (logger.debug()) { if (evinfo != null) { logger.debug("TRANS-TO_EVENT: fetched event with guid"); } else { logger.debug("TRANS-TO_EVENT: did not find event with guid"); } } if (evinfo != null) { if (rid != null) { // We just retrieved it's master masterEI = evinfo; masterEI.setInstanceOnly(true); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; ical.addComponent(masterEI); } else if (methodType == ScheduleMethods.methodTypeCancel) { // This should never have an rid for cancel of entire event. evinfo.setInstanceOnly(evinfo.getEvent().getSuppressed()); } else { // Presumably sent an update for the entire event. No longer suppressed master evinfo.getEvent().setSuppressed(false); } } else if (rid != null) { /* Manufacture a master for the instance */ masterEI = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); final BwEvent e = masterEI.getEvent(); // XXX This seems bogus final DtStart mdtStart; final String bogusDate = "19980118"; final String bogusTime = "T230000"; // Base dtstart on the recurrence id. final boolean isDateType = ridObj.getDateType(); if (isDateType) { mdtStart = new DtStart(new Date(bogusDate)); } else if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + bogusTime + "Z"); } else if (ridObj.getTzid() == null) { mdtStart = new DtStart(bogusDate + bogusTime); } else { mdtStart = new DtStart(bogusDate + bogusTime, Timezones.getTz(ridObj.getTzid())); } IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), masterEI, mdtStart, null, null); e.setRecurring(true); // e.addRdate(ridObj); final var sum = (Summary)pl.getProperty(Property.SUMMARY); e.setSummary(sum.getValue()); e.setSuppressed(true); ical.addComponent(masterEI); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; masterEI.setInstanceOnly(rid != null); } } if (evinfo == null) { evinfo = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); } else if (evinfo.getEvent().getEntityType() != entityType) { return Response.notOk(resp, failed, "org.bedework.mismatched.entity.type: " + val); } final ChangeTable chg = evinfo.getChangeset( cb.getPrincipal().getPrincipalRef()); if (rid != null) { final String evrid = evinfo.getEvent().getRecurrenceId(); if ((evrid == null) || (!evrid.equals(rid))) { logger. warn("Mismatched rid ev=" + evrid + " expected " + rid); chg.changed(PropertyInfoIndex.RECURRENCE_ID, evrid, rid); // XXX spurious??? } if (masterEI.getEvent().getSuppressed()) { masterEI.getEvent().addRdate(ridObj); } } ev = evinfo.getEvent(); ev.setScheduleMethod(methodType); DtEnd dtEnd = null; if (entityType == IcalDefs.entityTypeTodo) { final Due due = pl.getProperty(Property.DUE); if (due != null ) { dtEnd = new DtEnd(due.getParameters(), due.getValue()); } } else { dtEnd = pl.getProperty(Property.DTEND); } final Duration duration = pl.getProperty(Property.DURATION); IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), evinfo, dtStart, dtEnd, duration); for (final Property prop: pl) { testXparams(prop, hasXparams); //debug("ical prop " + prop.getClass().getName()); String pval = prop.getValue(); if ((pval != null) && (pval.length() == 0)) { pval = null; } final PropertyInfoIndex pi; if (prop instanceof XProperty) { pi = PropertyInfoIndex.XPROP; } else { pi = PropertyInfoIndex.fromName(prop.getName()); } if (pi == null) { logger.debug("Unknown property with name " + prop.getName() + " class " + prop.getClass() + " and value " + pval); continue; } chg.present(pi); switch (pi) { case ACCEPT_RESPONSE: /* ------------------- Accept Response -------------------- */ String sval = prop.getValue(); if (chg.changed(pi, ev.getPollAcceptResponse(), sval)) { ev.setPollAcceptResponse(sval); } break; case ATTACH: /* ------------------- Attachment -------------------- */ chg.addValue(pi, IcalUtil.getAttachment((Attach)prop)); break; case ATTENDEE: /* ------------------- Attendee -------------------- */ if (methodType == ScheduleMethods.methodTypePublish) { if (cb.getStrictness() == IcalCallback.conformanceStrict) { return Response.notOk(resp, failed, CalFacadeException.attendeesInPublish); } //if (cb.getStrictness() == IcalCallback.conformanceWarn) { // warn("Had attendees for PUBLISH"); //} } final Attendee attPr = (Attendee)prop; if (evinfo.getNewEvent() || !mergeAttendees) { chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { final String pUri = cb.getCaladdr(attPr.getValue()); if (pUri.equals(attUri)) { /* Only update for our own attendee * We're doing a PUT and this must be the attendee updating their * partstat. We don't allow them to change other attendees * whatever the PUT content says. */ chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { // Use the value we currently have boolean found = false; for (final BwAttendee att: ev.getAttendees()) { if (pUri.equals(att.getAttendeeUri())) { chg.addValue(pi, att.clone()); found = true; break; } } if (!found) { // An added attendee final BwAttendee att = IcalUtil .getAttendee(cb, attPr); att.setPartstat(IcalDefs.partstatValNeedsAction); chg.addValue(pi, att); } } } break; case BUSYTYPE: final int ibt = BwEvent.fromBusyTypeString(pval); if (chg.changed(pi, ev.getBusyType(), ibt)) { ev.setBusyType(ibt); } break; case CATEGORIES: /* ------------------- Categories -------------------- */ final Categories cats = (Categories)prop; final TextList cl = cats.getCategories(); String lang = IcalUtil.getLang(cats); if (cl != null) { /* Got some categories */ for (final String wd: cl) { if (wd == null) { continue; } final BwString key = new BwString(lang, wd); final var fcResp = cb.findCategory(key); final BwCategory cat; if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isNotFound()) { cat = BwCategory.makeCategory(); cat.setWord(key); cb.addCategory(cat); } else { cat = fcResp.getEntity(); } chg.addValue(pi, cat); } } break; case CLASS: /* ------------------- Class -------------------- */ if (chg.changed(pi, ev.getClassification(), pval)) { ev.setClassification(pval); } break; case COMMENT: /* ------------------- Comment -------------------- */ chg.addValue(pi, new BwString(null, pval)); break; case COMPLETED: /* ------------------- Completed -------------------- */ if (chg.changed(pi, ev.getCompleted(), pval)) { ev.setCompleted(pval); } break; case CONCEPT: /* ------------------- Concept -------------------- */ final Concept c = (Concept)prop; final String cval = c.getValue(); if (cval != null) { /* Got a concept */ chg.addValue(PropertyInfoIndex.XPROP, BwXproperty.makeIcalProperty("CONCEPT", null, cval)); } break; case CONTACT: /* ------------------- Contact -------------------- */ final String altrep = getAltRepPar(prop); lang = IcalUtil.getLang(prop); final String uid = getUidPar(prop); final BwString nm = new BwString(lang, pval); BwContact contact = null; if (uid != null) { final var fcResp = cb.getContact(uid); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { final var fcResp = cb.findContact(nm); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { contact = BwContact.makeContact(); contact.setCn(nm); contact.setLink(altrep); cb.addContact(contact); } else { contact.setCn(nm); contact.setLink(altrep); } chg.addValue(pi, contact); break; case CREATED: /* ------------------- Created -------------------- */ if (chg.changed(pi, ev.getCreated(), pval)) { ev.setCreated(pval); } break; case DESCRIPTION: /* ------------------- Description -------------------- */ if (chg.changed(pi, ev.getDescription(), pval)) { ev.setDescription(pval); } break; case DTEND: /* ------------------- DtEnd -------------------- */ break; case DTSTAMP: /* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval); break; case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE: /* -------------------- Due ------------------------ */ break; case DURATION: /* ------------------- Duration -------------------- */ break; case EXDATE: /* ------------------- ExDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case EXRULE: /* ------------------- ExRule -------------------- */ chg.addValue(pi, pval); break; case FREEBUSY: /* ------------------- freebusy -------------------- */ final FreeBusy fbusy = (FreeBusy)prop; final PeriodList perpl = fbusy.getPeriods(); final Parameter par = IcalUtil.getParameter(fbusy, "FBTYPE"); final int fbtype; if (par == null) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY)) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY_TENTATIVE)) { fbtype = BwFreeBusyComponent.typeBusyTentative; } else if (par.equals(FbType.BUSY_UNAVAILABLE)) { fbtype = BwFreeBusyComponent.typeBusyUnavailable; } else if (par.equals(FbType.FREE)) { fbtype = BwFreeBusyComponent.typeFree; } else { if (logger.debug()) { logger.debug("Unsupported parameter " + par.getName()); } return Response.notOk(resp, failed, "Unsupported parameter " + par.getName()); } final BwFreeBusyComponent fbc = new BwFreeBusyComponent(); fbc.setType(fbtype); for (final Period per : perpl) { fbc.addPeriod(per); } ev.addFreeBusyPeriod(fbc); break; case GEO: /* ------------------- Geo -------------------- */ final Geo g = (Geo)prop; final BwGeo geo = new BwGeo(g.getLatitude(), g.getLongitude()); if (chg.changed(pi, ev.getGeo(), geo)) { ev.setGeo(geo); } break; case LAST_MODIFIED: /* ------------------- LastModified -------------------- */ if (chg.changed(pi, ev.getLastmod(), pval)) { ev.setLastmod(pval); } break; case LOCATION: /* ------------------- Location -------------------- */ BwLocation loc = null; //String uid = getUidPar(prop); /* At the moment Mozilla lightning is broken and this leads to all * sorts of problems. if (uid != null) { loc = cb.getLocation(uid); } */ lang = IcalUtil.getLang(prop); BwString addr = null; if (pval != null) { if (loc == null) { addr = new BwString(lang, pval); final var fcResp = cb.findLocation(addr); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { loc = fcResp.getEntity(); } } if (loc == null) { loc = BwLocation.makeLocation(); loc.setAddress(addr); cb.addLocation(loc); } } final BwLocation evloc = ev.getLocation(); if (chg.changed(pi, evloc, loc)) { // CHGTBL - this only shows that it's a different location object ev.setLocation(loc); } else if ((loc != null) && (evloc != null)) { // See if the value is changed final String evval = evloc.getAddress().getValue(); final String inval = loc.getAddress().getValue(); if (!evval.equals(inval)) { chg.changed(pi, evval, inval); evloc.getAddress().setValue(inval); } } break; case ORGANIZER: /* ------------------- Organizer -------------------- */ final BwOrganizer org = IcalUtil.getOrganizer(cb, (Organizer)prop); final BwOrganizer evorg = ev.getOrganizer(); final BwOrganizer evorgCopy; if (evorg == null) { evorgCopy = null; } else { evorgCopy = (BwOrganizer)evorg.clone(); } if (chg.changed(pi, evorgCopy, org)) { if (evorg == null) { ev.setOrganizer(org); } else { evorg.update(org); } } break; case PERCENT_COMPLETE: /* ------------------- PercentComplete -------------------- */ Integer ival = ((PercentComplete)prop).getPercentage(); if (chg.changed(pi, ev.getPercentComplete(), ival)) { ev.setPercentComplete(ival); } break; case POLL_MODE: /* ------------------- Poll mode -------------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollMode(), sval)) { ev.setPollMode(sval); } break; case POLL_PROPERTIES: /* ------------------- Poll properties ---------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollProperties(), sval)) { ev.setPollProperties(sval); } break; case POLL_WINNER: /* ------------------- Poll winner -------------------- */ ival = ((PollWinner)prop).getPollwinner(); if (chg.changed(pi, ev.getPollWinner(), ival)) { ev.setPollWinner(ival); } break; case PRIORITY: /* ------------------- Priority -------------------- */ ival = ((Priority)prop).getLevel(); if (chg.changed(pi, ev.getPriority(), ival)) { ev.setPriority(ival); } break; case RDATE: /* ------------------- RDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case RECURRENCE_ID: /* ------------------- RecurrenceID -------------------- */ // Done above break; case RELATED_TO: /* ------------------- RelatedTo -------------------- */ final RelatedTo irelto = (RelatedTo)prop; final BwRelatedTo relto = new BwRelatedTo(); final String parval = IcalUtil.getParameterVal(irelto, "RELTYPE"); if (parval != null) { relto.setRelType(parval); } relto.setValue(irelto.getValue()); if (chg.changed(pi, ev.getRelatedTo(), relto)) { ev.setRelatedTo(relto); } break; case REQUEST_STATUS: /* ------------------- RequestStatus -------------------- */ final BwRequestStatus rs = BwRequestStatus .fromRequestStatus((RequestStatus)prop); chg.addValue(pi, rs); break; case RESOURCES: /* ------------------- Resources -------------------- */ final TextList rl = ((Resources)prop).getResources(); if (rl != null) { /* Got some resources */ lang = IcalUtil.getLang(prop); for (final String s: rl) { final BwString rsrc = new BwString(lang, s); chg.addValue(pi, rsrc); } } break; case RRULE: /* ------------------- RRule -------------------- */ chg.addValue(pi, pval); break; case SEQUENCE: /* ------------------- Sequence -------------------- */ final int seq = ((Sequence)prop).getSequenceNo(); if (seq != ev.getSequence()) { chg.changed(pi, ev.getSequence(), seq); ev.setSequence(seq); } break; case STATUS: /* ------------------- Status -------------------- */ if (chg.changed(pi, ev.getStatus(), pval)) { ev.setStatus(pval); } break; case SUMMARY: /* ------------------- Summary -------------------- */ if (chg.changed(pi, ev.getSummary(), pval)) { ev.setSummary(pval); } break; case TRANSP: /* ------------------- Transp -------------------- */ if (chg.changed(pi, ev.getPeruserTransparency( cb.getPrincipal() .getPrincipalRef()), pval)) { final BwXproperty pu = ev.setPeruserTransparency( cb.getPrincipal().getPrincipalRef(), pval); if (pu != null) { chg.addValue(PropertyInfoIndex.XPROP, pu); } } break; case UID: /* ------------------- Uid -------------------- */ /* We did this above */ break; case URL: /* ------------------- Url -------------------- */ if (chg.changed(pi, ev.getLink(), pval)) { ev.setLink(pval); } break; case XPROP: /* ------------------------- x-property --------------------------- */ final String name = prop.getName(); if (name.equalsIgnoreCase(BwXproperty.bedeworkCost)) { if (chg.changed(PropertyInfoIndex.COST, ev.getCost(), pval)) { ev.setCost(pval); } break; } if (name.equalsIgnoreCase(BwXproperty.xBedeworkCategories)) { if (checkCategory(cb, chg, ev, null, pval)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkLocation)) { if (checkLocation(cb, chg, ev, prop)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkContact)) { if (checkContact(cb, chg, ev, null, pval)) { break; } } /* See if this is an x-category that can be converted to a real category */ final XProperty xp = (XProperty)prop; chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(name, xp.getParameters() .toString(), pval)); break; default: if (logger.debug()) { logger.debug("Unsupported property with index " + pi + "; class " + prop.getClass() + " and value " + pval); } } } /* =================== Process sub-components =============== */ final ComponentList<Component> subComps; if (val instanceof ComponentContainer) { subComps = ((ComponentContainer<Component>)val).getComponents(); } else { subComps = null; } final Set<Integer> pids; if (vpoll) { pids = new TreeSet<>(); final BwEvent vp = evinfo.getEvent(); if (!Util.isEmpty(vp.getPollItems())) { vp.clearPollItems(); } } else { pids = null; } if (!Util.isEmpty(subComps)) { for (final var subComp: subComps) { if (subComp instanceof Available) { if (!(val instanceof VAvailability)) { return Response.error(resp, "AVAILABLE only valid in VAVAILABLE"); } final var avlResp = processAvailable(cb, cal, ical, (VAvailability)val, (Available)subComp, evinfo); if (!avlResp.isOk()) { return Response.fromResponse(resp, avlResp); } continue; } if (subComp instanceof Participant) { if (vpoll) { final var vresp = processVoter(cb, (VPoll)val, (Participant)subComp, evinfo, chg, mergeAttendees); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Participant object"); continue; } if (subComp instanceof VResource) { logger.warn("Unimplemented VResource object"); continue; } if (subComp instanceof VLocation) { logger.warn("Unimplemented VLocation object"); continue; } if (subComp instanceof VAlarm) { final var aresp = VAlarmUtil.processAlarm(cb, val, (VAlarm)subComp, ev, currentPrincipal, chg); if (!aresp.isOk()) { return Response.fromResponse(resp, aresp); } continue; } if (vpoll && (event || task)) { final var vresp = processCandidate((VPoll)val, subComp, evinfo, pids, chg); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Component object: " + subComp); } } /* Fix up timestamps. */ if (ev.getCreated() == null) { if (ev.getLastmod() != null) { ev.setCreated(ev.getLastmod()); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); } else { ev.updateDtstamp(); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } } if (ev.getLastmod() == null) { // created cannot be null now ev.setLastmod(ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } processTimezones(ev, ical, chg); /* Remove any recipients and originator */ if (ev.getRecipients() != null) { ev.getRecipients().clear(); } ev.setOriginator(null); if (hasXparams.value) { /* Save a text copy of the entire event as an x-property */ final Component valCopy = val.copy(); /* Remove potentially large values */ final Description desp = valCopy.getProperty(Property.DESCRIPTION); if (desp != null) { desp.setValue(null); } final Attach attachp = valCopy.getProperty(Property.ATTACH); // Don't store the entire attachment - we just need the parameters. if (attachp != null) { final Value v = attachp.getParameter(Parameter.VALUE); if (v != null) { attachp.setValue(String.valueOf(attachp.getValue().hashCode())); } } chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(BwXproperty.bedeworkIcal, null, valCopy.toString())); } chg.processChanges(ev, true, false); ev.setRecurring(ev.isRecurringEntity()); if (logger.debug()) { logger.debug(chg.toString()); logger.debug(ev.toString()); } if (masterEI != null) { // Just return notfound as this event is on its override list return Response.notFound(resp); } resp.setEntity(evinfo); return resp; } catch (final Throwable t) { if (logger.debug()) { logger.error(t); } return Response.error(resp, t); } }
NONSATD
true
masterEI, mdtStart, null, null); e.setRecurring(true); // e.addRdate(ridObj); final var sum = (Summary)pl.getProperty(Property.SUMMARY); e.setSummary(sum.getValue());
mdtStart = new DtStart(bogusDate + bogusTime + "Z"); } else if (ridObj.getTzid() == null) { mdtStart = new DtStart(bogusDate + bogusTime); } else { mdtStart = new DtStart(bogusDate + bogusTime, Timezones.getTz(ridObj.getTzid())); } IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), masterEI, mdtStart, null, null); e.setRecurring(true); // e.addRdate(ridObj); final var sum = (Summary)pl.getProperty(Property.SUMMARY); e.setSummary(sum.getValue()); e.setSuppressed(true); ical.addComponent(masterEI); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; masterEI.setInstanceOnly(rid != null); } } if (evinfo == null) {
final BwEvent e = masterEI.getEvent(); // XXX This seems bogus final DtStart mdtStart; final String bogusDate = "19980118"; final String bogusTime = "T230000"; // Base dtstart on the recurrence id. final boolean isDateType = ridObj.getDateType(); if (isDateType) { mdtStart = new DtStart(new Date(bogusDate)); } else if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + bogusTime + "Z"); } else if (ridObj.getTzid() == null) { mdtStart = new DtStart(bogusDate + bogusTime); } else { mdtStart = new DtStart(bogusDate + bogusTime, Timezones.getTz(ridObj.getTzid())); } IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), masterEI, mdtStart, null, null); e.setRecurring(true); // e.addRdate(ridObj); final var sum = (Summary)pl.getProperty(Property.SUMMARY); e.setSummary(sum.getValue()); e.setSuppressed(true); ical.addComponent(masterEI); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; masterEI.setInstanceOnly(rid != null); } } if (evinfo == null) { evinfo = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); } else if (evinfo.getEvent().getEntityType() != entityType) { return Response.notOk(resp, failed, "org.bedework.mismatched.entity.type: " + val); } final ChangeTable chg = evinfo.getChangeset( cb.getPrincipal().getPrincipalRef()); if (rid != null) { final String evrid = evinfo.getEvent().getRecurrenceId();
7,893
20
// XXX spurious???
public static GetEntityResponse<EventInfo> toEvent( final IcalCallback cb, final BwCalendar cal, final Icalendar ical, final Component val, final boolean mergeAttendees) { final var resp = new GetEntityResponse<EventInfo>(); if (val == null) { return Response.notOk(resp, failed, "No component supplied"); } String currentPrincipal = null; final BwPrincipal principal = cb.getPrincipal(); if (principal != null) { currentPrincipal = principal.getPrincipalRef(); } final Holder<Boolean> hasXparams = new Holder<>(Boolean.FALSE); final int methodType = ical.getMethodType(); String attUri = null; if (mergeAttendees) { // We'll need this later. attUri = cb.getCaladdr(cb.getPrincipal().getPrincipalRef()); } final String colPath; if (cal == null) { colPath = null; } else { colPath = cal.getPath(); } try { final PropertyList<Property> pl = val.getProperties(); boolean vpoll = false; boolean event = false; boolean task = false; if (pl == null) { // Empty component return Response.notOk(resp, failed, "Empty component"); } final int entityType; if (val instanceof VEvent) { entityType = IcalDefs.entityTypeEvent; event = true; } else if (val instanceof VToDo) { entityType = IcalDefs.entityTypeTodo; task = true; } else if (val instanceof VJournal) { entityType = IcalDefs.entityTypeJournal; } else if (val instanceof VFreeBusy) { entityType = IcalDefs.entityTypeFreeAndBusy; } else if (val instanceof VAvailability) { entityType = IcalDefs.entityTypeVavailability; } else if (val instanceof Available) { entityType = IcalDefs.entityTypeAvailable; } else if (val instanceof VPoll) { entityType = IcalDefs.entityTypeVpoll; vpoll = true; } else { return Response.error(resp, "org.bedework.invalid.component.type: " + val.getName()); } // Get the guid from the component String guid = null; final Uid uidp = pl.getProperty(Property.UID); if (uidp != null) { testXparams(uidp, hasXparams); guid = uidp.getValue(); } if (guid == null) { /* XXX A guid is required - but are there devices out there without a * guid - and if so how do we handle it? */ return Response.notOk(resp, failed, CalFacadeException.noGuid); } /* See if we have a recurrence id */ BwDateTime ridObj = null; String rid = null; TimeZone ridTz = null; final RecurrenceId ridp = pl.getProperty(Property.RECURRENCE_ID); if (ridp != null) { testXparams(ridp, hasXparams); ridObj = BwDateTime.makeBwDateTime(ridp); if (ridObj.getRange() != null) { /* XXX What do I do with it? */ logger.warn("TRANS-TO_EVENT: Got a recurrence id range"); } rid = ridObj.getDate(); } EventInfo masterEI = null; EventInfo evinfo = null; final BwEvent ev; /* If we have a recurrence id see if we already have the master (we should * get a master + all its overrides). * * If so find the override and use the annnotation or if no override, * make one. * * If no override retrieve the event, add it to our table and then locate the * annotation. * * If there is no annotation, create one. * * It's possible we have been sent 'detached' instances of a recurring * event. This may happen if we are invited to one or more instances of a * meeting. In this case we try to retrieve the master and if it doesn't * exist we manufacture one. We consider such an instance an update to * that instance only and leave the others alone. */ /* We need this in a couple of places */ final DtStart dtStart = pl.getProperty(Property.DTSTART); /* if (rid != null) { // See if we have a new master event. If so create a proxy to that event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI == null) { masterEI = makeNewEvent(cb, chg, entityType, guid, cal); BwEvent e = masterEI.getEvent(); // XXX This seems bogus DtStart mdtStart; String bogusDate = "19980118T230000"; if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + "Z"); } else if (dtStart.getTimeZone() == null) { mdtStart = new DtStart(bogusDate); } else { mdtStart = new DtStart(bogusDate + "Z", dtStart.getTimeZone()); } setDates(e, mdtStart, null, null, chg); e.setRecurring(true); e.addRdate(ridObj); e.setSuppressed(true); ical.addComponent(masterEI); } if (masterEI != null) { evinfo = masterEI.findOverride(rid); } } */ /* If this is a recurrence instance see if we can find the master We only need this because the master may follow the overrides. */ if (rid != null) { // See if we have a new master event. If so create a proxy to this event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI != null) { evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; } } if ((evinfo == null) && (cal != null) && (cal.getCalType() != BwCalendar.calTypeInbox) && (cal.getCalType() != BwCalendar.calTypePendingInbox) && (cal.getCalType() != BwCalendar.calTypeOutbox)) { if (logger.debug()) { logger.debug("TRANS-TO_EVENT: try to fetch event with guid=" + guid); } final GetEntitiesResponse<EventInfo> eisResp = cb.getEvent(colPath, guid); if (eisResp.isError()) { return Response.fromResponse(resp, eisResp); } final var eis = eisResp.getEntities(); if (!Util.isEmpty(eis)) { if (eis.size() > 1) { // DORECUR - wrong again return Response.notOk(resp, failed, "More than one event returned for guid."); } evinfo = eis.iterator().next(); } if (logger.debug()) { if (evinfo != null) { logger.debug("TRANS-TO_EVENT: fetched event with guid"); } else { logger.debug("TRANS-TO_EVENT: did not find event with guid"); } } if (evinfo != null) { if (rid != null) { // We just retrieved it's master masterEI = evinfo; masterEI.setInstanceOnly(true); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; ical.addComponent(masterEI); } else if (methodType == ScheduleMethods.methodTypeCancel) { // This should never have an rid for cancel of entire event. evinfo.setInstanceOnly(evinfo.getEvent().getSuppressed()); } else { // Presumably sent an update for the entire event. No longer suppressed master evinfo.getEvent().setSuppressed(false); } } else if (rid != null) { /* Manufacture a master for the instance */ masterEI = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); final BwEvent e = masterEI.getEvent(); // XXX This seems bogus final DtStart mdtStart; final String bogusDate = "19980118"; final String bogusTime = "T230000"; // Base dtstart on the recurrence id. final boolean isDateType = ridObj.getDateType(); if (isDateType) { mdtStart = new DtStart(new Date(bogusDate)); } else if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + bogusTime + "Z"); } else if (ridObj.getTzid() == null) { mdtStart = new DtStart(bogusDate + bogusTime); } else { mdtStart = new DtStart(bogusDate + bogusTime, Timezones.getTz(ridObj.getTzid())); } IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), masterEI, mdtStart, null, null); e.setRecurring(true); // e.addRdate(ridObj); final var sum = (Summary)pl.getProperty(Property.SUMMARY); e.setSummary(sum.getValue()); e.setSuppressed(true); ical.addComponent(masterEI); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; masterEI.setInstanceOnly(rid != null); } } if (evinfo == null) { evinfo = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); } else if (evinfo.getEvent().getEntityType() != entityType) { return Response.notOk(resp, failed, "org.bedework.mismatched.entity.type: " + val); } final ChangeTable chg = evinfo.getChangeset( cb.getPrincipal().getPrincipalRef()); if (rid != null) { final String evrid = evinfo.getEvent().getRecurrenceId(); if ((evrid == null) || (!evrid.equals(rid))) { logger. warn("Mismatched rid ev=" + evrid + " expected " + rid); chg.changed(PropertyInfoIndex.RECURRENCE_ID, evrid, rid); // XXX spurious??? } if (masterEI.getEvent().getSuppressed()) { masterEI.getEvent().addRdate(ridObj); } } ev = evinfo.getEvent(); ev.setScheduleMethod(methodType); DtEnd dtEnd = null; if (entityType == IcalDefs.entityTypeTodo) { final Due due = pl.getProperty(Property.DUE); if (due != null ) { dtEnd = new DtEnd(due.getParameters(), due.getValue()); } } else { dtEnd = pl.getProperty(Property.DTEND); } final Duration duration = pl.getProperty(Property.DURATION); IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), evinfo, dtStart, dtEnd, duration); for (final Property prop: pl) { testXparams(prop, hasXparams); //debug("ical prop " + prop.getClass().getName()); String pval = prop.getValue(); if ((pval != null) && (pval.length() == 0)) { pval = null; } final PropertyInfoIndex pi; if (prop instanceof XProperty) { pi = PropertyInfoIndex.XPROP; } else { pi = PropertyInfoIndex.fromName(prop.getName()); } if (pi == null) { logger.debug("Unknown property with name " + prop.getName() + " class " + prop.getClass() + " and value " + pval); continue; } chg.present(pi); switch (pi) { case ACCEPT_RESPONSE: /* ------------------- Accept Response -------------------- */ String sval = prop.getValue(); if (chg.changed(pi, ev.getPollAcceptResponse(), sval)) { ev.setPollAcceptResponse(sval); } break; case ATTACH: /* ------------------- Attachment -------------------- */ chg.addValue(pi, IcalUtil.getAttachment((Attach)prop)); break; case ATTENDEE: /* ------------------- Attendee -------------------- */ if (methodType == ScheduleMethods.methodTypePublish) { if (cb.getStrictness() == IcalCallback.conformanceStrict) { return Response.notOk(resp, failed, CalFacadeException.attendeesInPublish); } //if (cb.getStrictness() == IcalCallback.conformanceWarn) { // warn("Had attendees for PUBLISH"); //} } final Attendee attPr = (Attendee)prop; if (evinfo.getNewEvent() || !mergeAttendees) { chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { final String pUri = cb.getCaladdr(attPr.getValue()); if (pUri.equals(attUri)) { /* Only update for our own attendee * We're doing a PUT and this must be the attendee updating their * partstat. We don't allow them to change other attendees * whatever the PUT content says. */ chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { // Use the value we currently have boolean found = false; for (final BwAttendee att: ev.getAttendees()) { if (pUri.equals(att.getAttendeeUri())) { chg.addValue(pi, att.clone()); found = true; break; } } if (!found) { // An added attendee final BwAttendee att = IcalUtil .getAttendee(cb, attPr); att.setPartstat(IcalDefs.partstatValNeedsAction); chg.addValue(pi, att); } } } break; case BUSYTYPE: final int ibt = BwEvent.fromBusyTypeString(pval); if (chg.changed(pi, ev.getBusyType(), ibt)) { ev.setBusyType(ibt); } break; case CATEGORIES: /* ------------------- Categories -------------------- */ final Categories cats = (Categories)prop; final TextList cl = cats.getCategories(); String lang = IcalUtil.getLang(cats); if (cl != null) { /* Got some categories */ for (final String wd: cl) { if (wd == null) { continue; } final BwString key = new BwString(lang, wd); final var fcResp = cb.findCategory(key); final BwCategory cat; if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isNotFound()) { cat = BwCategory.makeCategory(); cat.setWord(key); cb.addCategory(cat); } else { cat = fcResp.getEntity(); } chg.addValue(pi, cat); } } break; case CLASS: /* ------------------- Class -------------------- */ if (chg.changed(pi, ev.getClassification(), pval)) { ev.setClassification(pval); } break; case COMMENT: /* ------------------- Comment -------------------- */ chg.addValue(pi, new BwString(null, pval)); break; case COMPLETED: /* ------------------- Completed -------------------- */ if (chg.changed(pi, ev.getCompleted(), pval)) { ev.setCompleted(pval); } break; case CONCEPT: /* ------------------- Concept -------------------- */ final Concept c = (Concept)prop; final String cval = c.getValue(); if (cval != null) { /* Got a concept */ chg.addValue(PropertyInfoIndex.XPROP, BwXproperty.makeIcalProperty("CONCEPT", null, cval)); } break; case CONTACT: /* ------------------- Contact -------------------- */ final String altrep = getAltRepPar(prop); lang = IcalUtil.getLang(prop); final String uid = getUidPar(prop); final BwString nm = new BwString(lang, pval); BwContact contact = null; if (uid != null) { final var fcResp = cb.getContact(uid); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { final var fcResp = cb.findContact(nm); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { contact = BwContact.makeContact(); contact.setCn(nm); contact.setLink(altrep); cb.addContact(contact); } else { contact.setCn(nm); contact.setLink(altrep); } chg.addValue(pi, contact); break; case CREATED: /* ------------------- Created -------------------- */ if (chg.changed(pi, ev.getCreated(), pval)) { ev.setCreated(pval); } break; case DESCRIPTION: /* ------------------- Description -------------------- */ if (chg.changed(pi, ev.getDescription(), pval)) { ev.setDescription(pval); } break; case DTEND: /* ------------------- DtEnd -------------------- */ break; case DTSTAMP: /* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval); break; case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE: /* -------------------- Due ------------------------ */ break; case DURATION: /* ------------------- Duration -------------------- */ break; case EXDATE: /* ------------------- ExDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case EXRULE: /* ------------------- ExRule -------------------- */ chg.addValue(pi, pval); break; case FREEBUSY: /* ------------------- freebusy -------------------- */ final FreeBusy fbusy = (FreeBusy)prop; final PeriodList perpl = fbusy.getPeriods(); final Parameter par = IcalUtil.getParameter(fbusy, "FBTYPE"); final int fbtype; if (par == null) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY)) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY_TENTATIVE)) { fbtype = BwFreeBusyComponent.typeBusyTentative; } else if (par.equals(FbType.BUSY_UNAVAILABLE)) { fbtype = BwFreeBusyComponent.typeBusyUnavailable; } else if (par.equals(FbType.FREE)) { fbtype = BwFreeBusyComponent.typeFree; } else { if (logger.debug()) { logger.debug("Unsupported parameter " + par.getName()); } return Response.notOk(resp, failed, "Unsupported parameter " + par.getName()); } final BwFreeBusyComponent fbc = new BwFreeBusyComponent(); fbc.setType(fbtype); for (final Period per : perpl) { fbc.addPeriod(per); } ev.addFreeBusyPeriod(fbc); break; case GEO: /* ------------------- Geo -------------------- */ final Geo g = (Geo)prop; final BwGeo geo = new BwGeo(g.getLatitude(), g.getLongitude()); if (chg.changed(pi, ev.getGeo(), geo)) { ev.setGeo(geo); } break; case LAST_MODIFIED: /* ------------------- LastModified -------------------- */ if (chg.changed(pi, ev.getLastmod(), pval)) { ev.setLastmod(pval); } break; case LOCATION: /* ------------------- Location -------------------- */ BwLocation loc = null; //String uid = getUidPar(prop); /* At the moment Mozilla lightning is broken and this leads to all * sorts of problems. if (uid != null) { loc = cb.getLocation(uid); } */ lang = IcalUtil.getLang(prop); BwString addr = null; if (pval != null) { if (loc == null) { addr = new BwString(lang, pval); final var fcResp = cb.findLocation(addr); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { loc = fcResp.getEntity(); } } if (loc == null) { loc = BwLocation.makeLocation(); loc.setAddress(addr); cb.addLocation(loc); } } final BwLocation evloc = ev.getLocation(); if (chg.changed(pi, evloc, loc)) { // CHGTBL - this only shows that it's a different location object ev.setLocation(loc); } else if ((loc != null) && (evloc != null)) { // See if the value is changed final String evval = evloc.getAddress().getValue(); final String inval = loc.getAddress().getValue(); if (!evval.equals(inval)) { chg.changed(pi, evval, inval); evloc.getAddress().setValue(inval); } } break; case ORGANIZER: /* ------------------- Organizer -------------------- */ final BwOrganizer org = IcalUtil.getOrganizer(cb, (Organizer)prop); final BwOrganizer evorg = ev.getOrganizer(); final BwOrganizer evorgCopy; if (evorg == null) { evorgCopy = null; } else { evorgCopy = (BwOrganizer)evorg.clone(); } if (chg.changed(pi, evorgCopy, org)) { if (evorg == null) { ev.setOrganizer(org); } else { evorg.update(org); } } break; case PERCENT_COMPLETE: /* ------------------- PercentComplete -------------------- */ Integer ival = ((PercentComplete)prop).getPercentage(); if (chg.changed(pi, ev.getPercentComplete(), ival)) { ev.setPercentComplete(ival); } break; case POLL_MODE: /* ------------------- Poll mode -------------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollMode(), sval)) { ev.setPollMode(sval); } break; case POLL_PROPERTIES: /* ------------------- Poll properties ---------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollProperties(), sval)) { ev.setPollProperties(sval); } break; case POLL_WINNER: /* ------------------- Poll winner -------------------- */ ival = ((PollWinner)prop).getPollwinner(); if (chg.changed(pi, ev.getPollWinner(), ival)) { ev.setPollWinner(ival); } break; case PRIORITY: /* ------------------- Priority -------------------- */ ival = ((Priority)prop).getLevel(); if (chg.changed(pi, ev.getPriority(), ival)) { ev.setPriority(ival); } break; case RDATE: /* ------------------- RDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case RECURRENCE_ID: /* ------------------- RecurrenceID -------------------- */ // Done above break; case RELATED_TO: /* ------------------- RelatedTo -------------------- */ final RelatedTo irelto = (RelatedTo)prop; final BwRelatedTo relto = new BwRelatedTo(); final String parval = IcalUtil.getParameterVal(irelto, "RELTYPE"); if (parval != null) { relto.setRelType(parval); } relto.setValue(irelto.getValue()); if (chg.changed(pi, ev.getRelatedTo(), relto)) { ev.setRelatedTo(relto); } break; case REQUEST_STATUS: /* ------------------- RequestStatus -------------------- */ final BwRequestStatus rs = BwRequestStatus .fromRequestStatus((RequestStatus)prop); chg.addValue(pi, rs); break; case RESOURCES: /* ------------------- Resources -------------------- */ final TextList rl = ((Resources)prop).getResources(); if (rl != null) { /* Got some resources */ lang = IcalUtil.getLang(prop); for (final String s: rl) { final BwString rsrc = new BwString(lang, s); chg.addValue(pi, rsrc); } } break; case RRULE: /* ------------------- RRule -------------------- */ chg.addValue(pi, pval); break; case SEQUENCE: /* ------------------- Sequence -------------------- */ final int seq = ((Sequence)prop).getSequenceNo(); if (seq != ev.getSequence()) { chg.changed(pi, ev.getSequence(), seq); ev.setSequence(seq); } break; case STATUS: /* ------------------- Status -------------------- */ if (chg.changed(pi, ev.getStatus(), pval)) { ev.setStatus(pval); } break; case SUMMARY: /* ------------------- Summary -------------------- */ if (chg.changed(pi, ev.getSummary(), pval)) { ev.setSummary(pval); } break; case TRANSP: /* ------------------- Transp -------------------- */ if (chg.changed(pi, ev.getPeruserTransparency( cb.getPrincipal() .getPrincipalRef()), pval)) { final BwXproperty pu = ev.setPeruserTransparency( cb.getPrincipal().getPrincipalRef(), pval); if (pu != null) { chg.addValue(PropertyInfoIndex.XPROP, pu); } } break; case UID: /* ------------------- Uid -------------------- */ /* We did this above */ break; case URL: /* ------------------- Url -------------------- */ if (chg.changed(pi, ev.getLink(), pval)) { ev.setLink(pval); } break; case XPROP: /* ------------------------- x-property --------------------------- */ final String name = prop.getName(); if (name.equalsIgnoreCase(BwXproperty.bedeworkCost)) { if (chg.changed(PropertyInfoIndex.COST, ev.getCost(), pval)) { ev.setCost(pval); } break; } if (name.equalsIgnoreCase(BwXproperty.xBedeworkCategories)) { if (checkCategory(cb, chg, ev, null, pval)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkLocation)) { if (checkLocation(cb, chg, ev, prop)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkContact)) { if (checkContact(cb, chg, ev, null, pval)) { break; } } /* See if this is an x-category that can be converted to a real category */ final XProperty xp = (XProperty)prop; chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(name, xp.getParameters() .toString(), pval)); break; default: if (logger.debug()) { logger.debug("Unsupported property with index " + pi + "; class " + prop.getClass() + " and value " + pval); } } } /* =================== Process sub-components =============== */ final ComponentList<Component> subComps; if (val instanceof ComponentContainer) { subComps = ((ComponentContainer<Component>)val).getComponents(); } else { subComps = null; } final Set<Integer> pids; if (vpoll) { pids = new TreeSet<>(); final BwEvent vp = evinfo.getEvent(); if (!Util.isEmpty(vp.getPollItems())) { vp.clearPollItems(); } } else { pids = null; } if (!Util.isEmpty(subComps)) { for (final var subComp: subComps) { if (subComp instanceof Available) { if (!(val instanceof VAvailability)) { return Response.error(resp, "AVAILABLE only valid in VAVAILABLE"); } final var avlResp = processAvailable(cb, cal, ical, (VAvailability)val, (Available)subComp, evinfo); if (!avlResp.isOk()) { return Response.fromResponse(resp, avlResp); } continue; } if (subComp instanceof Participant) { if (vpoll) { final var vresp = processVoter(cb, (VPoll)val, (Participant)subComp, evinfo, chg, mergeAttendees); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Participant object"); continue; } if (subComp instanceof VResource) { logger.warn("Unimplemented VResource object"); continue; } if (subComp instanceof VLocation) { logger.warn("Unimplemented VLocation object"); continue; } if (subComp instanceof VAlarm) { final var aresp = VAlarmUtil.processAlarm(cb, val, (VAlarm)subComp, ev, currentPrincipal, chg); if (!aresp.isOk()) { return Response.fromResponse(resp, aresp); } continue; } if (vpoll && (event || task)) { final var vresp = processCandidate((VPoll)val, subComp, evinfo, pids, chg); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Component object: " + subComp); } } /* Fix up timestamps. */ if (ev.getCreated() == null) { if (ev.getLastmod() != null) { ev.setCreated(ev.getLastmod()); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); } else { ev.updateDtstamp(); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } } if (ev.getLastmod() == null) { // created cannot be null now ev.setLastmod(ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } processTimezones(ev, ical, chg); /* Remove any recipients and originator */ if (ev.getRecipients() != null) { ev.getRecipients().clear(); } ev.setOriginator(null); if (hasXparams.value) { /* Save a text copy of the entire event as an x-property */ final Component valCopy = val.copy(); /* Remove potentially large values */ final Description desp = valCopy.getProperty(Property.DESCRIPTION); if (desp != null) { desp.setValue(null); } final Attach attachp = valCopy.getProperty(Property.ATTACH); // Don't store the entire attachment - we just need the parameters. if (attachp != null) { final Value v = attachp.getParameter(Parameter.VALUE); if (v != null) { attachp.setValue(String.valueOf(attachp.getValue().hashCode())); } } chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(BwXproperty.bedeworkIcal, null, valCopy.toString())); } chg.processChanges(ev, true, false); ev.setRecurring(ev.isRecurringEntity()); if (logger.debug()) { logger.debug(chg.toString()); logger.debug(ev.toString()); } if (masterEI != null) { // Just return notfound as this event is on its override list return Response.notFound(resp); } resp.setEntity(evinfo); return resp; } catch (final Throwable t) { if (logger.debug()) { logger.error(t); } return Response.error(resp, t); } }
DEFECT
true
if ((evrid == null) || (!evrid.equals(rid))) { logger. warn("Mismatched rid ev=" + evrid + " expected " + rid); chg.changed(PropertyInfoIndex.RECURRENCE_ID, evrid, rid); // XXX spurious??? } if (masterEI.getEvent().getSuppressed()) {
return Response.notOk(resp, failed, "org.bedework.mismatched.entity.type: " + val); } final ChangeTable chg = evinfo.getChangeset( cb.getPrincipal().getPrincipalRef()); if (rid != null) { final String evrid = evinfo.getEvent().getRecurrenceId(); if ((evrid == null) || (!evrid.equals(rid))) { logger. warn("Mismatched rid ev=" + evrid + " expected " + rid); chg.changed(PropertyInfoIndex.RECURRENCE_ID, evrid, rid); // XXX spurious??? } if (masterEI.getEvent().getSuppressed()) { masterEI.getEvent().addRdate(ridObj); } } ev = evinfo.getEvent(); ev.setScheduleMethod(methodType); DtEnd dtEnd = null; if (entityType == IcalDefs.entityTypeTodo) { final Due due = pl.getProperty(Property.DUE);
e.setSuppressed(true); ical.addComponent(masterEI); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; masterEI.setInstanceOnly(rid != null); } } if (evinfo == null) { evinfo = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); } else if (evinfo.getEvent().getEntityType() != entityType) { return Response.notOk(resp, failed, "org.bedework.mismatched.entity.type: " + val); } final ChangeTable chg = evinfo.getChangeset( cb.getPrincipal().getPrincipalRef()); if (rid != null) { final String evrid = evinfo.getEvent().getRecurrenceId(); if ((evrid == null) || (!evrid.equals(rid))) { logger. warn("Mismatched rid ev=" + evrid + " expected " + rid); chg.changed(PropertyInfoIndex.RECURRENCE_ID, evrid, rid); // XXX spurious??? } if (masterEI.getEvent().getSuppressed()) { masterEI.getEvent().addRdate(ridObj); } } ev = evinfo.getEvent(); ev.setScheduleMethod(methodType); DtEnd dtEnd = null; if (entityType == IcalDefs.entityTypeTodo) { final Due due = pl.getProperty(Property.DUE); if (due != null ) { dtEnd = new DtEnd(due.getParameters(), due.getValue()); } } else { dtEnd = pl.getProperty(Property.DTEND); } final Duration duration = pl.getProperty(Property.DURATION); IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), evinfo, dtStart, dtEnd, duration); for (final Property prop: pl) {
7,893
21
//debug("ical prop " + prop.getClass().getName());
public static GetEntityResponse<EventInfo> toEvent( final IcalCallback cb, final BwCalendar cal, final Icalendar ical, final Component val, final boolean mergeAttendees) { final var resp = new GetEntityResponse<EventInfo>(); if (val == null) { return Response.notOk(resp, failed, "No component supplied"); } String currentPrincipal = null; final BwPrincipal principal = cb.getPrincipal(); if (principal != null) { currentPrincipal = principal.getPrincipalRef(); } final Holder<Boolean> hasXparams = new Holder<>(Boolean.FALSE); final int methodType = ical.getMethodType(); String attUri = null; if (mergeAttendees) { // We'll need this later. attUri = cb.getCaladdr(cb.getPrincipal().getPrincipalRef()); } final String colPath; if (cal == null) { colPath = null; } else { colPath = cal.getPath(); } try { final PropertyList<Property> pl = val.getProperties(); boolean vpoll = false; boolean event = false; boolean task = false; if (pl == null) { // Empty component return Response.notOk(resp, failed, "Empty component"); } final int entityType; if (val instanceof VEvent) { entityType = IcalDefs.entityTypeEvent; event = true; } else if (val instanceof VToDo) { entityType = IcalDefs.entityTypeTodo; task = true; } else if (val instanceof VJournal) { entityType = IcalDefs.entityTypeJournal; } else if (val instanceof VFreeBusy) { entityType = IcalDefs.entityTypeFreeAndBusy; } else if (val instanceof VAvailability) { entityType = IcalDefs.entityTypeVavailability; } else if (val instanceof Available) { entityType = IcalDefs.entityTypeAvailable; } else if (val instanceof VPoll) { entityType = IcalDefs.entityTypeVpoll; vpoll = true; } else { return Response.error(resp, "org.bedework.invalid.component.type: " + val.getName()); } // Get the guid from the component String guid = null; final Uid uidp = pl.getProperty(Property.UID); if (uidp != null) { testXparams(uidp, hasXparams); guid = uidp.getValue(); } if (guid == null) { /* XXX A guid is required - but are there devices out there without a * guid - and if so how do we handle it? */ return Response.notOk(resp, failed, CalFacadeException.noGuid); } /* See if we have a recurrence id */ BwDateTime ridObj = null; String rid = null; TimeZone ridTz = null; final RecurrenceId ridp = pl.getProperty(Property.RECURRENCE_ID); if (ridp != null) { testXparams(ridp, hasXparams); ridObj = BwDateTime.makeBwDateTime(ridp); if (ridObj.getRange() != null) { /* XXX What do I do with it? */ logger.warn("TRANS-TO_EVENT: Got a recurrence id range"); } rid = ridObj.getDate(); } EventInfo masterEI = null; EventInfo evinfo = null; final BwEvent ev; /* If we have a recurrence id see if we already have the master (we should * get a master + all its overrides). * * If so find the override and use the annnotation or if no override, * make one. * * If no override retrieve the event, add it to our table and then locate the * annotation. * * If there is no annotation, create one. * * It's possible we have been sent 'detached' instances of a recurring * event. This may happen if we are invited to one or more instances of a * meeting. In this case we try to retrieve the master and if it doesn't * exist we manufacture one. We consider such an instance an update to * that instance only and leave the others alone. */ /* We need this in a couple of places */ final DtStart dtStart = pl.getProperty(Property.DTSTART); /* if (rid != null) { // See if we have a new master event. If so create a proxy to that event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI == null) { masterEI = makeNewEvent(cb, chg, entityType, guid, cal); BwEvent e = masterEI.getEvent(); // XXX This seems bogus DtStart mdtStart; String bogusDate = "19980118T230000"; if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + "Z"); } else if (dtStart.getTimeZone() == null) { mdtStart = new DtStart(bogusDate); } else { mdtStart = new DtStart(bogusDate + "Z", dtStart.getTimeZone()); } setDates(e, mdtStart, null, null, chg); e.setRecurring(true); e.addRdate(ridObj); e.setSuppressed(true); ical.addComponent(masterEI); } if (masterEI != null) { evinfo = masterEI.findOverride(rid); } } */ /* If this is a recurrence instance see if we can find the master We only need this because the master may follow the overrides. */ if (rid != null) { // See if we have a new master event. If so create a proxy to this event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI != null) { evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; } } if ((evinfo == null) && (cal != null) && (cal.getCalType() != BwCalendar.calTypeInbox) && (cal.getCalType() != BwCalendar.calTypePendingInbox) && (cal.getCalType() != BwCalendar.calTypeOutbox)) { if (logger.debug()) { logger.debug("TRANS-TO_EVENT: try to fetch event with guid=" + guid); } final GetEntitiesResponse<EventInfo> eisResp = cb.getEvent(colPath, guid); if (eisResp.isError()) { return Response.fromResponse(resp, eisResp); } final var eis = eisResp.getEntities(); if (!Util.isEmpty(eis)) { if (eis.size() > 1) { // DORECUR - wrong again return Response.notOk(resp, failed, "More than one event returned for guid."); } evinfo = eis.iterator().next(); } if (logger.debug()) { if (evinfo != null) { logger.debug("TRANS-TO_EVENT: fetched event with guid"); } else { logger.debug("TRANS-TO_EVENT: did not find event with guid"); } } if (evinfo != null) { if (rid != null) { // We just retrieved it's master masterEI = evinfo; masterEI.setInstanceOnly(true); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; ical.addComponent(masterEI); } else if (methodType == ScheduleMethods.methodTypeCancel) { // This should never have an rid for cancel of entire event. evinfo.setInstanceOnly(evinfo.getEvent().getSuppressed()); } else { // Presumably sent an update for the entire event. No longer suppressed master evinfo.getEvent().setSuppressed(false); } } else if (rid != null) { /* Manufacture a master for the instance */ masterEI = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); final BwEvent e = masterEI.getEvent(); // XXX This seems bogus final DtStart mdtStart; final String bogusDate = "19980118"; final String bogusTime = "T230000"; // Base dtstart on the recurrence id. final boolean isDateType = ridObj.getDateType(); if (isDateType) { mdtStart = new DtStart(new Date(bogusDate)); } else if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + bogusTime + "Z"); } else if (ridObj.getTzid() == null) { mdtStart = new DtStart(bogusDate + bogusTime); } else { mdtStart = new DtStart(bogusDate + bogusTime, Timezones.getTz(ridObj.getTzid())); } IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), masterEI, mdtStart, null, null); e.setRecurring(true); // e.addRdate(ridObj); final var sum = (Summary)pl.getProperty(Property.SUMMARY); e.setSummary(sum.getValue()); e.setSuppressed(true); ical.addComponent(masterEI); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; masterEI.setInstanceOnly(rid != null); } } if (evinfo == null) { evinfo = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); } else if (evinfo.getEvent().getEntityType() != entityType) { return Response.notOk(resp, failed, "org.bedework.mismatched.entity.type: " + val); } final ChangeTable chg = evinfo.getChangeset( cb.getPrincipal().getPrincipalRef()); if (rid != null) { final String evrid = evinfo.getEvent().getRecurrenceId(); if ((evrid == null) || (!evrid.equals(rid))) { logger. warn("Mismatched rid ev=" + evrid + " expected " + rid); chg.changed(PropertyInfoIndex.RECURRENCE_ID, evrid, rid); // XXX spurious??? } if (masterEI.getEvent().getSuppressed()) { masterEI.getEvent().addRdate(ridObj); } } ev = evinfo.getEvent(); ev.setScheduleMethod(methodType); DtEnd dtEnd = null; if (entityType == IcalDefs.entityTypeTodo) { final Due due = pl.getProperty(Property.DUE); if (due != null ) { dtEnd = new DtEnd(due.getParameters(), due.getValue()); } } else { dtEnd = pl.getProperty(Property.DTEND); } final Duration duration = pl.getProperty(Property.DURATION); IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), evinfo, dtStart, dtEnd, duration); for (final Property prop: pl) { testXparams(prop, hasXparams); //debug("ical prop " + prop.getClass().getName()); String pval = prop.getValue(); if ((pval != null) && (pval.length() == 0)) { pval = null; } final PropertyInfoIndex pi; if (prop instanceof XProperty) { pi = PropertyInfoIndex.XPROP; } else { pi = PropertyInfoIndex.fromName(prop.getName()); } if (pi == null) { logger.debug("Unknown property with name " + prop.getName() + " class " + prop.getClass() + " and value " + pval); continue; } chg.present(pi); switch (pi) { case ACCEPT_RESPONSE: /* ------------------- Accept Response -------------------- */ String sval = prop.getValue(); if (chg.changed(pi, ev.getPollAcceptResponse(), sval)) { ev.setPollAcceptResponse(sval); } break; case ATTACH: /* ------------------- Attachment -------------------- */ chg.addValue(pi, IcalUtil.getAttachment((Attach)prop)); break; case ATTENDEE: /* ------------------- Attendee -------------------- */ if (methodType == ScheduleMethods.methodTypePublish) { if (cb.getStrictness() == IcalCallback.conformanceStrict) { return Response.notOk(resp, failed, CalFacadeException.attendeesInPublish); } //if (cb.getStrictness() == IcalCallback.conformanceWarn) { // warn("Had attendees for PUBLISH"); //} } final Attendee attPr = (Attendee)prop; if (evinfo.getNewEvent() || !mergeAttendees) { chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { final String pUri = cb.getCaladdr(attPr.getValue()); if (pUri.equals(attUri)) { /* Only update for our own attendee * We're doing a PUT and this must be the attendee updating their * partstat. We don't allow them to change other attendees * whatever the PUT content says. */ chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { // Use the value we currently have boolean found = false; for (final BwAttendee att: ev.getAttendees()) { if (pUri.equals(att.getAttendeeUri())) { chg.addValue(pi, att.clone()); found = true; break; } } if (!found) { // An added attendee final BwAttendee att = IcalUtil .getAttendee(cb, attPr); att.setPartstat(IcalDefs.partstatValNeedsAction); chg.addValue(pi, att); } } } break; case BUSYTYPE: final int ibt = BwEvent.fromBusyTypeString(pval); if (chg.changed(pi, ev.getBusyType(), ibt)) { ev.setBusyType(ibt); } break; case CATEGORIES: /* ------------------- Categories -------------------- */ final Categories cats = (Categories)prop; final TextList cl = cats.getCategories(); String lang = IcalUtil.getLang(cats); if (cl != null) { /* Got some categories */ for (final String wd: cl) { if (wd == null) { continue; } final BwString key = new BwString(lang, wd); final var fcResp = cb.findCategory(key); final BwCategory cat; if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isNotFound()) { cat = BwCategory.makeCategory(); cat.setWord(key); cb.addCategory(cat); } else { cat = fcResp.getEntity(); } chg.addValue(pi, cat); } } break; case CLASS: /* ------------------- Class -------------------- */ if (chg.changed(pi, ev.getClassification(), pval)) { ev.setClassification(pval); } break; case COMMENT: /* ------------------- Comment -------------------- */ chg.addValue(pi, new BwString(null, pval)); break; case COMPLETED: /* ------------------- Completed -------------------- */ if (chg.changed(pi, ev.getCompleted(), pval)) { ev.setCompleted(pval); } break; case CONCEPT: /* ------------------- Concept -------------------- */ final Concept c = (Concept)prop; final String cval = c.getValue(); if (cval != null) { /* Got a concept */ chg.addValue(PropertyInfoIndex.XPROP, BwXproperty.makeIcalProperty("CONCEPT", null, cval)); } break; case CONTACT: /* ------------------- Contact -------------------- */ final String altrep = getAltRepPar(prop); lang = IcalUtil.getLang(prop); final String uid = getUidPar(prop); final BwString nm = new BwString(lang, pval); BwContact contact = null; if (uid != null) { final var fcResp = cb.getContact(uid); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { final var fcResp = cb.findContact(nm); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { contact = BwContact.makeContact(); contact.setCn(nm); contact.setLink(altrep); cb.addContact(contact); } else { contact.setCn(nm); contact.setLink(altrep); } chg.addValue(pi, contact); break; case CREATED: /* ------------------- Created -------------------- */ if (chg.changed(pi, ev.getCreated(), pval)) { ev.setCreated(pval); } break; case DESCRIPTION: /* ------------------- Description -------------------- */ if (chg.changed(pi, ev.getDescription(), pval)) { ev.setDescription(pval); } break; case DTEND: /* ------------------- DtEnd -------------------- */ break; case DTSTAMP: /* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval); break; case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE: /* -------------------- Due ------------------------ */ break; case DURATION: /* ------------------- Duration -------------------- */ break; case EXDATE: /* ------------------- ExDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case EXRULE: /* ------------------- ExRule -------------------- */ chg.addValue(pi, pval); break; case FREEBUSY: /* ------------------- freebusy -------------------- */ final FreeBusy fbusy = (FreeBusy)prop; final PeriodList perpl = fbusy.getPeriods(); final Parameter par = IcalUtil.getParameter(fbusy, "FBTYPE"); final int fbtype; if (par == null) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY)) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY_TENTATIVE)) { fbtype = BwFreeBusyComponent.typeBusyTentative; } else if (par.equals(FbType.BUSY_UNAVAILABLE)) { fbtype = BwFreeBusyComponent.typeBusyUnavailable; } else if (par.equals(FbType.FREE)) { fbtype = BwFreeBusyComponent.typeFree; } else { if (logger.debug()) { logger.debug("Unsupported parameter " + par.getName()); } return Response.notOk(resp, failed, "Unsupported parameter " + par.getName()); } final BwFreeBusyComponent fbc = new BwFreeBusyComponent(); fbc.setType(fbtype); for (final Period per : perpl) { fbc.addPeriod(per); } ev.addFreeBusyPeriod(fbc); break; case GEO: /* ------------------- Geo -------------------- */ final Geo g = (Geo)prop; final BwGeo geo = new BwGeo(g.getLatitude(), g.getLongitude()); if (chg.changed(pi, ev.getGeo(), geo)) { ev.setGeo(geo); } break; case LAST_MODIFIED: /* ------------------- LastModified -------------------- */ if (chg.changed(pi, ev.getLastmod(), pval)) { ev.setLastmod(pval); } break; case LOCATION: /* ------------------- Location -------------------- */ BwLocation loc = null; //String uid = getUidPar(prop); /* At the moment Mozilla lightning is broken and this leads to all * sorts of problems. if (uid != null) { loc = cb.getLocation(uid); } */ lang = IcalUtil.getLang(prop); BwString addr = null; if (pval != null) { if (loc == null) { addr = new BwString(lang, pval); final var fcResp = cb.findLocation(addr); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { loc = fcResp.getEntity(); } } if (loc == null) { loc = BwLocation.makeLocation(); loc.setAddress(addr); cb.addLocation(loc); } } final BwLocation evloc = ev.getLocation(); if (chg.changed(pi, evloc, loc)) { // CHGTBL - this only shows that it's a different location object ev.setLocation(loc); } else if ((loc != null) && (evloc != null)) { // See if the value is changed final String evval = evloc.getAddress().getValue(); final String inval = loc.getAddress().getValue(); if (!evval.equals(inval)) { chg.changed(pi, evval, inval); evloc.getAddress().setValue(inval); } } break; case ORGANIZER: /* ------------------- Organizer -------------------- */ final BwOrganizer org = IcalUtil.getOrganizer(cb, (Organizer)prop); final BwOrganizer evorg = ev.getOrganizer(); final BwOrganizer evorgCopy; if (evorg == null) { evorgCopy = null; } else { evorgCopy = (BwOrganizer)evorg.clone(); } if (chg.changed(pi, evorgCopy, org)) { if (evorg == null) { ev.setOrganizer(org); } else { evorg.update(org); } } break; case PERCENT_COMPLETE: /* ------------------- PercentComplete -------------------- */ Integer ival = ((PercentComplete)prop).getPercentage(); if (chg.changed(pi, ev.getPercentComplete(), ival)) { ev.setPercentComplete(ival); } break; case POLL_MODE: /* ------------------- Poll mode -------------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollMode(), sval)) { ev.setPollMode(sval); } break; case POLL_PROPERTIES: /* ------------------- Poll properties ---------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollProperties(), sval)) { ev.setPollProperties(sval); } break; case POLL_WINNER: /* ------------------- Poll winner -------------------- */ ival = ((PollWinner)prop).getPollwinner(); if (chg.changed(pi, ev.getPollWinner(), ival)) { ev.setPollWinner(ival); } break; case PRIORITY: /* ------------------- Priority -------------------- */ ival = ((Priority)prop).getLevel(); if (chg.changed(pi, ev.getPriority(), ival)) { ev.setPriority(ival); } break; case RDATE: /* ------------------- RDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case RECURRENCE_ID: /* ------------------- RecurrenceID -------------------- */ // Done above break; case RELATED_TO: /* ------------------- RelatedTo -------------------- */ final RelatedTo irelto = (RelatedTo)prop; final BwRelatedTo relto = new BwRelatedTo(); final String parval = IcalUtil.getParameterVal(irelto, "RELTYPE"); if (parval != null) { relto.setRelType(parval); } relto.setValue(irelto.getValue()); if (chg.changed(pi, ev.getRelatedTo(), relto)) { ev.setRelatedTo(relto); } break; case REQUEST_STATUS: /* ------------------- RequestStatus -------------------- */ final BwRequestStatus rs = BwRequestStatus .fromRequestStatus((RequestStatus)prop); chg.addValue(pi, rs); break; case RESOURCES: /* ------------------- Resources -------------------- */ final TextList rl = ((Resources)prop).getResources(); if (rl != null) { /* Got some resources */ lang = IcalUtil.getLang(prop); for (final String s: rl) { final BwString rsrc = new BwString(lang, s); chg.addValue(pi, rsrc); } } break; case RRULE: /* ------------------- RRule -------------------- */ chg.addValue(pi, pval); break; case SEQUENCE: /* ------------------- Sequence -------------------- */ final int seq = ((Sequence)prop).getSequenceNo(); if (seq != ev.getSequence()) { chg.changed(pi, ev.getSequence(), seq); ev.setSequence(seq); } break; case STATUS: /* ------------------- Status -------------------- */ if (chg.changed(pi, ev.getStatus(), pval)) { ev.setStatus(pval); } break; case SUMMARY: /* ------------------- Summary -------------------- */ if (chg.changed(pi, ev.getSummary(), pval)) { ev.setSummary(pval); } break; case TRANSP: /* ------------------- Transp -------------------- */ if (chg.changed(pi, ev.getPeruserTransparency( cb.getPrincipal() .getPrincipalRef()), pval)) { final BwXproperty pu = ev.setPeruserTransparency( cb.getPrincipal().getPrincipalRef(), pval); if (pu != null) { chg.addValue(PropertyInfoIndex.XPROP, pu); } } break; case UID: /* ------------------- Uid -------------------- */ /* We did this above */ break; case URL: /* ------------------- Url -------------------- */ if (chg.changed(pi, ev.getLink(), pval)) { ev.setLink(pval); } break; case XPROP: /* ------------------------- x-property --------------------------- */ final String name = prop.getName(); if (name.equalsIgnoreCase(BwXproperty.bedeworkCost)) { if (chg.changed(PropertyInfoIndex.COST, ev.getCost(), pval)) { ev.setCost(pval); } break; } if (name.equalsIgnoreCase(BwXproperty.xBedeworkCategories)) { if (checkCategory(cb, chg, ev, null, pval)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkLocation)) { if (checkLocation(cb, chg, ev, prop)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkContact)) { if (checkContact(cb, chg, ev, null, pval)) { break; } } /* See if this is an x-category that can be converted to a real category */ final XProperty xp = (XProperty)prop; chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(name, xp.getParameters() .toString(), pval)); break; default: if (logger.debug()) { logger.debug("Unsupported property with index " + pi + "; class " + prop.getClass() + " and value " + pval); } } } /* =================== Process sub-components =============== */ final ComponentList<Component> subComps; if (val instanceof ComponentContainer) { subComps = ((ComponentContainer<Component>)val).getComponents(); } else { subComps = null; } final Set<Integer> pids; if (vpoll) { pids = new TreeSet<>(); final BwEvent vp = evinfo.getEvent(); if (!Util.isEmpty(vp.getPollItems())) { vp.clearPollItems(); } } else { pids = null; } if (!Util.isEmpty(subComps)) { for (final var subComp: subComps) { if (subComp instanceof Available) { if (!(val instanceof VAvailability)) { return Response.error(resp, "AVAILABLE only valid in VAVAILABLE"); } final var avlResp = processAvailable(cb, cal, ical, (VAvailability)val, (Available)subComp, evinfo); if (!avlResp.isOk()) { return Response.fromResponse(resp, avlResp); } continue; } if (subComp instanceof Participant) { if (vpoll) { final var vresp = processVoter(cb, (VPoll)val, (Participant)subComp, evinfo, chg, mergeAttendees); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Participant object"); continue; } if (subComp instanceof VResource) { logger.warn("Unimplemented VResource object"); continue; } if (subComp instanceof VLocation) { logger.warn("Unimplemented VLocation object"); continue; } if (subComp instanceof VAlarm) { final var aresp = VAlarmUtil.processAlarm(cb, val, (VAlarm)subComp, ev, currentPrincipal, chg); if (!aresp.isOk()) { return Response.fromResponse(resp, aresp); } continue; } if (vpoll && (event || task)) { final var vresp = processCandidate((VPoll)val, subComp, evinfo, pids, chg); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Component object: " + subComp); } } /* Fix up timestamps. */ if (ev.getCreated() == null) { if (ev.getLastmod() != null) { ev.setCreated(ev.getLastmod()); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); } else { ev.updateDtstamp(); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } } if (ev.getLastmod() == null) { // created cannot be null now ev.setLastmod(ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } processTimezones(ev, ical, chg); /* Remove any recipients and originator */ if (ev.getRecipients() != null) { ev.getRecipients().clear(); } ev.setOriginator(null); if (hasXparams.value) { /* Save a text copy of the entire event as an x-property */ final Component valCopy = val.copy(); /* Remove potentially large values */ final Description desp = valCopy.getProperty(Property.DESCRIPTION); if (desp != null) { desp.setValue(null); } final Attach attachp = valCopy.getProperty(Property.ATTACH); // Don't store the entire attachment - we just need the parameters. if (attachp != null) { final Value v = attachp.getParameter(Parameter.VALUE); if (v != null) { attachp.setValue(String.valueOf(attachp.getValue().hashCode())); } } chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(BwXproperty.bedeworkIcal, null, valCopy.toString())); } chg.processChanges(ev, true, false); ev.setRecurring(ev.isRecurringEntity()); if (logger.debug()) { logger.debug(chg.toString()); logger.debug(ev.toString()); } if (masterEI != null) { // Just return notfound as this event is on its override list return Response.notFound(resp); } resp.setEntity(evinfo); return resp; } catch (final Throwable t) { if (logger.debug()) { logger.error(t); } return Response.error(resp, t); } }
NONSATD
true
for (final Property prop: pl) { testXparams(prop, hasXparams); //debug("ical prop " + prop.getClass().getName()); String pval = prop.getValue(); if ((pval != null) && (pval.length() == 0)) {
dtEnd = new DtEnd(due.getParameters(), due.getValue()); } } else { dtEnd = pl.getProperty(Property.DTEND); } final Duration duration = pl.getProperty(Property.DURATION); IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), evinfo, dtStart, dtEnd, duration); for (final Property prop: pl) { testXparams(prop, hasXparams); //debug("ical prop " + prop.getClass().getName()); String pval = prop.getValue(); if ((pval != null) && (pval.length() == 0)) { pval = null; } final PropertyInfoIndex pi; if (prop instanceof XProperty) { pi = PropertyInfoIndex.XPROP; } else { pi = PropertyInfoIndex.fromName(prop.getName()); }
if (masterEI.getEvent().getSuppressed()) { masterEI.getEvent().addRdate(ridObj); } } ev = evinfo.getEvent(); ev.setScheduleMethod(methodType); DtEnd dtEnd = null; if (entityType == IcalDefs.entityTypeTodo) { final Due due = pl.getProperty(Property.DUE); if (due != null ) { dtEnd = new DtEnd(due.getParameters(), due.getValue()); } } else { dtEnd = pl.getProperty(Property.DTEND); } final Duration duration = pl.getProperty(Property.DURATION); IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), evinfo, dtStart, dtEnd, duration); for (final Property prop: pl) { testXparams(prop, hasXparams); //debug("ical prop " + prop.getClass().getName()); String pval = prop.getValue(); if ((pval != null) && (pval.length() == 0)) { pval = null; } final PropertyInfoIndex pi; if (prop instanceof XProperty) { pi = PropertyInfoIndex.XPROP; } else { pi = PropertyInfoIndex.fromName(prop.getName()); } if (pi == null) { logger.debug("Unknown property with name " + prop.getName() + " class " + prop.getClass() + " and value " + pval); continue; } chg.present(pi); switch (pi) { case ACCEPT_RESPONSE: /* ------------------- Accept Response -------------------- */
7,893
22
/* ------------------- Accept Response -------------------- */
public static GetEntityResponse<EventInfo> toEvent( final IcalCallback cb, final BwCalendar cal, final Icalendar ical, final Component val, final boolean mergeAttendees) { final var resp = new GetEntityResponse<EventInfo>(); if (val == null) { return Response.notOk(resp, failed, "No component supplied"); } String currentPrincipal = null; final BwPrincipal principal = cb.getPrincipal(); if (principal != null) { currentPrincipal = principal.getPrincipalRef(); } final Holder<Boolean> hasXparams = new Holder<>(Boolean.FALSE); final int methodType = ical.getMethodType(); String attUri = null; if (mergeAttendees) { // We'll need this later. attUri = cb.getCaladdr(cb.getPrincipal().getPrincipalRef()); } final String colPath; if (cal == null) { colPath = null; } else { colPath = cal.getPath(); } try { final PropertyList<Property> pl = val.getProperties(); boolean vpoll = false; boolean event = false; boolean task = false; if (pl == null) { // Empty component return Response.notOk(resp, failed, "Empty component"); } final int entityType; if (val instanceof VEvent) { entityType = IcalDefs.entityTypeEvent; event = true; } else if (val instanceof VToDo) { entityType = IcalDefs.entityTypeTodo; task = true; } else if (val instanceof VJournal) { entityType = IcalDefs.entityTypeJournal; } else if (val instanceof VFreeBusy) { entityType = IcalDefs.entityTypeFreeAndBusy; } else if (val instanceof VAvailability) { entityType = IcalDefs.entityTypeVavailability; } else if (val instanceof Available) { entityType = IcalDefs.entityTypeAvailable; } else if (val instanceof VPoll) { entityType = IcalDefs.entityTypeVpoll; vpoll = true; } else { return Response.error(resp, "org.bedework.invalid.component.type: " + val.getName()); } // Get the guid from the component String guid = null; final Uid uidp = pl.getProperty(Property.UID); if (uidp != null) { testXparams(uidp, hasXparams); guid = uidp.getValue(); } if (guid == null) { /* XXX A guid is required - but are there devices out there without a * guid - and if so how do we handle it? */ return Response.notOk(resp, failed, CalFacadeException.noGuid); } /* See if we have a recurrence id */ BwDateTime ridObj = null; String rid = null; TimeZone ridTz = null; final RecurrenceId ridp = pl.getProperty(Property.RECURRENCE_ID); if (ridp != null) { testXparams(ridp, hasXparams); ridObj = BwDateTime.makeBwDateTime(ridp); if (ridObj.getRange() != null) { /* XXX What do I do with it? */ logger.warn("TRANS-TO_EVENT: Got a recurrence id range"); } rid = ridObj.getDate(); } EventInfo masterEI = null; EventInfo evinfo = null; final BwEvent ev; /* If we have a recurrence id see if we already have the master (we should * get a master + all its overrides). * * If so find the override and use the annnotation or if no override, * make one. * * If no override retrieve the event, add it to our table and then locate the * annotation. * * If there is no annotation, create one. * * It's possible we have been sent 'detached' instances of a recurring * event. This may happen if we are invited to one or more instances of a * meeting. In this case we try to retrieve the master and if it doesn't * exist we manufacture one. We consider such an instance an update to * that instance only and leave the others alone. */ /* We need this in a couple of places */ final DtStart dtStart = pl.getProperty(Property.DTSTART); /* if (rid != null) { // See if we have a new master event. If so create a proxy to that event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI == null) { masterEI = makeNewEvent(cb, chg, entityType, guid, cal); BwEvent e = masterEI.getEvent(); // XXX This seems bogus DtStart mdtStart; String bogusDate = "19980118T230000"; if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + "Z"); } else if (dtStart.getTimeZone() == null) { mdtStart = new DtStart(bogusDate); } else { mdtStart = new DtStart(bogusDate + "Z", dtStart.getTimeZone()); } setDates(e, mdtStart, null, null, chg); e.setRecurring(true); e.addRdate(ridObj); e.setSuppressed(true); ical.addComponent(masterEI); } if (masterEI != null) { evinfo = masterEI.findOverride(rid); } } */ /* If this is a recurrence instance see if we can find the master We only need this because the master may follow the overrides. */ if (rid != null) { // See if we have a new master event. If so create a proxy to this event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI != null) { evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; } } if ((evinfo == null) && (cal != null) && (cal.getCalType() != BwCalendar.calTypeInbox) && (cal.getCalType() != BwCalendar.calTypePendingInbox) && (cal.getCalType() != BwCalendar.calTypeOutbox)) { if (logger.debug()) { logger.debug("TRANS-TO_EVENT: try to fetch event with guid=" + guid); } final GetEntitiesResponse<EventInfo> eisResp = cb.getEvent(colPath, guid); if (eisResp.isError()) { return Response.fromResponse(resp, eisResp); } final var eis = eisResp.getEntities(); if (!Util.isEmpty(eis)) { if (eis.size() > 1) { // DORECUR - wrong again return Response.notOk(resp, failed, "More than one event returned for guid."); } evinfo = eis.iterator().next(); } if (logger.debug()) { if (evinfo != null) { logger.debug("TRANS-TO_EVENT: fetched event with guid"); } else { logger.debug("TRANS-TO_EVENT: did not find event with guid"); } } if (evinfo != null) { if (rid != null) { // We just retrieved it's master masterEI = evinfo; masterEI.setInstanceOnly(true); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; ical.addComponent(masterEI); } else if (methodType == ScheduleMethods.methodTypeCancel) { // This should never have an rid for cancel of entire event. evinfo.setInstanceOnly(evinfo.getEvent().getSuppressed()); } else { // Presumably sent an update for the entire event. No longer suppressed master evinfo.getEvent().setSuppressed(false); } } else if (rid != null) { /* Manufacture a master for the instance */ masterEI = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); final BwEvent e = masterEI.getEvent(); // XXX This seems bogus final DtStart mdtStart; final String bogusDate = "19980118"; final String bogusTime = "T230000"; // Base dtstart on the recurrence id. final boolean isDateType = ridObj.getDateType(); if (isDateType) { mdtStart = new DtStart(new Date(bogusDate)); } else if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + bogusTime + "Z"); } else if (ridObj.getTzid() == null) { mdtStart = new DtStart(bogusDate + bogusTime); } else { mdtStart = new DtStart(bogusDate + bogusTime, Timezones.getTz(ridObj.getTzid())); } IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), masterEI, mdtStart, null, null); e.setRecurring(true); // e.addRdate(ridObj); final var sum = (Summary)pl.getProperty(Property.SUMMARY); e.setSummary(sum.getValue()); e.setSuppressed(true); ical.addComponent(masterEI); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; masterEI.setInstanceOnly(rid != null); } } if (evinfo == null) { evinfo = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); } else if (evinfo.getEvent().getEntityType() != entityType) { return Response.notOk(resp, failed, "org.bedework.mismatched.entity.type: " + val); } final ChangeTable chg = evinfo.getChangeset( cb.getPrincipal().getPrincipalRef()); if (rid != null) { final String evrid = evinfo.getEvent().getRecurrenceId(); if ((evrid == null) || (!evrid.equals(rid))) { logger. warn("Mismatched rid ev=" + evrid + " expected " + rid); chg.changed(PropertyInfoIndex.RECURRENCE_ID, evrid, rid); // XXX spurious??? } if (masterEI.getEvent().getSuppressed()) { masterEI.getEvent().addRdate(ridObj); } } ev = evinfo.getEvent(); ev.setScheduleMethod(methodType); DtEnd dtEnd = null; if (entityType == IcalDefs.entityTypeTodo) { final Due due = pl.getProperty(Property.DUE); if (due != null ) { dtEnd = new DtEnd(due.getParameters(), due.getValue()); } } else { dtEnd = pl.getProperty(Property.DTEND); } final Duration duration = pl.getProperty(Property.DURATION); IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), evinfo, dtStart, dtEnd, duration); for (final Property prop: pl) { testXparams(prop, hasXparams); //debug("ical prop " + prop.getClass().getName()); String pval = prop.getValue(); if ((pval != null) && (pval.length() == 0)) { pval = null; } final PropertyInfoIndex pi; if (prop instanceof XProperty) { pi = PropertyInfoIndex.XPROP; } else { pi = PropertyInfoIndex.fromName(prop.getName()); } if (pi == null) { logger.debug("Unknown property with name " + prop.getName() + " class " + prop.getClass() + " and value " + pval); continue; } chg.present(pi); switch (pi) { case ACCEPT_RESPONSE: /* ------------------- Accept Response -------------------- */ String sval = prop.getValue(); if (chg.changed(pi, ev.getPollAcceptResponse(), sval)) { ev.setPollAcceptResponse(sval); } break; case ATTACH: /* ------------------- Attachment -------------------- */ chg.addValue(pi, IcalUtil.getAttachment((Attach)prop)); break; case ATTENDEE: /* ------------------- Attendee -------------------- */ if (methodType == ScheduleMethods.methodTypePublish) { if (cb.getStrictness() == IcalCallback.conformanceStrict) { return Response.notOk(resp, failed, CalFacadeException.attendeesInPublish); } //if (cb.getStrictness() == IcalCallback.conformanceWarn) { // warn("Had attendees for PUBLISH"); //} } final Attendee attPr = (Attendee)prop; if (evinfo.getNewEvent() || !mergeAttendees) { chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { final String pUri = cb.getCaladdr(attPr.getValue()); if (pUri.equals(attUri)) { /* Only update for our own attendee * We're doing a PUT and this must be the attendee updating their * partstat. We don't allow them to change other attendees * whatever the PUT content says. */ chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { // Use the value we currently have boolean found = false; for (final BwAttendee att: ev.getAttendees()) { if (pUri.equals(att.getAttendeeUri())) { chg.addValue(pi, att.clone()); found = true; break; } } if (!found) { // An added attendee final BwAttendee att = IcalUtil .getAttendee(cb, attPr); att.setPartstat(IcalDefs.partstatValNeedsAction); chg.addValue(pi, att); } } } break; case BUSYTYPE: final int ibt = BwEvent.fromBusyTypeString(pval); if (chg.changed(pi, ev.getBusyType(), ibt)) { ev.setBusyType(ibt); } break; case CATEGORIES: /* ------------------- Categories -------------------- */ final Categories cats = (Categories)prop; final TextList cl = cats.getCategories(); String lang = IcalUtil.getLang(cats); if (cl != null) { /* Got some categories */ for (final String wd: cl) { if (wd == null) { continue; } final BwString key = new BwString(lang, wd); final var fcResp = cb.findCategory(key); final BwCategory cat; if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isNotFound()) { cat = BwCategory.makeCategory(); cat.setWord(key); cb.addCategory(cat); } else { cat = fcResp.getEntity(); } chg.addValue(pi, cat); } } break; case CLASS: /* ------------------- Class -------------------- */ if (chg.changed(pi, ev.getClassification(), pval)) { ev.setClassification(pval); } break; case COMMENT: /* ------------------- Comment -------------------- */ chg.addValue(pi, new BwString(null, pval)); break; case COMPLETED: /* ------------------- Completed -------------------- */ if (chg.changed(pi, ev.getCompleted(), pval)) { ev.setCompleted(pval); } break; case CONCEPT: /* ------------------- Concept -------------------- */ final Concept c = (Concept)prop; final String cval = c.getValue(); if (cval != null) { /* Got a concept */ chg.addValue(PropertyInfoIndex.XPROP, BwXproperty.makeIcalProperty("CONCEPT", null, cval)); } break; case CONTACT: /* ------------------- Contact -------------------- */ final String altrep = getAltRepPar(prop); lang = IcalUtil.getLang(prop); final String uid = getUidPar(prop); final BwString nm = new BwString(lang, pval); BwContact contact = null; if (uid != null) { final var fcResp = cb.getContact(uid); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { final var fcResp = cb.findContact(nm); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { contact = BwContact.makeContact(); contact.setCn(nm); contact.setLink(altrep); cb.addContact(contact); } else { contact.setCn(nm); contact.setLink(altrep); } chg.addValue(pi, contact); break; case CREATED: /* ------------------- Created -------------------- */ if (chg.changed(pi, ev.getCreated(), pval)) { ev.setCreated(pval); } break; case DESCRIPTION: /* ------------------- Description -------------------- */ if (chg.changed(pi, ev.getDescription(), pval)) { ev.setDescription(pval); } break; case DTEND: /* ------------------- DtEnd -------------------- */ break; case DTSTAMP: /* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval); break; case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE: /* -------------------- Due ------------------------ */ break; case DURATION: /* ------------------- Duration -------------------- */ break; case EXDATE: /* ------------------- ExDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case EXRULE: /* ------------------- ExRule -------------------- */ chg.addValue(pi, pval); break; case FREEBUSY: /* ------------------- freebusy -------------------- */ final FreeBusy fbusy = (FreeBusy)prop; final PeriodList perpl = fbusy.getPeriods(); final Parameter par = IcalUtil.getParameter(fbusy, "FBTYPE"); final int fbtype; if (par == null) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY)) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY_TENTATIVE)) { fbtype = BwFreeBusyComponent.typeBusyTentative; } else if (par.equals(FbType.BUSY_UNAVAILABLE)) { fbtype = BwFreeBusyComponent.typeBusyUnavailable; } else if (par.equals(FbType.FREE)) { fbtype = BwFreeBusyComponent.typeFree; } else { if (logger.debug()) { logger.debug("Unsupported parameter " + par.getName()); } return Response.notOk(resp, failed, "Unsupported parameter " + par.getName()); } final BwFreeBusyComponent fbc = new BwFreeBusyComponent(); fbc.setType(fbtype); for (final Period per : perpl) { fbc.addPeriod(per); } ev.addFreeBusyPeriod(fbc); break; case GEO: /* ------------------- Geo -------------------- */ final Geo g = (Geo)prop; final BwGeo geo = new BwGeo(g.getLatitude(), g.getLongitude()); if (chg.changed(pi, ev.getGeo(), geo)) { ev.setGeo(geo); } break; case LAST_MODIFIED: /* ------------------- LastModified -------------------- */ if (chg.changed(pi, ev.getLastmod(), pval)) { ev.setLastmod(pval); } break; case LOCATION: /* ------------------- Location -------------------- */ BwLocation loc = null; //String uid = getUidPar(prop); /* At the moment Mozilla lightning is broken and this leads to all * sorts of problems. if (uid != null) { loc = cb.getLocation(uid); } */ lang = IcalUtil.getLang(prop); BwString addr = null; if (pval != null) { if (loc == null) { addr = new BwString(lang, pval); final var fcResp = cb.findLocation(addr); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { loc = fcResp.getEntity(); } } if (loc == null) { loc = BwLocation.makeLocation(); loc.setAddress(addr); cb.addLocation(loc); } } final BwLocation evloc = ev.getLocation(); if (chg.changed(pi, evloc, loc)) { // CHGTBL - this only shows that it's a different location object ev.setLocation(loc); } else if ((loc != null) && (evloc != null)) { // See if the value is changed final String evval = evloc.getAddress().getValue(); final String inval = loc.getAddress().getValue(); if (!evval.equals(inval)) { chg.changed(pi, evval, inval); evloc.getAddress().setValue(inval); } } break; case ORGANIZER: /* ------------------- Organizer -------------------- */ final BwOrganizer org = IcalUtil.getOrganizer(cb, (Organizer)prop); final BwOrganizer evorg = ev.getOrganizer(); final BwOrganizer evorgCopy; if (evorg == null) { evorgCopy = null; } else { evorgCopy = (BwOrganizer)evorg.clone(); } if (chg.changed(pi, evorgCopy, org)) { if (evorg == null) { ev.setOrganizer(org); } else { evorg.update(org); } } break; case PERCENT_COMPLETE: /* ------------------- PercentComplete -------------------- */ Integer ival = ((PercentComplete)prop).getPercentage(); if (chg.changed(pi, ev.getPercentComplete(), ival)) { ev.setPercentComplete(ival); } break; case POLL_MODE: /* ------------------- Poll mode -------------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollMode(), sval)) { ev.setPollMode(sval); } break; case POLL_PROPERTIES: /* ------------------- Poll properties ---------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollProperties(), sval)) { ev.setPollProperties(sval); } break; case POLL_WINNER: /* ------------------- Poll winner -------------------- */ ival = ((PollWinner)prop).getPollwinner(); if (chg.changed(pi, ev.getPollWinner(), ival)) { ev.setPollWinner(ival); } break; case PRIORITY: /* ------------------- Priority -------------------- */ ival = ((Priority)prop).getLevel(); if (chg.changed(pi, ev.getPriority(), ival)) { ev.setPriority(ival); } break; case RDATE: /* ------------------- RDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case RECURRENCE_ID: /* ------------------- RecurrenceID -------------------- */ // Done above break; case RELATED_TO: /* ------------------- RelatedTo -------------------- */ final RelatedTo irelto = (RelatedTo)prop; final BwRelatedTo relto = new BwRelatedTo(); final String parval = IcalUtil.getParameterVal(irelto, "RELTYPE"); if (parval != null) { relto.setRelType(parval); } relto.setValue(irelto.getValue()); if (chg.changed(pi, ev.getRelatedTo(), relto)) { ev.setRelatedTo(relto); } break; case REQUEST_STATUS: /* ------------------- RequestStatus -------------------- */ final BwRequestStatus rs = BwRequestStatus .fromRequestStatus((RequestStatus)prop); chg.addValue(pi, rs); break; case RESOURCES: /* ------------------- Resources -------------------- */ final TextList rl = ((Resources)prop).getResources(); if (rl != null) { /* Got some resources */ lang = IcalUtil.getLang(prop); for (final String s: rl) { final BwString rsrc = new BwString(lang, s); chg.addValue(pi, rsrc); } } break; case RRULE: /* ------------------- RRule -------------------- */ chg.addValue(pi, pval); break; case SEQUENCE: /* ------------------- Sequence -------------------- */ final int seq = ((Sequence)prop).getSequenceNo(); if (seq != ev.getSequence()) { chg.changed(pi, ev.getSequence(), seq); ev.setSequence(seq); } break; case STATUS: /* ------------------- Status -------------------- */ if (chg.changed(pi, ev.getStatus(), pval)) { ev.setStatus(pval); } break; case SUMMARY: /* ------------------- Summary -------------------- */ if (chg.changed(pi, ev.getSummary(), pval)) { ev.setSummary(pval); } break; case TRANSP: /* ------------------- Transp -------------------- */ if (chg.changed(pi, ev.getPeruserTransparency( cb.getPrincipal() .getPrincipalRef()), pval)) { final BwXproperty pu = ev.setPeruserTransparency( cb.getPrincipal().getPrincipalRef(), pval); if (pu != null) { chg.addValue(PropertyInfoIndex.XPROP, pu); } } break; case UID: /* ------------------- Uid -------------------- */ /* We did this above */ break; case URL: /* ------------------- Url -------------------- */ if (chg.changed(pi, ev.getLink(), pval)) { ev.setLink(pval); } break; case XPROP: /* ------------------------- x-property --------------------------- */ final String name = prop.getName(); if (name.equalsIgnoreCase(BwXproperty.bedeworkCost)) { if (chg.changed(PropertyInfoIndex.COST, ev.getCost(), pval)) { ev.setCost(pval); } break; } if (name.equalsIgnoreCase(BwXproperty.xBedeworkCategories)) { if (checkCategory(cb, chg, ev, null, pval)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkLocation)) { if (checkLocation(cb, chg, ev, prop)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkContact)) { if (checkContact(cb, chg, ev, null, pval)) { break; } } /* See if this is an x-category that can be converted to a real category */ final XProperty xp = (XProperty)prop; chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(name, xp.getParameters() .toString(), pval)); break; default: if (logger.debug()) { logger.debug("Unsupported property with index " + pi + "; class " + prop.getClass() + " and value " + pval); } } } /* =================== Process sub-components =============== */ final ComponentList<Component> subComps; if (val instanceof ComponentContainer) { subComps = ((ComponentContainer<Component>)val).getComponents(); } else { subComps = null; } final Set<Integer> pids; if (vpoll) { pids = new TreeSet<>(); final BwEvent vp = evinfo.getEvent(); if (!Util.isEmpty(vp.getPollItems())) { vp.clearPollItems(); } } else { pids = null; } if (!Util.isEmpty(subComps)) { for (final var subComp: subComps) { if (subComp instanceof Available) { if (!(val instanceof VAvailability)) { return Response.error(resp, "AVAILABLE only valid in VAVAILABLE"); } final var avlResp = processAvailable(cb, cal, ical, (VAvailability)val, (Available)subComp, evinfo); if (!avlResp.isOk()) { return Response.fromResponse(resp, avlResp); } continue; } if (subComp instanceof Participant) { if (vpoll) { final var vresp = processVoter(cb, (VPoll)val, (Participant)subComp, evinfo, chg, mergeAttendees); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Participant object"); continue; } if (subComp instanceof VResource) { logger.warn("Unimplemented VResource object"); continue; } if (subComp instanceof VLocation) { logger.warn("Unimplemented VLocation object"); continue; } if (subComp instanceof VAlarm) { final var aresp = VAlarmUtil.processAlarm(cb, val, (VAlarm)subComp, ev, currentPrincipal, chg); if (!aresp.isOk()) { return Response.fromResponse(resp, aresp); } continue; } if (vpoll && (event || task)) { final var vresp = processCandidate((VPoll)val, subComp, evinfo, pids, chg); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Component object: " + subComp); } } /* Fix up timestamps. */ if (ev.getCreated() == null) { if (ev.getLastmod() != null) { ev.setCreated(ev.getLastmod()); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); } else { ev.updateDtstamp(); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } } if (ev.getLastmod() == null) { // created cannot be null now ev.setLastmod(ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } processTimezones(ev, ical, chg); /* Remove any recipients and originator */ if (ev.getRecipients() != null) { ev.getRecipients().clear(); } ev.setOriginator(null); if (hasXparams.value) { /* Save a text copy of the entire event as an x-property */ final Component valCopy = val.copy(); /* Remove potentially large values */ final Description desp = valCopy.getProperty(Property.DESCRIPTION); if (desp != null) { desp.setValue(null); } final Attach attachp = valCopy.getProperty(Property.ATTACH); // Don't store the entire attachment - we just need the parameters. if (attachp != null) { final Value v = attachp.getParameter(Parameter.VALUE); if (v != null) { attachp.setValue(String.valueOf(attachp.getValue().hashCode())); } } chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(BwXproperty.bedeworkIcal, null, valCopy.toString())); } chg.processChanges(ev, true, false); ev.setRecurring(ev.isRecurringEntity()); if (logger.debug()) { logger.debug(chg.toString()); logger.debug(ev.toString()); } if (masterEI != null) { // Just return notfound as this event is on its override list return Response.notFound(resp); } resp.setEntity(evinfo); return resp; } catch (final Throwable t) { if (logger.debug()) { logger.error(t); } return Response.error(resp, t); } }
NONSATD
true
switch (pi) { case ACCEPT_RESPONSE: /* ------------------- Accept Response -------------------- */ String sval = prop.getValue(); if (chg.changed(pi, ev.getPollAcceptResponse(), sval)) {
} if (pi == null) { logger.debug("Unknown property with name " + prop.getName() + " class " + prop.getClass() + " and value " + pval); continue; } chg.present(pi); switch (pi) { case ACCEPT_RESPONSE: /* ------------------- Accept Response -------------------- */ String sval = prop.getValue(); if (chg.changed(pi, ev.getPollAcceptResponse(), sval)) { ev.setPollAcceptResponse(sval); } break; case ATTACH: /* ------------------- Attachment -------------------- */ chg.addValue(pi, IcalUtil.getAttachment((Attach)prop)); break; case ATTENDEE:
//debug("ical prop " + prop.getClass().getName()); String pval = prop.getValue(); if ((pval != null) && (pval.length() == 0)) { pval = null; } final PropertyInfoIndex pi; if (prop instanceof XProperty) { pi = PropertyInfoIndex.XPROP; } else { pi = PropertyInfoIndex.fromName(prop.getName()); } if (pi == null) { logger.debug("Unknown property with name " + prop.getName() + " class " + prop.getClass() + " and value " + pval); continue; } chg.present(pi); switch (pi) { case ACCEPT_RESPONSE: /* ------------------- Accept Response -------------------- */ String sval = prop.getValue(); if (chg.changed(pi, ev.getPollAcceptResponse(), sval)) { ev.setPollAcceptResponse(sval); } break; case ATTACH: /* ------------------- Attachment -------------------- */ chg.addValue(pi, IcalUtil.getAttachment((Attach)prop)); break; case ATTENDEE: /* ------------------- Attendee -------------------- */ if (methodType == ScheduleMethods.methodTypePublish) { if (cb.getStrictness() == IcalCallback.conformanceStrict) { return Response.notOk(resp, failed, CalFacadeException.attendeesInPublish); } //if (cb.getStrictness() == IcalCallback.conformanceWarn) { // warn("Had attendees for PUBLISH"); //} }
7,893
23
/* ------------------- Attachment -------------------- */
public static GetEntityResponse<EventInfo> toEvent( final IcalCallback cb, final BwCalendar cal, final Icalendar ical, final Component val, final boolean mergeAttendees) { final var resp = new GetEntityResponse<EventInfo>(); if (val == null) { return Response.notOk(resp, failed, "No component supplied"); } String currentPrincipal = null; final BwPrincipal principal = cb.getPrincipal(); if (principal != null) { currentPrincipal = principal.getPrincipalRef(); } final Holder<Boolean> hasXparams = new Holder<>(Boolean.FALSE); final int methodType = ical.getMethodType(); String attUri = null; if (mergeAttendees) { // We'll need this later. attUri = cb.getCaladdr(cb.getPrincipal().getPrincipalRef()); } final String colPath; if (cal == null) { colPath = null; } else { colPath = cal.getPath(); } try { final PropertyList<Property> pl = val.getProperties(); boolean vpoll = false; boolean event = false; boolean task = false; if (pl == null) { // Empty component return Response.notOk(resp, failed, "Empty component"); } final int entityType; if (val instanceof VEvent) { entityType = IcalDefs.entityTypeEvent; event = true; } else if (val instanceof VToDo) { entityType = IcalDefs.entityTypeTodo; task = true; } else if (val instanceof VJournal) { entityType = IcalDefs.entityTypeJournal; } else if (val instanceof VFreeBusy) { entityType = IcalDefs.entityTypeFreeAndBusy; } else if (val instanceof VAvailability) { entityType = IcalDefs.entityTypeVavailability; } else if (val instanceof Available) { entityType = IcalDefs.entityTypeAvailable; } else if (val instanceof VPoll) { entityType = IcalDefs.entityTypeVpoll; vpoll = true; } else { return Response.error(resp, "org.bedework.invalid.component.type: " + val.getName()); } // Get the guid from the component String guid = null; final Uid uidp = pl.getProperty(Property.UID); if (uidp != null) { testXparams(uidp, hasXparams); guid = uidp.getValue(); } if (guid == null) { /* XXX A guid is required - but are there devices out there without a * guid - and if so how do we handle it? */ return Response.notOk(resp, failed, CalFacadeException.noGuid); } /* See if we have a recurrence id */ BwDateTime ridObj = null; String rid = null; TimeZone ridTz = null; final RecurrenceId ridp = pl.getProperty(Property.RECURRENCE_ID); if (ridp != null) { testXparams(ridp, hasXparams); ridObj = BwDateTime.makeBwDateTime(ridp); if (ridObj.getRange() != null) { /* XXX What do I do with it? */ logger.warn("TRANS-TO_EVENT: Got a recurrence id range"); } rid = ridObj.getDate(); } EventInfo masterEI = null; EventInfo evinfo = null; final BwEvent ev; /* If we have a recurrence id see if we already have the master (we should * get a master + all its overrides). * * If so find the override and use the annnotation or if no override, * make one. * * If no override retrieve the event, add it to our table and then locate the * annotation. * * If there is no annotation, create one. * * It's possible we have been sent 'detached' instances of a recurring * event. This may happen if we are invited to one or more instances of a * meeting. In this case we try to retrieve the master and if it doesn't * exist we manufacture one. We consider such an instance an update to * that instance only and leave the others alone. */ /* We need this in a couple of places */ final DtStart dtStart = pl.getProperty(Property.DTSTART); /* if (rid != null) { // See if we have a new master event. If so create a proxy to that event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI == null) { masterEI = makeNewEvent(cb, chg, entityType, guid, cal); BwEvent e = masterEI.getEvent(); // XXX This seems bogus DtStart mdtStart; String bogusDate = "19980118T230000"; if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + "Z"); } else if (dtStart.getTimeZone() == null) { mdtStart = new DtStart(bogusDate); } else { mdtStart = new DtStart(bogusDate + "Z", dtStart.getTimeZone()); } setDates(e, mdtStart, null, null, chg); e.setRecurring(true); e.addRdate(ridObj); e.setSuppressed(true); ical.addComponent(masterEI); } if (masterEI != null) { evinfo = masterEI.findOverride(rid); } } */ /* If this is a recurrence instance see if we can find the master We only need this because the master may follow the overrides. */ if (rid != null) { // See if we have a new master event. If so create a proxy to this event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI != null) { evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; } } if ((evinfo == null) && (cal != null) && (cal.getCalType() != BwCalendar.calTypeInbox) && (cal.getCalType() != BwCalendar.calTypePendingInbox) && (cal.getCalType() != BwCalendar.calTypeOutbox)) { if (logger.debug()) { logger.debug("TRANS-TO_EVENT: try to fetch event with guid=" + guid); } final GetEntitiesResponse<EventInfo> eisResp = cb.getEvent(colPath, guid); if (eisResp.isError()) { return Response.fromResponse(resp, eisResp); } final var eis = eisResp.getEntities(); if (!Util.isEmpty(eis)) { if (eis.size() > 1) { // DORECUR - wrong again return Response.notOk(resp, failed, "More than one event returned for guid."); } evinfo = eis.iterator().next(); } if (logger.debug()) { if (evinfo != null) { logger.debug("TRANS-TO_EVENT: fetched event with guid"); } else { logger.debug("TRANS-TO_EVENT: did not find event with guid"); } } if (evinfo != null) { if (rid != null) { // We just retrieved it's master masterEI = evinfo; masterEI.setInstanceOnly(true); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; ical.addComponent(masterEI); } else if (methodType == ScheduleMethods.methodTypeCancel) { // This should never have an rid for cancel of entire event. evinfo.setInstanceOnly(evinfo.getEvent().getSuppressed()); } else { // Presumably sent an update for the entire event. No longer suppressed master evinfo.getEvent().setSuppressed(false); } } else if (rid != null) { /* Manufacture a master for the instance */ masterEI = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); final BwEvent e = masterEI.getEvent(); // XXX This seems bogus final DtStart mdtStart; final String bogusDate = "19980118"; final String bogusTime = "T230000"; // Base dtstart on the recurrence id. final boolean isDateType = ridObj.getDateType(); if (isDateType) { mdtStart = new DtStart(new Date(bogusDate)); } else if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + bogusTime + "Z"); } else if (ridObj.getTzid() == null) { mdtStart = new DtStart(bogusDate + bogusTime); } else { mdtStart = new DtStart(bogusDate + bogusTime, Timezones.getTz(ridObj.getTzid())); } IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), masterEI, mdtStart, null, null); e.setRecurring(true); // e.addRdate(ridObj); final var sum = (Summary)pl.getProperty(Property.SUMMARY); e.setSummary(sum.getValue()); e.setSuppressed(true); ical.addComponent(masterEI); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; masterEI.setInstanceOnly(rid != null); } } if (evinfo == null) { evinfo = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); } else if (evinfo.getEvent().getEntityType() != entityType) { return Response.notOk(resp, failed, "org.bedework.mismatched.entity.type: " + val); } final ChangeTable chg = evinfo.getChangeset( cb.getPrincipal().getPrincipalRef()); if (rid != null) { final String evrid = evinfo.getEvent().getRecurrenceId(); if ((evrid == null) || (!evrid.equals(rid))) { logger. warn("Mismatched rid ev=" + evrid + " expected " + rid); chg.changed(PropertyInfoIndex.RECURRENCE_ID, evrid, rid); // XXX spurious??? } if (masterEI.getEvent().getSuppressed()) { masterEI.getEvent().addRdate(ridObj); } } ev = evinfo.getEvent(); ev.setScheduleMethod(methodType); DtEnd dtEnd = null; if (entityType == IcalDefs.entityTypeTodo) { final Due due = pl.getProperty(Property.DUE); if (due != null ) { dtEnd = new DtEnd(due.getParameters(), due.getValue()); } } else { dtEnd = pl.getProperty(Property.DTEND); } final Duration duration = pl.getProperty(Property.DURATION); IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), evinfo, dtStart, dtEnd, duration); for (final Property prop: pl) { testXparams(prop, hasXparams); //debug("ical prop " + prop.getClass().getName()); String pval = prop.getValue(); if ((pval != null) && (pval.length() == 0)) { pval = null; } final PropertyInfoIndex pi; if (prop instanceof XProperty) { pi = PropertyInfoIndex.XPROP; } else { pi = PropertyInfoIndex.fromName(prop.getName()); } if (pi == null) { logger.debug("Unknown property with name " + prop.getName() + " class " + prop.getClass() + " and value " + pval); continue; } chg.present(pi); switch (pi) { case ACCEPT_RESPONSE: /* ------------------- Accept Response -------------------- */ String sval = prop.getValue(); if (chg.changed(pi, ev.getPollAcceptResponse(), sval)) { ev.setPollAcceptResponse(sval); } break; case ATTACH: /* ------------------- Attachment -------------------- */ chg.addValue(pi, IcalUtil.getAttachment((Attach)prop)); break; case ATTENDEE: /* ------------------- Attendee -------------------- */ if (methodType == ScheduleMethods.methodTypePublish) { if (cb.getStrictness() == IcalCallback.conformanceStrict) { return Response.notOk(resp, failed, CalFacadeException.attendeesInPublish); } //if (cb.getStrictness() == IcalCallback.conformanceWarn) { // warn("Had attendees for PUBLISH"); //} } final Attendee attPr = (Attendee)prop; if (evinfo.getNewEvent() || !mergeAttendees) { chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { final String pUri = cb.getCaladdr(attPr.getValue()); if (pUri.equals(attUri)) { /* Only update for our own attendee * We're doing a PUT and this must be the attendee updating their * partstat. We don't allow them to change other attendees * whatever the PUT content says. */ chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { // Use the value we currently have boolean found = false; for (final BwAttendee att: ev.getAttendees()) { if (pUri.equals(att.getAttendeeUri())) { chg.addValue(pi, att.clone()); found = true; break; } } if (!found) { // An added attendee final BwAttendee att = IcalUtil .getAttendee(cb, attPr); att.setPartstat(IcalDefs.partstatValNeedsAction); chg.addValue(pi, att); } } } break; case BUSYTYPE: final int ibt = BwEvent.fromBusyTypeString(pval); if (chg.changed(pi, ev.getBusyType(), ibt)) { ev.setBusyType(ibt); } break; case CATEGORIES: /* ------------------- Categories -------------------- */ final Categories cats = (Categories)prop; final TextList cl = cats.getCategories(); String lang = IcalUtil.getLang(cats); if (cl != null) { /* Got some categories */ for (final String wd: cl) { if (wd == null) { continue; } final BwString key = new BwString(lang, wd); final var fcResp = cb.findCategory(key); final BwCategory cat; if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isNotFound()) { cat = BwCategory.makeCategory(); cat.setWord(key); cb.addCategory(cat); } else { cat = fcResp.getEntity(); } chg.addValue(pi, cat); } } break; case CLASS: /* ------------------- Class -------------------- */ if (chg.changed(pi, ev.getClassification(), pval)) { ev.setClassification(pval); } break; case COMMENT: /* ------------------- Comment -------------------- */ chg.addValue(pi, new BwString(null, pval)); break; case COMPLETED: /* ------------------- Completed -------------------- */ if (chg.changed(pi, ev.getCompleted(), pval)) { ev.setCompleted(pval); } break; case CONCEPT: /* ------------------- Concept -------------------- */ final Concept c = (Concept)prop; final String cval = c.getValue(); if (cval != null) { /* Got a concept */ chg.addValue(PropertyInfoIndex.XPROP, BwXproperty.makeIcalProperty("CONCEPT", null, cval)); } break; case CONTACT: /* ------------------- Contact -------------------- */ final String altrep = getAltRepPar(prop); lang = IcalUtil.getLang(prop); final String uid = getUidPar(prop); final BwString nm = new BwString(lang, pval); BwContact contact = null; if (uid != null) { final var fcResp = cb.getContact(uid); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { final var fcResp = cb.findContact(nm); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { contact = BwContact.makeContact(); contact.setCn(nm); contact.setLink(altrep); cb.addContact(contact); } else { contact.setCn(nm); contact.setLink(altrep); } chg.addValue(pi, contact); break; case CREATED: /* ------------------- Created -------------------- */ if (chg.changed(pi, ev.getCreated(), pval)) { ev.setCreated(pval); } break; case DESCRIPTION: /* ------------------- Description -------------------- */ if (chg.changed(pi, ev.getDescription(), pval)) { ev.setDescription(pval); } break; case DTEND: /* ------------------- DtEnd -------------------- */ break; case DTSTAMP: /* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval); break; case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE: /* -------------------- Due ------------------------ */ break; case DURATION: /* ------------------- Duration -------------------- */ break; case EXDATE: /* ------------------- ExDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case EXRULE: /* ------------------- ExRule -------------------- */ chg.addValue(pi, pval); break; case FREEBUSY: /* ------------------- freebusy -------------------- */ final FreeBusy fbusy = (FreeBusy)prop; final PeriodList perpl = fbusy.getPeriods(); final Parameter par = IcalUtil.getParameter(fbusy, "FBTYPE"); final int fbtype; if (par == null) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY)) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY_TENTATIVE)) { fbtype = BwFreeBusyComponent.typeBusyTentative; } else if (par.equals(FbType.BUSY_UNAVAILABLE)) { fbtype = BwFreeBusyComponent.typeBusyUnavailable; } else if (par.equals(FbType.FREE)) { fbtype = BwFreeBusyComponent.typeFree; } else { if (logger.debug()) { logger.debug("Unsupported parameter " + par.getName()); } return Response.notOk(resp, failed, "Unsupported parameter " + par.getName()); } final BwFreeBusyComponent fbc = new BwFreeBusyComponent(); fbc.setType(fbtype); for (final Period per : perpl) { fbc.addPeriod(per); } ev.addFreeBusyPeriod(fbc); break; case GEO: /* ------------------- Geo -------------------- */ final Geo g = (Geo)prop; final BwGeo geo = new BwGeo(g.getLatitude(), g.getLongitude()); if (chg.changed(pi, ev.getGeo(), geo)) { ev.setGeo(geo); } break; case LAST_MODIFIED: /* ------------------- LastModified -------------------- */ if (chg.changed(pi, ev.getLastmod(), pval)) { ev.setLastmod(pval); } break; case LOCATION: /* ------------------- Location -------------------- */ BwLocation loc = null; //String uid = getUidPar(prop); /* At the moment Mozilla lightning is broken and this leads to all * sorts of problems. if (uid != null) { loc = cb.getLocation(uid); } */ lang = IcalUtil.getLang(prop); BwString addr = null; if (pval != null) { if (loc == null) { addr = new BwString(lang, pval); final var fcResp = cb.findLocation(addr); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { loc = fcResp.getEntity(); } } if (loc == null) { loc = BwLocation.makeLocation(); loc.setAddress(addr); cb.addLocation(loc); } } final BwLocation evloc = ev.getLocation(); if (chg.changed(pi, evloc, loc)) { // CHGTBL - this only shows that it's a different location object ev.setLocation(loc); } else if ((loc != null) && (evloc != null)) { // See if the value is changed final String evval = evloc.getAddress().getValue(); final String inval = loc.getAddress().getValue(); if (!evval.equals(inval)) { chg.changed(pi, evval, inval); evloc.getAddress().setValue(inval); } } break; case ORGANIZER: /* ------------------- Organizer -------------------- */ final BwOrganizer org = IcalUtil.getOrganizer(cb, (Organizer)prop); final BwOrganizer evorg = ev.getOrganizer(); final BwOrganizer evorgCopy; if (evorg == null) { evorgCopy = null; } else { evorgCopy = (BwOrganizer)evorg.clone(); } if (chg.changed(pi, evorgCopy, org)) { if (evorg == null) { ev.setOrganizer(org); } else { evorg.update(org); } } break; case PERCENT_COMPLETE: /* ------------------- PercentComplete -------------------- */ Integer ival = ((PercentComplete)prop).getPercentage(); if (chg.changed(pi, ev.getPercentComplete(), ival)) { ev.setPercentComplete(ival); } break; case POLL_MODE: /* ------------------- Poll mode -------------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollMode(), sval)) { ev.setPollMode(sval); } break; case POLL_PROPERTIES: /* ------------------- Poll properties ---------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollProperties(), sval)) { ev.setPollProperties(sval); } break; case POLL_WINNER: /* ------------------- Poll winner -------------------- */ ival = ((PollWinner)prop).getPollwinner(); if (chg.changed(pi, ev.getPollWinner(), ival)) { ev.setPollWinner(ival); } break; case PRIORITY: /* ------------------- Priority -------------------- */ ival = ((Priority)prop).getLevel(); if (chg.changed(pi, ev.getPriority(), ival)) { ev.setPriority(ival); } break; case RDATE: /* ------------------- RDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case RECURRENCE_ID: /* ------------------- RecurrenceID -------------------- */ // Done above break; case RELATED_TO: /* ------------------- RelatedTo -------------------- */ final RelatedTo irelto = (RelatedTo)prop; final BwRelatedTo relto = new BwRelatedTo(); final String parval = IcalUtil.getParameterVal(irelto, "RELTYPE"); if (parval != null) { relto.setRelType(parval); } relto.setValue(irelto.getValue()); if (chg.changed(pi, ev.getRelatedTo(), relto)) { ev.setRelatedTo(relto); } break; case REQUEST_STATUS: /* ------------------- RequestStatus -------------------- */ final BwRequestStatus rs = BwRequestStatus .fromRequestStatus((RequestStatus)prop); chg.addValue(pi, rs); break; case RESOURCES: /* ------------------- Resources -------------------- */ final TextList rl = ((Resources)prop).getResources(); if (rl != null) { /* Got some resources */ lang = IcalUtil.getLang(prop); for (final String s: rl) { final BwString rsrc = new BwString(lang, s); chg.addValue(pi, rsrc); } } break; case RRULE: /* ------------------- RRule -------------------- */ chg.addValue(pi, pval); break; case SEQUENCE: /* ------------------- Sequence -------------------- */ final int seq = ((Sequence)prop).getSequenceNo(); if (seq != ev.getSequence()) { chg.changed(pi, ev.getSequence(), seq); ev.setSequence(seq); } break; case STATUS: /* ------------------- Status -------------------- */ if (chg.changed(pi, ev.getStatus(), pval)) { ev.setStatus(pval); } break; case SUMMARY: /* ------------------- Summary -------------------- */ if (chg.changed(pi, ev.getSummary(), pval)) { ev.setSummary(pval); } break; case TRANSP: /* ------------------- Transp -------------------- */ if (chg.changed(pi, ev.getPeruserTransparency( cb.getPrincipal() .getPrincipalRef()), pval)) { final BwXproperty pu = ev.setPeruserTransparency( cb.getPrincipal().getPrincipalRef(), pval); if (pu != null) { chg.addValue(PropertyInfoIndex.XPROP, pu); } } break; case UID: /* ------------------- Uid -------------------- */ /* We did this above */ break; case URL: /* ------------------- Url -------------------- */ if (chg.changed(pi, ev.getLink(), pval)) { ev.setLink(pval); } break; case XPROP: /* ------------------------- x-property --------------------------- */ final String name = prop.getName(); if (name.equalsIgnoreCase(BwXproperty.bedeworkCost)) { if (chg.changed(PropertyInfoIndex.COST, ev.getCost(), pval)) { ev.setCost(pval); } break; } if (name.equalsIgnoreCase(BwXproperty.xBedeworkCategories)) { if (checkCategory(cb, chg, ev, null, pval)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkLocation)) { if (checkLocation(cb, chg, ev, prop)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkContact)) { if (checkContact(cb, chg, ev, null, pval)) { break; } } /* See if this is an x-category that can be converted to a real category */ final XProperty xp = (XProperty)prop; chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(name, xp.getParameters() .toString(), pval)); break; default: if (logger.debug()) { logger.debug("Unsupported property with index " + pi + "; class " + prop.getClass() + " and value " + pval); } } } /* =================== Process sub-components =============== */ final ComponentList<Component> subComps; if (val instanceof ComponentContainer) { subComps = ((ComponentContainer<Component>)val).getComponents(); } else { subComps = null; } final Set<Integer> pids; if (vpoll) { pids = new TreeSet<>(); final BwEvent vp = evinfo.getEvent(); if (!Util.isEmpty(vp.getPollItems())) { vp.clearPollItems(); } } else { pids = null; } if (!Util.isEmpty(subComps)) { for (final var subComp: subComps) { if (subComp instanceof Available) { if (!(val instanceof VAvailability)) { return Response.error(resp, "AVAILABLE only valid in VAVAILABLE"); } final var avlResp = processAvailable(cb, cal, ical, (VAvailability)val, (Available)subComp, evinfo); if (!avlResp.isOk()) { return Response.fromResponse(resp, avlResp); } continue; } if (subComp instanceof Participant) { if (vpoll) { final var vresp = processVoter(cb, (VPoll)val, (Participant)subComp, evinfo, chg, mergeAttendees); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Participant object"); continue; } if (subComp instanceof VResource) { logger.warn("Unimplemented VResource object"); continue; } if (subComp instanceof VLocation) { logger.warn("Unimplemented VLocation object"); continue; } if (subComp instanceof VAlarm) { final var aresp = VAlarmUtil.processAlarm(cb, val, (VAlarm)subComp, ev, currentPrincipal, chg); if (!aresp.isOk()) { return Response.fromResponse(resp, aresp); } continue; } if (vpoll && (event || task)) { final var vresp = processCandidate((VPoll)val, subComp, evinfo, pids, chg); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Component object: " + subComp); } } /* Fix up timestamps. */ if (ev.getCreated() == null) { if (ev.getLastmod() != null) { ev.setCreated(ev.getLastmod()); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); } else { ev.updateDtstamp(); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } } if (ev.getLastmod() == null) { // created cannot be null now ev.setLastmod(ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } processTimezones(ev, ical, chg); /* Remove any recipients and originator */ if (ev.getRecipients() != null) { ev.getRecipients().clear(); } ev.setOriginator(null); if (hasXparams.value) { /* Save a text copy of the entire event as an x-property */ final Component valCopy = val.copy(); /* Remove potentially large values */ final Description desp = valCopy.getProperty(Property.DESCRIPTION); if (desp != null) { desp.setValue(null); } final Attach attachp = valCopy.getProperty(Property.ATTACH); // Don't store the entire attachment - we just need the parameters. if (attachp != null) { final Value v = attachp.getParameter(Parameter.VALUE); if (v != null) { attachp.setValue(String.valueOf(attachp.getValue().hashCode())); } } chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(BwXproperty.bedeworkIcal, null, valCopy.toString())); } chg.processChanges(ev, true, false); ev.setRecurring(ev.isRecurringEntity()); if (logger.debug()) { logger.debug(chg.toString()); logger.debug(ev.toString()); } if (masterEI != null) { // Just return notfound as this event is on its override list return Response.notFound(resp); } resp.setEntity(evinfo); return resp; } catch (final Throwable t) { if (logger.debug()) { logger.error(t); } return Response.error(resp, t); } }
NONSATD
true
break; case ATTACH: /* ------------------- Attachment -------------------- */ chg.addValue(pi, IcalUtil.getAttachment((Attach)prop)); break;
chg.present(pi); switch (pi) { case ACCEPT_RESPONSE: /* ------------------- Accept Response -------------------- */ String sval = prop.getValue(); if (chg.changed(pi, ev.getPollAcceptResponse(), sval)) { ev.setPollAcceptResponse(sval); } break; case ATTACH: /* ------------------- Attachment -------------------- */ chg.addValue(pi, IcalUtil.getAttachment((Attach)prop)); break; case ATTENDEE: /* ------------------- Attendee -------------------- */ if (methodType == ScheduleMethods.methodTypePublish) { if (cb.getStrictness() == IcalCallback.conformanceStrict) { return Response.notOk(resp, failed, CalFacadeException.attendeesInPublish); } //if (cb.getStrictness() == IcalCallback.conformanceWarn) {
pi = PropertyInfoIndex.XPROP; } else { pi = PropertyInfoIndex.fromName(prop.getName()); } if (pi == null) { logger.debug("Unknown property with name " + prop.getName() + " class " + prop.getClass() + " and value " + pval); continue; } chg.present(pi); switch (pi) { case ACCEPT_RESPONSE: /* ------------------- Accept Response -------------------- */ String sval = prop.getValue(); if (chg.changed(pi, ev.getPollAcceptResponse(), sval)) { ev.setPollAcceptResponse(sval); } break; case ATTACH: /* ------------------- Attachment -------------------- */ chg.addValue(pi, IcalUtil.getAttachment((Attach)prop)); break; case ATTENDEE: /* ------------------- Attendee -------------------- */ if (methodType == ScheduleMethods.methodTypePublish) { if (cb.getStrictness() == IcalCallback.conformanceStrict) { return Response.notOk(resp, failed, CalFacadeException.attendeesInPublish); } //if (cb.getStrictness() == IcalCallback.conformanceWarn) { // warn("Had attendees for PUBLISH"); //} } final Attendee attPr = (Attendee)prop; if (evinfo.getNewEvent() || !mergeAttendees) { chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { final String pUri = cb.getCaladdr(attPr.getValue()); if (pUri.equals(attUri)) { /* Only update for our own attendee
7,893
24
/* ------------------- Attendee -------------------- */
public static GetEntityResponse<EventInfo> toEvent( final IcalCallback cb, final BwCalendar cal, final Icalendar ical, final Component val, final boolean mergeAttendees) { final var resp = new GetEntityResponse<EventInfo>(); if (val == null) { return Response.notOk(resp, failed, "No component supplied"); } String currentPrincipal = null; final BwPrincipal principal = cb.getPrincipal(); if (principal != null) { currentPrincipal = principal.getPrincipalRef(); } final Holder<Boolean> hasXparams = new Holder<>(Boolean.FALSE); final int methodType = ical.getMethodType(); String attUri = null; if (mergeAttendees) { // We'll need this later. attUri = cb.getCaladdr(cb.getPrincipal().getPrincipalRef()); } final String colPath; if (cal == null) { colPath = null; } else { colPath = cal.getPath(); } try { final PropertyList<Property> pl = val.getProperties(); boolean vpoll = false; boolean event = false; boolean task = false; if (pl == null) { // Empty component return Response.notOk(resp, failed, "Empty component"); } final int entityType; if (val instanceof VEvent) { entityType = IcalDefs.entityTypeEvent; event = true; } else if (val instanceof VToDo) { entityType = IcalDefs.entityTypeTodo; task = true; } else if (val instanceof VJournal) { entityType = IcalDefs.entityTypeJournal; } else if (val instanceof VFreeBusy) { entityType = IcalDefs.entityTypeFreeAndBusy; } else if (val instanceof VAvailability) { entityType = IcalDefs.entityTypeVavailability; } else if (val instanceof Available) { entityType = IcalDefs.entityTypeAvailable; } else if (val instanceof VPoll) { entityType = IcalDefs.entityTypeVpoll; vpoll = true; } else { return Response.error(resp, "org.bedework.invalid.component.type: " + val.getName()); } // Get the guid from the component String guid = null; final Uid uidp = pl.getProperty(Property.UID); if (uidp != null) { testXparams(uidp, hasXparams); guid = uidp.getValue(); } if (guid == null) { /* XXX A guid is required - but are there devices out there without a * guid - and if so how do we handle it? */ return Response.notOk(resp, failed, CalFacadeException.noGuid); } /* See if we have a recurrence id */ BwDateTime ridObj = null; String rid = null; TimeZone ridTz = null; final RecurrenceId ridp = pl.getProperty(Property.RECURRENCE_ID); if (ridp != null) { testXparams(ridp, hasXparams); ridObj = BwDateTime.makeBwDateTime(ridp); if (ridObj.getRange() != null) { /* XXX What do I do with it? */ logger.warn("TRANS-TO_EVENT: Got a recurrence id range"); } rid = ridObj.getDate(); } EventInfo masterEI = null; EventInfo evinfo = null; final BwEvent ev; /* If we have a recurrence id see if we already have the master (we should * get a master + all its overrides). * * If so find the override and use the annnotation or if no override, * make one. * * If no override retrieve the event, add it to our table and then locate the * annotation. * * If there is no annotation, create one. * * It's possible we have been sent 'detached' instances of a recurring * event. This may happen if we are invited to one or more instances of a * meeting. In this case we try to retrieve the master and if it doesn't * exist we manufacture one. We consider such an instance an update to * that instance only and leave the others alone. */ /* We need this in a couple of places */ final DtStart dtStart = pl.getProperty(Property.DTSTART); /* if (rid != null) { // See if we have a new master event. If so create a proxy to that event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI == null) { masterEI = makeNewEvent(cb, chg, entityType, guid, cal); BwEvent e = masterEI.getEvent(); // XXX This seems bogus DtStart mdtStart; String bogusDate = "19980118T230000"; if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + "Z"); } else if (dtStart.getTimeZone() == null) { mdtStart = new DtStart(bogusDate); } else { mdtStart = new DtStart(bogusDate + "Z", dtStart.getTimeZone()); } setDates(e, mdtStart, null, null, chg); e.setRecurring(true); e.addRdate(ridObj); e.setSuppressed(true); ical.addComponent(masterEI); } if (masterEI != null) { evinfo = masterEI.findOverride(rid); } } */ /* If this is a recurrence instance see if we can find the master We only need this because the master may follow the overrides. */ if (rid != null) { // See if we have a new master event. If so create a proxy to this event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI != null) { evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; } } if ((evinfo == null) && (cal != null) && (cal.getCalType() != BwCalendar.calTypeInbox) && (cal.getCalType() != BwCalendar.calTypePendingInbox) && (cal.getCalType() != BwCalendar.calTypeOutbox)) { if (logger.debug()) { logger.debug("TRANS-TO_EVENT: try to fetch event with guid=" + guid); } final GetEntitiesResponse<EventInfo> eisResp = cb.getEvent(colPath, guid); if (eisResp.isError()) { return Response.fromResponse(resp, eisResp); } final var eis = eisResp.getEntities(); if (!Util.isEmpty(eis)) { if (eis.size() > 1) { // DORECUR - wrong again return Response.notOk(resp, failed, "More than one event returned for guid."); } evinfo = eis.iterator().next(); } if (logger.debug()) { if (evinfo != null) { logger.debug("TRANS-TO_EVENT: fetched event with guid"); } else { logger.debug("TRANS-TO_EVENT: did not find event with guid"); } } if (evinfo != null) { if (rid != null) { // We just retrieved it's master masterEI = evinfo; masterEI.setInstanceOnly(true); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; ical.addComponent(masterEI); } else if (methodType == ScheduleMethods.methodTypeCancel) { // This should never have an rid for cancel of entire event. evinfo.setInstanceOnly(evinfo.getEvent().getSuppressed()); } else { // Presumably sent an update for the entire event. No longer suppressed master evinfo.getEvent().setSuppressed(false); } } else if (rid != null) { /* Manufacture a master for the instance */ masterEI = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); final BwEvent e = masterEI.getEvent(); // XXX This seems bogus final DtStart mdtStart; final String bogusDate = "19980118"; final String bogusTime = "T230000"; // Base dtstart on the recurrence id. final boolean isDateType = ridObj.getDateType(); if (isDateType) { mdtStart = new DtStart(new Date(bogusDate)); } else if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + bogusTime + "Z"); } else if (ridObj.getTzid() == null) { mdtStart = new DtStart(bogusDate + bogusTime); } else { mdtStart = new DtStart(bogusDate + bogusTime, Timezones.getTz(ridObj.getTzid())); } IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), masterEI, mdtStart, null, null); e.setRecurring(true); // e.addRdate(ridObj); final var sum = (Summary)pl.getProperty(Property.SUMMARY); e.setSummary(sum.getValue()); e.setSuppressed(true); ical.addComponent(masterEI); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; masterEI.setInstanceOnly(rid != null); } } if (evinfo == null) { evinfo = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); } else if (evinfo.getEvent().getEntityType() != entityType) { return Response.notOk(resp, failed, "org.bedework.mismatched.entity.type: " + val); } final ChangeTable chg = evinfo.getChangeset( cb.getPrincipal().getPrincipalRef()); if (rid != null) { final String evrid = evinfo.getEvent().getRecurrenceId(); if ((evrid == null) || (!evrid.equals(rid))) { logger. warn("Mismatched rid ev=" + evrid + " expected " + rid); chg.changed(PropertyInfoIndex.RECURRENCE_ID, evrid, rid); // XXX spurious??? } if (masterEI.getEvent().getSuppressed()) { masterEI.getEvent().addRdate(ridObj); } } ev = evinfo.getEvent(); ev.setScheduleMethod(methodType); DtEnd dtEnd = null; if (entityType == IcalDefs.entityTypeTodo) { final Due due = pl.getProperty(Property.DUE); if (due != null ) { dtEnd = new DtEnd(due.getParameters(), due.getValue()); } } else { dtEnd = pl.getProperty(Property.DTEND); } final Duration duration = pl.getProperty(Property.DURATION); IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), evinfo, dtStart, dtEnd, duration); for (final Property prop: pl) { testXparams(prop, hasXparams); //debug("ical prop " + prop.getClass().getName()); String pval = prop.getValue(); if ((pval != null) && (pval.length() == 0)) { pval = null; } final PropertyInfoIndex pi; if (prop instanceof XProperty) { pi = PropertyInfoIndex.XPROP; } else { pi = PropertyInfoIndex.fromName(prop.getName()); } if (pi == null) { logger.debug("Unknown property with name " + prop.getName() + " class " + prop.getClass() + " and value " + pval); continue; } chg.present(pi); switch (pi) { case ACCEPT_RESPONSE: /* ------------------- Accept Response -------------------- */ String sval = prop.getValue(); if (chg.changed(pi, ev.getPollAcceptResponse(), sval)) { ev.setPollAcceptResponse(sval); } break; case ATTACH: /* ------------------- Attachment -------------------- */ chg.addValue(pi, IcalUtil.getAttachment((Attach)prop)); break; case ATTENDEE: /* ------------------- Attendee -------------------- */ if (methodType == ScheduleMethods.methodTypePublish) { if (cb.getStrictness() == IcalCallback.conformanceStrict) { return Response.notOk(resp, failed, CalFacadeException.attendeesInPublish); } //if (cb.getStrictness() == IcalCallback.conformanceWarn) { // warn("Had attendees for PUBLISH"); //} } final Attendee attPr = (Attendee)prop; if (evinfo.getNewEvent() || !mergeAttendees) { chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { final String pUri = cb.getCaladdr(attPr.getValue()); if (pUri.equals(attUri)) { /* Only update for our own attendee * We're doing a PUT and this must be the attendee updating their * partstat. We don't allow them to change other attendees * whatever the PUT content says. */ chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { // Use the value we currently have boolean found = false; for (final BwAttendee att: ev.getAttendees()) { if (pUri.equals(att.getAttendeeUri())) { chg.addValue(pi, att.clone()); found = true; break; } } if (!found) { // An added attendee final BwAttendee att = IcalUtil .getAttendee(cb, attPr); att.setPartstat(IcalDefs.partstatValNeedsAction); chg.addValue(pi, att); } } } break; case BUSYTYPE: final int ibt = BwEvent.fromBusyTypeString(pval); if (chg.changed(pi, ev.getBusyType(), ibt)) { ev.setBusyType(ibt); } break; case CATEGORIES: /* ------------------- Categories -------------------- */ final Categories cats = (Categories)prop; final TextList cl = cats.getCategories(); String lang = IcalUtil.getLang(cats); if (cl != null) { /* Got some categories */ for (final String wd: cl) { if (wd == null) { continue; } final BwString key = new BwString(lang, wd); final var fcResp = cb.findCategory(key); final BwCategory cat; if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isNotFound()) { cat = BwCategory.makeCategory(); cat.setWord(key); cb.addCategory(cat); } else { cat = fcResp.getEntity(); } chg.addValue(pi, cat); } } break; case CLASS: /* ------------------- Class -------------------- */ if (chg.changed(pi, ev.getClassification(), pval)) { ev.setClassification(pval); } break; case COMMENT: /* ------------------- Comment -------------------- */ chg.addValue(pi, new BwString(null, pval)); break; case COMPLETED: /* ------------------- Completed -------------------- */ if (chg.changed(pi, ev.getCompleted(), pval)) { ev.setCompleted(pval); } break; case CONCEPT: /* ------------------- Concept -------------------- */ final Concept c = (Concept)prop; final String cval = c.getValue(); if (cval != null) { /* Got a concept */ chg.addValue(PropertyInfoIndex.XPROP, BwXproperty.makeIcalProperty("CONCEPT", null, cval)); } break; case CONTACT: /* ------------------- Contact -------------------- */ final String altrep = getAltRepPar(prop); lang = IcalUtil.getLang(prop); final String uid = getUidPar(prop); final BwString nm = new BwString(lang, pval); BwContact contact = null; if (uid != null) { final var fcResp = cb.getContact(uid); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { final var fcResp = cb.findContact(nm); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { contact = BwContact.makeContact(); contact.setCn(nm); contact.setLink(altrep); cb.addContact(contact); } else { contact.setCn(nm); contact.setLink(altrep); } chg.addValue(pi, contact); break; case CREATED: /* ------------------- Created -------------------- */ if (chg.changed(pi, ev.getCreated(), pval)) { ev.setCreated(pval); } break; case DESCRIPTION: /* ------------------- Description -------------------- */ if (chg.changed(pi, ev.getDescription(), pval)) { ev.setDescription(pval); } break; case DTEND: /* ------------------- DtEnd -------------------- */ break; case DTSTAMP: /* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval); break; case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE: /* -------------------- Due ------------------------ */ break; case DURATION: /* ------------------- Duration -------------------- */ break; case EXDATE: /* ------------------- ExDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case EXRULE: /* ------------------- ExRule -------------------- */ chg.addValue(pi, pval); break; case FREEBUSY: /* ------------------- freebusy -------------------- */ final FreeBusy fbusy = (FreeBusy)prop; final PeriodList perpl = fbusy.getPeriods(); final Parameter par = IcalUtil.getParameter(fbusy, "FBTYPE"); final int fbtype; if (par == null) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY)) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY_TENTATIVE)) { fbtype = BwFreeBusyComponent.typeBusyTentative; } else if (par.equals(FbType.BUSY_UNAVAILABLE)) { fbtype = BwFreeBusyComponent.typeBusyUnavailable; } else if (par.equals(FbType.FREE)) { fbtype = BwFreeBusyComponent.typeFree; } else { if (logger.debug()) { logger.debug("Unsupported parameter " + par.getName()); } return Response.notOk(resp, failed, "Unsupported parameter " + par.getName()); } final BwFreeBusyComponent fbc = new BwFreeBusyComponent(); fbc.setType(fbtype); for (final Period per : perpl) { fbc.addPeriod(per); } ev.addFreeBusyPeriod(fbc); break; case GEO: /* ------------------- Geo -------------------- */ final Geo g = (Geo)prop; final BwGeo geo = new BwGeo(g.getLatitude(), g.getLongitude()); if (chg.changed(pi, ev.getGeo(), geo)) { ev.setGeo(geo); } break; case LAST_MODIFIED: /* ------------------- LastModified -------------------- */ if (chg.changed(pi, ev.getLastmod(), pval)) { ev.setLastmod(pval); } break; case LOCATION: /* ------------------- Location -------------------- */ BwLocation loc = null; //String uid = getUidPar(prop); /* At the moment Mozilla lightning is broken and this leads to all * sorts of problems. if (uid != null) { loc = cb.getLocation(uid); } */ lang = IcalUtil.getLang(prop); BwString addr = null; if (pval != null) { if (loc == null) { addr = new BwString(lang, pval); final var fcResp = cb.findLocation(addr); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { loc = fcResp.getEntity(); } } if (loc == null) { loc = BwLocation.makeLocation(); loc.setAddress(addr); cb.addLocation(loc); } } final BwLocation evloc = ev.getLocation(); if (chg.changed(pi, evloc, loc)) { // CHGTBL - this only shows that it's a different location object ev.setLocation(loc); } else if ((loc != null) && (evloc != null)) { // See if the value is changed final String evval = evloc.getAddress().getValue(); final String inval = loc.getAddress().getValue(); if (!evval.equals(inval)) { chg.changed(pi, evval, inval); evloc.getAddress().setValue(inval); } } break; case ORGANIZER: /* ------------------- Organizer -------------------- */ final BwOrganizer org = IcalUtil.getOrganizer(cb, (Organizer)prop); final BwOrganizer evorg = ev.getOrganizer(); final BwOrganizer evorgCopy; if (evorg == null) { evorgCopy = null; } else { evorgCopy = (BwOrganizer)evorg.clone(); } if (chg.changed(pi, evorgCopy, org)) { if (evorg == null) { ev.setOrganizer(org); } else { evorg.update(org); } } break; case PERCENT_COMPLETE: /* ------------------- PercentComplete -------------------- */ Integer ival = ((PercentComplete)prop).getPercentage(); if (chg.changed(pi, ev.getPercentComplete(), ival)) { ev.setPercentComplete(ival); } break; case POLL_MODE: /* ------------------- Poll mode -------------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollMode(), sval)) { ev.setPollMode(sval); } break; case POLL_PROPERTIES: /* ------------------- Poll properties ---------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollProperties(), sval)) { ev.setPollProperties(sval); } break; case POLL_WINNER: /* ------------------- Poll winner -------------------- */ ival = ((PollWinner)prop).getPollwinner(); if (chg.changed(pi, ev.getPollWinner(), ival)) { ev.setPollWinner(ival); } break; case PRIORITY: /* ------------------- Priority -------------------- */ ival = ((Priority)prop).getLevel(); if (chg.changed(pi, ev.getPriority(), ival)) { ev.setPriority(ival); } break; case RDATE: /* ------------------- RDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case RECURRENCE_ID: /* ------------------- RecurrenceID -------------------- */ // Done above break; case RELATED_TO: /* ------------------- RelatedTo -------------------- */ final RelatedTo irelto = (RelatedTo)prop; final BwRelatedTo relto = new BwRelatedTo(); final String parval = IcalUtil.getParameterVal(irelto, "RELTYPE"); if (parval != null) { relto.setRelType(parval); } relto.setValue(irelto.getValue()); if (chg.changed(pi, ev.getRelatedTo(), relto)) { ev.setRelatedTo(relto); } break; case REQUEST_STATUS: /* ------------------- RequestStatus -------------------- */ final BwRequestStatus rs = BwRequestStatus .fromRequestStatus((RequestStatus)prop); chg.addValue(pi, rs); break; case RESOURCES: /* ------------------- Resources -------------------- */ final TextList rl = ((Resources)prop).getResources(); if (rl != null) { /* Got some resources */ lang = IcalUtil.getLang(prop); for (final String s: rl) { final BwString rsrc = new BwString(lang, s); chg.addValue(pi, rsrc); } } break; case RRULE: /* ------------------- RRule -------------------- */ chg.addValue(pi, pval); break; case SEQUENCE: /* ------------------- Sequence -------------------- */ final int seq = ((Sequence)prop).getSequenceNo(); if (seq != ev.getSequence()) { chg.changed(pi, ev.getSequence(), seq); ev.setSequence(seq); } break; case STATUS: /* ------------------- Status -------------------- */ if (chg.changed(pi, ev.getStatus(), pval)) { ev.setStatus(pval); } break; case SUMMARY: /* ------------------- Summary -------------------- */ if (chg.changed(pi, ev.getSummary(), pval)) { ev.setSummary(pval); } break; case TRANSP: /* ------------------- Transp -------------------- */ if (chg.changed(pi, ev.getPeruserTransparency( cb.getPrincipal() .getPrincipalRef()), pval)) { final BwXproperty pu = ev.setPeruserTransparency( cb.getPrincipal().getPrincipalRef(), pval); if (pu != null) { chg.addValue(PropertyInfoIndex.XPROP, pu); } } break; case UID: /* ------------------- Uid -------------------- */ /* We did this above */ break; case URL: /* ------------------- Url -------------------- */ if (chg.changed(pi, ev.getLink(), pval)) { ev.setLink(pval); } break; case XPROP: /* ------------------------- x-property --------------------------- */ final String name = prop.getName(); if (name.equalsIgnoreCase(BwXproperty.bedeworkCost)) { if (chg.changed(PropertyInfoIndex.COST, ev.getCost(), pval)) { ev.setCost(pval); } break; } if (name.equalsIgnoreCase(BwXproperty.xBedeworkCategories)) { if (checkCategory(cb, chg, ev, null, pval)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkLocation)) { if (checkLocation(cb, chg, ev, prop)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkContact)) { if (checkContact(cb, chg, ev, null, pval)) { break; } } /* See if this is an x-category that can be converted to a real category */ final XProperty xp = (XProperty)prop; chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(name, xp.getParameters() .toString(), pval)); break; default: if (logger.debug()) { logger.debug("Unsupported property with index " + pi + "; class " + prop.getClass() + " and value " + pval); } } } /* =================== Process sub-components =============== */ final ComponentList<Component> subComps; if (val instanceof ComponentContainer) { subComps = ((ComponentContainer<Component>)val).getComponents(); } else { subComps = null; } final Set<Integer> pids; if (vpoll) { pids = new TreeSet<>(); final BwEvent vp = evinfo.getEvent(); if (!Util.isEmpty(vp.getPollItems())) { vp.clearPollItems(); } } else { pids = null; } if (!Util.isEmpty(subComps)) { for (final var subComp: subComps) { if (subComp instanceof Available) { if (!(val instanceof VAvailability)) { return Response.error(resp, "AVAILABLE only valid in VAVAILABLE"); } final var avlResp = processAvailable(cb, cal, ical, (VAvailability)val, (Available)subComp, evinfo); if (!avlResp.isOk()) { return Response.fromResponse(resp, avlResp); } continue; } if (subComp instanceof Participant) { if (vpoll) { final var vresp = processVoter(cb, (VPoll)val, (Participant)subComp, evinfo, chg, mergeAttendees); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Participant object"); continue; } if (subComp instanceof VResource) { logger.warn("Unimplemented VResource object"); continue; } if (subComp instanceof VLocation) { logger.warn("Unimplemented VLocation object"); continue; } if (subComp instanceof VAlarm) { final var aresp = VAlarmUtil.processAlarm(cb, val, (VAlarm)subComp, ev, currentPrincipal, chg); if (!aresp.isOk()) { return Response.fromResponse(resp, aresp); } continue; } if (vpoll && (event || task)) { final var vresp = processCandidate((VPoll)val, subComp, evinfo, pids, chg); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Component object: " + subComp); } } /* Fix up timestamps. */ if (ev.getCreated() == null) { if (ev.getLastmod() != null) { ev.setCreated(ev.getLastmod()); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); } else { ev.updateDtstamp(); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } } if (ev.getLastmod() == null) { // created cannot be null now ev.setLastmod(ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } processTimezones(ev, ical, chg); /* Remove any recipients and originator */ if (ev.getRecipients() != null) { ev.getRecipients().clear(); } ev.setOriginator(null); if (hasXparams.value) { /* Save a text copy of the entire event as an x-property */ final Component valCopy = val.copy(); /* Remove potentially large values */ final Description desp = valCopy.getProperty(Property.DESCRIPTION); if (desp != null) { desp.setValue(null); } final Attach attachp = valCopy.getProperty(Property.ATTACH); // Don't store the entire attachment - we just need the parameters. if (attachp != null) { final Value v = attachp.getParameter(Parameter.VALUE); if (v != null) { attachp.setValue(String.valueOf(attachp.getValue().hashCode())); } } chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(BwXproperty.bedeworkIcal, null, valCopy.toString())); } chg.processChanges(ev, true, false); ev.setRecurring(ev.isRecurringEntity()); if (logger.debug()) { logger.debug(chg.toString()); logger.debug(ev.toString()); } if (masterEI != null) { // Just return notfound as this event is on its override list return Response.notFound(resp); } resp.setEntity(evinfo); return resp; } catch (final Throwable t) { if (logger.debug()) { logger.error(t); } return Response.error(resp, t); } }
NONSATD
true
break; case ATTENDEE: /* ------------------- Attendee -------------------- */ if (methodType == ScheduleMethods.methodTypePublish) { if (cb.getStrictness() == IcalCallback.conformanceStrict) {
String sval = prop.getValue(); if (chg.changed(pi, ev.getPollAcceptResponse(), sval)) { ev.setPollAcceptResponse(sval); } break; case ATTACH: /* ------------------- Attachment -------------------- */ chg.addValue(pi, IcalUtil.getAttachment((Attach)prop)); break; case ATTENDEE: /* ------------------- Attendee -------------------- */ if (methodType == ScheduleMethods.methodTypePublish) { if (cb.getStrictness() == IcalCallback.conformanceStrict) { return Response.notOk(resp, failed, CalFacadeException.attendeesInPublish); } //if (cb.getStrictness() == IcalCallback.conformanceWarn) { // warn("Had attendees for PUBLISH"); //} } final Attendee attPr = (Attendee)prop;
if (pi == null) { logger.debug("Unknown property with name " + prop.getName() + " class " + prop.getClass() + " and value " + pval); continue; } chg.present(pi); switch (pi) { case ACCEPT_RESPONSE: /* ------------------- Accept Response -------------------- */ String sval = prop.getValue(); if (chg.changed(pi, ev.getPollAcceptResponse(), sval)) { ev.setPollAcceptResponse(sval); } break; case ATTACH: /* ------------------- Attachment -------------------- */ chg.addValue(pi, IcalUtil.getAttachment((Attach)prop)); break; case ATTENDEE: /* ------------------- Attendee -------------------- */ if (methodType == ScheduleMethods.methodTypePublish) { if (cb.getStrictness() == IcalCallback.conformanceStrict) { return Response.notOk(resp, failed, CalFacadeException.attendeesInPublish); } //if (cb.getStrictness() == IcalCallback.conformanceWarn) { // warn("Had attendees for PUBLISH"); //} } final Attendee attPr = (Attendee)prop; if (evinfo.getNewEvent() || !mergeAttendees) { chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { final String pUri = cb.getCaladdr(attPr.getValue()); if (pUri.equals(attUri)) { /* Only update for our own attendee * We're doing a PUT and this must be the attendee updating their * partstat. We don't allow them to change other attendees * whatever the PUT content says. */
7,893
25
//if (cb.getStrictness() == IcalCallback.conformanceWarn) { // warn("Had attendees for PUBLISH"); //}
public static GetEntityResponse<EventInfo> toEvent( final IcalCallback cb, final BwCalendar cal, final Icalendar ical, final Component val, final boolean mergeAttendees) { final var resp = new GetEntityResponse<EventInfo>(); if (val == null) { return Response.notOk(resp, failed, "No component supplied"); } String currentPrincipal = null; final BwPrincipal principal = cb.getPrincipal(); if (principal != null) { currentPrincipal = principal.getPrincipalRef(); } final Holder<Boolean> hasXparams = new Holder<>(Boolean.FALSE); final int methodType = ical.getMethodType(); String attUri = null; if (mergeAttendees) { // We'll need this later. attUri = cb.getCaladdr(cb.getPrincipal().getPrincipalRef()); } final String colPath; if (cal == null) { colPath = null; } else { colPath = cal.getPath(); } try { final PropertyList<Property> pl = val.getProperties(); boolean vpoll = false; boolean event = false; boolean task = false; if (pl == null) { // Empty component return Response.notOk(resp, failed, "Empty component"); } final int entityType; if (val instanceof VEvent) { entityType = IcalDefs.entityTypeEvent; event = true; } else if (val instanceof VToDo) { entityType = IcalDefs.entityTypeTodo; task = true; } else if (val instanceof VJournal) { entityType = IcalDefs.entityTypeJournal; } else if (val instanceof VFreeBusy) { entityType = IcalDefs.entityTypeFreeAndBusy; } else if (val instanceof VAvailability) { entityType = IcalDefs.entityTypeVavailability; } else if (val instanceof Available) { entityType = IcalDefs.entityTypeAvailable; } else if (val instanceof VPoll) { entityType = IcalDefs.entityTypeVpoll; vpoll = true; } else { return Response.error(resp, "org.bedework.invalid.component.type: " + val.getName()); } // Get the guid from the component String guid = null; final Uid uidp = pl.getProperty(Property.UID); if (uidp != null) { testXparams(uidp, hasXparams); guid = uidp.getValue(); } if (guid == null) { /* XXX A guid is required - but are there devices out there without a * guid - and if so how do we handle it? */ return Response.notOk(resp, failed, CalFacadeException.noGuid); } /* See if we have a recurrence id */ BwDateTime ridObj = null; String rid = null; TimeZone ridTz = null; final RecurrenceId ridp = pl.getProperty(Property.RECURRENCE_ID); if (ridp != null) { testXparams(ridp, hasXparams); ridObj = BwDateTime.makeBwDateTime(ridp); if (ridObj.getRange() != null) { /* XXX What do I do with it? */ logger.warn("TRANS-TO_EVENT: Got a recurrence id range"); } rid = ridObj.getDate(); } EventInfo masterEI = null; EventInfo evinfo = null; final BwEvent ev; /* If we have a recurrence id see if we already have the master (we should * get a master + all its overrides). * * If so find the override and use the annnotation or if no override, * make one. * * If no override retrieve the event, add it to our table and then locate the * annotation. * * If there is no annotation, create one. * * It's possible we have been sent 'detached' instances of a recurring * event. This may happen if we are invited to one or more instances of a * meeting. In this case we try to retrieve the master and if it doesn't * exist we manufacture one. We consider such an instance an update to * that instance only and leave the others alone. */ /* We need this in a couple of places */ final DtStart dtStart = pl.getProperty(Property.DTSTART); /* if (rid != null) { // See if we have a new master event. If so create a proxy to that event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI == null) { masterEI = makeNewEvent(cb, chg, entityType, guid, cal); BwEvent e = masterEI.getEvent(); // XXX This seems bogus DtStart mdtStart; String bogusDate = "19980118T230000"; if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + "Z"); } else if (dtStart.getTimeZone() == null) { mdtStart = new DtStart(bogusDate); } else { mdtStart = new DtStart(bogusDate + "Z", dtStart.getTimeZone()); } setDates(e, mdtStart, null, null, chg); e.setRecurring(true); e.addRdate(ridObj); e.setSuppressed(true); ical.addComponent(masterEI); } if (masterEI != null) { evinfo = masterEI.findOverride(rid); } } */ /* If this is a recurrence instance see if we can find the master We only need this because the master may follow the overrides. */ if (rid != null) { // See if we have a new master event. If so create a proxy to this event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI != null) { evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; } } if ((evinfo == null) && (cal != null) && (cal.getCalType() != BwCalendar.calTypeInbox) && (cal.getCalType() != BwCalendar.calTypePendingInbox) && (cal.getCalType() != BwCalendar.calTypeOutbox)) { if (logger.debug()) { logger.debug("TRANS-TO_EVENT: try to fetch event with guid=" + guid); } final GetEntitiesResponse<EventInfo> eisResp = cb.getEvent(colPath, guid); if (eisResp.isError()) { return Response.fromResponse(resp, eisResp); } final var eis = eisResp.getEntities(); if (!Util.isEmpty(eis)) { if (eis.size() > 1) { // DORECUR - wrong again return Response.notOk(resp, failed, "More than one event returned for guid."); } evinfo = eis.iterator().next(); } if (logger.debug()) { if (evinfo != null) { logger.debug("TRANS-TO_EVENT: fetched event with guid"); } else { logger.debug("TRANS-TO_EVENT: did not find event with guid"); } } if (evinfo != null) { if (rid != null) { // We just retrieved it's master masterEI = evinfo; masterEI.setInstanceOnly(true); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; ical.addComponent(masterEI); } else if (methodType == ScheduleMethods.methodTypeCancel) { // This should never have an rid for cancel of entire event. evinfo.setInstanceOnly(evinfo.getEvent().getSuppressed()); } else { // Presumably sent an update for the entire event. No longer suppressed master evinfo.getEvent().setSuppressed(false); } } else if (rid != null) { /* Manufacture a master for the instance */ masterEI = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); final BwEvent e = masterEI.getEvent(); // XXX This seems bogus final DtStart mdtStart; final String bogusDate = "19980118"; final String bogusTime = "T230000"; // Base dtstart on the recurrence id. final boolean isDateType = ridObj.getDateType(); if (isDateType) { mdtStart = new DtStart(new Date(bogusDate)); } else if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + bogusTime + "Z"); } else if (ridObj.getTzid() == null) { mdtStart = new DtStart(bogusDate + bogusTime); } else { mdtStart = new DtStart(bogusDate + bogusTime, Timezones.getTz(ridObj.getTzid())); } IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), masterEI, mdtStart, null, null); e.setRecurring(true); // e.addRdate(ridObj); final var sum = (Summary)pl.getProperty(Property.SUMMARY); e.setSummary(sum.getValue()); e.setSuppressed(true); ical.addComponent(masterEI); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; masterEI.setInstanceOnly(rid != null); } } if (evinfo == null) { evinfo = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); } else if (evinfo.getEvent().getEntityType() != entityType) { return Response.notOk(resp, failed, "org.bedework.mismatched.entity.type: " + val); } final ChangeTable chg = evinfo.getChangeset( cb.getPrincipal().getPrincipalRef()); if (rid != null) { final String evrid = evinfo.getEvent().getRecurrenceId(); if ((evrid == null) || (!evrid.equals(rid))) { logger. warn("Mismatched rid ev=" + evrid + " expected " + rid); chg.changed(PropertyInfoIndex.RECURRENCE_ID, evrid, rid); // XXX spurious??? } if (masterEI.getEvent().getSuppressed()) { masterEI.getEvent().addRdate(ridObj); } } ev = evinfo.getEvent(); ev.setScheduleMethod(methodType); DtEnd dtEnd = null; if (entityType == IcalDefs.entityTypeTodo) { final Due due = pl.getProperty(Property.DUE); if (due != null ) { dtEnd = new DtEnd(due.getParameters(), due.getValue()); } } else { dtEnd = pl.getProperty(Property.DTEND); } final Duration duration = pl.getProperty(Property.DURATION); IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), evinfo, dtStart, dtEnd, duration); for (final Property prop: pl) { testXparams(prop, hasXparams); //debug("ical prop " + prop.getClass().getName()); String pval = prop.getValue(); if ((pval != null) && (pval.length() == 0)) { pval = null; } final PropertyInfoIndex pi; if (prop instanceof XProperty) { pi = PropertyInfoIndex.XPROP; } else { pi = PropertyInfoIndex.fromName(prop.getName()); } if (pi == null) { logger.debug("Unknown property with name " + prop.getName() + " class " + prop.getClass() + " and value " + pval); continue; } chg.present(pi); switch (pi) { case ACCEPT_RESPONSE: /* ------------------- Accept Response -------------------- */ String sval = prop.getValue(); if (chg.changed(pi, ev.getPollAcceptResponse(), sval)) { ev.setPollAcceptResponse(sval); } break; case ATTACH: /* ------------------- Attachment -------------------- */ chg.addValue(pi, IcalUtil.getAttachment((Attach)prop)); break; case ATTENDEE: /* ------------------- Attendee -------------------- */ if (methodType == ScheduleMethods.methodTypePublish) { if (cb.getStrictness() == IcalCallback.conformanceStrict) { return Response.notOk(resp, failed, CalFacadeException.attendeesInPublish); } //if (cb.getStrictness() == IcalCallback.conformanceWarn) { // warn("Had attendees for PUBLISH"); //} } final Attendee attPr = (Attendee)prop; if (evinfo.getNewEvent() || !mergeAttendees) { chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { final String pUri = cb.getCaladdr(attPr.getValue()); if (pUri.equals(attUri)) { /* Only update for our own attendee * We're doing a PUT and this must be the attendee updating their * partstat. We don't allow them to change other attendees * whatever the PUT content says. */ chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { // Use the value we currently have boolean found = false; for (final BwAttendee att: ev.getAttendees()) { if (pUri.equals(att.getAttendeeUri())) { chg.addValue(pi, att.clone()); found = true; break; } } if (!found) { // An added attendee final BwAttendee att = IcalUtil .getAttendee(cb, attPr); att.setPartstat(IcalDefs.partstatValNeedsAction); chg.addValue(pi, att); } } } break; case BUSYTYPE: final int ibt = BwEvent.fromBusyTypeString(pval); if (chg.changed(pi, ev.getBusyType(), ibt)) { ev.setBusyType(ibt); } break; case CATEGORIES: /* ------------------- Categories -------------------- */ final Categories cats = (Categories)prop; final TextList cl = cats.getCategories(); String lang = IcalUtil.getLang(cats); if (cl != null) { /* Got some categories */ for (final String wd: cl) { if (wd == null) { continue; } final BwString key = new BwString(lang, wd); final var fcResp = cb.findCategory(key); final BwCategory cat; if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isNotFound()) { cat = BwCategory.makeCategory(); cat.setWord(key); cb.addCategory(cat); } else { cat = fcResp.getEntity(); } chg.addValue(pi, cat); } } break; case CLASS: /* ------------------- Class -------------------- */ if (chg.changed(pi, ev.getClassification(), pval)) { ev.setClassification(pval); } break; case COMMENT: /* ------------------- Comment -------------------- */ chg.addValue(pi, new BwString(null, pval)); break; case COMPLETED: /* ------------------- Completed -------------------- */ if (chg.changed(pi, ev.getCompleted(), pval)) { ev.setCompleted(pval); } break; case CONCEPT: /* ------------------- Concept -------------------- */ final Concept c = (Concept)prop; final String cval = c.getValue(); if (cval != null) { /* Got a concept */ chg.addValue(PropertyInfoIndex.XPROP, BwXproperty.makeIcalProperty("CONCEPT", null, cval)); } break; case CONTACT: /* ------------------- Contact -------------------- */ final String altrep = getAltRepPar(prop); lang = IcalUtil.getLang(prop); final String uid = getUidPar(prop); final BwString nm = new BwString(lang, pval); BwContact contact = null; if (uid != null) { final var fcResp = cb.getContact(uid); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { final var fcResp = cb.findContact(nm); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { contact = BwContact.makeContact(); contact.setCn(nm); contact.setLink(altrep); cb.addContact(contact); } else { contact.setCn(nm); contact.setLink(altrep); } chg.addValue(pi, contact); break; case CREATED: /* ------------------- Created -------------------- */ if (chg.changed(pi, ev.getCreated(), pval)) { ev.setCreated(pval); } break; case DESCRIPTION: /* ------------------- Description -------------------- */ if (chg.changed(pi, ev.getDescription(), pval)) { ev.setDescription(pval); } break; case DTEND: /* ------------------- DtEnd -------------------- */ break; case DTSTAMP: /* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval); break; case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE: /* -------------------- Due ------------------------ */ break; case DURATION: /* ------------------- Duration -------------------- */ break; case EXDATE: /* ------------------- ExDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case EXRULE: /* ------------------- ExRule -------------------- */ chg.addValue(pi, pval); break; case FREEBUSY: /* ------------------- freebusy -------------------- */ final FreeBusy fbusy = (FreeBusy)prop; final PeriodList perpl = fbusy.getPeriods(); final Parameter par = IcalUtil.getParameter(fbusy, "FBTYPE"); final int fbtype; if (par == null) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY)) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY_TENTATIVE)) { fbtype = BwFreeBusyComponent.typeBusyTentative; } else if (par.equals(FbType.BUSY_UNAVAILABLE)) { fbtype = BwFreeBusyComponent.typeBusyUnavailable; } else if (par.equals(FbType.FREE)) { fbtype = BwFreeBusyComponent.typeFree; } else { if (logger.debug()) { logger.debug("Unsupported parameter " + par.getName()); } return Response.notOk(resp, failed, "Unsupported parameter " + par.getName()); } final BwFreeBusyComponent fbc = new BwFreeBusyComponent(); fbc.setType(fbtype); for (final Period per : perpl) { fbc.addPeriod(per); } ev.addFreeBusyPeriod(fbc); break; case GEO: /* ------------------- Geo -------------------- */ final Geo g = (Geo)prop; final BwGeo geo = new BwGeo(g.getLatitude(), g.getLongitude()); if (chg.changed(pi, ev.getGeo(), geo)) { ev.setGeo(geo); } break; case LAST_MODIFIED: /* ------------------- LastModified -------------------- */ if (chg.changed(pi, ev.getLastmod(), pval)) { ev.setLastmod(pval); } break; case LOCATION: /* ------------------- Location -------------------- */ BwLocation loc = null; //String uid = getUidPar(prop); /* At the moment Mozilla lightning is broken and this leads to all * sorts of problems. if (uid != null) { loc = cb.getLocation(uid); } */ lang = IcalUtil.getLang(prop); BwString addr = null; if (pval != null) { if (loc == null) { addr = new BwString(lang, pval); final var fcResp = cb.findLocation(addr); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { loc = fcResp.getEntity(); } } if (loc == null) { loc = BwLocation.makeLocation(); loc.setAddress(addr); cb.addLocation(loc); } } final BwLocation evloc = ev.getLocation(); if (chg.changed(pi, evloc, loc)) { // CHGTBL - this only shows that it's a different location object ev.setLocation(loc); } else if ((loc != null) && (evloc != null)) { // See if the value is changed final String evval = evloc.getAddress().getValue(); final String inval = loc.getAddress().getValue(); if (!evval.equals(inval)) { chg.changed(pi, evval, inval); evloc.getAddress().setValue(inval); } } break; case ORGANIZER: /* ------------------- Organizer -------------------- */ final BwOrganizer org = IcalUtil.getOrganizer(cb, (Organizer)prop); final BwOrganizer evorg = ev.getOrganizer(); final BwOrganizer evorgCopy; if (evorg == null) { evorgCopy = null; } else { evorgCopy = (BwOrganizer)evorg.clone(); } if (chg.changed(pi, evorgCopy, org)) { if (evorg == null) { ev.setOrganizer(org); } else { evorg.update(org); } } break; case PERCENT_COMPLETE: /* ------------------- PercentComplete -------------------- */ Integer ival = ((PercentComplete)prop).getPercentage(); if (chg.changed(pi, ev.getPercentComplete(), ival)) { ev.setPercentComplete(ival); } break; case POLL_MODE: /* ------------------- Poll mode -------------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollMode(), sval)) { ev.setPollMode(sval); } break; case POLL_PROPERTIES: /* ------------------- Poll properties ---------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollProperties(), sval)) { ev.setPollProperties(sval); } break; case POLL_WINNER: /* ------------------- Poll winner -------------------- */ ival = ((PollWinner)prop).getPollwinner(); if (chg.changed(pi, ev.getPollWinner(), ival)) { ev.setPollWinner(ival); } break; case PRIORITY: /* ------------------- Priority -------------------- */ ival = ((Priority)prop).getLevel(); if (chg.changed(pi, ev.getPriority(), ival)) { ev.setPriority(ival); } break; case RDATE: /* ------------------- RDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case RECURRENCE_ID: /* ------------------- RecurrenceID -------------------- */ // Done above break; case RELATED_TO: /* ------------------- RelatedTo -------------------- */ final RelatedTo irelto = (RelatedTo)prop; final BwRelatedTo relto = new BwRelatedTo(); final String parval = IcalUtil.getParameterVal(irelto, "RELTYPE"); if (parval != null) { relto.setRelType(parval); } relto.setValue(irelto.getValue()); if (chg.changed(pi, ev.getRelatedTo(), relto)) { ev.setRelatedTo(relto); } break; case REQUEST_STATUS: /* ------------------- RequestStatus -------------------- */ final BwRequestStatus rs = BwRequestStatus .fromRequestStatus((RequestStatus)prop); chg.addValue(pi, rs); break; case RESOURCES: /* ------------------- Resources -------------------- */ final TextList rl = ((Resources)prop).getResources(); if (rl != null) { /* Got some resources */ lang = IcalUtil.getLang(prop); for (final String s: rl) { final BwString rsrc = new BwString(lang, s); chg.addValue(pi, rsrc); } } break; case RRULE: /* ------------------- RRule -------------------- */ chg.addValue(pi, pval); break; case SEQUENCE: /* ------------------- Sequence -------------------- */ final int seq = ((Sequence)prop).getSequenceNo(); if (seq != ev.getSequence()) { chg.changed(pi, ev.getSequence(), seq); ev.setSequence(seq); } break; case STATUS: /* ------------------- Status -------------------- */ if (chg.changed(pi, ev.getStatus(), pval)) { ev.setStatus(pval); } break; case SUMMARY: /* ------------------- Summary -------------------- */ if (chg.changed(pi, ev.getSummary(), pval)) { ev.setSummary(pval); } break; case TRANSP: /* ------------------- Transp -------------------- */ if (chg.changed(pi, ev.getPeruserTransparency( cb.getPrincipal() .getPrincipalRef()), pval)) { final BwXproperty pu = ev.setPeruserTransparency( cb.getPrincipal().getPrincipalRef(), pval); if (pu != null) { chg.addValue(PropertyInfoIndex.XPROP, pu); } } break; case UID: /* ------------------- Uid -------------------- */ /* We did this above */ break; case URL: /* ------------------- Url -------------------- */ if (chg.changed(pi, ev.getLink(), pval)) { ev.setLink(pval); } break; case XPROP: /* ------------------------- x-property --------------------------- */ final String name = prop.getName(); if (name.equalsIgnoreCase(BwXproperty.bedeworkCost)) { if (chg.changed(PropertyInfoIndex.COST, ev.getCost(), pval)) { ev.setCost(pval); } break; } if (name.equalsIgnoreCase(BwXproperty.xBedeworkCategories)) { if (checkCategory(cb, chg, ev, null, pval)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkLocation)) { if (checkLocation(cb, chg, ev, prop)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkContact)) { if (checkContact(cb, chg, ev, null, pval)) { break; } } /* See if this is an x-category that can be converted to a real category */ final XProperty xp = (XProperty)prop; chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(name, xp.getParameters() .toString(), pval)); break; default: if (logger.debug()) { logger.debug("Unsupported property with index " + pi + "; class " + prop.getClass() + " and value " + pval); } } } /* =================== Process sub-components =============== */ final ComponentList<Component> subComps; if (val instanceof ComponentContainer) { subComps = ((ComponentContainer<Component>)val).getComponents(); } else { subComps = null; } final Set<Integer> pids; if (vpoll) { pids = new TreeSet<>(); final BwEvent vp = evinfo.getEvent(); if (!Util.isEmpty(vp.getPollItems())) { vp.clearPollItems(); } } else { pids = null; } if (!Util.isEmpty(subComps)) { for (final var subComp: subComps) { if (subComp instanceof Available) { if (!(val instanceof VAvailability)) { return Response.error(resp, "AVAILABLE only valid in VAVAILABLE"); } final var avlResp = processAvailable(cb, cal, ical, (VAvailability)val, (Available)subComp, evinfo); if (!avlResp.isOk()) { return Response.fromResponse(resp, avlResp); } continue; } if (subComp instanceof Participant) { if (vpoll) { final var vresp = processVoter(cb, (VPoll)val, (Participant)subComp, evinfo, chg, mergeAttendees); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Participant object"); continue; } if (subComp instanceof VResource) { logger.warn("Unimplemented VResource object"); continue; } if (subComp instanceof VLocation) { logger.warn("Unimplemented VLocation object"); continue; } if (subComp instanceof VAlarm) { final var aresp = VAlarmUtil.processAlarm(cb, val, (VAlarm)subComp, ev, currentPrincipal, chg); if (!aresp.isOk()) { return Response.fromResponse(resp, aresp); } continue; } if (vpoll && (event || task)) { final var vresp = processCandidate((VPoll)val, subComp, evinfo, pids, chg); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Component object: " + subComp); } } /* Fix up timestamps. */ if (ev.getCreated() == null) { if (ev.getLastmod() != null) { ev.setCreated(ev.getLastmod()); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); } else { ev.updateDtstamp(); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } } if (ev.getLastmod() == null) { // created cannot be null now ev.setLastmod(ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } processTimezones(ev, ical, chg); /* Remove any recipients and originator */ if (ev.getRecipients() != null) { ev.getRecipients().clear(); } ev.setOriginator(null); if (hasXparams.value) { /* Save a text copy of the entire event as an x-property */ final Component valCopy = val.copy(); /* Remove potentially large values */ final Description desp = valCopy.getProperty(Property.DESCRIPTION); if (desp != null) { desp.setValue(null); } final Attach attachp = valCopy.getProperty(Property.ATTACH); // Don't store the entire attachment - we just need the parameters. if (attachp != null) { final Value v = attachp.getParameter(Parameter.VALUE); if (v != null) { attachp.setValue(String.valueOf(attachp.getValue().hashCode())); } } chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(BwXproperty.bedeworkIcal, null, valCopy.toString())); } chg.processChanges(ev, true, false); ev.setRecurring(ev.isRecurringEntity()); if (logger.debug()) { logger.debug(chg.toString()); logger.debug(ev.toString()); } if (masterEI != null) { // Just return notfound as this event is on its override list return Response.notFound(resp); } resp.setEntity(evinfo); return resp; } catch (final Throwable t) { if (logger.debug()) { logger.error(t); } return Response.error(resp, t); } }
NONSATD
true
CalFacadeException.attendeesInPublish); } //if (cb.getStrictness() == IcalCallback.conformanceWarn) { // warn("Had attendees for PUBLISH"); //} } final Attendee attPr = (Attendee)prop;
/* ------------------- Attachment -------------------- */ chg.addValue(pi, IcalUtil.getAttachment((Attach)prop)); break; case ATTENDEE: /* ------------------- Attendee -------------------- */ if (methodType == ScheduleMethods.methodTypePublish) { if (cb.getStrictness() == IcalCallback.conformanceStrict) { return Response.notOk(resp, failed, CalFacadeException.attendeesInPublish); } //if (cb.getStrictness() == IcalCallback.conformanceWarn) { // warn("Had attendees for PUBLISH"); //} } final Attendee attPr = (Attendee)prop; if (evinfo.getNewEvent() || !mergeAttendees) { chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { final String pUri = cb.getCaladdr(attPr.getValue()); if (pUri.equals(attUri)) { /* Only update for our own attendee * We're doing a PUT and this must be the attendee updating their * partstat. We don't allow them to change other attendees
chg.present(pi); switch (pi) { case ACCEPT_RESPONSE: /* ------------------- Accept Response -------------------- */ String sval = prop.getValue(); if (chg.changed(pi, ev.getPollAcceptResponse(), sval)) { ev.setPollAcceptResponse(sval); } break; case ATTACH: /* ------------------- Attachment -------------------- */ chg.addValue(pi, IcalUtil.getAttachment((Attach)prop)); break; case ATTENDEE: /* ------------------- Attendee -------------------- */ if (methodType == ScheduleMethods.methodTypePublish) { if (cb.getStrictness() == IcalCallback.conformanceStrict) { return Response.notOk(resp, failed, CalFacadeException.attendeesInPublish); } //if (cb.getStrictness() == IcalCallback.conformanceWarn) { // warn("Had attendees for PUBLISH"); //} } final Attendee attPr = (Attendee)prop; if (evinfo.getNewEvent() || !mergeAttendees) { chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { final String pUri = cb.getCaladdr(attPr.getValue()); if (pUri.equals(attUri)) { /* Only update for our own attendee * We're doing a PUT and this must be the attendee updating their * partstat. We don't allow them to change other attendees * whatever the PUT content says. */ chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { // Use the value we currently have boolean found = false; for (final BwAttendee att: ev.getAttendees()) { if (pUri.equals(att.getAttendeeUri())) { chg.addValue(pi, att.clone()); found = true;
7,893
26
/* Only update for our own attendee * We're doing a PUT and this must be the attendee updating their * partstat. We don't allow them to change other attendees * whatever the PUT content says. */
public static GetEntityResponse<EventInfo> toEvent( final IcalCallback cb, final BwCalendar cal, final Icalendar ical, final Component val, final boolean mergeAttendees) { final var resp = new GetEntityResponse<EventInfo>(); if (val == null) { return Response.notOk(resp, failed, "No component supplied"); } String currentPrincipal = null; final BwPrincipal principal = cb.getPrincipal(); if (principal != null) { currentPrincipal = principal.getPrincipalRef(); } final Holder<Boolean> hasXparams = new Holder<>(Boolean.FALSE); final int methodType = ical.getMethodType(); String attUri = null; if (mergeAttendees) { // We'll need this later. attUri = cb.getCaladdr(cb.getPrincipal().getPrincipalRef()); } final String colPath; if (cal == null) { colPath = null; } else { colPath = cal.getPath(); } try { final PropertyList<Property> pl = val.getProperties(); boolean vpoll = false; boolean event = false; boolean task = false; if (pl == null) { // Empty component return Response.notOk(resp, failed, "Empty component"); } final int entityType; if (val instanceof VEvent) { entityType = IcalDefs.entityTypeEvent; event = true; } else if (val instanceof VToDo) { entityType = IcalDefs.entityTypeTodo; task = true; } else if (val instanceof VJournal) { entityType = IcalDefs.entityTypeJournal; } else if (val instanceof VFreeBusy) { entityType = IcalDefs.entityTypeFreeAndBusy; } else if (val instanceof VAvailability) { entityType = IcalDefs.entityTypeVavailability; } else if (val instanceof Available) { entityType = IcalDefs.entityTypeAvailable; } else if (val instanceof VPoll) { entityType = IcalDefs.entityTypeVpoll; vpoll = true; } else { return Response.error(resp, "org.bedework.invalid.component.type: " + val.getName()); } // Get the guid from the component String guid = null; final Uid uidp = pl.getProperty(Property.UID); if (uidp != null) { testXparams(uidp, hasXparams); guid = uidp.getValue(); } if (guid == null) { /* XXX A guid is required - but are there devices out there without a * guid - and if so how do we handle it? */ return Response.notOk(resp, failed, CalFacadeException.noGuid); } /* See if we have a recurrence id */ BwDateTime ridObj = null; String rid = null; TimeZone ridTz = null; final RecurrenceId ridp = pl.getProperty(Property.RECURRENCE_ID); if (ridp != null) { testXparams(ridp, hasXparams); ridObj = BwDateTime.makeBwDateTime(ridp); if (ridObj.getRange() != null) { /* XXX What do I do with it? */ logger.warn("TRANS-TO_EVENT: Got a recurrence id range"); } rid = ridObj.getDate(); } EventInfo masterEI = null; EventInfo evinfo = null; final BwEvent ev; /* If we have a recurrence id see if we already have the master (we should * get a master + all its overrides). * * If so find the override and use the annnotation or if no override, * make one. * * If no override retrieve the event, add it to our table and then locate the * annotation. * * If there is no annotation, create one. * * It's possible we have been sent 'detached' instances of a recurring * event. This may happen if we are invited to one or more instances of a * meeting. In this case we try to retrieve the master and if it doesn't * exist we manufacture one. We consider such an instance an update to * that instance only and leave the others alone. */ /* We need this in a couple of places */ final DtStart dtStart = pl.getProperty(Property.DTSTART); /* if (rid != null) { // See if we have a new master event. If so create a proxy to that event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI == null) { masterEI = makeNewEvent(cb, chg, entityType, guid, cal); BwEvent e = masterEI.getEvent(); // XXX This seems bogus DtStart mdtStart; String bogusDate = "19980118T230000"; if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + "Z"); } else if (dtStart.getTimeZone() == null) { mdtStart = new DtStart(bogusDate); } else { mdtStart = new DtStart(bogusDate + "Z", dtStart.getTimeZone()); } setDates(e, mdtStart, null, null, chg); e.setRecurring(true); e.addRdate(ridObj); e.setSuppressed(true); ical.addComponent(masterEI); } if (masterEI != null) { evinfo = masterEI.findOverride(rid); } } */ /* If this is a recurrence instance see if we can find the master We only need this because the master may follow the overrides. */ if (rid != null) { // See if we have a new master event. If so create a proxy to this event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI != null) { evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; } } if ((evinfo == null) && (cal != null) && (cal.getCalType() != BwCalendar.calTypeInbox) && (cal.getCalType() != BwCalendar.calTypePendingInbox) && (cal.getCalType() != BwCalendar.calTypeOutbox)) { if (logger.debug()) { logger.debug("TRANS-TO_EVENT: try to fetch event with guid=" + guid); } final GetEntitiesResponse<EventInfo> eisResp = cb.getEvent(colPath, guid); if (eisResp.isError()) { return Response.fromResponse(resp, eisResp); } final var eis = eisResp.getEntities(); if (!Util.isEmpty(eis)) { if (eis.size() > 1) { // DORECUR - wrong again return Response.notOk(resp, failed, "More than one event returned for guid."); } evinfo = eis.iterator().next(); } if (logger.debug()) { if (evinfo != null) { logger.debug("TRANS-TO_EVENT: fetched event with guid"); } else { logger.debug("TRANS-TO_EVENT: did not find event with guid"); } } if (evinfo != null) { if (rid != null) { // We just retrieved it's master masterEI = evinfo; masterEI.setInstanceOnly(true); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; ical.addComponent(masterEI); } else if (methodType == ScheduleMethods.methodTypeCancel) { // This should never have an rid for cancel of entire event. evinfo.setInstanceOnly(evinfo.getEvent().getSuppressed()); } else { // Presumably sent an update for the entire event. No longer suppressed master evinfo.getEvent().setSuppressed(false); } } else if (rid != null) { /* Manufacture a master for the instance */ masterEI = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); final BwEvent e = masterEI.getEvent(); // XXX This seems bogus final DtStart mdtStart; final String bogusDate = "19980118"; final String bogusTime = "T230000"; // Base dtstart on the recurrence id. final boolean isDateType = ridObj.getDateType(); if (isDateType) { mdtStart = new DtStart(new Date(bogusDate)); } else if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + bogusTime + "Z"); } else if (ridObj.getTzid() == null) { mdtStart = new DtStart(bogusDate + bogusTime); } else { mdtStart = new DtStart(bogusDate + bogusTime, Timezones.getTz(ridObj.getTzid())); } IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), masterEI, mdtStart, null, null); e.setRecurring(true); // e.addRdate(ridObj); final var sum = (Summary)pl.getProperty(Property.SUMMARY); e.setSummary(sum.getValue()); e.setSuppressed(true); ical.addComponent(masterEI); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; masterEI.setInstanceOnly(rid != null); } } if (evinfo == null) { evinfo = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); } else if (evinfo.getEvent().getEntityType() != entityType) { return Response.notOk(resp, failed, "org.bedework.mismatched.entity.type: " + val); } final ChangeTable chg = evinfo.getChangeset( cb.getPrincipal().getPrincipalRef()); if (rid != null) { final String evrid = evinfo.getEvent().getRecurrenceId(); if ((evrid == null) || (!evrid.equals(rid))) { logger. warn("Mismatched rid ev=" + evrid + " expected " + rid); chg.changed(PropertyInfoIndex.RECURRENCE_ID, evrid, rid); // XXX spurious??? } if (masterEI.getEvent().getSuppressed()) { masterEI.getEvent().addRdate(ridObj); } } ev = evinfo.getEvent(); ev.setScheduleMethod(methodType); DtEnd dtEnd = null; if (entityType == IcalDefs.entityTypeTodo) { final Due due = pl.getProperty(Property.DUE); if (due != null ) { dtEnd = new DtEnd(due.getParameters(), due.getValue()); } } else { dtEnd = pl.getProperty(Property.DTEND); } final Duration duration = pl.getProperty(Property.DURATION); IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), evinfo, dtStart, dtEnd, duration); for (final Property prop: pl) { testXparams(prop, hasXparams); //debug("ical prop " + prop.getClass().getName()); String pval = prop.getValue(); if ((pval != null) && (pval.length() == 0)) { pval = null; } final PropertyInfoIndex pi; if (prop instanceof XProperty) { pi = PropertyInfoIndex.XPROP; } else { pi = PropertyInfoIndex.fromName(prop.getName()); } if (pi == null) { logger.debug("Unknown property with name " + prop.getName() + " class " + prop.getClass() + " and value " + pval); continue; } chg.present(pi); switch (pi) { case ACCEPT_RESPONSE: /* ------------------- Accept Response -------------------- */ String sval = prop.getValue(); if (chg.changed(pi, ev.getPollAcceptResponse(), sval)) { ev.setPollAcceptResponse(sval); } break; case ATTACH: /* ------------------- Attachment -------------------- */ chg.addValue(pi, IcalUtil.getAttachment((Attach)prop)); break; case ATTENDEE: /* ------------------- Attendee -------------------- */ if (methodType == ScheduleMethods.methodTypePublish) { if (cb.getStrictness() == IcalCallback.conformanceStrict) { return Response.notOk(resp, failed, CalFacadeException.attendeesInPublish); } //if (cb.getStrictness() == IcalCallback.conformanceWarn) { // warn("Had attendees for PUBLISH"); //} } final Attendee attPr = (Attendee)prop; if (evinfo.getNewEvent() || !mergeAttendees) { chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { final String pUri = cb.getCaladdr(attPr.getValue()); if (pUri.equals(attUri)) { /* Only update for our own attendee * We're doing a PUT and this must be the attendee updating their * partstat. We don't allow them to change other attendees * whatever the PUT content says. */ chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { // Use the value we currently have boolean found = false; for (final BwAttendee att: ev.getAttendees()) { if (pUri.equals(att.getAttendeeUri())) { chg.addValue(pi, att.clone()); found = true; break; } } if (!found) { // An added attendee final BwAttendee att = IcalUtil .getAttendee(cb, attPr); att.setPartstat(IcalDefs.partstatValNeedsAction); chg.addValue(pi, att); } } } break; case BUSYTYPE: final int ibt = BwEvent.fromBusyTypeString(pval); if (chg.changed(pi, ev.getBusyType(), ibt)) { ev.setBusyType(ibt); } break; case CATEGORIES: /* ------------------- Categories -------------------- */ final Categories cats = (Categories)prop; final TextList cl = cats.getCategories(); String lang = IcalUtil.getLang(cats); if (cl != null) { /* Got some categories */ for (final String wd: cl) { if (wd == null) { continue; } final BwString key = new BwString(lang, wd); final var fcResp = cb.findCategory(key); final BwCategory cat; if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isNotFound()) { cat = BwCategory.makeCategory(); cat.setWord(key); cb.addCategory(cat); } else { cat = fcResp.getEntity(); } chg.addValue(pi, cat); } } break; case CLASS: /* ------------------- Class -------------------- */ if (chg.changed(pi, ev.getClassification(), pval)) { ev.setClassification(pval); } break; case COMMENT: /* ------------------- Comment -------------------- */ chg.addValue(pi, new BwString(null, pval)); break; case COMPLETED: /* ------------------- Completed -------------------- */ if (chg.changed(pi, ev.getCompleted(), pval)) { ev.setCompleted(pval); } break; case CONCEPT: /* ------------------- Concept -------------------- */ final Concept c = (Concept)prop; final String cval = c.getValue(); if (cval != null) { /* Got a concept */ chg.addValue(PropertyInfoIndex.XPROP, BwXproperty.makeIcalProperty("CONCEPT", null, cval)); } break; case CONTACT: /* ------------------- Contact -------------------- */ final String altrep = getAltRepPar(prop); lang = IcalUtil.getLang(prop); final String uid = getUidPar(prop); final BwString nm = new BwString(lang, pval); BwContact contact = null; if (uid != null) { final var fcResp = cb.getContact(uid); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { final var fcResp = cb.findContact(nm); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { contact = BwContact.makeContact(); contact.setCn(nm); contact.setLink(altrep); cb.addContact(contact); } else { contact.setCn(nm); contact.setLink(altrep); } chg.addValue(pi, contact); break; case CREATED: /* ------------------- Created -------------------- */ if (chg.changed(pi, ev.getCreated(), pval)) { ev.setCreated(pval); } break; case DESCRIPTION: /* ------------------- Description -------------------- */ if (chg.changed(pi, ev.getDescription(), pval)) { ev.setDescription(pval); } break; case DTEND: /* ------------------- DtEnd -------------------- */ break; case DTSTAMP: /* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval); break; case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE: /* -------------------- Due ------------------------ */ break; case DURATION: /* ------------------- Duration -------------------- */ break; case EXDATE: /* ------------------- ExDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case EXRULE: /* ------------------- ExRule -------------------- */ chg.addValue(pi, pval); break; case FREEBUSY: /* ------------------- freebusy -------------------- */ final FreeBusy fbusy = (FreeBusy)prop; final PeriodList perpl = fbusy.getPeriods(); final Parameter par = IcalUtil.getParameter(fbusy, "FBTYPE"); final int fbtype; if (par == null) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY)) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY_TENTATIVE)) { fbtype = BwFreeBusyComponent.typeBusyTentative; } else if (par.equals(FbType.BUSY_UNAVAILABLE)) { fbtype = BwFreeBusyComponent.typeBusyUnavailable; } else if (par.equals(FbType.FREE)) { fbtype = BwFreeBusyComponent.typeFree; } else { if (logger.debug()) { logger.debug("Unsupported parameter " + par.getName()); } return Response.notOk(resp, failed, "Unsupported parameter " + par.getName()); } final BwFreeBusyComponent fbc = new BwFreeBusyComponent(); fbc.setType(fbtype); for (final Period per : perpl) { fbc.addPeriod(per); } ev.addFreeBusyPeriod(fbc); break; case GEO: /* ------------------- Geo -------------------- */ final Geo g = (Geo)prop; final BwGeo geo = new BwGeo(g.getLatitude(), g.getLongitude()); if (chg.changed(pi, ev.getGeo(), geo)) { ev.setGeo(geo); } break; case LAST_MODIFIED: /* ------------------- LastModified -------------------- */ if (chg.changed(pi, ev.getLastmod(), pval)) { ev.setLastmod(pval); } break; case LOCATION: /* ------------------- Location -------------------- */ BwLocation loc = null; //String uid = getUidPar(prop); /* At the moment Mozilla lightning is broken and this leads to all * sorts of problems. if (uid != null) { loc = cb.getLocation(uid); } */ lang = IcalUtil.getLang(prop); BwString addr = null; if (pval != null) { if (loc == null) { addr = new BwString(lang, pval); final var fcResp = cb.findLocation(addr); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { loc = fcResp.getEntity(); } } if (loc == null) { loc = BwLocation.makeLocation(); loc.setAddress(addr); cb.addLocation(loc); } } final BwLocation evloc = ev.getLocation(); if (chg.changed(pi, evloc, loc)) { // CHGTBL - this only shows that it's a different location object ev.setLocation(loc); } else if ((loc != null) && (evloc != null)) { // See if the value is changed final String evval = evloc.getAddress().getValue(); final String inval = loc.getAddress().getValue(); if (!evval.equals(inval)) { chg.changed(pi, evval, inval); evloc.getAddress().setValue(inval); } } break; case ORGANIZER: /* ------------------- Organizer -------------------- */ final BwOrganizer org = IcalUtil.getOrganizer(cb, (Organizer)prop); final BwOrganizer evorg = ev.getOrganizer(); final BwOrganizer evorgCopy; if (evorg == null) { evorgCopy = null; } else { evorgCopy = (BwOrganizer)evorg.clone(); } if (chg.changed(pi, evorgCopy, org)) { if (evorg == null) { ev.setOrganizer(org); } else { evorg.update(org); } } break; case PERCENT_COMPLETE: /* ------------------- PercentComplete -------------------- */ Integer ival = ((PercentComplete)prop).getPercentage(); if (chg.changed(pi, ev.getPercentComplete(), ival)) { ev.setPercentComplete(ival); } break; case POLL_MODE: /* ------------------- Poll mode -------------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollMode(), sval)) { ev.setPollMode(sval); } break; case POLL_PROPERTIES: /* ------------------- Poll properties ---------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollProperties(), sval)) { ev.setPollProperties(sval); } break; case POLL_WINNER: /* ------------------- Poll winner -------------------- */ ival = ((PollWinner)prop).getPollwinner(); if (chg.changed(pi, ev.getPollWinner(), ival)) { ev.setPollWinner(ival); } break; case PRIORITY: /* ------------------- Priority -------------------- */ ival = ((Priority)prop).getLevel(); if (chg.changed(pi, ev.getPriority(), ival)) { ev.setPriority(ival); } break; case RDATE: /* ------------------- RDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case RECURRENCE_ID: /* ------------------- RecurrenceID -------------------- */ // Done above break; case RELATED_TO: /* ------------------- RelatedTo -------------------- */ final RelatedTo irelto = (RelatedTo)prop; final BwRelatedTo relto = new BwRelatedTo(); final String parval = IcalUtil.getParameterVal(irelto, "RELTYPE"); if (parval != null) { relto.setRelType(parval); } relto.setValue(irelto.getValue()); if (chg.changed(pi, ev.getRelatedTo(), relto)) { ev.setRelatedTo(relto); } break; case REQUEST_STATUS: /* ------------------- RequestStatus -------------------- */ final BwRequestStatus rs = BwRequestStatus .fromRequestStatus((RequestStatus)prop); chg.addValue(pi, rs); break; case RESOURCES: /* ------------------- Resources -------------------- */ final TextList rl = ((Resources)prop).getResources(); if (rl != null) { /* Got some resources */ lang = IcalUtil.getLang(prop); for (final String s: rl) { final BwString rsrc = new BwString(lang, s); chg.addValue(pi, rsrc); } } break; case RRULE: /* ------------------- RRule -------------------- */ chg.addValue(pi, pval); break; case SEQUENCE: /* ------------------- Sequence -------------------- */ final int seq = ((Sequence)prop).getSequenceNo(); if (seq != ev.getSequence()) { chg.changed(pi, ev.getSequence(), seq); ev.setSequence(seq); } break; case STATUS: /* ------------------- Status -------------------- */ if (chg.changed(pi, ev.getStatus(), pval)) { ev.setStatus(pval); } break; case SUMMARY: /* ------------------- Summary -------------------- */ if (chg.changed(pi, ev.getSummary(), pval)) { ev.setSummary(pval); } break; case TRANSP: /* ------------------- Transp -------------------- */ if (chg.changed(pi, ev.getPeruserTransparency( cb.getPrincipal() .getPrincipalRef()), pval)) { final BwXproperty pu = ev.setPeruserTransparency( cb.getPrincipal().getPrincipalRef(), pval); if (pu != null) { chg.addValue(PropertyInfoIndex.XPROP, pu); } } break; case UID: /* ------------------- Uid -------------------- */ /* We did this above */ break; case URL: /* ------------------- Url -------------------- */ if (chg.changed(pi, ev.getLink(), pval)) { ev.setLink(pval); } break; case XPROP: /* ------------------------- x-property --------------------------- */ final String name = prop.getName(); if (name.equalsIgnoreCase(BwXproperty.bedeworkCost)) { if (chg.changed(PropertyInfoIndex.COST, ev.getCost(), pval)) { ev.setCost(pval); } break; } if (name.equalsIgnoreCase(BwXproperty.xBedeworkCategories)) { if (checkCategory(cb, chg, ev, null, pval)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkLocation)) { if (checkLocation(cb, chg, ev, prop)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkContact)) { if (checkContact(cb, chg, ev, null, pval)) { break; } } /* See if this is an x-category that can be converted to a real category */ final XProperty xp = (XProperty)prop; chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(name, xp.getParameters() .toString(), pval)); break; default: if (logger.debug()) { logger.debug("Unsupported property with index " + pi + "; class " + prop.getClass() + " and value " + pval); } } } /* =================== Process sub-components =============== */ final ComponentList<Component> subComps; if (val instanceof ComponentContainer) { subComps = ((ComponentContainer<Component>)val).getComponents(); } else { subComps = null; } final Set<Integer> pids; if (vpoll) { pids = new TreeSet<>(); final BwEvent vp = evinfo.getEvent(); if (!Util.isEmpty(vp.getPollItems())) { vp.clearPollItems(); } } else { pids = null; } if (!Util.isEmpty(subComps)) { for (final var subComp: subComps) { if (subComp instanceof Available) { if (!(val instanceof VAvailability)) { return Response.error(resp, "AVAILABLE only valid in VAVAILABLE"); } final var avlResp = processAvailable(cb, cal, ical, (VAvailability)val, (Available)subComp, evinfo); if (!avlResp.isOk()) { return Response.fromResponse(resp, avlResp); } continue; } if (subComp instanceof Participant) { if (vpoll) { final var vresp = processVoter(cb, (VPoll)val, (Participant)subComp, evinfo, chg, mergeAttendees); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Participant object"); continue; } if (subComp instanceof VResource) { logger.warn("Unimplemented VResource object"); continue; } if (subComp instanceof VLocation) { logger.warn("Unimplemented VLocation object"); continue; } if (subComp instanceof VAlarm) { final var aresp = VAlarmUtil.processAlarm(cb, val, (VAlarm)subComp, ev, currentPrincipal, chg); if (!aresp.isOk()) { return Response.fromResponse(resp, aresp); } continue; } if (vpoll && (event || task)) { final var vresp = processCandidate((VPoll)val, subComp, evinfo, pids, chg); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Component object: " + subComp); } } /* Fix up timestamps. */ if (ev.getCreated() == null) { if (ev.getLastmod() != null) { ev.setCreated(ev.getLastmod()); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); } else { ev.updateDtstamp(); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } } if (ev.getLastmod() == null) { // created cannot be null now ev.setLastmod(ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } processTimezones(ev, ical, chg); /* Remove any recipients and originator */ if (ev.getRecipients() != null) { ev.getRecipients().clear(); } ev.setOriginator(null); if (hasXparams.value) { /* Save a text copy of the entire event as an x-property */ final Component valCopy = val.copy(); /* Remove potentially large values */ final Description desp = valCopy.getProperty(Property.DESCRIPTION); if (desp != null) { desp.setValue(null); } final Attach attachp = valCopy.getProperty(Property.ATTACH); // Don't store the entire attachment - we just need the parameters. if (attachp != null) { final Value v = attachp.getParameter(Parameter.VALUE); if (v != null) { attachp.setValue(String.valueOf(attachp.getValue().hashCode())); } } chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(BwXproperty.bedeworkIcal, null, valCopy.toString())); } chg.processChanges(ev, true, false); ev.setRecurring(ev.isRecurringEntity()); if (logger.debug()) { logger.debug(chg.toString()); logger.debug(ev.toString()); } if (masterEI != null) { // Just return notfound as this event is on its override list return Response.notFound(resp); } resp.setEntity(evinfo); return resp; } catch (final Throwable t) { if (logger.debug()) { logger.error(t); } return Response.error(resp, t); } }
NONSATD
true
final String pUri = cb.getCaladdr(attPr.getValue()); if (pUri.equals(attUri)) { /* Only update for our own attendee * We're doing a PUT and this must be the attendee updating their * partstat. We don't allow them to change other attendees * whatever the PUT content says. */ chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else {
//if (cb.getStrictness() == IcalCallback.conformanceWarn) { // warn("Had attendees for PUBLISH"); //} } final Attendee attPr = (Attendee)prop; if (evinfo.getNewEvent() || !mergeAttendees) { chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { final String pUri = cb.getCaladdr(attPr.getValue()); if (pUri.equals(attUri)) { /* Only update for our own attendee * We're doing a PUT and this must be the attendee updating their * partstat. We don't allow them to change other attendees * whatever the PUT content says. */ chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { // Use the value we currently have boolean found = false; for (final BwAttendee att: ev.getAttendees()) { if (pUri.equals(att.getAttendeeUri())) { chg.addValue(pi, att.clone()); found = true; break; }
/* ------------------- Attachment -------------------- */ chg.addValue(pi, IcalUtil.getAttachment((Attach)prop)); break; case ATTENDEE: /* ------------------- Attendee -------------------- */ if (methodType == ScheduleMethods.methodTypePublish) { if (cb.getStrictness() == IcalCallback.conformanceStrict) { return Response.notOk(resp, failed, CalFacadeException.attendeesInPublish); } //if (cb.getStrictness() == IcalCallback.conformanceWarn) { // warn("Had attendees for PUBLISH"); //} } final Attendee attPr = (Attendee)prop; if (evinfo.getNewEvent() || !mergeAttendees) { chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { final String pUri = cb.getCaladdr(attPr.getValue()); if (pUri.equals(attUri)) { /* Only update for our own attendee * We're doing a PUT and this must be the attendee updating their * partstat. We don't allow them to change other attendees * whatever the PUT content says. */ chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { // Use the value we currently have boolean found = false; for (final BwAttendee att: ev.getAttendees()) { if (pUri.equals(att.getAttendeeUri())) { chg.addValue(pi, att.clone()); found = true; break; } } if (!found) { // An added attendee final BwAttendee att = IcalUtil .getAttendee(cb, attPr); att.setPartstat(IcalDefs.partstatValNeedsAction); chg.addValue(pi, att); } } }
7,893
27
// Use the value we currently have
public static GetEntityResponse<EventInfo> toEvent( final IcalCallback cb, final BwCalendar cal, final Icalendar ical, final Component val, final boolean mergeAttendees) { final var resp = new GetEntityResponse<EventInfo>(); if (val == null) { return Response.notOk(resp, failed, "No component supplied"); } String currentPrincipal = null; final BwPrincipal principal = cb.getPrincipal(); if (principal != null) { currentPrincipal = principal.getPrincipalRef(); } final Holder<Boolean> hasXparams = new Holder<>(Boolean.FALSE); final int methodType = ical.getMethodType(); String attUri = null; if (mergeAttendees) { // We'll need this later. attUri = cb.getCaladdr(cb.getPrincipal().getPrincipalRef()); } final String colPath; if (cal == null) { colPath = null; } else { colPath = cal.getPath(); } try { final PropertyList<Property> pl = val.getProperties(); boolean vpoll = false; boolean event = false; boolean task = false; if (pl == null) { // Empty component return Response.notOk(resp, failed, "Empty component"); } final int entityType; if (val instanceof VEvent) { entityType = IcalDefs.entityTypeEvent; event = true; } else if (val instanceof VToDo) { entityType = IcalDefs.entityTypeTodo; task = true; } else if (val instanceof VJournal) { entityType = IcalDefs.entityTypeJournal; } else if (val instanceof VFreeBusy) { entityType = IcalDefs.entityTypeFreeAndBusy; } else if (val instanceof VAvailability) { entityType = IcalDefs.entityTypeVavailability; } else if (val instanceof Available) { entityType = IcalDefs.entityTypeAvailable; } else if (val instanceof VPoll) { entityType = IcalDefs.entityTypeVpoll; vpoll = true; } else { return Response.error(resp, "org.bedework.invalid.component.type: " + val.getName()); } // Get the guid from the component String guid = null; final Uid uidp = pl.getProperty(Property.UID); if (uidp != null) { testXparams(uidp, hasXparams); guid = uidp.getValue(); } if (guid == null) { /* XXX A guid is required - but are there devices out there without a * guid - and if so how do we handle it? */ return Response.notOk(resp, failed, CalFacadeException.noGuid); } /* See if we have a recurrence id */ BwDateTime ridObj = null; String rid = null; TimeZone ridTz = null; final RecurrenceId ridp = pl.getProperty(Property.RECURRENCE_ID); if (ridp != null) { testXparams(ridp, hasXparams); ridObj = BwDateTime.makeBwDateTime(ridp); if (ridObj.getRange() != null) { /* XXX What do I do with it? */ logger.warn("TRANS-TO_EVENT: Got a recurrence id range"); } rid = ridObj.getDate(); } EventInfo masterEI = null; EventInfo evinfo = null; final BwEvent ev; /* If we have a recurrence id see if we already have the master (we should * get a master + all its overrides). * * If so find the override and use the annnotation or if no override, * make one. * * If no override retrieve the event, add it to our table and then locate the * annotation. * * If there is no annotation, create one. * * It's possible we have been sent 'detached' instances of a recurring * event. This may happen if we are invited to one or more instances of a * meeting. In this case we try to retrieve the master and if it doesn't * exist we manufacture one. We consider such an instance an update to * that instance only and leave the others alone. */ /* We need this in a couple of places */ final DtStart dtStart = pl.getProperty(Property.DTSTART); /* if (rid != null) { // See if we have a new master event. If so create a proxy to that event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI == null) { masterEI = makeNewEvent(cb, chg, entityType, guid, cal); BwEvent e = masterEI.getEvent(); // XXX This seems bogus DtStart mdtStart; String bogusDate = "19980118T230000"; if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + "Z"); } else if (dtStart.getTimeZone() == null) { mdtStart = new DtStart(bogusDate); } else { mdtStart = new DtStart(bogusDate + "Z", dtStart.getTimeZone()); } setDates(e, mdtStart, null, null, chg); e.setRecurring(true); e.addRdate(ridObj); e.setSuppressed(true); ical.addComponent(masterEI); } if (masterEI != null) { evinfo = masterEI.findOverride(rid); } } */ /* If this is a recurrence instance see if we can find the master We only need this because the master may follow the overrides. */ if (rid != null) { // See if we have a new master event. If so create a proxy to this event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI != null) { evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; } } if ((evinfo == null) && (cal != null) && (cal.getCalType() != BwCalendar.calTypeInbox) && (cal.getCalType() != BwCalendar.calTypePendingInbox) && (cal.getCalType() != BwCalendar.calTypeOutbox)) { if (logger.debug()) { logger.debug("TRANS-TO_EVENT: try to fetch event with guid=" + guid); } final GetEntitiesResponse<EventInfo> eisResp = cb.getEvent(colPath, guid); if (eisResp.isError()) { return Response.fromResponse(resp, eisResp); } final var eis = eisResp.getEntities(); if (!Util.isEmpty(eis)) { if (eis.size() > 1) { // DORECUR - wrong again return Response.notOk(resp, failed, "More than one event returned for guid."); } evinfo = eis.iterator().next(); } if (logger.debug()) { if (evinfo != null) { logger.debug("TRANS-TO_EVENT: fetched event with guid"); } else { logger.debug("TRANS-TO_EVENT: did not find event with guid"); } } if (evinfo != null) { if (rid != null) { // We just retrieved it's master masterEI = evinfo; masterEI.setInstanceOnly(true); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; ical.addComponent(masterEI); } else if (methodType == ScheduleMethods.methodTypeCancel) { // This should never have an rid for cancel of entire event. evinfo.setInstanceOnly(evinfo.getEvent().getSuppressed()); } else { // Presumably sent an update for the entire event. No longer suppressed master evinfo.getEvent().setSuppressed(false); } } else if (rid != null) { /* Manufacture a master for the instance */ masterEI = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); final BwEvent e = masterEI.getEvent(); // XXX This seems bogus final DtStart mdtStart; final String bogusDate = "19980118"; final String bogusTime = "T230000"; // Base dtstart on the recurrence id. final boolean isDateType = ridObj.getDateType(); if (isDateType) { mdtStart = new DtStart(new Date(bogusDate)); } else if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + bogusTime + "Z"); } else if (ridObj.getTzid() == null) { mdtStart = new DtStart(bogusDate + bogusTime); } else { mdtStart = new DtStart(bogusDate + bogusTime, Timezones.getTz(ridObj.getTzid())); } IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), masterEI, mdtStart, null, null); e.setRecurring(true); // e.addRdate(ridObj); final var sum = (Summary)pl.getProperty(Property.SUMMARY); e.setSummary(sum.getValue()); e.setSuppressed(true); ical.addComponent(masterEI); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; masterEI.setInstanceOnly(rid != null); } } if (evinfo == null) { evinfo = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); } else if (evinfo.getEvent().getEntityType() != entityType) { return Response.notOk(resp, failed, "org.bedework.mismatched.entity.type: " + val); } final ChangeTable chg = evinfo.getChangeset( cb.getPrincipal().getPrincipalRef()); if (rid != null) { final String evrid = evinfo.getEvent().getRecurrenceId(); if ((evrid == null) || (!evrid.equals(rid))) { logger. warn("Mismatched rid ev=" + evrid + " expected " + rid); chg.changed(PropertyInfoIndex.RECURRENCE_ID, evrid, rid); // XXX spurious??? } if (masterEI.getEvent().getSuppressed()) { masterEI.getEvent().addRdate(ridObj); } } ev = evinfo.getEvent(); ev.setScheduleMethod(methodType); DtEnd dtEnd = null; if (entityType == IcalDefs.entityTypeTodo) { final Due due = pl.getProperty(Property.DUE); if (due != null ) { dtEnd = new DtEnd(due.getParameters(), due.getValue()); } } else { dtEnd = pl.getProperty(Property.DTEND); } final Duration duration = pl.getProperty(Property.DURATION); IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), evinfo, dtStart, dtEnd, duration); for (final Property prop: pl) { testXparams(prop, hasXparams); //debug("ical prop " + prop.getClass().getName()); String pval = prop.getValue(); if ((pval != null) && (pval.length() == 0)) { pval = null; } final PropertyInfoIndex pi; if (prop instanceof XProperty) { pi = PropertyInfoIndex.XPROP; } else { pi = PropertyInfoIndex.fromName(prop.getName()); } if (pi == null) { logger.debug("Unknown property with name " + prop.getName() + " class " + prop.getClass() + " and value " + pval); continue; } chg.present(pi); switch (pi) { case ACCEPT_RESPONSE: /* ------------------- Accept Response -------------------- */ String sval = prop.getValue(); if (chg.changed(pi, ev.getPollAcceptResponse(), sval)) { ev.setPollAcceptResponse(sval); } break; case ATTACH: /* ------------------- Attachment -------------------- */ chg.addValue(pi, IcalUtil.getAttachment((Attach)prop)); break; case ATTENDEE: /* ------------------- Attendee -------------------- */ if (methodType == ScheduleMethods.methodTypePublish) { if (cb.getStrictness() == IcalCallback.conformanceStrict) { return Response.notOk(resp, failed, CalFacadeException.attendeesInPublish); } //if (cb.getStrictness() == IcalCallback.conformanceWarn) { // warn("Had attendees for PUBLISH"); //} } final Attendee attPr = (Attendee)prop; if (evinfo.getNewEvent() || !mergeAttendees) { chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { final String pUri = cb.getCaladdr(attPr.getValue()); if (pUri.equals(attUri)) { /* Only update for our own attendee * We're doing a PUT and this must be the attendee updating their * partstat. We don't allow them to change other attendees * whatever the PUT content says. */ chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { // Use the value we currently have boolean found = false; for (final BwAttendee att: ev.getAttendees()) { if (pUri.equals(att.getAttendeeUri())) { chg.addValue(pi, att.clone()); found = true; break; } } if (!found) { // An added attendee final BwAttendee att = IcalUtil .getAttendee(cb, attPr); att.setPartstat(IcalDefs.partstatValNeedsAction); chg.addValue(pi, att); } } } break; case BUSYTYPE: final int ibt = BwEvent.fromBusyTypeString(pval); if (chg.changed(pi, ev.getBusyType(), ibt)) { ev.setBusyType(ibt); } break; case CATEGORIES: /* ------------------- Categories -------------------- */ final Categories cats = (Categories)prop; final TextList cl = cats.getCategories(); String lang = IcalUtil.getLang(cats); if (cl != null) { /* Got some categories */ for (final String wd: cl) { if (wd == null) { continue; } final BwString key = new BwString(lang, wd); final var fcResp = cb.findCategory(key); final BwCategory cat; if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isNotFound()) { cat = BwCategory.makeCategory(); cat.setWord(key); cb.addCategory(cat); } else { cat = fcResp.getEntity(); } chg.addValue(pi, cat); } } break; case CLASS: /* ------------------- Class -------------------- */ if (chg.changed(pi, ev.getClassification(), pval)) { ev.setClassification(pval); } break; case COMMENT: /* ------------------- Comment -------------------- */ chg.addValue(pi, new BwString(null, pval)); break; case COMPLETED: /* ------------------- Completed -------------------- */ if (chg.changed(pi, ev.getCompleted(), pval)) { ev.setCompleted(pval); } break; case CONCEPT: /* ------------------- Concept -------------------- */ final Concept c = (Concept)prop; final String cval = c.getValue(); if (cval != null) { /* Got a concept */ chg.addValue(PropertyInfoIndex.XPROP, BwXproperty.makeIcalProperty("CONCEPT", null, cval)); } break; case CONTACT: /* ------------------- Contact -------------------- */ final String altrep = getAltRepPar(prop); lang = IcalUtil.getLang(prop); final String uid = getUidPar(prop); final BwString nm = new BwString(lang, pval); BwContact contact = null; if (uid != null) { final var fcResp = cb.getContact(uid); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { final var fcResp = cb.findContact(nm); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { contact = BwContact.makeContact(); contact.setCn(nm); contact.setLink(altrep); cb.addContact(contact); } else { contact.setCn(nm); contact.setLink(altrep); } chg.addValue(pi, contact); break; case CREATED: /* ------------------- Created -------------------- */ if (chg.changed(pi, ev.getCreated(), pval)) { ev.setCreated(pval); } break; case DESCRIPTION: /* ------------------- Description -------------------- */ if (chg.changed(pi, ev.getDescription(), pval)) { ev.setDescription(pval); } break; case DTEND: /* ------------------- DtEnd -------------------- */ break; case DTSTAMP: /* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval); break; case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE: /* -------------------- Due ------------------------ */ break; case DURATION: /* ------------------- Duration -------------------- */ break; case EXDATE: /* ------------------- ExDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case EXRULE: /* ------------------- ExRule -------------------- */ chg.addValue(pi, pval); break; case FREEBUSY: /* ------------------- freebusy -------------------- */ final FreeBusy fbusy = (FreeBusy)prop; final PeriodList perpl = fbusy.getPeriods(); final Parameter par = IcalUtil.getParameter(fbusy, "FBTYPE"); final int fbtype; if (par == null) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY)) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY_TENTATIVE)) { fbtype = BwFreeBusyComponent.typeBusyTentative; } else if (par.equals(FbType.BUSY_UNAVAILABLE)) { fbtype = BwFreeBusyComponent.typeBusyUnavailable; } else if (par.equals(FbType.FREE)) { fbtype = BwFreeBusyComponent.typeFree; } else { if (logger.debug()) { logger.debug("Unsupported parameter " + par.getName()); } return Response.notOk(resp, failed, "Unsupported parameter " + par.getName()); } final BwFreeBusyComponent fbc = new BwFreeBusyComponent(); fbc.setType(fbtype); for (final Period per : perpl) { fbc.addPeriod(per); } ev.addFreeBusyPeriod(fbc); break; case GEO: /* ------------------- Geo -------------------- */ final Geo g = (Geo)prop; final BwGeo geo = new BwGeo(g.getLatitude(), g.getLongitude()); if (chg.changed(pi, ev.getGeo(), geo)) { ev.setGeo(geo); } break; case LAST_MODIFIED: /* ------------------- LastModified -------------------- */ if (chg.changed(pi, ev.getLastmod(), pval)) { ev.setLastmod(pval); } break; case LOCATION: /* ------------------- Location -------------------- */ BwLocation loc = null; //String uid = getUidPar(prop); /* At the moment Mozilla lightning is broken and this leads to all * sorts of problems. if (uid != null) { loc = cb.getLocation(uid); } */ lang = IcalUtil.getLang(prop); BwString addr = null; if (pval != null) { if (loc == null) { addr = new BwString(lang, pval); final var fcResp = cb.findLocation(addr); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { loc = fcResp.getEntity(); } } if (loc == null) { loc = BwLocation.makeLocation(); loc.setAddress(addr); cb.addLocation(loc); } } final BwLocation evloc = ev.getLocation(); if (chg.changed(pi, evloc, loc)) { // CHGTBL - this only shows that it's a different location object ev.setLocation(loc); } else if ((loc != null) && (evloc != null)) { // See if the value is changed final String evval = evloc.getAddress().getValue(); final String inval = loc.getAddress().getValue(); if (!evval.equals(inval)) { chg.changed(pi, evval, inval); evloc.getAddress().setValue(inval); } } break; case ORGANIZER: /* ------------------- Organizer -------------------- */ final BwOrganizer org = IcalUtil.getOrganizer(cb, (Organizer)prop); final BwOrganizer evorg = ev.getOrganizer(); final BwOrganizer evorgCopy; if (evorg == null) { evorgCopy = null; } else { evorgCopy = (BwOrganizer)evorg.clone(); } if (chg.changed(pi, evorgCopy, org)) { if (evorg == null) { ev.setOrganizer(org); } else { evorg.update(org); } } break; case PERCENT_COMPLETE: /* ------------------- PercentComplete -------------------- */ Integer ival = ((PercentComplete)prop).getPercentage(); if (chg.changed(pi, ev.getPercentComplete(), ival)) { ev.setPercentComplete(ival); } break; case POLL_MODE: /* ------------------- Poll mode -------------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollMode(), sval)) { ev.setPollMode(sval); } break; case POLL_PROPERTIES: /* ------------------- Poll properties ---------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollProperties(), sval)) { ev.setPollProperties(sval); } break; case POLL_WINNER: /* ------------------- Poll winner -------------------- */ ival = ((PollWinner)prop).getPollwinner(); if (chg.changed(pi, ev.getPollWinner(), ival)) { ev.setPollWinner(ival); } break; case PRIORITY: /* ------------------- Priority -------------------- */ ival = ((Priority)prop).getLevel(); if (chg.changed(pi, ev.getPriority(), ival)) { ev.setPriority(ival); } break; case RDATE: /* ------------------- RDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case RECURRENCE_ID: /* ------------------- RecurrenceID -------------------- */ // Done above break; case RELATED_TO: /* ------------------- RelatedTo -------------------- */ final RelatedTo irelto = (RelatedTo)prop; final BwRelatedTo relto = new BwRelatedTo(); final String parval = IcalUtil.getParameterVal(irelto, "RELTYPE"); if (parval != null) { relto.setRelType(parval); } relto.setValue(irelto.getValue()); if (chg.changed(pi, ev.getRelatedTo(), relto)) { ev.setRelatedTo(relto); } break; case REQUEST_STATUS: /* ------------------- RequestStatus -------------------- */ final BwRequestStatus rs = BwRequestStatus .fromRequestStatus((RequestStatus)prop); chg.addValue(pi, rs); break; case RESOURCES: /* ------------------- Resources -------------------- */ final TextList rl = ((Resources)prop).getResources(); if (rl != null) { /* Got some resources */ lang = IcalUtil.getLang(prop); for (final String s: rl) { final BwString rsrc = new BwString(lang, s); chg.addValue(pi, rsrc); } } break; case RRULE: /* ------------------- RRule -------------------- */ chg.addValue(pi, pval); break; case SEQUENCE: /* ------------------- Sequence -------------------- */ final int seq = ((Sequence)prop).getSequenceNo(); if (seq != ev.getSequence()) { chg.changed(pi, ev.getSequence(), seq); ev.setSequence(seq); } break; case STATUS: /* ------------------- Status -------------------- */ if (chg.changed(pi, ev.getStatus(), pval)) { ev.setStatus(pval); } break; case SUMMARY: /* ------------------- Summary -------------------- */ if (chg.changed(pi, ev.getSummary(), pval)) { ev.setSummary(pval); } break; case TRANSP: /* ------------------- Transp -------------------- */ if (chg.changed(pi, ev.getPeruserTransparency( cb.getPrincipal() .getPrincipalRef()), pval)) { final BwXproperty pu = ev.setPeruserTransparency( cb.getPrincipal().getPrincipalRef(), pval); if (pu != null) { chg.addValue(PropertyInfoIndex.XPROP, pu); } } break; case UID: /* ------------------- Uid -------------------- */ /* We did this above */ break; case URL: /* ------------------- Url -------------------- */ if (chg.changed(pi, ev.getLink(), pval)) { ev.setLink(pval); } break; case XPROP: /* ------------------------- x-property --------------------------- */ final String name = prop.getName(); if (name.equalsIgnoreCase(BwXproperty.bedeworkCost)) { if (chg.changed(PropertyInfoIndex.COST, ev.getCost(), pval)) { ev.setCost(pval); } break; } if (name.equalsIgnoreCase(BwXproperty.xBedeworkCategories)) { if (checkCategory(cb, chg, ev, null, pval)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkLocation)) { if (checkLocation(cb, chg, ev, prop)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkContact)) { if (checkContact(cb, chg, ev, null, pval)) { break; } } /* See if this is an x-category that can be converted to a real category */ final XProperty xp = (XProperty)prop; chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(name, xp.getParameters() .toString(), pval)); break; default: if (logger.debug()) { logger.debug("Unsupported property with index " + pi + "; class " + prop.getClass() + " and value " + pval); } } } /* =================== Process sub-components =============== */ final ComponentList<Component> subComps; if (val instanceof ComponentContainer) { subComps = ((ComponentContainer<Component>)val).getComponents(); } else { subComps = null; } final Set<Integer> pids; if (vpoll) { pids = new TreeSet<>(); final BwEvent vp = evinfo.getEvent(); if (!Util.isEmpty(vp.getPollItems())) { vp.clearPollItems(); } } else { pids = null; } if (!Util.isEmpty(subComps)) { for (final var subComp: subComps) { if (subComp instanceof Available) { if (!(val instanceof VAvailability)) { return Response.error(resp, "AVAILABLE only valid in VAVAILABLE"); } final var avlResp = processAvailable(cb, cal, ical, (VAvailability)val, (Available)subComp, evinfo); if (!avlResp.isOk()) { return Response.fromResponse(resp, avlResp); } continue; } if (subComp instanceof Participant) { if (vpoll) { final var vresp = processVoter(cb, (VPoll)val, (Participant)subComp, evinfo, chg, mergeAttendees); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Participant object"); continue; } if (subComp instanceof VResource) { logger.warn("Unimplemented VResource object"); continue; } if (subComp instanceof VLocation) { logger.warn("Unimplemented VLocation object"); continue; } if (subComp instanceof VAlarm) { final var aresp = VAlarmUtil.processAlarm(cb, val, (VAlarm)subComp, ev, currentPrincipal, chg); if (!aresp.isOk()) { return Response.fromResponse(resp, aresp); } continue; } if (vpoll && (event || task)) { final var vresp = processCandidate((VPoll)val, subComp, evinfo, pids, chg); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Component object: " + subComp); } } /* Fix up timestamps. */ if (ev.getCreated() == null) { if (ev.getLastmod() != null) { ev.setCreated(ev.getLastmod()); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); } else { ev.updateDtstamp(); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } } if (ev.getLastmod() == null) { // created cannot be null now ev.setLastmod(ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } processTimezones(ev, ical, chg); /* Remove any recipients and originator */ if (ev.getRecipients() != null) { ev.getRecipients().clear(); } ev.setOriginator(null); if (hasXparams.value) { /* Save a text copy of the entire event as an x-property */ final Component valCopy = val.copy(); /* Remove potentially large values */ final Description desp = valCopy.getProperty(Property.DESCRIPTION); if (desp != null) { desp.setValue(null); } final Attach attachp = valCopy.getProperty(Property.ATTACH); // Don't store the entire attachment - we just need the parameters. if (attachp != null) { final Value v = attachp.getParameter(Parameter.VALUE); if (v != null) { attachp.setValue(String.valueOf(attachp.getValue().hashCode())); } } chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(BwXproperty.bedeworkIcal, null, valCopy.toString())); } chg.processChanges(ev, true, false); ev.setRecurring(ev.isRecurringEntity()); if (logger.debug()) { logger.debug(chg.toString()); logger.debug(ev.toString()); } if (masterEI != null) { // Just return notfound as this event is on its override list return Response.notFound(resp); } resp.setEntity(evinfo); return resp; } catch (final Throwable t) { if (logger.debug()) { logger.error(t); } return Response.error(resp, t); } }
NONSATD
true
chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { // Use the value we currently have boolean found = false; for (final BwAttendee att: ev.getAttendees()) {
} else { final String pUri = cb.getCaladdr(attPr.getValue()); if (pUri.equals(attUri)) { /* Only update for our own attendee * We're doing a PUT and this must be the attendee updating their * partstat. We don't allow them to change other attendees * whatever the PUT content says. */ chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { // Use the value we currently have boolean found = false; for (final BwAttendee att: ev.getAttendees()) { if (pUri.equals(att.getAttendeeUri())) { chg.addValue(pi, att.clone()); found = true; break; } } if (!found) { // An added attendee
return Response.notOk(resp, failed, CalFacadeException.attendeesInPublish); } //if (cb.getStrictness() == IcalCallback.conformanceWarn) { // warn("Had attendees for PUBLISH"); //} } final Attendee attPr = (Attendee)prop; if (evinfo.getNewEvent() || !mergeAttendees) { chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { final String pUri = cb.getCaladdr(attPr.getValue()); if (pUri.equals(attUri)) { /* Only update for our own attendee * We're doing a PUT and this must be the attendee updating their * partstat. We don't allow them to change other attendees * whatever the PUT content says. */ chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { // Use the value we currently have boolean found = false; for (final BwAttendee att: ev.getAttendees()) { if (pUri.equals(att.getAttendeeUri())) { chg.addValue(pi, att.clone()); found = true; break; } } if (!found) { // An added attendee final BwAttendee att = IcalUtil .getAttendee(cb, attPr); att.setPartstat(IcalDefs.partstatValNeedsAction); chg.addValue(pi, att); } } } break; case BUSYTYPE: final int ibt = BwEvent.fromBusyTypeString(pval);
7,893
28
// An added attendee
public static GetEntityResponse<EventInfo> toEvent( final IcalCallback cb, final BwCalendar cal, final Icalendar ical, final Component val, final boolean mergeAttendees) { final var resp = new GetEntityResponse<EventInfo>(); if (val == null) { return Response.notOk(resp, failed, "No component supplied"); } String currentPrincipal = null; final BwPrincipal principal = cb.getPrincipal(); if (principal != null) { currentPrincipal = principal.getPrincipalRef(); } final Holder<Boolean> hasXparams = new Holder<>(Boolean.FALSE); final int methodType = ical.getMethodType(); String attUri = null; if (mergeAttendees) { // We'll need this later. attUri = cb.getCaladdr(cb.getPrincipal().getPrincipalRef()); } final String colPath; if (cal == null) { colPath = null; } else { colPath = cal.getPath(); } try { final PropertyList<Property> pl = val.getProperties(); boolean vpoll = false; boolean event = false; boolean task = false; if (pl == null) { // Empty component return Response.notOk(resp, failed, "Empty component"); } final int entityType; if (val instanceof VEvent) { entityType = IcalDefs.entityTypeEvent; event = true; } else if (val instanceof VToDo) { entityType = IcalDefs.entityTypeTodo; task = true; } else if (val instanceof VJournal) { entityType = IcalDefs.entityTypeJournal; } else if (val instanceof VFreeBusy) { entityType = IcalDefs.entityTypeFreeAndBusy; } else if (val instanceof VAvailability) { entityType = IcalDefs.entityTypeVavailability; } else if (val instanceof Available) { entityType = IcalDefs.entityTypeAvailable; } else if (val instanceof VPoll) { entityType = IcalDefs.entityTypeVpoll; vpoll = true; } else { return Response.error(resp, "org.bedework.invalid.component.type: " + val.getName()); } // Get the guid from the component String guid = null; final Uid uidp = pl.getProperty(Property.UID); if (uidp != null) { testXparams(uidp, hasXparams); guid = uidp.getValue(); } if (guid == null) { /* XXX A guid is required - but are there devices out there without a * guid - and if so how do we handle it? */ return Response.notOk(resp, failed, CalFacadeException.noGuid); } /* See if we have a recurrence id */ BwDateTime ridObj = null; String rid = null; TimeZone ridTz = null; final RecurrenceId ridp = pl.getProperty(Property.RECURRENCE_ID); if (ridp != null) { testXparams(ridp, hasXparams); ridObj = BwDateTime.makeBwDateTime(ridp); if (ridObj.getRange() != null) { /* XXX What do I do with it? */ logger.warn("TRANS-TO_EVENT: Got a recurrence id range"); } rid = ridObj.getDate(); } EventInfo masterEI = null; EventInfo evinfo = null; final BwEvent ev; /* If we have a recurrence id see if we already have the master (we should * get a master + all its overrides). * * If so find the override and use the annnotation or if no override, * make one. * * If no override retrieve the event, add it to our table and then locate the * annotation. * * If there is no annotation, create one. * * It's possible we have been sent 'detached' instances of a recurring * event. This may happen if we are invited to one or more instances of a * meeting. In this case we try to retrieve the master and if it doesn't * exist we manufacture one. We consider such an instance an update to * that instance only and leave the others alone. */ /* We need this in a couple of places */ final DtStart dtStart = pl.getProperty(Property.DTSTART); /* if (rid != null) { // See if we have a new master event. If so create a proxy to that event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI == null) { masterEI = makeNewEvent(cb, chg, entityType, guid, cal); BwEvent e = masterEI.getEvent(); // XXX This seems bogus DtStart mdtStart; String bogusDate = "19980118T230000"; if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + "Z"); } else if (dtStart.getTimeZone() == null) { mdtStart = new DtStart(bogusDate); } else { mdtStart = new DtStart(bogusDate + "Z", dtStart.getTimeZone()); } setDates(e, mdtStart, null, null, chg); e.setRecurring(true); e.addRdate(ridObj); e.setSuppressed(true); ical.addComponent(masterEI); } if (masterEI != null) { evinfo = masterEI.findOverride(rid); } } */ /* If this is a recurrence instance see if we can find the master We only need this because the master may follow the overrides. */ if (rid != null) { // See if we have a new master event. If so create a proxy to this event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI != null) { evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; } } if ((evinfo == null) && (cal != null) && (cal.getCalType() != BwCalendar.calTypeInbox) && (cal.getCalType() != BwCalendar.calTypePendingInbox) && (cal.getCalType() != BwCalendar.calTypeOutbox)) { if (logger.debug()) { logger.debug("TRANS-TO_EVENT: try to fetch event with guid=" + guid); } final GetEntitiesResponse<EventInfo> eisResp = cb.getEvent(colPath, guid); if (eisResp.isError()) { return Response.fromResponse(resp, eisResp); } final var eis = eisResp.getEntities(); if (!Util.isEmpty(eis)) { if (eis.size() > 1) { // DORECUR - wrong again return Response.notOk(resp, failed, "More than one event returned for guid."); } evinfo = eis.iterator().next(); } if (logger.debug()) { if (evinfo != null) { logger.debug("TRANS-TO_EVENT: fetched event with guid"); } else { logger.debug("TRANS-TO_EVENT: did not find event with guid"); } } if (evinfo != null) { if (rid != null) { // We just retrieved it's master masterEI = evinfo; masterEI.setInstanceOnly(true); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; ical.addComponent(masterEI); } else if (methodType == ScheduleMethods.methodTypeCancel) { // This should never have an rid for cancel of entire event. evinfo.setInstanceOnly(evinfo.getEvent().getSuppressed()); } else { // Presumably sent an update for the entire event. No longer suppressed master evinfo.getEvent().setSuppressed(false); } } else if (rid != null) { /* Manufacture a master for the instance */ masterEI = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); final BwEvent e = masterEI.getEvent(); // XXX This seems bogus final DtStart mdtStart; final String bogusDate = "19980118"; final String bogusTime = "T230000"; // Base dtstart on the recurrence id. final boolean isDateType = ridObj.getDateType(); if (isDateType) { mdtStart = new DtStart(new Date(bogusDate)); } else if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + bogusTime + "Z"); } else if (ridObj.getTzid() == null) { mdtStart = new DtStart(bogusDate + bogusTime); } else { mdtStart = new DtStart(bogusDate + bogusTime, Timezones.getTz(ridObj.getTzid())); } IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), masterEI, mdtStart, null, null); e.setRecurring(true); // e.addRdate(ridObj); final var sum = (Summary)pl.getProperty(Property.SUMMARY); e.setSummary(sum.getValue()); e.setSuppressed(true); ical.addComponent(masterEI); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; masterEI.setInstanceOnly(rid != null); } } if (evinfo == null) { evinfo = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); } else if (evinfo.getEvent().getEntityType() != entityType) { return Response.notOk(resp, failed, "org.bedework.mismatched.entity.type: " + val); } final ChangeTable chg = evinfo.getChangeset( cb.getPrincipal().getPrincipalRef()); if (rid != null) { final String evrid = evinfo.getEvent().getRecurrenceId(); if ((evrid == null) || (!evrid.equals(rid))) { logger. warn("Mismatched rid ev=" + evrid + " expected " + rid); chg.changed(PropertyInfoIndex.RECURRENCE_ID, evrid, rid); // XXX spurious??? } if (masterEI.getEvent().getSuppressed()) { masterEI.getEvent().addRdate(ridObj); } } ev = evinfo.getEvent(); ev.setScheduleMethod(methodType); DtEnd dtEnd = null; if (entityType == IcalDefs.entityTypeTodo) { final Due due = pl.getProperty(Property.DUE); if (due != null ) { dtEnd = new DtEnd(due.getParameters(), due.getValue()); } } else { dtEnd = pl.getProperty(Property.DTEND); } final Duration duration = pl.getProperty(Property.DURATION); IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), evinfo, dtStart, dtEnd, duration); for (final Property prop: pl) { testXparams(prop, hasXparams); //debug("ical prop " + prop.getClass().getName()); String pval = prop.getValue(); if ((pval != null) && (pval.length() == 0)) { pval = null; } final PropertyInfoIndex pi; if (prop instanceof XProperty) { pi = PropertyInfoIndex.XPROP; } else { pi = PropertyInfoIndex.fromName(prop.getName()); } if (pi == null) { logger.debug("Unknown property with name " + prop.getName() + " class " + prop.getClass() + " and value " + pval); continue; } chg.present(pi); switch (pi) { case ACCEPT_RESPONSE: /* ------------------- Accept Response -------------------- */ String sval = prop.getValue(); if (chg.changed(pi, ev.getPollAcceptResponse(), sval)) { ev.setPollAcceptResponse(sval); } break; case ATTACH: /* ------------------- Attachment -------------------- */ chg.addValue(pi, IcalUtil.getAttachment((Attach)prop)); break; case ATTENDEE: /* ------------------- Attendee -------------------- */ if (methodType == ScheduleMethods.methodTypePublish) { if (cb.getStrictness() == IcalCallback.conformanceStrict) { return Response.notOk(resp, failed, CalFacadeException.attendeesInPublish); } //if (cb.getStrictness() == IcalCallback.conformanceWarn) { // warn("Had attendees for PUBLISH"); //} } final Attendee attPr = (Attendee)prop; if (evinfo.getNewEvent() || !mergeAttendees) { chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { final String pUri = cb.getCaladdr(attPr.getValue()); if (pUri.equals(attUri)) { /* Only update for our own attendee * We're doing a PUT and this must be the attendee updating their * partstat. We don't allow them to change other attendees * whatever the PUT content says. */ chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { // Use the value we currently have boolean found = false; for (final BwAttendee att: ev.getAttendees()) { if (pUri.equals(att.getAttendeeUri())) { chg.addValue(pi, att.clone()); found = true; break; } } if (!found) { // An added attendee final BwAttendee att = IcalUtil .getAttendee(cb, attPr); att.setPartstat(IcalDefs.partstatValNeedsAction); chg.addValue(pi, att); } } } break; case BUSYTYPE: final int ibt = BwEvent.fromBusyTypeString(pval); if (chg.changed(pi, ev.getBusyType(), ibt)) { ev.setBusyType(ibt); } break; case CATEGORIES: /* ------------------- Categories -------------------- */ final Categories cats = (Categories)prop; final TextList cl = cats.getCategories(); String lang = IcalUtil.getLang(cats); if (cl != null) { /* Got some categories */ for (final String wd: cl) { if (wd == null) { continue; } final BwString key = new BwString(lang, wd); final var fcResp = cb.findCategory(key); final BwCategory cat; if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isNotFound()) { cat = BwCategory.makeCategory(); cat.setWord(key); cb.addCategory(cat); } else { cat = fcResp.getEntity(); } chg.addValue(pi, cat); } } break; case CLASS: /* ------------------- Class -------------------- */ if (chg.changed(pi, ev.getClassification(), pval)) { ev.setClassification(pval); } break; case COMMENT: /* ------------------- Comment -------------------- */ chg.addValue(pi, new BwString(null, pval)); break; case COMPLETED: /* ------------------- Completed -------------------- */ if (chg.changed(pi, ev.getCompleted(), pval)) { ev.setCompleted(pval); } break; case CONCEPT: /* ------------------- Concept -------------------- */ final Concept c = (Concept)prop; final String cval = c.getValue(); if (cval != null) { /* Got a concept */ chg.addValue(PropertyInfoIndex.XPROP, BwXproperty.makeIcalProperty("CONCEPT", null, cval)); } break; case CONTACT: /* ------------------- Contact -------------------- */ final String altrep = getAltRepPar(prop); lang = IcalUtil.getLang(prop); final String uid = getUidPar(prop); final BwString nm = new BwString(lang, pval); BwContact contact = null; if (uid != null) { final var fcResp = cb.getContact(uid); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { final var fcResp = cb.findContact(nm); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { contact = BwContact.makeContact(); contact.setCn(nm); contact.setLink(altrep); cb.addContact(contact); } else { contact.setCn(nm); contact.setLink(altrep); } chg.addValue(pi, contact); break; case CREATED: /* ------------------- Created -------------------- */ if (chg.changed(pi, ev.getCreated(), pval)) { ev.setCreated(pval); } break; case DESCRIPTION: /* ------------------- Description -------------------- */ if (chg.changed(pi, ev.getDescription(), pval)) { ev.setDescription(pval); } break; case DTEND: /* ------------------- DtEnd -------------------- */ break; case DTSTAMP: /* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval); break; case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE: /* -------------------- Due ------------------------ */ break; case DURATION: /* ------------------- Duration -------------------- */ break; case EXDATE: /* ------------------- ExDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case EXRULE: /* ------------------- ExRule -------------------- */ chg.addValue(pi, pval); break; case FREEBUSY: /* ------------------- freebusy -------------------- */ final FreeBusy fbusy = (FreeBusy)prop; final PeriodList perpl = fbusy.getPeriods(); final Parameter par = IcalUtil.getParameter(fbusy, "FBTYPE"); final int fbtype; if (par == null) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY)) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY_TENTATIVE)) { fbtype = BwFreeBusyComponent.typeBusyTentative; } else if (par.equals(FbType.BUSY_UNAVAILABLE)) { fbtype = BwFreeBusyComponent.typeBusyUnavailable; } else if (par.equals(FbType.FREE)) { fbtype = BwFreeBusyComponent.typeFree; } else { if (logger.debug()) { logger.debug("Unsupported parameter " + par.getName()); } return Response.notOk(resp, failed, "Unsupported parameter " + par.getName()); } final BwFreeBusyComponent fbc = new BwFreeBusyComponent(); fbc.setType(fbtype); for (final Period per : perpl) { fbc.addPeriod(per); } ev.addFreeBusyPeriod(fbc); break; case GEO: /* ------------------- Geo -------------------- */ final Geo g = (Geo)prop; final BwGeo geo = new BwGeo(g.getLatitude(), g.getLongitude()); if (chg.changed(pi, ev.getGeo(), geo)) { ev.setGeo(geo); } break; case LAST_MODIFIED: /* ------------------- LastModified -------------------- */ if (chg.changed(pi, ev.getLastmod(), pval)) { ev.setLastmod(pval); } break; case LOCATION: /* ------------------- Location -------------------- */ BwLocation loc = null; //String uid = getUidPar(prop); /* At the moment Mozilla lightning is broken and this leads to all * sorts of problems. if (uid != null) { loc = cb.getLocation(uid); } */ lang = IcalUtil.getLang(prop); BwString addr = null; if (pval != null) { if (loc == null) { addr = new BwString(lang, pval); final var fcResp = cb.findLocation(addr); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { loc = fcResp.getEntity(); } } if (loc == null) { loc = BwLocation.makeLocation(); loc.setAddress(addr); cb.addLocation(loc); } } final BwLocation evloc = ev.getLocation(); if (chg.changed(pi, evloc, loc)) { // CHGTBL - this only shows that it's a different location object ev.setLocation(loc); } else if ((loc != null) && (evloc != null)) { // See if the value is changed final String evval = evloc.getAddress().getValue(); final String inval = loc.getAddress().getValue(); if (!evval.equals(inval)) { chg.changed(pi, evval, inval); evloc.getAddress().setValue(inval); } } break; case ORGANIZER: /* ------------------- Organizer -------------------- */ final BwOrganizer org = IcalUtil.getOrganizer(cb, (Organizer)prop); final BwOrganizer evorg = ev.getOrganizer(); final BwOrganizer evorgCopy; if (evorg == null) { evorgCopy = null; } else { evorgCopy = (BwOrganizer)evorg.clone(); } if (chg.changed(pi, evorgCopy, org)) { if (evorg == null) { ev.setOrganizer(org); } else { evorg.update(org); } } break; case PERCENT_COMPLETE: /* ------------------- PercentComplete -------------------- */ Integer ival = ((PercentComplete)prop).getPercentage(); if (chg.changed(pi, ev.getPercentComplete(), ival)) { ev.setPercentComplete(ival); } break; case POLL_MODE: /* ------------------- Poll mode -------------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollMode(), sval)) { ev.setPollMode(sval); } break; case POLL_PROPERTIES: /* ------------------- Poll properties ---------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollProperties(), sval)) { ev.setPollProperties(sval); } break; case POLL_WINNER: /* ------------------- Poll winner -------------------- */ ival = ((PollWinner)prop).getPollwinner(); if (chg.changed(pi, ev.getPollWinner(), ival)) { ev.setPollWinner(ival); } break; case PRIORITY: /* ------------------- Priority -------------------- */ ival = ((Priority)prop).getLevel(); if (chg.changed(pi, ev.getPriority(), ival)) { ev.setPriority(ival); } break; case RDATE: /* ------------------- RDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case RECURRENCE_ID: /* ------------------- RecurrenceID -------------------- */ // Done above break; case RELATED_TO: /* ------------------- RelatedTo -------------------- */ final RelatedTo irelto = (RelatedTo)prop; final BwRelatedTo relto = new BwRelatedTo(); final String parval = IcalUtil.getParameterVal(irelto, "RELTYPE"); if (parval != null) { relto.setRelType(parval); } relto.setValue(irelto.getValue()); if (chg.changed(pi, ev.getRelatedTo(), relto)) { ev.setRelatedTo(relto); } break; case REQUEST_STATUS: /* ------------------- RequestStatus -------------------- */ final BwRequestStatus rs = BwRequestStatus .fromRequestStatus((RequestStatus)prop); chg.addValue(pi, rs); break; case RESOURCES: /* ------------------- Resources -------------------- */ final TextList rl = ((Resources)prop).getResources(); if (rl != null) { /* Got some resources */ lang = IcalUtil.getLang(prop); for (final String s: rl) { final BwString rsrc = new BwString(lang, s); chg.addValue(pi, rsrc); } } break; case RRULE: /* ------------------- RRule -------------------- */ chg.addValue(pi, pval); break; case SEQUENCE: /* ------------------- Sequence -------------------- */ final int seq = ((Sequence)prop).getSequenceNo(); if (seq != ev.getSequence()) { chg.changed(pi, ev.getSequence(), seq); ev.setSequence(seq); } break; case STATUS: /* ------------------- Status -------------------- */ if (chg.changed(pi, ev.getStatus(), pval)) { ev.setStatus(pval); } break; case SUMMARY: /* ------------------- Summary -------------------- */ if (chg.changed(pi, ev.getSummary(), pval)) { ev.setSummary(pval); } break; case TRANSP: /* ------------------- Transp -------------------- */ if (chg.changed(pi, ev.getPeruserTransparency( cb.getPrincipal() .getPrincipalRef()), pval)) { final BwXproperty pu = ev.setPeruserTransparency( cb.getPrincipal().getPrincipalRef(), pval); if (pu != null) { chg.addValue(PropertyInfoIndex.XPROP, pu); } } break; case UID: /* ------------------- Uid -------------------- */ /* We did this above */ break; case URL: /* ------------------- Url -------------------- */ if (chg.changed(pi, ev.getLink(), pval)) { ev.setLink(pval); } break; case XPROP: /* ------------------------- x-property --------------------------- */ final String name = prop.getName(); if (name.equalsIgnoreCase(BwXproperty.bedeworkCost)) { if (chg.changed(PropertyInfoIndex.COST, ev.getCost(), pval)) { ev.setCost(pval); } break; } if (name.equalsIgnoreCase(BwXproperty.xBedeworkCategories)) { if (checkCategory(cb, chg, ev, null, pval)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkLocation)) { if (checkLocation(cb, chg, ev, prop)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkContact)) { if (checkContact(cb, chg, ev, null, pval)) { break; } } /* See if this is an x-category that can be converted to a real category */ final XProperty xp = (XProperty)prop; chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(name, xp.getParameters() .toString(), pval)); break; default: if (logger.debug()) { logger.debug("Unsupported property with index " + pi + "; class " + prop.getClass() + " and value " + pval); } } } /* =================== Process sub-components =============== */ final ComponentList<Component> subComps; if (val instanceof ComponentContainer) { subComps = ((ComponentContainer<Component>)val).getComponents(); } else { subComps = null; } final Set<Integer> pids; if (vpoll) { pids = new TreeSet<>(); final BwEvent vp = evinfo.getEvent(); if (!Util.isEmpty(vp.getPollItems())) { vp.clearPollItems(); } } else { pids = null; } if (!Util.isEmpty(subComps)) { for (final var subComp: subComps) { if (subComp instanceof Available) { if (!(val instanceof VAvailability)) { return Response.error(resp, "AVAILABLE only valid in VAVAILABLE"); } final var avlResp = processAvailable(cb, cal, ical, (VAvailability)val, (Available)subComp, evinfo); if (!avlResp.isOk()) { return Response.fromResponse(resp, avlResp); } continue; } if (subComp instanceof Participant) { if (vpoll) { final var vresp = processVoter(cb, (VPoll)val, (Participant)subComp, evinfo, chg, mergeAttendees); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Participant object"); continue; } if (subComp instanceof VResource) { logger.warn("Unimplemented VResource object"); continue; } if (subComp instanceof VLocation) { logger.warn("Unimplemented VLocation object"); continue; } if (subComp instanceof VAlarm) { final var aresp = VAlarmUtil.processAlarm(cb, val, (VAlarm)subComp, ev, currentPrincipal, chg); if (!aresp.isOk()) { return Response.fromResponse(resp, aresp); } continue; } if (vpoll && (event || task)) { final var vresp = processCandidate((VPoll)val, subComp, evinfo, pids, chg); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Component object: " + subComp); } } /* Fix up timestamps. */ if (ev.getCreated() == null) { if (ev.getLastmod() != null) { ev.setCreated(ev.getLastmod()); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); } else { ev.updateDtstamp(); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } } if (ev.getLastmod() == null) { // created cannot be null now ev.setLastmod(ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } processTimezones(ev, ical, chg); /* Remove any recipients and originator */ if (ev.getRecipients() != null) { ev.getRecipients().clear(); } ev.setOriginator(null); if (hasXparams.value) { /* Save a text copy of the entire event as an x-property */ final Component valCopy = val.copy(); /* Remove potentially large values */ final Description desp = valCopy.getProperty(Property.DESCRIPTION); if (desp != null) { desp.setValue(null); } final Attach attachp = valCopy.getProperty(Property.ATTACH); // Don't store the entire attachment - we just need the parameters. if (attachp != null) { final Value v = attachp.getParameter(Parameter.VALUE); if (v != null) { attachp.setValue(String.valueOf(attachp.getValue().hashCode())); } } chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(BwXproperty.bedeworkIcal, null, valCopy.toString())); } chg.processChanges(ev, true, false); ev.setRecurring(ev.isRecurringEntity()); if (logger.debug()) { logger.debug(chg.toString()); logger.debug(ev.toString()); } if (masterEI != null) { // Just return notfound as this event is on its override list return Response.notFound(resp); } resp.setEntity(evinfo); return resp; } catch (final Throwable t) { if (logger.debug()) { logger.error(t); } return Response.error(resp, t); } }
NONSATD
true
} if (!found) { // An added attendee final BwAttendee att = IcalUtil .getAttendee(cb, attPr);
// Use the value we currently have boolean found = false; for (final BwAttendee att: ev.getAttendees()) { if (pUri.equals(att.getAttendeeUri())) { chg.addValue(pi, att.clone()); found = true; break; } } if (!found) { // An added attendee final BwAttendee att = IcalUtil .getAttendee(cb, attPr); att.setPartstat(IcalDefs.partstatValNeedsAction); chg.addValue(pi, att); } } } break; case BUSYTYPE: final int ibt = BwEvent.fromBusyTypeString(pval);
} else { final String pUri = cb.getCaladdr(attPr.getValue()); if (pUri.equals(attUri)) { /* Only update for our own attendee * We're doing a PUT and this must be the attendee updating their * partstat. We don't allow them to change other attendees * whatever the PUT content says. */ chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { // Use the value we currently have boolean found = false; for (final BwAttendee att: ev.getAttendees()) { if (pUri.equals(att.getAttendeeUri())) { chg.addValue(pi, att.clone()); found = true; break; } } if (!found) { // An added attendee final BwAttendee att = IcalUtil .getAttendee(cb, attPr); att.setPartstat(IcalDefs.partstatValNeedsAction); chg.addValue(pi, att); } } } break; case BUSYTYPE: final int ibt = BwEvent.fromBusyTypeString(pval); if (chg.changed(pi, ev.getBusyType(), ibt)) { ev.setBusyType(ibt); } break; case CATEGORIES: /* ------------------- Categories -------------------- */ final Categories cats = (Categories)prop; final TextList cl = cats.getCategories();
7,893
29
/* ------------------- Categories -------------------- */
public static GetEntityResponse<EventInfo> toEvent( final IcalCallback cb, final BwCalendar cal, final Icalendar ical, final Component val, final boolean mergeAttendees) { final var resp = new GetEntityResponse<EventInfo>(); if (val == null) { return Response.notOk(resp, failed, "No component supplied"); } String currentPrincipal = null; final BwPrincipal principal = cb.getPrincipal(); if (principal != null) { currentPrincipal = principal.getPrincipalRef(); } final Holder<Boolean> hasXparams = new Holder<>(Boolean.FALSE); final int methodType = ical.getMethodType(); String attUri = null; if (mergeAttendees) { // We'll need this later. attUri = cb.getCaladdr(cb.getPrincipal().getPrincipalRef()); } final String colPath; if (cal == null) { colPath = null; } else { colPath = cal.getPath(); } try { final PropertyList<Property> pl = val.getProperties(); boolean vpoll = false; boolean event = false; boolean task = false; if (pl == null) { // Empty component return Response.notOk(resp, failed, "Empty component"); } final int entityType; if (val instanceof VEvent) { entityType = IcalDefs.entityTypeEvent; event = true; } else if (val instanceof VToDo) { entityType = IcalDefs.entityTypeTodo; task = true; } else if (val instanceof VJournal) { entityType = IcalDefs.entityTypeJournal; } else if (val instanceof VFreeBusy) { entityType = IcalDefs.entityTypeFreeAndBusy; } else if (val instanceof VAvailability) { entityType = IcalDefs.entityTypeVavailability; } else if (val instanceof Available) { entityType = IcalDefs.entityTypeAvailable; } else if (val instanceof VPoll) { entityType = IcalDefs.entityTypeVpoll; vpoll = true; } else { return Response.error(resp, "org.bedework.invalid.component.type: " + val.getName()); } // Get the guid from the component String guid = null; final Uid uidp = pl.getProperty(Property.UID); if (uidp != null) { testXparams(uidp, hasXparams); guid = uidp.getValue(); } if (guid == null) { /* XXX A guid is required - but are there devices out there without a * guid - and if so how do we handle it? */ return Response.notOk(resp, failed, CalFacadeException.noGuid); } /* See if we have a recurrence id */ BwDateTime ridObj = null; String rid = null; TimeZone ridTz = null; final RecurrenceId ridp = pl.getProperty(Property.RECURRENCE_ID); if (ridp != null) { testXparams(ridp, hasXparams); ridObj = BwDateTime.makeBwDateTime(ridp); if (ridObj.getRange() != null) { /* XXX What do I do with it? */ logger.warn("TRANS-TO_EVENT: Got a recurrence id range"); } rid = ridObj.getDate(); } EventInfo masterEI = null; EventInfo evinfo = null; final BwEvent ev; /* If we have a recurrence id see if we already have the master (we should * get a master + all its overrides). * * If so find the override and use the annnotation or if no override, * make one. * * If no override retrieve the event, add it to our table and then locate the * annotation. * * If there is no annotation, create one. * * It's possible we have been sent 'detached' instances of a recurring * event. This may happen if we are invited to one or more instances of a * meeting. In this case we try to retrieve the master and if it doesn't * exist we manufacture one. We consider such an instance an update to * that instance only and leave the others alone. */ /* We need this in a couple of places */ final DtStart dtStart = pl.getProperty(Property.DTSTART); /* if (rid != null) { // See if we have a new master event. If so create a proxy to that event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI == null) { masterEI = makeNewEvent(cb, chg, entityType, guid, cal); BwEvent e = masterEI.getEvent(); // XXX This seems bogus DtStart mdtStart; String bogusDate = "19980118T230000"; if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + "Z"); } else if (dtStart.getTimeZone() == null) { mdtStart = new DtStart(bogusDate); } else { mdtStart = new DtStart(bogusDate + "Z", dtStart.getTimeZone()); } setDates(e, mdtStart, null, null, chg); e.setRecurring(true); e.addRdate(ridObj); e.setSuppressed(true); ical.addComponent(masterEI); } if (masterEI != null) { evinfo = masterEI.findOverride(rid); } } */ /* If this is a recurrence instance see if we can find the master We only need this because the master may follow the overrides. */ if (rid != null) { // See if we have a new master event. If so create a proxy to this event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI != null) { evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; } } if ((evinfo == null) && (cal != null) && (cal.getCalType() != BwCalendar.calTypeInbox) && (cal.getCalType() != BwCalendar.calTypePendingInbox) && (cal.getCalType() != BwCalendar.calTypeOutbox)) { if (logger.debug()) { logger.debug("TRANS-TO_EVENT: try to fetch event with guid=" + guid); } final GetEntitiesResponse<EventInfo> eisResp = cb.getEvent(colPath, guid); if (eisResp.isError()) { return Response.fromResponse(resp, eisResp); } final var eis = eisResp.getEntities(); if (!Util.isEmpty(eis)) { if (eis.size() > 1) { // DORECUR - wrong again return Response.notOk(resp, failed, "More than one event returned for guid."); } evinfo = eis.iterator().next(); } if (logger.debug()) { if (evinfo != null) { logger.debug("TRANS-TO_EVENT: fetched event with guid"); } else { logger.debug("TRANS-TO_EVENT: did not find event with guid"); } } if (evinfo != null) { if (rid != null) { // We just retrieved it's master masterEI = evinfo; masterEI.setInstanceOnly(true); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; ical.addComponent(masterEI); } else if (methodType == ScheduleMethods.methodTypeCancel) { // This should never have an rid for cancel of entire event. evinfo.setInstanceOnly(evinfo.getEvent().getSuppressed()); } else { // Presumably sent an update for the entire event. No longer suppressed master evinfo.getEvent().setSuppressed(false); } } else if (rid != null) { /* Manufacture a master for the instance */ masterEI = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); final BwEvent e = masterEI.getEvent(); // XXX This seems bogus final DtStart mdtStart; final String bogusDate = "19980118"; final String bogusTime = "T230000"; // Base dtstart on the recurrence id. final boolean isDateType = ridObj.getDateType(); if (isDateType) { mdtStart = new DtStart(new Date(bogusDate)); } else if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + bogusTime + "Z"); } else if (ridObj.getTzid() == null) { mdtStart = new DtStart(bogusDate + bogusTime); } else { mdtStart = new DtStart(bogusDate + bogusTime, Timezones.getTz(ridObj.getTzid())); } IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), masterEI, mdtStart, null, null); e.setRecurring(true); // e.addRdate(ridObj); final var sum = (Summary)pl.getProperty(Property.SUMMARY); e.setSummary(sum.getValue()); e.setSuppressed(true); ical.addComponent(masterEI); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; masterEI.setInstanceOnly(rid != null); } } if (evinfo == null) { evinfo = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); } else if (evinfo.getEvent().getEntityType() != entityType) { return Response.notOk(resp, failed, "org.bedework.mismatched.entity.type: " + val); } final ChangeTable chg = evinfo.getChangeset( cb.getPrincipal().getPrincipalRef()); if (rid != null) { final String evrid = evinfo.getEvent().getRecurrenceId(); if ((evrid == null) || (!evrid.equals(rid))) { logger. warn("Mismatched rid ev=" + evrid + " expected " + rid); chg.changed(PropertyInfoIndex.RECURRENCE_ID, evrid, rid); // XXX spurious??? } if (masterEI.getEvent().getSuppressed()) { masterEI.getEvent().addRdate(ridObj); } } ev = evinfo.getEvent(); ev.setScheduleMethod(methodType); DtEnd dtEnd = null; if (entityType == IcalDefs.entityTypeTodo) { final Due due = pl.getProperty(Property.DUE); if (due != null ) { dtEnd = new DtEnd(due.getParameters(), due.getValue()); } } else { dtEnd = pl.getProperty(Property.DTEND); } final Duration duration = pl.getProperty(Property.DURATION); IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), evinfo, dtStart, dtEnd, duration); for (final Property prop: pl) { testXparams(prop, hasXparams); //debug("ical prop " + prop.getClass().getName()); String pval = prop.getValue(); if ((pval != null) && (pval.length() == 0)) { pval = null; } final PropertyInfoIndex pi; if (prop instanceof XProperty) { pi = PropertyInfoIndex.XPROP; } else { pi = PropertyInfoIndex.fromName(prop.getName()); } if (pi == null) { logger.debug("Unknown property with name " + prop.getName() + " class " + prop.getClass() + " and value " + pval); continue; } chg.present(pi); switch (pi) { case ACCEPT_RESPONSE: /* ------------------- Accept Response -------------------- */ String sval = prop.getValue(); if (chg.changed(pi, ev.getPollAcceptResponse(), sval)) { ev.setPollAcceptResponse(sval); } break; case ATTACH: /* ------------------- Attachment -------------------- */ chg.addValue(pi, IcalUtil.getAttachment((Attach)prop)); break; case ATTENDEE: /* ------------------- Attendee -------------------- */ if (methodType == ScheduleMethods.methodTypePublish) { if (cb.getStrictness() == IcalCallback.conformanceStrict) { return Response.notOk(resp, failed, CalFacadeException.attendeesInPublish); } //if (cb.getStrictness() == IcalCallback.conformanceWarn) { // warn("Had attendees for PUBLISH"); //} } final Attendee attPr = (Attendee)prop; if (evinfo.getNewEvent() || !mergeAttendees) { chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { final String pUri = cb.getCaladdr(attPr.getValue()); if (pUri.equals(attUri)) { /* Only update for our own attendee * We're doing a PUT and this must be the attendee updating their * partstat. We don't allow them to change other attendees * whatever the PUT content says. */ chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { // Use the value we currently have boolean found = false; for (final BwAttendee att: ev.getAttendees()) { if (pUri.equals(att.getAttendeeUri())) { chg.addValue(pi, att.clone()); found = true; break; } } if (!found) { // An added attendee final BwAttendee att = IcalUtil .getAttendee(cb, attPr); att.setPartstat(IcalDefs.partstatValNeedsAction); chg.addValue(pi, att); } } } break; case BUSYTYPE: final int ibt = BwEvent.fromBusyTypeString(pval); if (chg.changed(pi, ev.getBusyType(), ibt)) { ev.setBusyType(ibt); } break; case CATEGORIES: /* ------------------- Categories -------------------- */ final Categories cats = (Categories)prop; final TextList cl = cats.getCategories(); String lang = IcalUtil.getLang(cats); if (cl != null) { /* Got some categories */ for (final String wd: cl) { if (wd == null) { continue; } final BwString key = new BwString(lang, wd); final var fcResp = cb.findCategory(key); final BwCategory cat; if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isNotFound()) { cat = BwCategory.makeCategory(); cat.setWord(key); cb.addCategory(cat); } else { cat = fcResp.getEntity(); } chg.addValue(pi, cat); } } break; case CLASS: /* ------------------- Class -------------------- */ if (chg.changed(pi, ev.getClassification(), pval)) { ev.setClassification(pval); } break; case COMMENT: /* ------------------- Comment -------------------- */ chg.addValue(pi, new BwString(null, pval)); break; case COMPLETED: /* ------------------- Completed -------------------- */ if (chg.changed(pi, ev.getCompleted(), pval)) { ev.setCompleted(pval); } break; case CONCEPT: /* ------------------- Concept -------------------- */ final Concept c = (Concept)prop; final String cval = c.getValue(); if (cval != null) { /* Got a concept */ chg.addValue(PropertyInfoIndex.XPROP, BwXproperty.makeIcalProperty("CONCEPT", null, cval)); } break; case CONTACT: /* ------------------- Contact -------------------- */ final String altrep = getAltRepPar(prop); lang = IcalUtil.getLang(prop); final String uid = getUidPar(prop); final BwString nm = new BwString(lang, pval); BwContact contact = null; if (uid != null) { final var fcResp = cb.getContact(uid); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { final var fcResp = cb.findContact(nm); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { contact = BwContact.makeContact(); contact.setCn(nm); contact.setLink(altrep); cb.addContact(contact); } else { contact.setCn(nm); contact.setLink(altrep); } chg.addValue(pi, contact); break; case CREATED: /* ------------------- Created -------------------- */ if (chg.changed(pi, ev.getCreated(), pval)) { ev.setCreated(pval); } break; case DESCRIPTION: /* ------------------- Description -------------------- */ if (chg.changed(pi, ev.getDescription(), pval)) { ev.setDescription(pval); } break; case DTEND: /* ------------------- DtEnd -------------------- */ break; case DTSTAMP: /* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval); break; case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE: /* -------------------- Due ------------------------ */ break; case DURATION: /* ------------------- Duration -------------------- */ break; case EXDATE: /* ------------------- ExDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case EXRULE: /* ------------------- ExRule -------------------- */ chg.addValue(pi, pval); break; case FREEBUSY: /* ------------------- freebusy -------------------- */ final FreeBusy fbusy = (FreeBusy)prop; final PeriodList perpl = fbusy.getPeriods(); final Parameter par = IcalUtil.getParameter(fbusy, "FBTYPE"); final int fbtype; if (par == null) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY)) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY_TENTATIVE)) { fbtype = BwFreeBusyComponent.typeBusyTentative; } else if (par.equals(FbType.BUSY_UNAVAILABLE)) { fbtype = BwFreeBusyComponent.typeBusyUnavailable; } else if (par.equals(FbType.FREE)) { fbtype = BwFreeBusyComponent.typeFree; } else { if (logger.debug()) { logger.debug("Unsupported parameter " + par.getName()); } return Response.notOk(resp, failed, "Unsupported parameter " + par.getName()); } final BwFreeBusyComponent fbc = new BwFreeBusyComponent(); fbc.setType(fbtype); for (final Period per : perpl) { fbc.addPeriod(per); } ev.addFreeBusyPeriod(fbc); break; case GEO: /* ------------------- Geo -------------------- */ final Geo g = (Geo)prop; final BwGeo geo = new BwGeo(g.getLatitude(), g.getLongitude()); if (chg.changed(pi, ev.getGeo(), geo)) { ev.setGeo(geo); } break; case LAST_MODIFIED: /* ------------------- LastModified -------------------- */ if (chg.changed(pi, ev.getLastmod(), pval)) { ev.setLastmod(pval); } break; case LOCATION: /* ------------------- Location -------------------- */ BwLocation loc = null; //String uid = getUidPar(prop); /* At the moment Mozilla lightning is broken and this leads to all * sorts of problems. if (uid != null) { loc = cb.getLocation(uid); } */ lang = IcalUtil.getLang(prop); BwString addr = null; if (pval != null) { if (loc == null) { addr = new BwString(lang, pval); final var fcResp = cb.findLocation(addr); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { loc = fcResp.getEntity(); } } if (loc == null) { loc = BwLocation.makeLocation(); loc.setAddress(addr); cb.addLocation(loc); } } final BwLocation evloc = ev.getLocation(); if (chg.changed(pi, evloc, loc)) { // CHGTBL - this only shows that it's a different location object ev.setLocation(loc); } else if ((loc != null) && (evloc != null)) { // See if the value is changed final String evval = evloc.getAddress().getValue(); final String inval = loc.getAddress().getValue(); if (!evval.equals(inval)) { chg.changed(pi, evval, inval); evloc.getAddress().setValue(inval); } } break; case ORGANIZER: /* ------------------- Organizer -------------------- */ final BwOrganizer org = IcalUtil.getOrganizer(cb, (Organizer)prop); final BwOrganizer evorg = ev.getOrganizer(); final BwOrganizer evorgCopy; if (evorg == null) { evorgCopy = null; } else { evorgCopy = (BwOrganizer)evorg.clone(); } if (chg.changed(pi, evorgCopy, org)) { if (evorg == null) { ev.setOrganizer(org); } else { evorg.update(org); } } break; case PERCENT_COMPLETE: /* ------------------- PercentComplete -------------------- */ Integer ival = ((PercentComplete)prop).getPercentage(); if (chg.changed(pi, ev.getPercentComplete(), ival)) { ev.setPercentComplete(ival); } break; case POLL_MODE: /* ------------------- Poll mode -------------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollMode(), sval)) { ev.setPollMode(sval); } break; case POLL_PROPERTIES: /* ------------------- Poll properties ---------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollProperties(), sval)) { ev.setPollProperties(sval); } break; case POLL_WINNER: /* ------------------- Poll winner -------------------- */ ival = ((PollWinner)prop).getPollwinner(); if (chg.changed(pi, ev.getPollWinner(), ival)) { ev.setPollWinner(ival); } break; case PRIORITY: /* ------------------- Priority -------------------- */ ival = ((Priority)prop).getLevel(); if (chg.changed(pi, ev.getPriority(), ival)) { ev.setPriority(ival); } break; case RDATE: /* ------------------- RDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case RECURRENCE_ID: /* ------------------- RecurrenceID -------------------- */ // Done above break; case RELATED_TO: /* ------------------- RelatedTo -------------------- */ final RelatedTo irelto = (RelatedTo)prop; final BwRelatedTo relto = new BwRelatedTo(); final String parval = IcalUtil.getParameterVal(irelto, "RELTYPE"); if (parval != null) { relto.setRelType(parval); } relto.setValue(irelto.getValue()); if (chg.changed(pi, ev.getRelatedTo(), relto)) { ev.setRelatedTo(relto); } break; case REQUEST_STATUS: /* ------------------- RequestStatus -------------------- */ final BwRequestStatus rs = BwRequestStatus .fromRequestStatus((RequestStatus)prop); chg.addValue(pi, rs); break; case RESOURCES: /* ------------------- Resources -------------------- */ final TextList rl = ((Resources)prop).getResources(); if (rl != null) { /* Got some resources */ lang = IcalUtil.getLang(prop); for (final String s: rl) { final BwString rsrc = new BwString(lang, s); chg.addValue(pi, rsrc); } } break; case RRULE: /* ------------------- RRule -------------------- */ chg.addValue(pi, pval); break; case SEQUENCE: /* ------------------- Sequence -------------------- */ final int seq = ((Sequence)prop).getSequenceNo(); if (seq != ev.getSequence()) { chg.changed(pi, ev.getSequence(), seq); ev.setSequence(seq); } break; case STATUS: /* ------------------- Status -------------------- */ if (chg.changed(pi, ev.getStatus(), pval)) { ev.setStatus(pval); } break; case SUMMARY: /* ------------------- Summary -------------------- */ if (chg.changed(pi, ev.getSummary(), pval)) { ev.setSummary(pval); } break; case TRANSP: /* ------------------- Transp -------------------- */ if (chg.changed(pi, ev.getPeruserTransparency( cb.getPrincipal() .getPrincipalRef()), pval)) { final BwXproperty pu = ev.setPeruserTransparency( cb.getPrincipal().getPrincipalRef(), pval); if (pu != null) { chg.addValue(PropertyInfoIndex.XPROP, pu); } } break; case UID: /* ------------------- Uid -------------------- */ /* We did this above */ break; case URL: /* ------------------- Url -------------------- */ if (chg.changed(pi, ev.getLink(), pval)) { ev.setLink(pval); } break; case XPROP: /* ------------------------- x-property --------------------------- */ final String name = prop.getName(); if (name.equalsIgnoreCase(BwXproperty.bedeworkCost)) { if (chg.changed(PropertyInfoIndex.COST, ev.getCost(), pval)) { ev.setCost(pval); } break; } if (name.equalsIgnoreCase(BwXproperty.xBedeworkCategories)) { if (checkCategory(cb, chg, ev, null, pval)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkLocation)) { if (checkLocation(cb, chg, ev, prop)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkContact)) { if (checkContact(cb, chg, ev, null, pval)) { break; } } /* See if this is an x-category that can be converted to a real category */ final XProperty xp = (XProperty)prop; chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(name, xp.getParameters() .toString(), pval)); break; default: if (logger.debug()) { logger.debug("Unsupported property with index " + pi + "; class " + prop.getClass() + " and value " + pval); } } } /* =================== Process sub-components =============== */ final ComponentList<Component> subComps; if (val instanceof ComponentContainer) { subComps = ((ComponentContainer<Component>)val).getComponents(); } else { subComps = null; } final Set<Integer> pids; if (vpoll) { pids = new TreeSet<>(); final BwEvent vp = evinfo.getEvent(); if (!Util.isEmpty(vp.getPollItems())) { vp.clearPollItems(); } } else { pids = null; } if (!Util.isEmpty(subComps)) { for (final var subComp: subComps) { if (subComp instanceof Available) { if (!(val instanceof VAvailability)) { return Response.error(resp, "AVAILABLE only valid in VAVAILABLE"); } final var avlResp = processAvailable(cb, cal, ical, (VAvailability)val, (Available)subComp, evinfo); if (!avlResp.isOk()) { return Response.fromResponse(resp, avlResp); } continue; } if (subComp instanceof Participant) { if (vpoll) { final var vresp = processVoter(cb, (VPoll)val, (Participant)subComp, evinfo, chg, mergeAttendees); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Participant object"); continue; } if (subComp instanceof VResource) { logger.warn("Unimplemented VResource object"); continue; } if (subComp instanceof VLocation) { logger.warn("Unimplemented VLocation object"); continue; } if (subComp instanceof VAlarm) { final var aresp = VAlarmUtil.processAlarm(cb, val, (VAlarm)subComp, ev, currentPrincipal, chg); if (!aresp.isOk()) { return Response.fromResponse(resp, aresp); } continue; } if (vpoll && (event || task)) { final var vresp = processCandidate((VPoll)val, subComp, evinfo, pids, chg); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Component object: " + subComp); } } /* Fix up timestamps. */ if (ev.getCreated() == null) { if (ev.getLastmod() != null) { ev.setCreated(ev.getLastmod()); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); } else { ev.updateDtstamp(); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } } if (ev.getLastmod() == null) { // created cannot be null now ev.setLastmod(ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } processTimezones(ev, ical, chg); /* Remove any recipients and originator */ if (ev.getRecipients() != null) { ev.getRecipients().clear(); } ev.setOriginator(null); if (hasXparams.value) { /* Save a text copy of the entire event as an x-property */ final Component valCopy = val.copy(); /* Remove potentially large values */ final Description desp = valCopy.getProperty(Property.DESCRIPTION); if (desp != null) { desp.setValue(null); } final Attach attachp = valCopy.getProperty(Property.ATTACH); // Don't store the entire attachment - we just need the parameters. if (attachp != null) { final Value v = attachp.getParameter(Parameter.VALUE); if (v != null) { attachp.setValue(String.valueOf(attachp.getValue().hashCode())); } } chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(BwXproperty.bedeworkIcal, null, valCopy.toString())); } chg.processChanges(ev, true, false); ev.setRecurring(ev.isRecurringEntity()); if (logger.debug()) { logger.debug(chg.toString()); logger.debug(ev.toString()); } if (masterEI != null) { // Just return notfound as this event is on its override list return Response.notFound(resp); } resp.setEntity(evinfo); return resp; } catch (final Throwable t) { if (logger.debug()) { logger.error(t); } return Response.error(resp, t); } }
NONSATD
true
break; case CATEGORIES: /* ------------------- Categories -------------------- */ final Categories cats = (Categories)prop; final TextList cl = cats.getCategories();
break; case BUSYTYPE: final int ibt = BwEvent.fromBusyTypeString(pval); if (chg.changed(pi, ev.getBusyType(), ibt)) { ev.setBusyType(ibt); } break; case CATEGORIES: /* ------------------- Categories -------------------- */ final Categories cats = (Categories)prop; final TextList cl = cats.getCategories(); String lang = IcalUtil.getLang(cats); if (cl != null) { /* Got some categories */ for (final String wd: cl) { if (wd == null) { continue; } final BwString key = new BwString(lang, wd);
} if (!found) { // An added attendee final BwAttendee att = IcalUtil .getAttendee(cb, attPr); att.setPartstat(IcalDefs.partstatValNeedsAction); chg.addValue(pi, att); } } } break; case BUSYTYPE: final int ibt = BwEvent.fromBusyTypeString(pval); if (chg.changed(pi, ev.getBusyType(), ibt)) { ev.setBusyType(ibt); } break; case CATEGORIES: /* ------------------- Categories -------------------- */ final Categories cats = (Categories)prop; final TextList cl = cats.getCategories(); String lang = IcalUtil.getLang(cats); if (cl != null) { /* Got some categories */ for (final String wd: cl) { if (wd == null) { continue; } final BwString key = new BwString(lang, wd); final var fcResp = cb.findCategory(key); final BwCategory cat; if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isNotFound()) { cat = BwCategory.makeCategory(); cat.setWord(key); cb.addCategory(cat); } else {
7,893
30
/* Got some categories */
public static GetEntityResponse<EventInfo> toEvent( final IcalCallback cb, final BwCalendar cal, final Icalendar ical, final Component val, final boolean mergeAttendees) { final var resp = new GetEntityResponse<EventInfo>(); if (val == null) { return Response.notOk(resp, failed, "No component supplied"); } String currentPrincipal = null; final BwPrincipal principal = cb.getPrincipal(); if (principal != null) { currentPrincipal = principal.getPrincipalRef(); } final Holder<Boolean> hasXparams = new Holder<>(Boolean.FALSE); final int methodType = ical.getMethodType(); String attUri = null; if (mergeAttendees) { // We'll need this later. attUri = cb.getCaladdr(cb.getPrincipal().getPrincipalRef()); } final String colPath; if (cal == null) { colPath = null; } else { colPath = cal.getPath(); } try { final PropertyList<Property> pl = val.getProperties(); boolean vpoll = false; boolean event = false; boolean task = false; if (pl == null) { // Empty component return Response.notOk(resp, failed, "Empty component"); } final int entityType; if (val instanceof VEvent) { entityType = IcalDefs.entityTypeEvent; event = true; } else if (val instanceof VToDo) { entityType = IcalDefs.entityTypeTodo; task = true; } else if (val instanceof VJournal) { entityType = IcalDefs.entityTypeJournal; } else if (val instanceof VFreeBusy) { entityType = IcalDefs.entityTypeFreeAndBusy; } else if (val instanceof VAvailability) { entityType = IcalDefs.entityTypeVavailability; } else if (val instanceof Available) { entityType = IcalDefs.entityTypeAvailable; } else if (val instanceof VPoll) { entityType = IcalDefs.entityTypeVpoll; vpoll = true; } else { return Response.error(resp, "org.bedework.invalid.component.type: " + val.getName()); } // Get the guid from the component String guid = null; final Uid uidp = pl.getProperty(Property.UID); if (uidp != null) { testXparams(uidp, hasXparams); guid = uidp.getValue(); } if (guid == null) { /* XXX A guid is required - but are there devices out there without a * guid - and if so how do we handle it? */ return Response.notOk(resp, failed, CalFacadeException.noGuid); } /* See if we have a recurrence id */ BwDateTime ridObj = null; String rid = null; TimeZone ridTz = null; final RecurrenceId ridp = pl.getProperty(Property.RECURRENCE_ID); if (ridp != null) { testXparams(ridp, hasXparams); ridObj = BwDateTime.makeBwDateTime(ridp); if (ridObj.getRange() != null) { /* XXX What do I do with it? */ logger.warn("TRANS-TO_EVENT: Got a recurrence id range"); } rid = ridObj.getDate(); } EventInfo masterEI = null; EventInfo evinfo = null; final BwEvent ev; /* If we have a recurrence id see if we already have the master (we should * get a master + all its overrides). * * If so find the override and use the annnotation or if no override, * make one. * * If no override retrieve the event, add it to our table and then locate the * annotation. * * If there is no annotation, create one. * * It's possible we have been sent 'detached' instances of a recurring * event. This may happen if we are invited to one or more instances of a * meeting. In this case we try to retrieve the master and if it doesn't * exist we manufacture one. We consider such an instance an update to * that instance only and leave the others alone. */ /* We need this in a couple of places */ final DtStart dtStart = pl.getProperty(Property.DTSTART); /* if (rid != null) { // See if we have a new master event. If so create a proxy to that event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI == null) { masterEI = makeNewEvent(cb, chg, entityType, guid, cal); BwEvent e = masterEI.getEvent(); // XXX This seems bogus DtStart mdtStart; String bogusDate = "19980118T230000"; if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + "Z"); } else if (dtStart.getTimeZone() == null) { mdtStart = new DtStart(bogusDate); } else { mdtStart = new DtStart(bogusDate + "Z", dtStart.getTimeZone()); } setDates(e, mdtStart, null, null, chg); e.setRecurring(true); e.addRdate(ridObj); e.setSuppressed(true); ical.addComponent(masterEI); } if (masterEI != null) { evinfo = masterEI.findOverride(rid); } } */ /* If this is a recurrence instance see if we can find the master We only need this because the master may follow the overrides. */ if (rid != null) { // See if we have a new master event. If so create a proxy to this event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI != null) { evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; } } if ((evinfo == null) && (cal != null) && (cal.getCalType() != BwCalendar.calTypeInbox) && (cal.getCalType() != BwCalendar.calTypePendingInbox) && (cal.getCalType() != BwCalendar.calTypeOutbox)) { if (logger.debug()) { logger.debug("TRANS-TO_EVENT: try to fetch event with guid=" + guid); } final GetEntitiesResponse<EventInfo> eisResp = cb.getEvent(colPath, guid); if (eisResp.isError()) { return Response.fromResponse(resp, eisResp); } final var eis = eisResp.getEntities(); if (!Util.isEmpty(eis)) { if (eis.size() > 1) { // DORECUR - wrong again return Response.notOk(resp, failed, "More than one event returned for guid."); } evinfo = eis.iterator().next(); } if (logger.debug()) { if (evinfo != null) { logger.debug("TRANS-TO_EVENT: fetched event with guid"); } else { logger.debug("TRANS-TO_EVENT: did not find event with guid"); } } if (evinfo != null) { if (rid != null) { // We just retrieved it's master masterEI = evinfo; masterEI.setInstanceOnly(true); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; ical.addComponent(masterEI); } else if (methodType == ScheduleMethods.methodTypeCancel) { // This should never have an rid for cancel of entire event. evinfo.setInstanceOnly(evinfo.getEvent().getSuppressed()); } else { // Presumably sent an update for the entire event. No longer suppressed master evinfo.getEvent().setSuppressed(false); } } else if (rid != null) { /* Manufacture a master for the instance */ masterEI = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); final BwEvent e = masterEI.getEvent(); // XXX This seems bogus final DtStart mdtStart; final String bogusDate = "19980118"; final String bogusTime = "T230000"; // Base dtstart on the recurrence id. final boolean isDateType = ridObj.getDateType(); if (isDateType) { mdtStart = new DtStart(new Date(bogusDate)); } else if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + bogusTime + "Z"); } else if (ridObj.getTzid() == null) { mdtStart = new DtStart(bogusDate + bogusTime); } else { mdtStart = new DtStart(bogusDate + bogusTime, Timezones.getTz(ridObj.getTzid())); } IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), masterEI, mdtStart, null, null); e.setRecurring(true); // e.addRdate(ridObj); final var sum = (Summary)pl.getProperty(Property.SUMMARY); e.setSummary(sum.getValue()); e.setSuppressed(true); ical.addComponent(masterEI); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; masterEI.setInstanceOnly(rid != null); } } if (evinfo == null) { evinfo = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); } else if (evinfo.getEvent().getEntityType() != entityType) { return Response.notOk(resp, failed, "org.bedework.mismatched.entity.type: " + val); } final ChangeTable chg = evinfo.getChangeset( cb.getPrincipal().getPrincipalRef()); if (rid != null) { final String evrid = evinfo.getEvent().getRecurrenceId(); if ((evrid == null) || (!evrid.equals(rid))) { logger. warn("Mismatched rid ev=" + evrid + " expected " + rid); chg.changed(PropertyInfoIndex.RECURRENCE_ID, evrid, rid); // XXX spurious??? } if (masterEI.getEvent().getSuppressed()) { masterEI.getEvent().addRdate(ridObj); } } ev = evinfo.getEvent(); ev.setScheduleMethod(methodType); DtEnd dtEnd = null; if (entityType == IcalDefs.entityTypeTodo) { final Due due = pl.getProperty(Property.DUE); if (due != null ) { dtEnd = new DtEnd(due.getParameters(), due.getValue()); } } else { dtEnd = pl.getProperty(Property.DTEND); } final Duration duration = pl.getProperty(Property.DURATION); IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), evinfo, dtStart, dtEnd, duration); for (final Property prop: pl) { testXparams(prop, hasXparams); //debug("ical prop " + prop.getClass().getName()); String pval = prop.getValue(); if ((pval != null) && (pval.length() == 0)) { pval = null; } final PropertyInfoIndex pi; if (prop instanceof XProperty) { pi = PropertyInfoIndex.XPROP; } else { pi = PropertyInfoIndex.fromName(prop.getName()); } if (pi == null) { logger.debug("Unknown property with name " + prop.getName() + " class " + prop.getClass() + " and value " + pval); continue; } chg.present(pi); switch (pi) { case ACCEPT_RESPONSE: /* ------------------- Accept Response -------------------- */ String sval = prop.getValue(); if (chg.changed(pi, ev.getPollAcceptResponse(), sval)) { ev.setPollAcceptResponse(sval); } break; case ATTACH: /* ------------------- Attachment -------------------- */ chg.addValue(pi, IcalUtil.getAttachment((Attach)prop)); break; case ATTENDEE: /* ------------------- Attendee -------------------- */ if (methodType == ScheduleMethods.methodTypePublish) { if (cb.getStrictness() == IcalCallback.conformanceStrict) { return Response.notOk(resp, failed, CalFacadeException.attendeesInPublish); } //if (cb.getStrictness() == IcalCallback.conformanceWarn) { // warn("Had attendees for PUBLISH"); //} } final Attendee attPr = (Attendee)prop; if (evinfo.getNewEvent() || !mergeAttendees) { chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { final String pUri = cb.getCaladdr(attPr.getValue()); if (pUri.equals(attUri)) { /* Only update for our own attendee * We're doing a PUT and this must be the attendee updating their * partstat. We don't allow them to change other attendees * whatever the PUT content says. */ chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { // Use the value we currently have boolean found = false; for (final BwAttendee att: ev.getAttendees()) { if (pUri.equals(att.getAttendeeUri())) { chg.addValue(pi, att.clone()); found = true; break; } } if (!found) { // An added attendee final BwAttendee att = IcalUtil .getAttendee(cb, attPr); att.setPartstat(IcalDefs.partstatValNeedsAction); chg.addValue(pi, att); } } } break; case BUSYTYPE: final int ibt = BwEvent.fromBusyTypeString(pval); if (chg.changed(pi, ev.getBusyType(), ibt)) { ev.setBusyType(ibt); } break; case CATEGORIES: /* ------------------- Categories -------------------- */ final Categories cats = (Categories)prop; final TextList cl = cats.getCategories(); String lang = IcalUtil.getLang(cats); if (cl != null) { /* Got some categories */ for (final String wd: cl) { if (wd == null) { continue; } final BwString key = new BwString(lang, wd); final var fcResp = cb.findCategory(key); final BwCategory cat; if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isNotFound()) { cat = BwCategory.makeCategory(); cat.setWord(key); cb.addCategory(cat); } else { cat = fcResp.getEntity(); } chg.addValue(pi, cat); } } break; case CLASS: /* ------------------- Class -------------------- */ if (chg.changed(pi, ev.getClassification(), pval)) { ev.setClassification(pval); } break; case COMMENT: /* ------------------- Comment -------------------- */ chg.addValue(pi, new BwString(null, pval)); break; case COMPLETED: /* ------------------- Completed -------------------- */ if (chg.changed(pi, ev.getCompleted(), pval)) { ev.setCompleted(pval); } break; case CONCEPT: /* ------------------- Concept -------------------- */ final Concept c = (Concept)prop; final String cval = c.getValue(); if (cval != null) { /* Got a concept */ chg.addValue(PropertyInfoIndex.XPROP, BwXproperty.makeIcalProperty("CONCEPT", null, cval)); } break; case CONTACT: /* ------------------- Contact -------------------- */ final String altrep = getAltRepPar(prop); lang = IcalUtil.getLang(prop); final String uid = getUidPar(prop); final BwString nm = new BwString(lang, pval); BwContact contact = null; if (uid != null) { final var fcResp = cb.getContact(uid); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { final var fcResp = cb.findContact(nm); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { contact = BwContact.makeContact(); contact.setCn(nm); contact.setLink(altrep); cb.addContact(contact); } else { contact.setCn(nm); contact.setLink(altrep); } chg.addValue(pi, contact); break; case CREATED: /* ------------------- Created -------------------- */ if (chg.changed(pi, ev.getCreated(), pval)) { ev.setCreated(pval); } break; case DESCRIPTION: /* ------------------- Description -------------------- */ if (chg.changed(pi, ev.getDescription(), pval)) { ev.setDescription(pval); } break; case DTEND: /* ------------------- DtEnd -------------------- */ break; case DTSTAMP: /* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval); break; case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE: /* -------------------- Due ------------------------ */ break; case DURATION: /* ------------------- Duration -------------------- */ break; case EXDATE: /* ------------------- ExDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case EXRULE: /* ------------------- ExRule -------------------- */ chg.addValue(pi, pval); break; case FREEBUSY: /* ------------------- freebusy -------------------- */ final FreeBusy fbusy = (FreeBusy)prop; final PeriodList perpl = fbusy.getPeriods(); final Parameter par = IcalUtil.getParameter(fbusy, "FBTYPE"); final int fbtype; if (par == null) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY)) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY_TENTATIVE)) { fbtype = BwFreeBusyComponent.typeBusyTentative; } else if (par.equals(FbType.BUSY_UNAVAILABLE)) { fbtype = BwFreeBusyComponent.typeBusyUnavailable; } else if (par.equals(FbType.FREE)) { fbtype = BwFreeBusyComponent.typeFree; } else { if (logger.debug()) { logger.debug("Unsupported parameter " + par.getName()); } return Response.notOk(resp, failed, "Unsupported parameter " + par.getName()); } final BwFreeBusyComponent fbc = new BwFreeBusyComponent(); fbc.setType(fbtype); for (final Period per : perpl) { fbc.addPeriod(per); } ev.addFreeBusyPeriod(fbc); break; case GEO: /* ------------------- Geo -------------------- */ final Geo g = (Geo)prop; final BwGeo geo = new BwGeo(g.getLatitude(), g.getLongitude()); if (chg.changed(pi, ev.getGeo(), geo)) { ev.setGeo(geo); } break; case LAST_MODIFIED: /* ------------------- LastModified -------------------- */ if (chg.changed(pi, ev.getLastmod(), pval)) { ev.setLastmod(pval); } break; case LOCATION: /* ------------------- Location -------------------- */ BwLocation loc = null; //String uid = getUidPar(prop); /* At the moment Mozilla lightning is broken and this leads to all * sorts of problems. if (uid != null) { loc = cb.getLocation(uid); } */ lang = IcalUtil.getLang(prop); BwString addr = null; if (pval != null) { if (loc == null) { addr = new BwString(lang, pval); final var fcResp = cb.findLocation(addr); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { loc = fcResp.getEntity(); } } if (loc == null) { loc = BwLocation.makeLocation(); loc.setAddress(addr); cb.addLocation(loc); } } final BwLocation evloc = ev.getLocation(); if (chg.changed(pi, evloc, loc)) { // CHGTBL - this only shows that it's a different location object ev.setLocation(loc); } else if ((loc != null) && (evloc != null)) { // See if the value is changed final String evval = evloc.getAddress().getValue(); final String inval = loc.getAddress().getValue(); if (!evval.equals(inval)) { chg.changed(pi, evval, inval); evloc.getAddress().setValue(inval); } } break; case ORGANIZER: /* ------------------- Organizer -------------------- */ final BwOrganizer org = IcalUtil.getOrganizer(cb, (Organizer)prop); final BwOrganizer evorg = ev.getOrganizer(); final BwOrganizer evorgCopy; if (evorg == null) { evorgCopy = null; } else { evorgCopy = (BwOrganizer)evorg.clone(); } if (chg.changed(pi, evorgCopy, org)) { if (evorg == null) { ev.setOrganizer(org); } else { evorg.update(org); } } break; case PERCENT_COMPLETE: /* ------------------- PercentComplete -------------------- */ Integer ival = ((PercentComplete)prop).getPercentage(); if (chg.changed(pi, ev.getPercentComplete(), ival)) { ev.setPercentComplete(ival); } break; case POLL_MODE: /* ------------------- Poll mode -------------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollMode(), sval)) { ev.setPollMode(sval); } break; case POLL_PROPERTIES: /* ------------------- Poll properties ---------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollProperties(), sval)) { ev.setPollProperties(sval); } break; case POLL_WINNER: /* ------------------- Poll winner -------------------- */ ival = ((PollWinner)prop).getPollwinner(); if (chg.changed(pi, ev.getPollWinner(), ival)) { ev.setPollWinner(ival); } break; case PRIORITY: /* ------------------- Priority -------------------- */ ival = ((Priority)prop).getLevel(); if (chg.changed(pi, ev.getPriority(), ival)) { ev.setPriority(ival); } break; case RDATE: /* ------------------- RDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case RECURRENCE_ID: /* ------------------- RecurrenceID -------------------- */ // Done above break; case RELATED_TO: /* ------------------- RelatedTo -------------------- */ final RelatedTo irelto = (RelatedTo)prop; final BwRelatedTo relto = new BwRelatedTo(); final String parval = IcalUtil.getParameterVal(irelto, "RELTYPE"); if (parval != null) { relto.setRelType(parval); } relto.setValue(irelto.getValue()); if (chg.changed(pi, ev.getRelatedTo(), relto)) { ev.setRelatedTo(relto); } break; case REQUEST_STATUS: /* ------------------- RequestStatus -------------------- */ final BwRequestStatus rs = BwRequestStatus .fromRequestStatus((RequestStatus)prop); chg.addValue(pi, rs); break; case RESOURCES: /* ------------------- Resources -------------------- */ final TextList rl = ((Resources)prop).getResources(); if (rl != null) { /* Got some resources */ lang = IcalUtil.getLang(prop); for (final String s: rl) { final BwString rsrc = new BwString(lang, s); chg.addValue(pi, rsrc); } } break; case RRULE: /* ------------------- RRule -------------------- */ chg.addValue(pi, pval); break; case SEQUENCE: /* ------------------- Sequence -------------------- */ final int seq = ((Sequence)prop).getSequenceNo(); if (seq != ev.getSequence()) { chg.changed(pi, ev.getSequence(), seq); ev.setSequence(seq); } break; case STATUS: /* ------------------- Status -------------------- */ if (chg.changed(pi, ev.getStatus(), pval)) { ev.setStatus(pval); } break; case SUMMARY: /* ------------------- Summary -------------------- */ if (chg.changed(pi, ev.getSummary(), pval)) { ev.setSummary(pval); } break; case TRANSP: /* ------------------- Transp -------------------- */ if (chg.changed(pi, ev.getPeruserTransparency( cb.getPrincipal() .getPrincipalRef()), pval)) { final BwXproperty pu = ev.setPeruserTransparency( cb.getPrincipal().getPrincipalRef(), pval); if (pu != null) { chg.addValue(PropertyInfoIndex.XPROP, pu); } } break; case UID: /* ------------------- Uid -------------------- */ /* We did this above */ break; case URL: /* ------------------- Url -------------------- */ if (chg.changed(pi, ev.getLink(), pval)) { ev.setLink(pval); } break; case XPROP: /* ------------------------- x-property --------------------------- */ final String name = prop.getName(); if (name.equalsIgnoreCase(BwXproperty.bedeworkCost)) { if (chg.changed(PropertyInfoIndex.COST, ev.getCost(), pval)) { ev.setCost(pval); } break; } if (name.equalsIgnoreCase(BwXproperty.xBedeworkCategories)) { if (checkCategory(cb, chg, ev, null, pval)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkLocation)) { if (checkLocation(cb, chg, ev, prop)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkContact)) { if (checkContact(cb, chg, ev, null, pval)) { break; } } /* See if this is an x-category that can be converted to a real category */ final XProperty xp = (XProperty)prop; chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(name, xp.getParameters() .toString(), pval)); break; default: if (logger.debug()) { logger.debug("Unsupported property with index " + pi + "; class " + prop.getClass() + " and value " + pval); } } } /* =================== Process sub-components =============== */ final ComponentList<Component> subComps; if (val instanceof ComponentContainer) { subComps = ((ComponentContainer<Component>)val).getComponents(); } else { subComps = null; } final Set<Integer> pids; if (vpoll) { pids = new TreeSet<>(); final BwEvent vp = evinfo.getEvent(); if (!Util.isEmpty(vp.getPollItems())) { vp.clearPollItems(); } } else { pids = null; } if (!Util.isEmpty(subComps)) { for (final var subComp: subComps) { if (subComp instanceof Available) { if (!(val instanceof VAvailability)) { return Response.error(resp, "AVAILABLE only valid in VAVAILABLE"); } final var avlResp = processAvailable(cb, cal, ical, (VAvailability)val, (Available)subComp, evinfo); if (!avlResp.isOk()) { return Response.fromResponse(resp, avlResp); } continue; } if (subComp instanceof Participant) { if (vpoll) { final var vresp = processVoter(cb, (VPoll)val, (Participant)subComp, evinfo, chg, mergeAttendees); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Participant object"); continue; } if (subComp instanceof VResource) { logger.warn("Unimplemented VResource object"); continue; } if (subComp instanceof VLocation) { logger.warn("Unimplemented VLocation object"); continue; } if (subComp instanceof VAlarm) { final var aresp = VAlarmUtil.processAlarm(cb, val, (VAlarm)subComp, ev, currentPrincipal, chg); if (!aresp.isOk()) { return Response.fromResponse(resp, aresp); } continue; } if (vpoll && (event || task)) { final var vresp = processCandidate((VPoll)val, subComp, evinfo, pids, chg); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Component object: " + subComp); } } /* Fix up timestamps. */ if (ev.getCreated() == null) { if (ev.getLastmod() != null) { ev.setCreated(ev.getLastmod()); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); } else { ev.updateDtstamp(); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } } if (ev.getLastmod() == null) { // created cannot be null now ev.setLastmod(ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } processTimezones(ev, ical, chg); /* Remove any recipients and originator */ if (ev.getRecipients() != null) { ev.getRecipients().clear(); } ev.setOriginator(null); if (hasXparams.value) { /* Save a text copy of the entire event as an x-property */ final Component valCopy = val.copy(); /* Remove potentially large values */ final Description desp = valCopy.getProperty(Property.DESCRIPTION); if (desp != null) { desp.setValue(null); } final Attach attachp = valCopy.getProperty(Property.ATTACH); // Don't store the entire attachment - we just need the parameters. if (attachp != null) { final Value v = attachp.getParameter(Parameter.VALUE); if (v != null) { attachp.setValue(String.valueOf(attachp.getValue().hashCode())); } } chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(BwXproperty.bedeworkIcal, null, valCopy.toString())); } chg.processChanges(ev, true, false); ev.setRecurring(ev.isRecurringEntity()); if (logger.debug()) { logger.debug(chg.toString()); logger.debug(ev.toString()); } if (masterEI != null) { // Just return notfound as this event is on its override list return Response.notFound(resp); } resp.setEntity(evinfo); return resp; } catch (final Throwable t) { if (logger.debug()) { logger.error(t); } return Response.error(resp, t); } }
NONSATD
true
String lang = IcalUtil.getLang(cats); if (cl != null) { /* Got some categories */ for (final String wd: cl) { if (wd == null) {
ibt)) { ev.setBusyType(ibt); } break; case CATEGORIES: /* ------------------- Categories -------------------- */ final Categories cats = (Categories)prop; final TextList cl = cats.getCategories(); String lang = IcalUtil.getLang(cats); if (cl != null) { /* Got some categories */ for (final String wd: cl) { if (wd == null) { continue; } final BwString key = new BwString(lang, wd); final var fcResp = cb.findCategory(key); final BwCategory cat; if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); }
att.setPartstat(IcalDefs.partstatValNeedsAction); chg.addValue(pi, att); } } } break; case BUSYTYPE: final int ibt = BwEvent.fromBusyTypeString(pval); if (chg.changed(pi, ev.getBusyType(), ibt)) { ev.setBusyType(ibt); } break; case CATEGORIES: /* ------------------- Categories -------------------- */ final Categories cats = (Categories)prop; final TextList cl = cats.getCategories(); String lang = IcalUtil.getLang(cats); if (cl != null) { /* Got some categories */ for (final String wd: cl) { if (wd == null) { continue; } final BwString key = new BwString(lang, wd); final var fcResp = cb.findCategory(key); final BwCategory cat; if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isNotFound()) { cat = BwCategory.makeCategory(); cat.setWord(key); cb.addCategory(cat); } else { cat = fcResp.getEntity(); } chg.addValue(pi, cat); } }
7,893
31
/* ------------------- Class -------------------- */
public static GetEntityResponse<EventInfo> toEvent( final IcalCallback cb, final BwCalendar cal, final Icalendar ical, final Component val, final boolean mergeAttendees) { final var resp = new GetEntityResponse<EventInfo>(); if (val == null) { return Response.notOk(resp, failed, "No component supplied"); } String currentPrincipal = null; final BwPrincipal principal = cb.getPrincipal(); if (principal != null) { currentPrincipal = principal.getPrincipalRef(); } final Holder<Boolean> hasXparams = new Holder<>(Boolean.FALSE); final int methodType = ical.getMethodType(); String attUri = null; if (mergeAttendees) { // We'll need this later. attUri = cb.getCaladdr(cb.getPrincipal().getPrincipalRef()); } final String colPath; if (cal == null) { colPath = null; } else { colPath = cal.getPath(); } try { final PropertyList<Property> pl = val.getProperties(); boolean vpoll = false; boolean event = false; boolean task = false; if (pl == null) { // Empty component return Response.notOk(resp, failed, "Empty component"); } final int entityType; if (val instanceof VEvent) { entityType = IcalDefs.entityTypeEvent; event = true; } else if (val instanceof VToDo) { entityType = IcalDefs.entityTypeTodo; task = true; } else if (val instanceof VJournal) { entityType = IcalDefs.entityTypeJournal; } else if (val instanceof VFreeBusy) { entityType = IcalDefs.entityTypeFreeAndBusy; } else if (val instanceof VAvailability) { entityType = IcalDefs.entityTypeVavailability; } else if (val instanceof Available) { entityType = IcalDefs.entityTypeAvailable; } else if (val instanceof VPoll) { entityType = IcalDefs.entityTypeVpoll; vpoll = true; } else { return Response.error(resp, "org.bedework.invalid.component.type: " + val.getName()); } // Get the guid from the component String guid = null; final Uid uidp = pl.getProperty(Property.UID); if (uidp != null) { testXparams(uidp, hasXparams); guid = uidp.getValue(); } if (guid == null) { /* XXX A guid is required - but are there devices out there without a * guid - and if so how do we handle it? */ return Response.notOk(resp, failed, CalFacadeException.noGuid); } /* See if we have a recurrence id */ BwDateTime ridObj = null; String rid = null; TimeZone ridTz = null; final RecurrenceId ridp = pl.getProperty(Property.RECURRENCE_ID); if (ridp != null) { testXparams(ridp, hasXparams); ridObj = BwDateTime.makeBwDateTime(ridp); if (ridObj.getRange() != null) { /* XXX What do I do with it? */ logger.warn("TRANS-TO_EVENT: Got a recurrence id range"); } rid = ridObj.getDate(); } EventInfo masterEI = null; EventInfo evinfo = null; final BwEvent ev; /* If we have a recurrence id see if we already have the master (we should * get a master + all its overrides). * * If so find the override and use the annnotation or if no override, * make one. * * If no override retrieve the event, add it to our table and then locate the * annotation. * * If there is no annotation, create one. * * It's possible we have been sent 'detached' instances of a recurring * event. This may happen if we are invited to one or more instances of a * meeting. In this case we try to retrieve the master and if it doesn't * exist we manufacture one. We consider such an instance an update to * that instance only and leave the others alone. */ /* We need this in a couple of places */ final DtStart dtStart = pl.getProperty(Property.DTSTART); /* if (rid != null) { // See if we have a new master event. If so create a proxy to that event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI == null) { masterEI = makeNewEvent(cb, chg, entityType, guid, cal); BwEvent e = masterEI.getEvent(); // XXX This seems bogus DtStart mdtStart; String bogusDate = "19980118T230000"; if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + "Z"); } else if (dtStart.getTimeZone() == null) { mdtStart = new DtStart(bogusDate); } else { mdtStart = new DtStart(bogusDate + "Z", dtStart.getTimeZone()); } setDates(e, mdtStart, null, null, chg); e.setRecurring(true); e.addRdate(ridObj); e.setSuppressed(true); ical.addComponent(masterEI); } if (masterEI != null) { evinfo = masterEI.findOverride(rid); } } */ /* If this is a recurrence instance see if we can find the master We only need this because the master may follow the overrides. */ if (rid != null) { // See if we have a new master event. If so create a proxy to this event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI != null) { evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; } } if ((evinfo == null) && (cal != null) && (cal.getCalType() != BwCalendar.calTypeInbox) && (cal.getCalType() != BwCalendar.calTypePendingInbox) && (cal.getCalType() != BwCalendar.calTypeOutbox)) { if (logger.debug()) { logger.debug("TRANS-TO_EVENT: try to fetch event with guid=" + guid); } final GetEntitiesResponse<EventInfo> eisResp = cb.getEvent(colPath, guid); if (eisResp.isError()) { return Response.fromResponse(resp, eisResp); } final var eis = eisResp.getEntities(); if (!Util.isEmpty(eis)) { if (eis.size() > 1) { // DORECUR - wrong again return Response.notOk(resp, failed, "More than one event returned for guid."); } evinfo = eis.iterator().next(); } if (logger.debug()) { if (evinfo != null) { logger.debug("TRANS-TO_EVENT: fetched event with guid"); } else { logger.debug("TRANS-TO_EVENT: did not find event with guid"); } } if (evinfo != null) { if (rid != null) { // We just retrieved it's master masterEI = evinfo; masterEI.setInstanceOnly(true); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; ical.addComponent(masterEI); } else if (methodType == ScheduleMethods.methodTypeCancel) { // This should never have an rid for cancel of entire event. evinfo.setInstanceOnly(evinfo.getEvent().getSuppressed()); } else { // Presumably sent an update for the entire event. No longer suppressed master evinfo.getEvent().setSuppressed(false); } } else if (rid != null) { /* Manufacture a master for the instance */ masterEI = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); final BwEvent e = masterEI.getEvent(); // XXX This seems bogus final DtStart mdtStart; final String bogusDate = "19980118"; final String bogusTime = "T230000"; // Base dtstart on the recurrence id. final boolean isDateType = ridObj.getDateType(); if (isDateType) { mdtStart = new DtStart(new Date(bogusDate)); } else if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + bogusTime + "Z"); } else if (ridObj.getTzid() == null) { mdtStart = new DtStart(bogusDate + bogusTime); } else { mdtStart = new DtStart(bogusDate + bogusTime, Timezones.getTz(ridObj.getTzid())); } IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), masterEI, mdtStart, null, null); e.setRecurring(true); // e.addRdate(ridObj); final var sum = (Summary)pl.getProperty(Property.SUMMARY); e.setSummary(sum.getValue()); e.setSuppressed(true); ical.addComponent(masterEI); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; masterEI.setInstanceOnly(rid != null); } } if (evinfo == null) { evinfo = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); } else if (evinfo.getEvent().getEntityType() != entityType) { return Response.notOk(resp, failed, "org.bedework.mismatched.entity.type: " + val); } final ChangeTable chg = evinfo.getChangeset( cb.getPrincipal().getPrincipalRef()); if (rid != null) { final String evrid = evinfo.getEvent().getRecurrenceId(); if ((evrid == null) || (!evrid.equals(rid))) { logger. warn("Mismatched rid ev=" + evrid + " expected " + rid); chg.changed(PropertyInfoIndex.RECURRENCE_ID, evrid, rid); // XXX spurious??? } if (masterEI.getEvent().getSuppressed()) { masterEI.getEvent().addRdate(ridObj); } } ev = evinfo.getEvent(); ev.setScheduleMethod(methodType); DtEnd dtEnd = null; if (entityType == IcalDefs.entityTypeTodo) { final Due due = pl.getProperty(Property.DUE); if (due != null ) { dtEnd = new DtEnd(due.getParameters(), due.getValue()); } } else { dtEnd = pl.getProperty(Property.DTEND); } final Duration duration = pl.getProperty(Property.DURATION); IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), evinfo, dtStart, dtEnd, duration); for (final Property prop: pl) { testXparams(prop, hasXparams); //debug("ical prop " + prop.getClass().getName()); String pval = prop.getValue(); if ((pval != null) && (pval.length() == 0)) { pval = null; } final PropertyInfoIndex pi; if (prop instanceof XProperty) { pi = PropertyInfoIndex.XPROP; } else { pi = PropertyInfoIndex.fromName(prop.getName()); } if (pi == null) { logger.debug("Unknown property with name " + prop.getName() + " class " + prop.getClass() + " and value " + pval); continue; } chg.present(pi); switch (pi) { case ACCEPT_RESPONSE: /* ------------------- Accept Response -------------------- */ String sval = prop.getValue(); if (chg.changed(pi, ev.getPollAcceptResponse(), sval)) { ev.setPollAcceptResponse(sval); } break; case ATTACH: /* ------------------- Attachment -------------------- */ chg.addValue(pi, IcalUtil.getAttachment((Attach)prop)); break; case ATTENDEE: /* ------------------- Attendee -------------------- */ if (methodType == ScheduleMethods.methodTypePublish) { if (cb.getStrictness() == IcalCallback.conformanceStrict) { return Response.notOk(resp, failed, CalFacadeException.attendeesInPublish); } //if (cb.getStrictness() == IcalCallback.conformanceWarn) { // warn("Had attendees for PUBLISH"); //} } final Attendee attPr = (Attendee)prop; if (evinfo.getNewEvent() || !mergeAttendees) { chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { final String pUri = cb.getCaladdr(attPr.getValue()); if (pUri.equals(attUri)) { /* Only update for our own attendee * We're doing a PUT and this must be the attendee updating their * partstat. We don't allow them to change other attendees * whatever the PUT content says. */ chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { // Use the value we currently have boolean found = false; for (final BwAttendee att: ev.getAttendees()) { if (pUri.equals(att.getAttendeeUri())) { chg.addValue(pi, att.clone()); found = true; break; } } if (!found) { // An added attendee final BwAttendee att = IcalUtil .getAttendee(cb, attPr); att.setPartstat(IcalDefs.partstatValNeedsAction); chg.addValue(pi, att); } } } break; case BUSYTYPE: final int ibt = BwEvent.fromBusyTypeString(pval); if (chg.changed(pi, ev.getBusyType(), ibt)) { ev.setBusyType(ibt); } break; case CATEGORIES: /* ------------------- Categories -------------------- */ final Categories cats = (Categories)prop; final TextList cl = cats.getCategories(); String lang = IcalUtil.getLang(cats); if (cl != null) { /* Got some categories */ for (final String wd: cl) { if (wd == null) { continue; } final BwString key = new BwString(lang, wd); final var fcResp = cb.findCategory(key); final BwCategory cat; if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isNotFound()) { cat = BwCategory.makeCategory(); cat.setWord(key); cb.addCategory(cat); } else { cat = fcResp.getEntity(); } chg.addValue(pi, cat); } } break; case CLASS: /* ------------------- Class -------------------- */ if (chg.changed(pi, ev.getClassification(), pval)) { ev.setClassification(pval); } break; case COMMENT: /* ------------------- Comment -------------------- */ chg.addValue(pi, new BwString(null, pval)); break; case COMPLETED: /* ------------------- Completed -------------------- */ if (chg.changed(pi, ev.getCompleted(), pval)) { ev.setCompleted(pval); } break; case CONCEPT: /* ------------------- Concept -------------------- */ final Concept c = (Concept)prop; final String cval = c.getValue(); if (cval != null) { /* Got a concept */ chg.addValue(PropertyInfoIndex.XPROP, BwXproperty.makeIcalProperty("CONCEPT", null, cval)); } break; case CONTACT: /* ------------------- Contact -------------------- */ final String altrep = getAltRepPar(prop); lang = IcalUtil.getLang(prop); final String uid = getUidPar(prop); final BwString nm = new BwString(lang, pval); BwContact contact = null; if (uid != null) { final var fcResp = cb.getContact(uid); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { final var fcResp = cb.findContact(nm); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { contact = BwContact.makeContact(); contact.setCn(nm); contact.setLink(altrep); cb.addContact(contact); } else { contact.setCn(nm); contact.setLink(altrep); } chg.addValue(pi, contact); break; case CREATED: /* ------------------- Created -------------------- */ if (chg.changed(pi, ev.getCreated(), pval)) { ev.setCreated(pval); } break; case DESCRIPTION: /* ------------------- Description -------------------- */ if (chg.changed(pi, ev.getDescription(), pval)) { ev.setDescription(pval); } break; case DTEND: /* ------------------- DtEnd -------------------- */ break; case DTSTAMP: /* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval); break; case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE: /* -------------------- Due ------------------------ */ break; case DURATION: /* ------------------- Duration -------------------- */ break; case EXDATE: /* ------------------- ExDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case EXRULE: /* ------------------- ExRule -------------------- */ chg.addValue(pi, pval); break; case FREEBUSY: /* ------------------- freebusy -------------------- */ final FreeBusy fbusy = (FreeBusy)prop; final PeriodList perpl = fbusy.getPeriods(); final Parameter par = IcalUtil.getParameter(fbusy, "FBTYPE"); final int fbtype; if (par == null) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY)) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY_TENTATIVE)) { fbtype = BwFreeBusyComponent.typeBusyTentative; } else if (par.equals(FbType.BUSY_UNAVAILABLE)) { fbtype = BwFreeBusyComponent.typeBusyUnavailable; } else if (par.equals(FbType.FREE)) { fbtype = BwFreeBusyComponent.typeFree; } else { if (logger.debug()) { logger.debug("Unsupported parameter " + par.getName()); } return Response.notOk(resp, failed, "Unsupported parameter " + par.getName()); } final BwFreeBusyComponent fbc = new BwFreeBusyComponent(); fbc.setType(fbtype); for (final Period per : perpl) { fbc.addPeriod(per); } ev.addFreeBusyPeriod(fbc); break; case GEO: /* ------------------- Geo -------------------- */ final Geo g = (Geo)prop; final BwGeo geo = new BwGeo(g.getLatitude(), g.getLongitude()); if (chg.changed(pi, ev.getGeo(), geo)) { ev.setGeo(geo); } break; case LAST_MODIFIED: /* ------------------- LastModified -------------------- */ if (chg.changed(pi, ev.getLastmod(), pval)) { ev.setLastmod(pval); } break; case LOCATION: /* ------------------- Location -------------------- */ BwLocation loc = null; //String uid = getUidPar(prop); /* At the moment Mozilla lightning is broken and this leads to all * sorts of problems. if (uid != null) { loc = cb.getLocation(uid); } */ lang = IcalUtil.getLang(prop); BwString addr = null; if (pval != null) { if (loc == null) { addr = new BwString(lang, pval); final var fcResp = cb.findLocation(addr); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { loc = fcResp.getEntity(); } } if (loc == null) { loc = BwLocation.makeLocation(); loc.setAddress(addr); cb.addLocation(loc); } } final BwLocation evloc = ev.getLocation(); if (chg.changed(pi, evloc, loc)) { // CHGTBL - this only shows that it's a different location object ev.setLocation(loc); } else if ((loc != null) && (evloc != null)) { // See if the value is changed final String evval = evloc.getAddress().getValue(); final String inval = loc.getAddress().getValue(); if (!evval.equals(inval)) { chg.changed(pi, evval, inval); evloc.getAddress().setValue(inval); } } break; case ORGANIZER: /* ------------------- Organizer -------------------- */ final BwOrganizer org = IcalUtil.getOrganizer(cb, (Organizer)prop); final BwOrganizer evorg = ev.getOrganizer(); final BwOrganizer evorgCopy; if (evorg == null) { evorgCopy = null; } else { evorgCopy = (BwOrganizer)evorg.clone(); } if (chg.changed(pi, evorgCopy, org)) { if (evorg == null) { ev.setOrganizer(org); } else { evorg.update(org); } } break; case PERCENT_COMPLETE: /* ------------------- PercentComplete -------------------- */ Integer ival = ((PercentComplete)prop).getPercentage(); if (chg.changed(pi, ev.getPercentComplete(), ival)) { ev.setPercentComplete(ival); } break; case POLL_MODE: /* ------------------- Poll mode -------------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollMode(), sval)) { ev.setPollMode(sval); } break; case POLL_PROPERTIES: /* ------------------- Poll properties ---------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollProperties(), sval)) { ev.setPollProperties(sval); } break; case POLL_WINNER: /* ------------------- Poll winner -------------------- */ ival = ((PollWinner)prop).getPollwinner(); if (chg.changed(pi, ev.getPollWinner(), ival)) { ev.setPollWinner(ival); } break; case PRIORITY: /* ------------------- Priority -------------------- */ ival = ((Priority)prop).getLevel(); if (chg.changed(pi, ev.getPriority(), ival)) { ev.setPriority(ival); } break; case RDATE: /* ------------------- RDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case RECURRENCE_ID: /* ------------------- RecurrenceID -------------------- */ // Done above break; case RELATED_TO: /* ------------------- RelatedTo -------------------- */ final RelatedTo irelto = (RelatedTo)prop; final BwRelatedTo relto = new BwRelatedTo(); final String parval = IcalUtil.getParameterVal(irelto, "RELTYPE"); if (parval != null) { relto.setRelType(parval); } relto.setValue(irelto.getValue()); if (chg.changed(pi, ev.getRelatedTo(), relto)) { ev.setRelatedTo(relto); } break; case REQUEST_STATUS: /* ------------------- RequestStatus -------------------- */ final BwRequestStatus rs = BwRequestStatus .fromRequestStatus((RequestStatus)prop); chg.addValue(pi, rs); break; case RESOURCES: /* ------------------- Resources -------------------- */ final TextList rl = ((Resources)prop).getResources(); if (rl != null) { /* Got some resources */ lang = IcalUtil.getLang(prop); for (final String s: rl) { final BwString rsrc = new BwString(lang, s); chg.addValue(pi, rsrc); } } break; case RRULE: /* ------------------- RRule -------------------- */ chg.addValue(pi, pval); break; case SEQUENCE: /* ------------------- Sequence -------------------- */ final int seq = ((Sequence)prop).getSequenceNo(); if (seq != ev.getSequence()) { chg.changed(pi, ev.getSequence(), seq); ev.setSequence(seq); } break; case STATUS: /* ------------------- Status -------------------- */ if (chg.changed(pi, ev.getStatus(), pval)) { ev.setStatus(pval); } break; case SUMMARY: /* ------------------- Summary -------------------- */ if (chg.changed(pi, ev.getSummary(), pval)) { ev.setSummary(pval); } break; case TRANSP: /* ------------------- Transp -------------------- */ if (chg.changed(pi, ev.getPeruserTransparency( cb.getPrincipal() .getPrincipalRef()), pval)) { final BwXproperty pu = ev.setPeruserTransparency( cb.getPrincipal().getPrincipalRef(), pval); if (pu != null) { chg.addValue(PropertyInfoIndex.XPROP, pu); } } break; case UID: /* ------------------- Uid -------------------- */ /* We did this above */ break; case URL: /* ------------------- Url -------------------- */ if (chg.changed(pi, ev.getLink(), pval)) { ev.setLink(pval); } break; case XPROP: /* ------------------------- x-property --------------------------- */ final String name = prop.getName(); if (name.equalsIgnoreCase(BwXproperty.bedeworkCost)) { if (chg.changed(PropertyInfoIndex.COST, ev.getCost(), pval)) { ev.setCost(pval); } break; } if (name.equalsIgnoreCase(BwXproperty.xBedeworkCategories)) { if (checkCategory(cb, chg, ev, null, pval)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkLocation)) { if (checkLocation(cb, chg, ev, prop)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkContact)) { if (checkContact(cb, chg, ev, null, pval)) { break; } } /* See if this is an x-category that can be converted to a real category */ final XProperty xp = (XProperty)prop; chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(name, xp.getParameters() .toString(), pval)); break; default: if (logger.debug()) { logger.debug("Unsupported property with index " + pi + "; class " + prop.getClass() + " and value " + pval); } } } /* =================== Process sub-components =============== */ final ComponentList<Component> subComps; if (val instanceof ComponentContainer) { subComps = ((ComponentContainer<Component>)val).getComponents(); } else { subComps = null; } final Set<Integer> pids; if (vpoll) { pids = new TreeSet<>(); final BwEvent vp = evinfo.getEvent(); if (!Util.isEmpty(vp.getPollItems())) { vp.clearPollItems(); } } else { pids = null; } if (!Util.isEmpty(subComps)) { for (final var subComp: subComps) { if (subComp instanceof Available) { if (!(val instanceof VAvailability)) { return Response.error(resp, "AVAILABLE only valid in VAVAILABLE"); } final var avlResp = processAvailable(cb, cal, ical, (VAvailability)val, (Available)subComp, evinfo); if (!avlResp.isOk()) { return Response.fromResponse(resp, avlResp); } continue; } if (subComp instanceof Participant) { if (vpoll) { final var vresp = processVoter(cb, (VPoll)val, (Participant)subComp, evinfo, chg, mergeAttendees); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Participant object"); continue; } if (subComp instanceof VResource) { logger.warn("Unimplemented VResource object"); continue; } if (subComp instanceof VLocation) { logger.warn("Unimplemented VLocation object"); continue; } if (subComp instanceof VAlarm) { final var aresp = VAlarmUtil.processAlarm(cb, val, (VAlarm)subComp, ev, currentPrincipal, chg); if (!aresp.isOk()) { return Response.fromResponse(resp, aresp); } continue; } if (vpoll && (event || task)) { final var vresp = processCandidate((VPoll)val, subComp, evinfo, pids, chg); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Component object: " + subComp); } } /* Fix up timestamps. */ if (ev.getCreated() == null) { if (ev.getLastmod() != null) { ev.setCreated(ev.getLastmod()); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); } else { ev.updateDtstamp(); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } } if (ev.getLastmod() == null) { // created cannot be null now ev.setLastmod(ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } processTimezones(ev, ical, chg); /* Remove any recipients and originator */ if (ev.getRecipients() != null) { ev.getRecipients().clear(); } ev.setOriginator(null); if (hasXparams.value) { /* Save a text copy of the entire event as an x-property */ final Component valCopy = val.copy(); /* Remove potentially large values */ final Description desp = valCopy.getProperty(Property.DESCRIPTION); if (desp != null) { desp.setValue(null); } final Attach attachp = valCopy.getProperty(Property.ATTACH); // Don't store the entire attachment - we just need the parameters. if (attachp != null) { final Value v = attachp.getParameter(Parameter.VALUE); if (v != null) { attachp.setValue(String.valueOf(attachp.getValue().hashCode())); } } chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(BwXproperty.bedeworkIcal, null, valCopy.toString())); } chg.processChanges(ev, true, false); ev.setRecurring(ev.isRecurringEntity()); if (logger.debug()) { logger.debug(chg.toString()); logger.debug(ev.toString()); } if (masterEI != null) { // Just return notfound as this event is on its override list return Response.notFound(resp); } resp.setEntity(evinfo); return resp; } catch (final Throwable t) { if (logger.debug()) { logger.error(t); } return Response.error(resp, t); } }
NONSATD
true
break; case CLASS: /* ------------------- Class -------------------- */ if (chg.changed(pi, ev.getClassification(), pval)) { ev.setClassification(pval);
cat.setWord(key); cb.addCategory(cat); } else { cat = fcResp.getEntity(); } chg.addValue(pi, cat); } } break; case CLASS: /* ------------------- Class -------------------- */ if (chg.changed(pi, ev.getClassification(), pval)) { ev.setClassification(pval); } break; case COMMENT: /* ------------------- Comment -------------------- */ chg.addValue(pi, new BwString(null, pval)); break; case COMPLETED:
continue; } final BwString key = new BwString(lang, wd); final var fcResp = cb.findCategory(key); final BwCategory cat; if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isNotFound()) { cat = BwCategory.makeCategory(); cat.setWord(key); cb.addCategory(cat); } else { cat = fcResp.getEntity(); } chg.addValue(pi, cat); } } break; case CLASS: /* ------------------- Class -------------------- */ if (chg.changed(pi, ev.getClassification(), pval)) { ev.setClassification(pval); } break; case COMMENT: /* ------------------- Comment -------------------- */ chg.addValue(pi, new BwString(null, pval)); break; case COMPLETED: /* ------------------- Completed -------------------- */ if (chg.changed(pi, ev.getCompleted(), pval)) { ev.setCompleted(pval); } break; case CONCEPT: /* ------------------- Concept -------------------- */ final Concept c = (Concept)prop; final String cval = c.getValue(); if (cval != null) {
7,893
32
/* ------------------- Comment -------------------- */
public static GetEntityResponse<EventInfo> toEvent( final IcalCallback cb, final BwCalendar cal, final Icalendar ical, final Component val, final boolean mergeAttendees) { final var resp = new GetEntityResponse<EventInfo>(); if (val == null) { return Response.notOk(resp, failed, "No component supplied"); } String currentPrincipal = null; final BwPrincipal principal = cb.getPrincipal(); if (principal != null) { currentPrincipal = principal.getPrincipalRef(); } final Holder<Boolean> hasXparams = new Holder<>(Boolean.FALSE); final int methodType = ical.getMethodType(); String attUri = null; if (mergeAttendees) { // We'll need this later. attUri = cb.getCaladdr(cb.getPrincipal().getPrincipalRef()); } final String colPath; if (cal == null) { colPath = null; } else { colPath = cal.getPath(); } try { final PropertyList<Property> pl = val.getProperties(); boolean vpoll = false; boolean event = false; boolean task = false; if (pl == null) { // Empty component return Response.notOk(resp, failed, "Empty component"); } final int entityType; if (val instanceof VEvent) { entityType = IcalDefs.entityTypeEvent; event = true; } else if (val instanceof VToDo) { entityType = IcalDefs.entityTypeTodo; task = true; } else if (val instanceof VJournal) { entityType = IcalDefs.entityTypeJournal; } else if (val instanceof VFreeBusy) { entityType = IcalDefs.entityTypeFreeAndBusy; } else if (val instanceof VAvailability) { entityType = IcalDefs.entityTypeVavailability; } else if (val instanceof Available) { entityType = IcalDefs.entityTypeAvailable; } else if (val instanceof VPoll) { entityType = IcalDefs.entityTypeVpoll; vpoll = true; } else { return Response.error(resp, "org.bedework.invalid.component.type: " + val.getName()); } // Get the guid from the component String guid = null; final Uid uidp = pl.getProperty(Property.UID); if (uidp != null) { testXparams(uidp, hasXparams); guid = uidp.getValue(); } if (guid == null) { /* XXX A guid is required - but are there devices out there without a * guid - and if so how do we handle it? */ return Response.notOk(resp, failed, CalFacadeException.noGuid); } /* See if we have a recurrence id */ BwDateTime ridObj = null; String rid = null; TimeZone ridTz = null; final RecurrenceId ridp = pl.getProperty(Property.RECURRENCE_ID); if (ridp != null) { testXparams(ridp, hasXparams); ridObj = BwDateTime.makeBwDateTime(ridp); if (ridObj.getRange() != null) { /* XXX What do I do with it? */ logger.warn("TRANS-TO_EVENT: Got a recurrence id range"); } rid = ridObj.getDate(); } EventInfo masterEI = null; EventInfo evinfo = null; final BwEvent ev; /* If we have a recurrence id see if we already have the master (we should * get a master + all its overrides). * * If so find the override and use the annnotation or if no override, * make one. * * If no override retrieve the event, add it to our table and then locate the * annotation. * * If there is no annotation, create one. * * It's possible we have been sent 'detached' instances of a recurring * event. This may happen if we are invited to one or more instances of a * meeting. In this case we try to retrieve the master and if it doesn't * exist we manufacture one. We consider such an instance an update to * that instance only and leave the others alone. */ /* We need this in a couple of places */ final DtStart dtStart = pl.getProperty(Property.DTSTART); /* if (rid != null) { // See if we have a new master event. If so create a proxy to that event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI == null) { masterEI = makeNewEvent(cb, chg, entityType, guid, cal); BwEvent e = masterEI.getEvent(); // XXX This seems bogus DtStart mdtStart; String bogusDate = "19980118T230000"; if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + "Z"); } else if (dtStart.getTimeZone() == null) { mdtStart = new DtStart(bogusDate); } else { mdtStart = new DtStart(bogusDate + "Z", dtStart.getTimeZone()); } setDates(e, mdtStart, null, null, chg); e.setRecurring(true); e.addRdate(ridObj); e.setSuppressed(true); ical.addComponent(masterEI); } if (masterEI != null) { evinfo = masterEI.findOverride(rid); } } */ /* If this is a recurrence instance see if we can find the master We only need this because the master may follow the overrides. */ if (rid != null) { // See if we have a new master event. If so create a proxy to this event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI != null) { evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; } } if ((evinfo == null) && (cal != null) && (cal.getCalType() != BwCalendar.calTypeInbox) && (cal.getCalType() != BwCalendar.calTypePendingInbox) && (cal.getCalType() != BwCalendar.calTypeOutbox)) { if (logger.debug()) { logger.debug("TRANS-TO_EVENT: try to fetch event with guid=" + guid); } final GetEntitiesResponse<EventInfo> eisResp = cb.getEvent(colPath, guid); if (eisResp.isError()) { return Response.fromResponse(resp, eisResp); } final var eis = eisResp.getEntities(); if (!Util.isEmpty(eis)) { if (eis.size() > 1) { // DORECUR - wrong again return Response.notOk(resp, failed, "More than one event returned for guid."); } evinfo = eis.iterator().next(); } if (logger.debug()) { if (evinfo != null) { logger.debug("TRANS-TO_EVENT: fetched event with guid"); } else { logger.debug("TRANS-TO_EVENT: did not find event with guid"); } } if (evinfo != null) { if (rid != null) { // We just retrieved it's master masterEI = evinfo; masterEI.setInstanceOnly(true); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; ical.addComponent(masterEI); } else if (methodType == ScheduleMethods.methodTypeCancel) { // This should never have an rid for cancel of entire event. evinfo.setInstanceOnly(evinfo.getEvent().getSuppressed()); } else { // Presumably sent an update for the entire event. No longer suppressed master evinfo.getEvent().setSuppressed(false); } } else if (rid != null) { /* Manufacture a master for the instance */ masterEI = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); final BwEvent e = masterEI.getEvent(); // XXX This seems bogus final DtStart mdtStart; final String bogusDate = "19980118"; final String bogusTime = "T230000"; // Base dtstart on the recurrence id. final boolean isDateType = ridObj.getDateType(); if (isDateType) { mdtStart = new DtStart(new Date(bogusDate)); } else if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + bogusTime + "Z"); } else if (ridObj.getTzid() == null) { mdtStart = new DtStart(bogusDate + bogusTime); } else { mdtStart = new DtStart(bogusDate + bogusTime, Timezones.getTz(ridObj.getTzid())); } IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), masterEI, mdtStart, null, null); e.setRecurring(true); // e.addRdate(ridObj); final var sum = (Summary)pl.getProperty(Property.SUMMARY); e.setSummary(sum.getValue()); e.setSuppressed(true); ical.addComponent(masterEI); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; masterEI.setInstanceOnly(rid != null); } } if (evinfo == null) { evinfo = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); } else if (evinfo.getEvent().getEntityType() != entityType) { return Response.notOk(resp, failed, "org.bedework.mismatched.entity.type: " + val); } final ChangeTable chg = evinfo.getChangeset( cb.getPrincipal().getPrincipalRef()); if (rid != null) { final String evrid = evinfo.getEvent().getRecurrenceId(); if ((evrid == null) || (!evrid.equals(rid))) { logger. warn("Mismatched rid ev=" + evrid + " expected " + rid); chg.changed(PropertyInfoIndex.RECURRENCE_ID, evrid, rid); // XXX spurious??? } if (masterEI.getEvent().getSuppressed()) { masterEI.getEvent().addRdate(ridObj); } } ev = evinfo.getEvent(); ev.setScheduleMethod(methodType); DtEnd dtEnd = null; if (entityType == IcalDefs.entityTypeTodo) { final Due due = pl.getProperty(Property.DUE); if (due != null ) { dtEnd = new DtEnd(due.getParameters(), due.getValue()); } } else { dtEnd = pl.getProperty(Property.DTEND); } final Duration duration = pl.getProperty(Property.DURATION); IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), evinfo, dtStart, dtEnd, duration); for (final Property prop: pl) { testXparams(prop, hasXparams); //debug("ical prop " + prop.getClass().getName()); String pval = prop.getValue(); if ((pval != null) && (pval.length() == 0)) { pval = null; } final PropertyInfoIndex pi; if (prop instanceof XProperty) { pi = PropertyInfoIndex.XPROP; } else { pi = PropertyInfoIndex.fromName(prop.getName()); } if (pi == null) { logger.debug("Unknown property with name " + prop.getName() + " class " + prop.getClass() + " and value " + pval); continue; } chg.present(pi); switch (pi) { case ACCEPT_RESPONSE: /* ------------------- Accept Response -------------------- */ String sval = prop.getValue(); if (chg.changed(pi, ev.getPollAcceptResponse(), sval)) { ev.setPollAcceptResponse(sval); } break; case ATTACH: /* ------------------- Attachment -------------------- */ chg.addValue(pi, IcalUtil.getAttachment((Attach)prop)); break; case ATTENDEE: /* ------------------- Attendee -------------------- */ if (methodType == ScheduleMethods.methodTypePublish) { if (cb.getStrictness() == IcalCallback.conformanceStrict) { return Response.notOk(resp, failed, CalFacadeException.attendeesInPublish); } //if (cb.getStrictness() == IcalCallback.conformanceWarn) { // warn("Had attendees for PUBLISH"); //} } final Attendee attPr = (Attendee)prop; if (evinfo.getNewEvent() || !mergeAttendees) { chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { final String pUri = cb.getCaladdr(attPr.getValue()); if (pUri.equals(attUri)) { /* Only update for our own attendee * We're doing a PUT and this must be the attendee updating their * partstat. We don't allow them to change other attendees * whatever the PUT content says. */ chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { // Use the value we currently have boolean found = false; for (final BwAttendee att: ev.getAttendees()) { if (pUri.equals(att.getAttendeeUri())) { chg.addValue(pi, att.clone()); found = true; break; } } if (!found) { // An added attendee final BwAttendee att = IcalUtil .getAttendee(cb, attPr); att.setPartstat(IcalDefs.partstatValNeedsAction); chg.addValue(pi, att); } } } break; case BUSYTYPE: final int ibt = BwEvent.fromBusyTypeString(pval); if (chg.changed(pi, ev.getBusyType(), ibt)) { ev.setBusyType(ibt); } break; case CATEGORIES: /* ------------------- Categories -------------------- */ final Categories cats = (Categories)prop; final TextList cl = cats.getCategories(); String lang = IcalUtil.getLang(cats); if (cl != null) { /* Got some categories */ for (final String wd: cl) { if (wd == null) { continue; } final BwString key = new BwString(lang, wd); final var fcResp = cb.findCategory(key); final BwCategory cat; if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isNotFound()) { cat = BwCategory.makeCategory(); cat.setWord(key); cb.addCategory(cat); } else { cat = fcResp.getEntity(); } chg.addValue(pi, cat); } } break; case CLASS: /* ------------------- Class -------------------- */ if (chg.changed(pi, ev.getClassification(), pval)) { ev.setClassification(pval); } break; case COMMENT: /* ------------------- Comment -------------------- */ chg.addValue(pi, new BwString(null, pval)); break; case COMPLETED: /* ------------------- Completed -------------------- */ if (chg.changed(pi, ev.getCompleted(), pval)) { ev.setCompleted(pval); } break; case CONCEPT: /* ------------------- Concept -------------------- */ final Concept c = (Concept)prop; final String cval = c.getValue(); if (cval != null) { /* Got a concept */ chg.addValue(PropertyInfoIndex.XPROP, BwXproperty.makeIcalProperty("CONCEPT", null, cval)); } break; case CONTACT: /* ------------------- Contact -------------------- */ final String altrep = getAltRepPar(prop); lang = IcalUtil.getLang(prop); final String uid = getUidPar(prop); final BwString nm = new BwString(lang, pval); BwContact contact = null; if (uid != null) { final var fcResp = cb.getContact(uid); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { final var fcResp = cb.findContact(nm); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { contact = BwContact.makeContact(); contact.setCn(nm); contact.setLink(altrep); cb.addContact(contact); } else { contact.setCn(nm); contact.setLink(altrep); } chg.addValue(pi, contact); break; case CREATED: /* ------------------- Created -------------------- */ if (chg.changed(pi, ev.getCreated(), pval)) { ev.setCreated(pval); } break; case DESCRIPTION: /* ------------------- Description -------------------- */ if (chg.changed(pi, ev.getDescription(), pval)) { ev.setDescription(pval); } break; case DTEND: /* ------------------- DtEnd -------------------- */ break; case DTSTAMP: /* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval); break; case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE: /* -------------------- Due ------------------------ */ break; case DURATION: /* ------------------- Duration -------------------- */ break; case EXDATE: /* ------------------- ExDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case EXRULE: /* ------------------- ExRule -------------------- */ chg.addValue(pi, pval); break; case FREEBUSY: /* ------------------- freebusy -------------------- */ final FreeBusy fbusy = (FreeBusy)prop; final PeriodList perpl = fbusy.getPeriods(); final Parameter par = IcalUtil.getParameter(fbusy, "FBTYPE"); final int fbtype; if (par == null) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY)) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY_TENTATIVE)) { fbtype = BwFreeBusyComponent.typeBusyTentative; } else if (par.equals(FbType.BUSY_UNAVAILABLE)) { fbtype = BwFreeBusyComponent.typeBusyUnavailable; } else if (par.equals(FbType.FREE)) { fbtype = BwFreeBusyComponent.typeFree; } else { if (logger.debug()) { logger.debug("Unsupported parameter " + par.getName()); } return Response.notOk(resp, failed, "Unsupported parameter " + par.getName()); } final BwFreeBusyComponent fbc = new BwFreeBusyComponent(); fbc.setType(fbtype); for (final Period per : perpl) { fbc.addPeriod(per); } ev.addFreeBusyPeriod(fbc); break; case GEO: /* ------------------- Geo -------------------- */ final Geo g = (Geo)prop; final BwGeo geo = new BwGeo(g.getLatitude(), g.getLongitude()); if (chg.changed(pi, ev.getGeo(), geo)) { ev.setGeo(geo); } break; case LAST_MODIFIED: /* ------------------- LastModified -------------------- */ if (chg.changed(pi, ev.getLastmod(), pval)) { ev.setLastmod(pval); } break; case LOCATION: /* ------------------- Location -------------------- */ BwLocation loc = null; //String uid = getUidPar(prop); /* At the moment Mozilla lightning is broken and this leads to all * sorts of problems. if (uid != null) { loc = cb.getLocation(uid); } */ lang = IcalUtil.getLang(prop); BwString addr = null; if (pval != null) { if (loc == null) { addr = new BwString(lang, pval); final var fcResp = cb.findLocation(addr); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { loc = fcResp.getEntity(); } } if (loc == null) { loc = BwLocation.makeLocation(); loc.setAddress(addr); cb.addLocation(loc); } } final BwLocation evloc = ev.getLocation(); if (chg.changed(pi, evloc, loc)) { // CHGTBL - this only shows that it's a different location object ev.setLocation(loc); } else if ((loc != null) && (evloc != null)) { // See if the value is changed final String evval = evloc.getAddress().getValue(); final String inval = loc.getAddress().getValue(); if (!evval.equals(inval)) { chg.changed(pi, evval, inval); evloc.getAddress().setValue(inval); } } break; case ORGANIZER: /* ------------------- Organizer -------------------- */ final BwOrganizer org = IcalUtil.getOrganizer(cb, (Organizer)prop); final BwOrganizer evorg = ev.getOrganizer(); final BwOrganizer evorgCopy; if (evorg == null) { evorgCopy = null; } else { evorgCopy = (BwOrganizer)evorg.clone(); } if (chg.changed(pi, evorgCopy, org)) { if (evorg == null) { ev.setOrganizer(org); } else { evorg.update(org); } } break; case PERCENT_COMPLETE: /* ------------------- PercentComplete -------------------- */ Integer ival = ((PercentComplete)prop).getPercentage(); if (chg.changed(pi, ev.getPercentComplete(), ival)) { ev.setPercentComplete(ival); } break; case POLL_MODE: /* ------------------- Poll mode -------------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollMode(), sval)) { ev.setPollMode(sval); } break; case POLL_PROPERTIES: /* ------------------- Poll properties ---------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollProperties(), sval)) { ev.setPollProperties(sval); } break; case POLL_WINNER: /* ------------------- Poll winner -------------------- */ ival = ((PollWinner)prop).getPollwinner(); if (chg.changed(pi, ev.getPollWinner(), ival)) { ev.setPollWinner(ival); } break; case PRIORITY: /* ------------------- Priority -------------------- */ ival = ((Priority)prop).getLevel(); if (chg.changed(pi, ev.getPriority(), ival)) { ev.setPriority(ival); } break; case RDATE: /* ------------------- RDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case RECURRENCE_ID: /* ------------------- RecurrenceID -------------------- */ // Done above break; case RELATED_TO: /* ------------------- RelatedTo -------------------- */ final RelatedTo irelto = (RelatedTo)prop; final BwRelatedTo relto = new BwRelatedTo(); final String parval = IcalUtil.getParameterVal(irelto, "RELTYPE"); if (parval != null) { relto.setRelType(parval); } relto.setValue(irelto.getValue()); if (chg.changed(pi, ev.getRelatedTo(), relto)) { ev.setRelatedTo(relto); } break; case REQUEST_STATUS: /* ------------------- RequestStatus -------------------- */ final BwRequestStatus rs = BwRequestStatus .fromRequestStatus((RequestStatus)prop); chg.addValue(pi, rs); break; case RESOURCES: /* ------------------- Resources -------------------- */ final TextList rl = ((Resources)prop).getResources(); if (rl != null) { /* Got some resources */ lang = IcalUtil.getLang(prop); for (final String s: rl) { final BwString rsrc = new BwString(lang, s); chg.addValue(pi, rsrc); } } break; case RRULE: /* ------------------- RRule -------------------- */ chg.addValue(pi, pval); break; case SEQUENCE: /* ------------------- Sequence -------------------- */ final int seq = ((Sequence)prop).getSequenceNo(); if (seq != ev.getSequence()) { chg.changed(pi, ev.getSequence(), seq); ev.setSequence(seq); } break; case STATUS: /* ------------------- Status -------------------- */ if (chg.changed(pi, ev.getStatus(), pval)) { ev.setStatus(pval); } break; case SUMMARY: /* ------------------- Summary -------------------- */ if (chg.changed(pi, ev.getSummary(), pval)) { ev.setSummary(pval); } break; case TRANSP: /* ------------------- Transp -------------------- */ if (chg.changed(pi, ev.getPeruserTransparency( cb.getPrincipal() .getPrincipalRef()), pval)) { final BwXproperty pu = ev.setPeruserTransparency( cb.getPrincipal().getPrincipalRef(), pval); if (pu != null) { chg.addValue(PropertyInfoIndex.XPROP, pu); } } break; case UID: /* ------------------- Uid -------------------- */ /* We did this above */ break; case URL: /* ------------------- Url -------------------- */ if (chg.changed(pi, ev.getLink(), pval)) { ev.setLink(pval); } break; case XPROP: /* ------------------------- x-property --------------------------- */ final String name = prop.getName(); if (name.equalsIgnoreCase(BwXproperty.bedeworkCost)) { if (chg.changed(PropertyInfoIndex.COST, ev.getCost(), pval)) { ev.setCost(pval); } break; } if (name.equalsIgnoreCase(BwXproperty.xBedeworkCategories)) { if (checkCategory(cb, chg, ev, null, pval)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkLocation)) { if (checkLocation(cb, chg, ev, prop)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkContact)) { if (checkContact(cb, chg, ev, null, pval)) { break; } } /* See if this is an x-category that can be converted to a real category */ final XProperty xp = (XProperty)prop; chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(name, xp.getParameters() .toString(), pval)); break; default: if (logger.debug()) { logger.debug("Unsupported property with index " + pi + "; class " + prop.getClass() + " and value " + pval); } } } /* =================== Process sub-components =============== */ final ComponentList<Component> subComps; if (val instanceof ComponentContainer) { subComps = ((ComponentContainer<Component>)val).getComponents(); } else { subComps = null; } final Set<Integer> pids; if (vpoll) { pids = new TreeSet<>(); final BwEvent vp = evinfo.getEvent(); if (!Util.isEmpty(vp.getPollItems())) { vp.clearPollItems(); } } else { pids = null; } if (!Util.isEmpty(subComps)) { for (final var subComp: subComps) { if (subComp instanceof Available) { if (!(val instanceof VAvailability)) { return Response.error(resp, "AVAILABLE only valid in VAVAILABLE"); } final var avlResp = processAvailable(cb, cal, ical, (VAvailability)val, (Available)subComp, evinfo); if (!avlResp.isOk()) { return Response.fromResponse(resp, avlResp); } continue; } if (subComp instanceof Participant) { if (vpoll) { final var vresp = processVoter(cb, (VPoll)val, (Participant)subComp, evinfo, chg, mergeAttendees); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Participant object"); continue; } if (subComp instanceof VResource) { logger.warn("Unimplemented VResource object"); continue; } if (subComp instanceof VLocation) { logger.warn("Unimplemented VLocation object"); continue; } if (subComp instanceof VAlarm) { final var aresp = VAlarmUtil.processAlarm(cb, val, (VAlarm)subComp, ev, currentPrincipal, chg); if (!aresp.isOk()) { return Response.fromResponse(resp, aresp); } continue; } if (vpoll && (event || task)) { final var vresp = processCandidate((VPoll)val, subComp, evinfo, pids, chg); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Component object: " + subComp); } } /* Fix up timestamps. */ if (ev.getCreated() == null) { if (ev.getLastmod() != null) { ev.setCreated(ev.getLastmod()); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); } else { ev.updateDtstamp(); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } } if (ev.getLastmod() == null) { // created cannot be null now ev.setLastmod(ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } processTimezones(ev, ical, chg); /* Remove any recipients and originator */ if (ev.getRecipients() != null) { ev.getRecipients().clear(); } ev.setOriginator(null); if (hasXparams.value) { /* Save a text copy of the entire event as an x-property */ final Component valCopy = val.copy(); /* Remove potentially large values */ final Description desp = valCopy.getProperty(Property.DESCRIPTION); if (desp != null) { desp.setValue(null); } final Attach attachp = valCopy.getProperty(Property.ATTACH); // Don't store the entire attachment - we just need the parameters. if (attachp != null) { final Value v = attachp.getParameter(Parameter.VALUE); if (v != null) { attachp.setValue(String.valueOf(attachp.getValue().hashCode())); } } chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(BwXproperty.bedeworkIcal, null, valCopy.toString())); } chg.processChanges(ev, true, false); ev.setRecurring(ev.isRecurringEntity()); if (logger.debug()) { logger.debug(chg.toString()); logger.debug(ev.toString()); } if (masterEI != null) { // Just return notfound as this event is on its override list return Response.notFound(resp); } resp.setEntity(evinfo); return resp; } catch (final Throwable t) { if (logger.debug()) { logger.error(t); } return Response.error(resp, t); } }
NONSATD
true
break; case COMMENT: /* ------------------- Comment -------------------- */ chg.addValue(pi, new BwString(null, pval));
} } break; case CLASS: /* ------------------- Class -------------------- */ if (chg.changed(pi, ev.getClassification(), pval)) { ev.setClassification(pval); } break; case COMMENT: /* ------------------- Comment -------------------- */ chg.addValue(pi, new BwString(null, pval)); break; case COMPLETED: /* ------------------- Completed -------------------- */ if (chg.changed(pi, ev.getCompleted(), pval)) { ev.setCompleted(pval); } break; case CONCEPT:
return Response.fromResponse(resp, fcResp); } if (fcResp.isNotFound()) { cat = BwCategory.makeCategory(); cat.setWord(key); cb.addCategory(cat); } else { cat = fcResp.getEntity(); } chg.addValue(pi, cat); } } break; case CLASS: /* ------------------- Class -------------------- */ if (chg.changed(pi, ev.getClassification(), pval)) { ev.setClassification(pval); } break; case COMMENT: /* ------------------- Comment -------------------- */ chg.addValue(pi, new BwString(null, pval)); break; case COMPLETED: /* ------------------- Completed -------------------- */ if (chg.changed(pi, ev.getCompleted(), pval)) { ev.setCompleted(pval); } break; case CONCEPT: /* ------------------- Concept -------------------- */ final Concept c = (Concept)prop; final String cval = c.getValue(); if (cval != null) { /* Got a concept */ chg.addValue(PropertyInfoIndex.XPROP, BwXproperty.makeIcalProperty("CONCEPT", null, cval)); }
7,893
33
/* ------------------- Completed -------------------- */
public static GetEntityResponse<EventInfo> toEvent( final IcalCallback cb, final BwCalendar cal, final Icalendar ical, final Component val, final boolean mergeAttendees) { final var resp = new GetEntityResponse<EventInfo>(); if (val == null) { return Response.notOk(resp, failed, "No component supplied"); } String currentPrincipal = null; final BwPrincipal principal = cb.getPrincipal(); if (principal != null) { currentPrincipal = principal.getPrincipalRef(); } final Holder<Boolean> hasXparams = new Holder<>(Boolean.FALSE); final int methodType = ical.getMethodType(); String attUri = null; if (mergeAttendees) { // We'll need this later. attUri = cb.getCaladdr(cb.getPrincipal().getPrincipalRef()); } final String colPath; if (cal == null) { colPath = null; } else { colPath = cal.getPath(); } try { final PropertyList<Property> pl = val.getProperties(); boolean vpoll = false; boolean event = false; boolean task = false; if (pl == null) { // Empty component return Response.notOk(resp, failed, "Empty component"); } final int entityType; if (val instanceof VEvent) { entityType = IcalDefs.entityTypeEvent; event = true; } else if (val instanceof VToDo) { entityType = IcalDefs.entityTypeTodo; task = true; } else if (val instanceof VJournal) { entityType = IcalDefs.entityTypeJournal; } else if (val instanceof VFreeBusy) { entityType = IcalDefs.entityTypeFreeAndBusy; } else if (val instanceof VAvailability) { entityType = IcalDefs.entityTypeVavailability; } else if (val instanceof Available) { entityType = IcalDefs.entityTypeAvailable; } else if (val instanceof VPoll) { entityType = IcalDefs.entityTypeVpoll; vpoll = true; } else { return Response.error(resp, "org.bedework.invalid.component.type: " + val.getName()); } // Get the guid from the component String guid = null; final Uid uidp = pl.getProperty(Property.UID); if (uidp != null) { testXparams(uidp, hasXparams); guid = uidp.getValue(); } if (guid == null) { /* XXX A guid is required - but are there devices out there without a * guid - and if so how do we handle it? */ return Response.notOk(resp, failed, CalFacadeException.noGuid); } /* See if we have a recurrence id */ BwDateTime ridObj = null; String rid = null; TimeZone ridTz = null; final RecurrenceId ridp = pl.getProperty(Property.RECURRENCE_ID); if (ridp != null) { testXparams(ridp, hasXparams); ridObj = BwDateTime.makeBwDateTime(ridp); if (ridObj.getRange() != null) { /* XXX What do I do with it? */ logger.warn("TRANS-TO_EVENT: Got a recurrence id range"); } rid = ridObj.getDate(); } EventInfo masterEI = null; EventInfo evinfo = null; final BwEvent ev; /* If we have a recurrence id see if we already have the master (we should * get a master + all its overrides). * * If so find the override and use the annnotation or if no override, * make one. * * If no override retrieve the event, add it to our table and then locate the * annotation. * * If there is no annotation, create one. * * It's possible we have been sent 'detached' instances of a recurring * event. This may happen if we are invited to one or more instances of a * meeting. In this case we try to retrieve the master and if it doesn't * exist we manufacture one. We consider such an instance an update to * that instance only and leave the others alone. */ /* We need this in a couple of places */ final DtStart dtStart = pl.getProperty(Property.DTSTART); /* if (rid != null) { // See if we have a new master event. If so create a proxy to that event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI == null) { masterEI = makeNewEvent(cb, chg, entityType, guid, cal); BwEvent e = masterEI.getEvent(); // XXX This seems bogus DtStart mdtStart; String bogusDate = "19980118T230000"; if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + "Z"); } else if (dtStart.getTimeZone() == null) { mdtStart = new DtStart(bogusDate); } else { mdtStart = new DtStart(bogusDate + "Z", dtStart.getTimeZone()); } setDates(e, mdtStart, null, null, chg); e.setRecurring(true); e.addRdate(ridObj); e.setSuppressed(true); ical.addComponent(masterEI); } if (masterEI != null) { evinfo = masterEI.findOverride(rid); } } */ /* If this is a recurrence instance see if we can find the master We only need this because the master may follow the overrides. */ if (rid != null) { // See if we have a new master event. If so create a proxy to this event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI != null) { evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; } } if ((evinfo == null) && (cal != null) && (cal.getCalType() != BwCalendar.calTypeInbox) && (cal.getCalType() != BwCalendar.calTypePendingInbox) && (cal.getCalType() != BwCalendar.calTypeOutbox)) { if (logger.debug()) { logger.debug("TRANS-TO_EVENT: try to fetch event with guid=" + guid); } final GetEntitiesResponse<EventInfo> eisResp = cb.getEvent(colPath, guid); if (eisResp.isError()) { return Response.fromResponse(resp, eisResp); } final var eis = eisResp.getEntities(); if (!Util.isEmpty(eis)) { if (eis.size() > 1) { // DORECUR - wrong again return Response.notOk(resp, failed, "More than one event returned for guid."); } evinfo = eis.iterator().next(); } if (logger.debug()) { if (evinfo != null) { logger.debug("TRANS-TO_EVENT: fetched event with guid"); } else { logger.debug("TRANS-TO_EVENT: did not find event with guid"); } } if (evinfo != null) { if (rid != null) { // We just retrieved it's master masterEI = evinfo; masterEI.setInstanceOnly(true); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; ical.addComponent(masterEI); } else if (methodType == ScheduleMethods.methodTypeCancel) { // This should never have an rid for cancel of entire event. evinfo.setInstanceOnly(evinfo.getEvent().getSuppressed()); } else { // Presumably sent an update for the entire event. No longer suppressed master evinfo.getEvent().setSuppressed(false); } } else if (rid != null) { /* Manufacture a master for the instance */ masterEI = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); final BwEvent e = masterEI.getEvent(); // XXX This seems bogus final DtStart mdtStart; final String bogusDate = "19980118"; final String bogusTime = "T230000"; // Base dtstart on the recurrence id. final boolean isDateType = ridObj.getDateType(); if (isDateType) { mdtStart = new DtStart(new Date(bogusDate)); } else if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + bogusTime + "Z"); } else if (ridObj.getTzid() == null) { mdtStart = new DtStart(bogusDate + bogusTime); } else { mdtStart = new DtStart(bogusDate + bogusTime, Timezones.getTz(ridObj.getTzid())); } IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), masterEI, mdtStart, null, null); e.setRecurring(true); // e.addRdate(ridObj); final var sum = (Summary)pl.getProperty(Property.SUMMARY); e.setSummary(sum.getValue()); e.setSuppressed(true); ical.addComponent(masterEI); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; masterEI.setInstanceOnly(rid != null); } } if (evinfo == null) { evinfo = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); } else if (evinfo.getEvent().getEntityType() != entityType) { return Response.notOk(resp, failed, "org.bedework.mismatched.entity.type: " + val); } final ChangeTable chg = evinfo.getChangeset( cb.getPrincipal().getPrincipalRef()); if (rid != null) { final String evrid = evinfo.getEvent().getRecurrenceId(); if ((evrid == null) || (!evrid.equals(rid))) { logger. warn("Mismatched rid ev=" + evrid + " expected " + rid); chg.changed(PropertyInfoIndex.RECURRENCE_ID, evrid, rid); // XXX spurious??? } if (masterEI.getEvent().getSuppressed()) { masterEI.getEvent().addRdate(ridObj); } } ev = evinfo.getEvent(); ev.setScheduleMethod(methodType); DtEnd dtEnd = null; if (entityType == IcalDefs.entityTypeTodo) { final Due due = pl.getProperty(Property.DUE); if (due != null ) { dtEnd = new DtEnd(due.getParameters(), due.getValue()); } } else { dtEnd = pl.getProperty(Property.DTEND); } final Duration duration = pl.getProperty(Property.DURATION); IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), evinfo, dtStart, dtEnd, duration); for (final Property prop: pl) { testXparams(prop, hasXparams); //debug("ical prop " + prop.getClass().getName()); String pval = prop.getValue(); if ((pval != null) && (pval.length() == 0)) { pval = null; } final PropertyInfoIndex pi; if (prop instanceof XProperty) { pi = PropertyInfoIndex.XPROP; } else { pi = PropertyInfoIndex.fromName(prop.getName()); } if (pi == null) { logger.debug("Unknown property with name " + prop.getName() + " class " + prop.getClass() + " and value " + pval); continue; } chg.present(pi); switch (pi) { case ACCEPT_RESPONSE: /* ------------------- Accept Response -------------------- */ String sval = prop.getValue(); if (chg.changed(pi, ev.getPollAcceptResponse(), sval)) { ev.setPollAcceptResponse(sval); } break; case ATTACH: /* ------------------- Attachment -------------------- */ chg.addValue(pi, IcalUtil.getAttachment((Attach)prop)); break; case ATTENDEE: /* ------------------- Attendee -------------------- */ if (methodType == ScheduleMethods.methodTypePublish) { if (cb.getStrictness() == IcalCallback.conformanceStrict) { return Response.notOk(resp, failed, CalFacadeException.attendeesInPublish); } //if (cb.getStrictness() == IcalCallback.conformanceWarn) { // warn("Had attendees for PUBLISH"); //} } final Attendee attPr = (Attendee)prop; if (evinfo.getNewEvent() || !mergeAttendees) { chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { final String pUri = cb.getCaladdr(attPr.getValue()); if (pUri.equals(attUri)) { /* Only update for our own attendee * We're doing a PUT and this must be the attendee updating their * partstat. We don't allow them to change other attendees * whatever the PUT content says. */ chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { // Use the value we currently have boolean found = false; for (final BwAttendee att: ev.getAttendees()) { if (pUri.equals(att.getAttendeeUri())) { chg.addValue(pi, att.clone()); found = true; break; } } if (!found) { // An added attendee final BwAttendee att = IcalUtil .getAttendee(cb, attPr); att.setPartstat(IcalDefs.partstatValNeedsAction); chg.addValue(pi, att); } } } break; case BUSYTYPE: final int ibt = BwEvent.fromBusyTypeString(pval); if (chg.changed(pi, ev.getBusyType(), ibt)) { ev.setBusyType(ibt); } break; case CATEGORIES: /* ------------------- Categories -------------------- */ final Categories cats = (Categories)prop; final TextList cl = cats.getCategories(); String lang = IcalUtil.getLang(cats); if (cl != null) { /* Got some categories */ for (final String wd: cl) { if (wd == null) { continue; } final BwString key = new BwString(lang, wd); final var fcResp = cb.findCategory(key); final BwCategory cat; if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isNotFound()) { cat = BwCategory.makeCategory(); cat.setWord(key); cb.addCategory(cat); } else { cat = fcResp.getEntity(); } chg.addValue(pi, cat); } } break; case CLASS: /* ------------------- Class -------------------- */ if (chg.changed(pi, ev.getClassification(), pval)) { ev.setClassification(pval); } break; case COMMENT: /* ------------------- Comment -------------------- */ chg.addValue(pi, new BwString(null, pval)); break; case COMPLETED: /* ------------------- Completed -------------------- */ if (chg.changed(pi, ev.getCompleted(), pval)) { ev.setCompleted(pval); } break; case CONCEPT: /* ------------------- Concept -------------------- */ final Concept c = (Concept)prop; final String cval = c.getValue(); if (cval != null) { /* Got a concept */ chg.addValue(PropertyInfoIndex.XPROP, BwXproperty.makeIcalProperty("CONCEPT", null, cval)); } break; case CONTACT: /* ------------------- Contact -------------------- */ final String altrep = getAltRepPar(prop); lang = IcalUtil.getLang(prop); final String uid = getUidPar(prop); final BwString nm = new BwString(lang, pval); BwContact contact = null; if (uid != null) { final var fcResp = cb.getContact(uid); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { final var fcResp = cb.findContact(nm); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { contact = BwContact.makeContact(); contact.setCn(nm); contact.setLink(altrep); cb.addContact(contact); } else { contact.setCn(nm); contact.setLink(altrep); } chg.addValue(pi, contact); break; case CREATED: /* ------------------- Created -------------------- */ if (chg.changed(pi, ev.getCreated(), pval)) { ev.setCreated(pval); } break; case DESCRIPTION: /* ------------------- Description -------------------- */ if (chg.changed(pi, ev.getDescription(), pval)) { ev.setDescription(pval); } break; case DTEND: /* ------------------- DtEnd -------------------- */ break; case DTSTAMP: /* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval); break; case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE: /* -------------------- Due ------------------------ */ break; case DURATION: /* ------------------- Duration -------------------- */ break; case EXDATE: /* ------------------- ExDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case EXRULE: /* ------------------- ExRule -------------------- */ chg.addValue(pi, pval); break; case FREEBUSY: /* ------------------- freebusy -------------------- */ final FreeBusy fbusy = (FreeBusy)prop; final PeriodList perpl = fbusy.getPeriods(); final Parameter par = IcalUtil.getParameter(fbusy, "FBTYPE"); final int fbtype; if (par == null) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY)) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY_TENTATIVE)) { fbtype = BwFreeBusyComponent.typeBusyTentative; } else if (par.equals(FbType.BUSY_UNAVAILABLE)) { fbtype = BwFreeBusyComponent.typeBusyUnavailable; } else if (par.equals(FbType.FREE)) { fbtype = BwFreeBusyComponent.typeFree; } else { if (logger.debug()) { logger.debug("Unsupported parameter " + par.getName()); } return Response.notOk(resp, failed, "Unsupported parameter " + par.getName()); } final BwFreeBusyComponent fbc = new BwFreeBusyComponent(); fbc.setType(fbtype); for (final Period per : perpl) { fbc.addPeriod(per); } ev.addFreeBusyPeriod(fbc); break; case GEO: /* ------------------- Geo -------------------- */ final Geo g = (Geo)prop; final BwGeo geo = new BwGeo(g.getLatitude(), g.getLongitude()); if (chg.changed(pi, ev.getGeo(), geo)) { ev.setGeo(geo); } break; case LAST_MODIFIED: /* ------------------- LastModified -------------------- */ if (chg.changed(pi, ev.getLastmod(), pval)) { ev.setLastmod(pval); } break; case LOCATION: /* ------------------- Location -------------------- */ BwLocation loc = null; //String uid = getUidPar(prop); /* At the moment Mozilla lightning is broken and this leads to all * sorts of problems. if (uid != null) { loc = cb.getLocation(uid); } */ lang = IcalUtil.getLang(prop); BwString addr = null; if (pval != null) { if (loc == null) { addr = new BwString(lang, pval); final var fcResp = cb.findLocation(addr); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { loc = fcResp.getEntity(); } } if (loc == null) { loc = BwLocation.makeLocation(); loc.setAddress(addr); cb.addLocation(loc); } } final BwLocation evloc = ev.getLocation(); if (chg.changed(pi, evloc, loc)) { // CHGTBL - this only shows that it's a different location object ev.setLocation(loc); } else if ((loc != null) && (evloc != null)) { // See if the value is changed final String evval = evloc.getAddress().getValue(); final String inval = loc.getAddress().getValue(); if (!evval.equals(inval)) { chg.changed(pi, evval, inval); evloc.getAddress().setValue(inval); } } break; case ORGANIZER: /* ------------------- Organizer -------------------- */ final BwOrganizer org = IcalUtil.getOrganizer(cb, (Organizer)prop); final BwOrganizer evorg = ev.getOrganizer(); final BwOrganizer evorgCopy; if (evorg == null) { evorgCopy = null; } else { evorgCopy = (BwOrganizer)evorg.clone(); } if (chg.changed(pi, evorgCopy, org)) { if (evorg == null) { ev.setOrganizer(org); } else { evorg.update(org); } } break; case PERCENT_COMPLETE: /* ------------------- PercentComplete -------------------- */ Integer ival = ((PercentComplete)prop).getPercentage(); if (chg.changed(pi, ev.getPercentComplete(), ival)) { ev.setPercentComplete(ival); } break; case POLL_MODE: /* ------------------- Poll mode -------------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollMode(), sval)) { ev.setPollMode(sval); } break; case POLL_PROPERTIES: /* ------------------- Poll properties ---------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollProperties(), sval)) { ev.setPollProperties(sval); } break; case POLL_WINNER: /* ------------------- Poll winner -------------------- */ ival = ((PollWinner)prop).getPollwinner(); if (chg.changed(pi, ev.getPollWinner(), ival)) { ev.setPollWinner(ival); } break; case PRIORITY: /* ------------------- Priority -------------------- */ ival = ((Priority)prop).getLevel(); if (chg.changed(pi, ev.getPriority(), ival)) { ev.setPriority(ival); } break; case RDATE: /* ------------------- RDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case RECURRENCE_ID: /* ------------------- RecurrenceID -------------------- */ // Done above break; case RELATED_TO: /* ------------------- RelatedTo -------------------- */ final RelatedTo irelto = (RelatedTo)prop; final BwRelatedTo relto = new BwRelatedTo(); final String parval = IcalUtil.getParameterVal(irelto, "RELTYPE"); if (parval != null) { relto.setRelType(parval); } relto.setValue(irelto.getValue()); if (chg.changed(pi, ev.getRelatedTo(), relto)) { ev.setRelatedTo(relto); } break; case REQUEST_STATUS: /* ------------------- RequestStatus -------------------- */ final BwRequestStatus rs = BwRequestStatus .fromRequestStatus((RequestStatus)prop); chg.addValue(pi, rs); break; case RESOURCES: /* ------------------- Resources -------------------- */ final TextList rl = ((Resources)prop).getResources(); if (rl != null) { /* Got some resources */ lang = IcalUtil.getLang(prop); for (final String s: rl) { final BwString rsrc = new BwString(lang, s); chg.addValue(pi, rsrc); } } break; case RRULE: /* ------------------- RRule -------------------- */ chg.addValue(pi, pval); break; case SEQUENCE: /* ------------------- Sequence -------------------- */ final int seq = ((Sequence)prop).getSequenceNo(); if (seq != ev.getSequence()) { chg.changed(pi, ev.getSequence(), seq); ev.setSequence(seq); } break; case STATUS: /* ------------------- Status -------------------- */ if (chg.changed(pi, ev.getStatus(), pval)) { ev.setStatus(pval); } break; case SUMMARY: /* ------------------- Summary -------------------- */ if (chg.changed(pi, ev.getSummary(), pval)) { ev.setSummary(pval); } break; case TRANSP: /* ------------------- Transp -------------------- */ if (chg.changed(pi, ev.getPeruserTransparency( cb.getPrincipal() .getPrincipalRef()), pval)) { final BwXproperty pu = ev.setPeruserTransparency( cb.getPrincipal().getPrincipalRef(), pval); if (pu != null) { chg.addValue(PropertyInfoIndex.XPROP, pu); } } break; case UID: /* ------------------- Uid -------------------- */ /* We did this above */ break; case URL: /* ------------------- Url -------------------- */ if (chg.changed(pi, ev.getLink(), pval)) { ev.setLink(pval); } break; case XPROP: /* ------------------------- x-property --------------------------- */ final String name = prop.getName(); if (name.equalsIgnoreCase(BwXproperty.bedeworkCost)) { if (chg.changed(PropertyInfoIndex.COST, ev.getCost(), pval)) { ev.setCost(pval); } break; } if (name.equalsIgnoreCase(BwXproperty.xBedeworkCategories)) { if (checkCategory(cb, chg, ev, null, pval)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkLocation)) { if (checkLocation(cb, chg, ev, prop)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkContact)) { if (checkContact(cb, chg, ev, null, pval)) { break; } } /* See if this is an x-category that can be converted to a real category */ final XProperty xp = (XProperty)prop; chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(name, xp.getParameters() .toString(), pval)); break; default: if (logger.debug()) { logger.debug("Unsupported property with index " + pi + "; class " + prop.getClass() + " and value " + pval); } } } /* =================== Process sub-components =============== */ final ComponentList<Component> subComps; if (val instanceof ComponentContainer) { subComps = ((ComponentContainer<Component>)val).getComponents(); } else { subComps = null; } final Set<Integer> pids; if (vpoll) { pids = new TreeSet<>(); final BwEvent vp = evinfo.getEvent(); if (!Util.isEmpty(vp.getPollItems())) { vp.clearPollItems(); } } else { pids = null; } if (!Util.isEmpty(subComps)) { for (final var subComp: subComps) { if (subComp instanceof Available) { if (!(val instanceof VAvailability)) { return Response.error(resp, "AVAILABLE only valid in VAVAILABLE"); } final var avlResp = processAvailable(cb, cal, ical, (VAvailability)val, (Available)subComp, evinfo); if (!avlResp.isOk()) { return Response.fromResponse(resp, avlResp); } continue; } if (subComp instanceof Participant) { if (vpoll) { final var vresp = processVoter(cb, (VPoll)val, (Participant)subComp, evinfo, chg, mergeAttendees); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Participant object"); continue; } if (subComp instanceof VResource) { logger.warn("Unimplemented VResource object"); continue; } if (subComp instanceof VLocation) { logger.warn("Unimplemented VLocation object"); continue; } if (subComp instanceof VAlarm) { final var aresp = VAlarmUtil.processAlarm(cb, val, (VAlarm)subComp, ev, currentPrincipal, chg); if (!aresp.isOk()) { return Response.fromResponse(resp, aresp); } continue; } if (vpoll && (event || task)) { final var vresp = processCandidate((VPoll)val, subComp, evinfo, pids, chg); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Component object: " + subComp); } } /* Fix up timestamps. */ if (ev.getCreated() == null) { if (ev.getLastmod() != null) { ev.setCreated(ev.getLastmod()); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); } else { ev.updateDtstamp(); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } } if (ev.getLastmod() == null) { // created cannot be null now ev.setLastmod(ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } processTimezones(ev, ical, chg); /* Remove any recipients and originator */ if (ev.getRecipients() != null) { ev.getRecipients().clear(); } ev.setOriginator(null); if (hasXparams.value) { /* Save a text copy of the entire event as an x-property */ final Component valCopy = val.copy(); /* Remove potentially large values */ final Description desp = valCopy.getProperty(Property.DESCRIPTION); if (desp != null) { desp.setValue(null); } final Attach attachp = valCopy.getProperty(Property.ATTACH); // Don't store the entire attachment - we just need the parameters. if (attachp != null) { final Value v = attachp.getParameter(Parameter.VALUE); if (v != null) { attachp.setValue(String.valueOf(attachp.getValue().hashCode())); } } chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(BwXproperty.bedeworkIcal, null, valCopy.toString())); } chg.processChanges(ev, true, false); ev.setRecurring(ev.isRecurringEntity()); if (logger.debug()) { logger.debug(chg.toString()); logger.debug(ev.toString()); } if (masterEI != null) { // Just return notfound as this event is on its override list return Response.notFound(resp); } resp.setEntity(evinfo); return resp; } catch (final Throwable t) { if (logger.debug()) { logger.error(t); } return Response.error(resp, t); } }
NONSATD
true
break; case COMPLETED: /* ------------------- Completed -------------------- */ if (chg.changed(pi, ev.getCompleted(), pval)) { ev.setCompleted(pval);
if (chg.changed(pi, ev.getClassification(), pval)) { ev.setClassification(pval); } break; case COMMENT: /* ------------------- Comment -------------------- */ chg.addValue(pi, new BwString(null, pval)); break; case COMPLETED: /* ------------------- Completed -------------------- */ if (chg.changed(pi, ev.getCompleted(), pval)) { ev.setCompleted(pval); } break; case CONCEPT: /* ------------------- Concept -------------------- */ final Concept c = (Concept)prop; final String cval = c.getValue(); if (cval != null) { /* Got a concept */
cb.addCategory(cat); } else { cat = fcResp.getEntity(); } chg.addValue(pi, cat); } } break; case CLASS: /* ------------------- Class -------------------- */ if (chg.changed(pi, ev.getClassification(), pval)) { ev.setClassification(pval); } break; case COMMENT: /* ------------------- Comment -------------------- */ chg.addValue(pi, new BwString(null, pval)); break; case COMPLETED: /* ------------------- Completed -------------------- */ if (chg.changed(pi, ev.getCompleted(), pval)) { ev.setCompleted(pval); } break; case CONCEPT: /* ------------------- Concept -------------------- */ final Concept c = (Concept)prop; final String cval = c.getValue(); if (cval != null) { /* Got a concept */ chg.addValue(PropertyInfoIndex.XPROP, BwXproperty.makeIcalProperty("CONCEPT", null, cval)); } break; case CONTACT: /* ------------------- Contact -------------------- */ final String altrep = getAltRepPar(prop); lang = IcalUtil.getLang(prop);
7,893
34
/* ------------------- Concept -------------------- */
public static GetEntityResponse<EventInfo> toEvent( final IcalCallback cb, final BwCalendar cal, final Icalendar ical, final Component val, final boolean mergeAttendees) { final var resp = new GetEntityResponse<EventInfo>(); if (val == null) { return Response.notOk(resp, failed, "No component supplied"); } String currentPrincipal = null; final BwPrincipal principal = cb.getPrincipal(); if (principal != null) { currentPrincipal = principal.getPrincipalRef(); } final Holder<Boolean> hasXparams = new Holder<>(Boolean.FALSE); final int methodType = ical.getMethodType(); String attUri = null; if (mergeAttendees) { // We'll need this later. attUri = cb.getCaladdr(cb.getPrincipal().getPrincipalRef()); } final String colPath; if (cal == null) { colPath = null; } else { colPath = cal.getPath(); } try { final PropertyList<Property> pl = val.getProperties(); boolean vpoll = false; boolean event = false; boolean task = false; if (pl == null) { // Empty component return Response.notOk(resp, failed, "Empty component"); } final int entityType; if (val instanceof VEvent) { entityType = IcalDefs.entityTypeEvent; event = true; } else if (val instanceof VToDo) { entityType = IcalDefs.entityTypeTodo; task = true; } else if (val instanceof VJournal) { entityType = IcalDefs.entityTypeJournal; } else if (val instanceof VFreeBusy) { entityType = IcalDefs.entityTypeFreeAndBusy; } else if (val instanceof VAvailability) { entityType = IcalDefs.entityTypeVavailability; } else if (val instanceof Available) { entityType = IcalDefs.entityTypeAvailable; } else if (val instanceof VPoll) { entityType = IcalDefs.entityTypeVpoll; vpoll = true; } else { return Response.error(resp, "org.bedework.invalid.component.type: " + val.getName()); } // Get the guid from the component String guid = null; final Uid uidp = pl.getProperty(Property.UID); if (uidp != null) { testXparams(uidp, hasXparams); guid = uidp.getValue(); } if (guid == null) { /* XXX A guid is required - but are there devices out there without a * guid - and if so how do we handle it? */ return Response.notOk(resp, failed, CalFacadeException.noGuid); } /* See if we have a recurrence id */ BwDateTime ridObj = null; String rid = null; TimeZone ridTz = null; final RecurrenceId ridp = pl.getProperty(Property.RECURRENCE_ID); if (ridp != null) { testXparams(ridp, hasXparams); ridObj = BwDateTime.makeBwDateTime(ridp); if (ridObj.getRange() != null) { /* XXX What do I do with it? */ logger.warn("TRANS-TO_EVENT: Got a recurrence id range"); } rid = ridObj.getDate(); } EventInfo masterEI = null; EventInfo evinfo = null; final BwEvent ev; /* If we have a recurrence id see if we already have the master (we should * get a master + all its overrides). * * If so find the override and use the annnotation or if no override, * make one. * * If no override retrieve the event, add it to our table and then locate the * annotation. * * If there is no annotation, create one. * * It's possible we have been sent 'detached' instances of a recurring * event. This may happen if we are invited to one or more instances of a * meeting. In this case we try to retrieve the master and if it doesn't * exist we manufacture one. We consider such an instance an update to * that instance only and leave the others alone. */ /* We need this in a couple of places */ final DtStart dtStart = pl.getProperty(Property.DTSTART); /* if (rid != null) { // See if we have a new master event. If so create a proxy to that event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI == null) { masterEI = makeNewEvent(cb, chg, entityType, guid, cal); BwEvent e = masterEI.getEvent(); // XXX This seems bogus DtStart mdtStart; String bogusDate = "19980118T230000"; if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + "Z"); } else if (dtStart.getTimeZone() == null) { mdtStart = new DtStart(bogusDate); } else { mdtStart = new DtStart(bogusDate + "Z", dtStart.getTimeZone()); } setDates(e, mdtStart, null, null, chg); e.setRecurring(true); e.addRdate(ridObj); e.setSuppressed(true); ical.addComponent(masterEI); } if (masterEI != null) { evinfo = masterEI.findOverride(rid); } } */ /* If this is a recurrence instance see if we can find the master We only need this because the master may follow the overrides. */ if (rid != null) { // See if we have a new master event. If so create a proxy to this event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI != null) { evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; } } if ((evinfo == null) && (cal != null) && (cal.getCalType() != BwCalendar.calTypeInbox) && (cal.getCalType() != BwCalendar.calTypePendingInbox) && (cal.getCalType() != BwCalendar.calTypeOutbox)) { if (logger.debug()) { logger.debug("TRANS-TO_EVENT: try to fetch event with guid=" + guid); } final GetEntitiesResponse<EventInfo> eisResp = cb.getEvent(colPath, guid); if (eisResp.isError()) { return Response.fromResponse(resp, eisResp); } final var eis = eisResp.getEntities(); if (!Util.isEmpty(eis)) { if (eis.size() > 1) { // DORECUR - wrong again return Response.notOk(resp, failed, "More than one event returned for guid."); } evinfo = eis.iterator().next(); } if (logger.debug()) { if (evinfo != null) { logger.debug("TRANS-TO_EVENT: fetched event with guid"); } else { logger.debug("TRANS-TO_EVENT: did not find event with guid"); } } if (evinfo != null) { if (rid != null) { // We just retrieved it's master masterEI = evinfo; masterEI.setInstanceOnly(true); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; ical.addComponent(masterEI); } else if (methodType == ScheduleMethods.methodTypeCancel) { // This should never have an rid for cancel of entire event. evinfo.setInstanceOnly(evinfo.getEvent().getSuppressed()); } else { // Presumably sent an update for the entire event. No longer suppressed master evinfo.getEvent().setSuppressed(false); } } else if (rid != null) { /* Manufacture a master for the instance */ masterEI = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); final BwEvent e = masterEI.getEvent(); // XXX This seems bogus final DtStart mdtStart; final String bogusDate = "19980118"; final String bogusTime = "T230000"; // Base dtstart on the recurrence id. final boolean isDateType = ridObj.getDateType(); if (isDateType) { mdtStart = new DtStart(new Date(bogusDate)); } else if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + bogusTime + "Z"); } else if (ridObj.getTzid() == null) { mdtStart = new DtStart(bogusDate + bogusTime); } else { mdtStart = new DtStart(bogusDate + bogusTime, Timezones.getTz(ridObj.getTzid())); } IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), masterEI, mdtStart, null, null); e.setRecurring(true); // e.addRdate(ridObj); final var sum = (Summary)pl.getProperty(Property.SUMMARY); e.setSummary(sum.getValue()); e.setSuppressed(true); ical.addComponent(masterEI); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; masterEI.setInstanceOnly(rid != null); } } if (evinfo == null) { evinfo = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); } else if (evinfo.getEvent().getEntityType() != entityType) { return Response.notOk(resp, failed, "org.bedework.mismatched.entity.type: " + val); } final ChangeTable chg = evinfo.getChangeset( cb.getPrincipal().getPrincipalRef()); if (rid != null) { final String evrid = evinfo.getEvent().getRecurrenceId(); if ((evrid == null) || (!evrid.equals(rid))) { logger. warn("Mismatched rid ev=" + evrid + " expected " + rid); chg.changed(PropertyInfoIndex.RECURRENCE_ID, evrid, rid); // XXX spurious??? } if (masterEI.getEvent().getSuppressed()) { masterEI.getEvent().addRdate(ridObj); } } ev = evinfo.getEvent(); ev.setScheduleMethod(methodType); DtEnd dtEnd = null; if (entityType == IcalDefs.entityTypeTodo) { final Due due = pl.getProperty(Property.DUE); if (due != null ) { dtEnd = new DtEnd(due.getParameters(), due.getValue()); } } else { dtEnd = pl.getProperty(Property.DTEND); } final Duration duration = pl.getProperty(Property.DURATION); IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), evinfo, dtStart, dtEnd, duration); for (final Property prop: pl) { testXparams(prop, hasXparams); //debug("ical prop " + prop.getClass().getName()); String pval = prop.getValue(); if ((pval != null) && (pval.length() == 0)) { pval = null; } final PropertyInfoIndex pi; if (prop instanceof XProperty) { pi = PropertyInfoIndex.XPROP; } else { pi = PropertyInfoIndex.fromName(prop.getName()); } if (pi == null) { logger.debug("Unknown property with name " + prop.getName() + " class " + prop.getClass() + " and value " + pval); continue; } chg.present(pi); switch (pi) { case ACCEPT_RESPONSE: /* ------------------- Accept Response -------------------- */ String sval = prop.getValue(); if (chg.changed(pi, ev.getPollAcceptResponse(), sval)) { ev.setPollAcceptResponse(sval); } break; case ATTACH: /* ------------------- Attachment -------------------- */ chg.addValue(pi, IcalUtil.getAttachment((Attach)prop)); break; case ATTENDEE: /* ------------------- Attendee -------------------- */ if (methodType == ScheduleMethods.methodTypePublish) { if (cb.getStrictness() == IcalCallback.conformanceStrict) { return Response.notOk(resp, failed, CalFacadeException.attendeesInPublish); } //if (cb.getStrictness() == IcalCallback.conformanceWarn) { // warn("Had attendees for PUBLISH"); //} } final Attendee attPr = (Attendee)prop; if (evinfo.getNewEvent() || !mergeAttendees) { chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { final String pUri = cb.getCaladdr(attPr.getValue()); if (pUri.equals(attUri)) { /* Only update for our own attendee * We're doing a PUT and this must be the attendee updating their * partstat. We don't allow them to change other attendees * whatever the PUT content says. */ chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { // Use the value we currently have boolean found = false; for (final BwAttendee att: ev.getAttendees()) { if (pUri.equals(att.getAttendeeUri())) { chg.addValue(pi, att.clone()); found = true; break; } } if (!found) { // An added attendee final BwAttendee att = IcalUtil .getAttendee(cb, attPr); att.setPartstat(IcalDefs.partstatValNeedsAction); chg.addValue(pi, att); } } } break; case BUSYTYPE: final int ibt = BwEvent.fromBusyTypeString(pval); if (chg.changed(pi, ev.getBusyType(), ibt)) { ev.setBusyType(ibt); } break; case CATEGORIES: /* ------------------- Categories -------------------- */ final Categories cats = (Categories)prop; final TextList cl = cats.getCategories(); String lang = IcalUtil.getLang(cats); if (cl != null) { /* Got some categories */ for (final String wd: cl) { if (wd == null) { continue; } final BwString key = new BwString(lang, wd); final var fcResp = cb.findCategory(key); final BwCategory cat; if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isNotFound()) { cat = BwCategory.makeCategory(); cat.setWord(key); cb.addCategory(cat); } else { cat = fcResp.getEntity(); } chg.addValue(pi, cat); } } break; case CLASS: /* ------------------- Class -------------------- */ if (chg.changed(pi, ev.getClassification(), pval)) { ev.setClassification(pval); } break; case COMMENT: /* ------------------- Comment -------------------- */ chg.addValue(pi, new BwString(null, pval)); break; case COMPLETED: /* ------------------- Completed -------------------- */ if (chg.changed(pi, ev.getCompleted(), pval)) { ev.setCompleted(pval); } break; case CONCEPT: /* ------------------- Concept -------------------- */ final Concept c = (Concept)prop; final String cval = c.getValue(); if (cval != null) { /* Got a concept */ chg.addValue(PropertyInfoIndex.XPROP, BwXproperty.makeIcalProperty("CONCEPT", null, cval)); } break; case CONTACT: /* ------------------- Contact -------------------- */ final String altrep = getAltRepPar(prop); lang = IcalUtil.getLang(prop); final String uid = getUidPar(prop); final BwString nm = new BwString(lang, pval); BwContact contact = null; if (uid != null) { final var fcResp = cb.getContact(uid); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { final var fcResp = cb.findContact(nm); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { contact = BwContact.makeContact(); contact.setCn(nm); contact.setLink(altrep); cb.addContact(contact); } else { contact.setCn(nm); contact.setLink(altrep); } chg.addValue(pi, contact); break; case CREATED: /* ------------------- Created -------------------- */ if (chg.changed(pi, ev.getCreated(), pval)) { ev.setCreated(pval); } break; case DESCRIPTION: /* ------------------- Description -------------------- */ if (chg.changed(pi, ev.getDescription(), pval)) { ev.setDescription(pval); } break; case DTEND: /* ------------------- DtEnd -------------------- */ break; case DTSTAMP: /* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval); break; case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE: /* -------------------- Due ------------------------ */ break; case DURATION: /* ------------------- Duration -------------------- */ break; case EXDATE: /* ------------------- ExDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case EXRULE: /* ------------------- ExRule -------------------- */ chg.addValue(pi, pval); break; case FREEBUSY: /* ------------------- freebusy -------------------- */ final FreeBusy fbusy = (FreeBusy)prop; final PeriodList perpl = fbusy.getPeriods(); final Parameter par = IcalUtil.getParameter(fbusy, "FBTYPE"); final int fbtype; if (par == null) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY)) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY_TENTATIVE)) { fbtype = BwFreeBusyComponent.typeBusyTentative; } else if (par.equals(FbType.BUSY_UNAVAILABLE)) { fbtype = BwFreeBusyComponent.typeBusyUnavailable; } else if (par.equals(FbType.FREE)) { fbtype = BwFreeBusyComponent.typeFree; } else { if (logger.debug()) { logger.debug("Unsupported parameter " + par.getName()); } return Response.notOk(resp, failed, "Unsupported parameter " + par.getName()); } final BwFreeBusyComponent fbc = new BwFreeBusyComponent(); fbc.setType(fbtype); for (final Period per : perpl) { fbc.addPeriod(per); } ev.addFreeBusyPeriod(fbc); break; case GEO: /* ------------------- Geo -------------------- */ final Geo g = (Geo)prop; final BwGeo geo = new BwGeo(g.getLatitude(), g.getLongitude()); if (chg.changed(pi, ev.getGeo(), geo)) { ev.setGeo(geo); } break; case LAST_MODIFIED: /* ------------------- LastModified -------------------- */ if (chg.changed(pi, ev.getLastmod(), pval)) { ev.setLastmod(pval); } break; case LOCATION: /* ------------------- Location -------------------- */ BwLocation loc = null; //String uid = getUidPar(prop); /* At the moment Mozilla lightning is broken and this leads to all * sorts of problems. if (uid != null) { loc = cb.getLocation(uid); } */ lang = IcalUtil.getLang(prop); BwString addr = null; if (pval != null) { if (loc == null) { addr = new BwString(lang, pval); final var fcResp = cb.findLocation(addr); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { loc = fcResp.getEntity(); } } if (loc == null) { loc = BwLocation.makeLocation(); loc.setAddress(addr); cb.addLocation(loc); } } final BwLocation evloc = ev.getLocation(); if (chg.changed(pi, evloc, loc)) { // CHGTBL - this only shows that it's a different location object ev.setLocation(loc); } else if ((loc != null) && (evloc != null)) { // See if the value is changed final String evval = evloc.getAddress().getValue(); final String inval = loc.getAddress().getValue(); if (!evval.equals(inval)) { chg.changed(pi, evval, inval); evloc.getAddress().setValue(inval); } } break; case ORGANIZER: /* ------------------- Organizer -------------------- */ final BwOrganizer org = IcalUtil.getOrganizer(cb, (Organizer)prop); final BwOrganizer evorg = ev.getOrganizer(); final BwOrganizer evorgCopy; if (evorg == null) { evorgCopy = null; } else { evorgCopy = (BwOrganizer)evorg.clone(); } if (chg.changed(pi, evorgCopy, org)) { if (evorg == null) { ev.setOrganizer(org); } else { evorg.update(org); } } break; case PERCENT_COMPLETE: /* ------------------- PercentComplete -------------------- */ Integer ival = ((PercentComplete)prop).getPercentage(); if (chg.changed(pi, ev.getPercentComplete(), ival)) { ev.setPercentComplete(ival); } break; case POLL_MODE: /* ------------------- Poll mode -------------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollMode(), sval)) { ev.setPollMode(sval); } break; case POLL_PROPERTIES: /* ------------------- Poll properties ---------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollProperties(), sval)) { ev.setPollProperties(sval); } break; case POLL_WINNER: /* ------------------- Poll winner -------------------- */ ival = ((PollWinner)prop).getPollwinner(); if (chg.changed(pi, ev.getPollWinner(), ival)) { ev.setPollWinner(ival); } break; case PRIORITY: /* ------------------- Priority -------------------- */ ival = ((Priority)prop).getLevel(); if (chg.changed(pi, ev.getPriority(), ival)) { ev.setPriority(ival); } break; case RDATE: /* ------------------- RDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case RECURRENCE_ID: /* ------------------- RecurrenceID -------------------- */ // Done above break; case RELATED_TO: /* ------------------- RelatedTo -------------------- */ final RelatedTo irelto = (RelatedTo)prop; final BwRelatedTo relto = new BwRelatedTo(); final String parval = IcalUtil.getParameterVal(irelto, "RELTYPE"); if (parval != null) { relto.setRelType(parval); } relto.setValue(irelto.getValue()); if (chg.changed(pi, ev.getRelatedTo(), relto)) { ev.setRelatedTo(relto); } break; case REQUEST_STATUS: /* ------------------- RequestStatus -------------------- */ final BwRequestStatus rs = BwRequestStatus .fromRequestStatus((RequestStatus)prop); chg.addValue(pi, rs); break; case RESOURCES: /* ------------------- Resources -------------------- */ final TextList rl = ((Resources)prop).getResources(); if (rl != null) { /* Got some resources */ lang = IcalUtil.getLang(prop); for (final String s: rl) { final BwString rsrc = new BwString(lang, s); chg.addValue(pi, rsrc); } } break; case RRULE: /* ------------------- RRule -------------------- */ chg.addValue(pi, pval); break; case SEQUENCE: /* ------------------- Sequence -------------------- */ final int seq = ((Sequence)prop).getSequenceNo(); if (seq != ev.getSequence()) { chg.changed(pi, ev.getSequence(), seq); ev.setSequence(seq); } break; case STATUS: /* ------------------- Status -------------------- */ if (chg.changed(pi, ev.getStatus(), pval)) { ev.setStatus(pval); } break; case SUMMARY: /* ------------------- Summary -------------------- */ if (chg.changed(pi, ev.getSummary(), pval)) { ev.setSummary(pval); } break; case TRANSP: /* ------------------- Transp -------------------- */ if (chg.changed(pi, ev.getPeruserTransparency( cb.getPrincipal() .getPrincipalRef()), pval)) { final BwXproperty pu = ev.setPeruserTransparency( cb.getPrincipal().getPrincipalRef(), pval); if (pu != null) { chg.addValue(PropertyInfoIndex.XPROP, pu); } } break; case UID: /* ------------------- Uid -------------------- */ /* We did this above */ break; case URL: /* ------------------- Url -------------------- */ if (chg.changed(pi, ev.getLink(), pval)) { ev.setLink(pval); } break; case XPROP: /* ------------------------- x-property --------------------------- */ final String name = prop.getName(); if (name.equalsIgnoreCase(BwXproperty.bedeworkCost)) { if (chg.changed(PropertyInfoIndex.COST, ev.getCost(), pval)) { ev.setCost(pval); } break; } if (name.equalsIgnoreCase(BwXproperty.xBedeworkCategories)) { if (checkCategory(cb, chg, ev, null, pval)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkLocation)) { if (checkLocation(cb, chg, ev, prop)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkContact)) { if (checkContact(cb, chg, ev, null, pval)) { break; } } /* See if this is an x-category that can be converted to a real category */ final XProperty xp = (XProperty)prop; chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(name, xp.getParameters() .toString(), pval)); break; default: if (logger.debug()) { logger.debug("Unsupported property with index " + pi + "; class " + prop.getClass() + " and value " + pval); } } } /* =================== Process sub-components =============== */ final ComponentList<Component> subComps; if (val instanceof ComponentContainer) { subComps = ((ComponentContainer<Component>)val).getComponents(); } else { subComps = null; } final Set<Integer> pids; if (vpoll) { pids = new TreeSet<>(); final BwEvent vp = evinfo.getEvent(); if (!Util.isEmpty(vp.getPollItems())) { vp.clearPollItems(); } } else { pids = null; } if (!Util.isEmpty(subComps)) { for (final var subComp: subComps) { if (subComp instanceof Available) { if (!(val instanceof VAvailability)) { return Response.error(resp, "AVAILABLE only valid in VAVAILABLE"); } final var avlResp = processAvailable(cb, cal, ical, (VAvailability)val, (Available)subComp, evinfo); if (!avlResp.isOk()) { return Response.fromResponse(resp, avlResp); } continue; } if (subComp instanceof Participant) { if (vpoll) { final var vresp = processVoter(cb, (VPoll)val, (Participant)subComp, evinfo, chg, mergeAttendees); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Participant object"); continue; } if (subComp instanceof VResource) { logger.warn("Unimplemented VResource object"); continue; } if (subComp instanceof VLocation) { logger.warn("Unimplemented VLocation object"); continue; } if (subComp instanceof VAlarm) { final var aresp = VAlarmUtil.processAlarm(cb, val, (VAlarm)subComp, ev, currentPrincipal, chg); if (!aresp.isOk()) { return Response.fromResponse(resp, aresp); } continue; } if (vpoll && (event || task)) { final var vresp = processCandidate((VPoll)val, subComp, evinfo, pids, chg); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Component object: " + subComp); } } /* Fix up timestamps. */ if (ev.getCreated() == null) { if (ev.getLastmod() != null) { ev.setCreated(ev.getLastmod()); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); } else { ev.updateDtstamp(); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } } if (ev.getLastmod() == null) { // created cannot be null now ev.setLastmod(ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } processTimezones(ev, ical, chg); /* Remove any recipients and originator */ if (ev.getRecipients() != null) { ev.getRecipients().clear(); } ev.setOriginator(null); if (hasXparams.value) { /* Save a text copy of the entire event as an x-property */ final Component valCopy = val.copy(); /* Remove potentially large values */ final Description desp = valCopy.getProperty(Property.DESCRIPTION); if (desp != null) { desp.setValue(null); } final Attach attachp = valCopy.getProperty(Property.ATTACH); // Don't store the entire attachment - we just need the parameters. if (attachp != null) { final Value v = attachp.getParameter(Parameter.VALUE); if (v != null) { attachp.setValue(String.valueOf(attachp.getValue().hashCode())); } } chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(BwXproperty.bedeworkIcal, null, valCopy.toString())); } chg.processChanges(ev, true, false); ev.setRecurring(ev.isRecurringEntity()); if (logger.debug()) { logger.debug(chg.toString()); logger.debug(ev.toString()); } if (masterEI != null) { // Just return notfound as this event is on its override list return Response.notFound(resp); } resp.setEntity(evinfo); return resp; } catch (final Throwable t) { if (logger.debug()) { logger.error(t); } return Response.error(resp, t); } }
NONSATD
true
break; case CONCEPT: /* ------------------- Concept -------------------- */ final Concept c = (Concept)prop; final String cval = c.getValue();
chg.addValue(pi, new BwString(null, pval)); break; case COMPLETED: /* ------------------- Completed -------------------- */ if (chg.changed(pi, ev.getCompleted(), pval)) { ev.setCompleted(pval); } break; case CONCEPT: /* ------------------- Concept -------------------- */ final Concept c = (Concept)prop; final String cval = c.getValue(); if (cval != null) { /* Got a concept */ chg.addValue(PropertyInfoIndex.XPROP, BwXproperty.makeIcalProperty("CONCEPT", null, cval)); } break;
} break; case CLASS: /* ------------------- Class -------------------- */ if (chg.changed(pi, ev.getClassification(), pval)) { ev.setClassification(pval); } break; case COMMENT: /* ------------------- Comment -------------------- */ chg.addValue(pi, new BwString(null, pval)); break; case COMPLETED: /* ------------------- Completed -------------------- */ if (chg.changed(pi, ev.getCompleted(), pval)) { ev.setCompleted(pval); } break; case CONCEPT: /* ------------------- Concept -------------------- */ final Concept c = (Concept)prop; final String cval = c.getValue(); if (cval != null) { /* Got a concept */ chg.addValue(PropertyInfoIndex.XPROP, BwXproperty.makeIcalProperty("CONCEPT", null, cval)); } break; case CONTACT: /* ------------------- Contact -------------------- */ final String altrep = getAltRepPar(prop); lang = IcalUtil.getLang(prop); final String uid = getUidPar(prop); final BwString nm = new BwString(lang, pval); BwContact contact = null; if (uid != null) { final var fcResp = cb.getContact(uid); if (fcResp.isError()) {
7,893
35
/* Got a concept */
public static GetEntityResponse<EventInfo> toEvent( final IcalCallback cb, final BwCalendar cal, final Icalendar ical, final Component val, final boolean mergeAttendees) { final var resp = new GetEntityResponse<EventInfo>(); if (val == null) { return Response.notOk(resp, failed, "No component supplied"); } String currentPrincipal = null; final BwPrincipal principal = cb.getPrincipal(); if (principal != null) { currentPrincipal = principal.getPrincipalRef(); } final Holder<Boolean> hasXparams = new Holder<>(Boolean.FALSE); final int methodType = ical.getMethodType(); String attUri = null; if (mergeAttendees) { // We'll need this later. attUri = cb.getCaladdr(cb.getPrincipal().getPrincipalRef()); } final String colPath; if (cal == null) { colPath = null; } else { colPath = cal.getPath(); } try { final PropertyList<Property> pl = val.getProperties(); boolean vpoll = false; boolean event = false; boolean task = false; if (pl == null) { // Empty component return Response.notOk(resp, failed, "Empty component"); } final int entityType; if (val instanceof VEvent) { entityType = IcalDefs.entityTypeEvent; event = true; } else if (val instanceof VToDo) { entityType = IcalDefs.entityTypeTodo; task = true; } else if (val instanceof VJournal) { entityType = IcalDefs.entityTypeJournal; } else if (val instanceof VFreeBusy) { entityType = IcalDefs.entityTypeFreeAndBusy; } else if (val instanceof VAvailability) { entityType = IcalDefs.entityTypeVavailability; } else if (val instanceof Available) { entityType = IcalDefs.entityTypeAvailable; } else if (val instanceof VPoll) { entityType = IcalDefs.entityTypeVpoll; vpoll = true; } else { return Response.error(resp, "org.bedework.invalid.component.type: " + val.getName()); } // Get the guid from the component String guid = null; final Uid uidp = pl.getProperty(Property.UID); if (uidp != null) { testXparams(uidp, hasXparams); guid = uidp.getValue(); } if (guid == null) { /* XXX A guid is required - but are there devices out there without a * guid - and if so how do we handle it? */ return Response.notOk(resp, failed, CalFacadeException.noGuid); } /* See if we have a recurrence id */ BwDateTime ridObj = null; String rid = null; TimeZone ridTz = null; final RecurrenceId ridp = pl.getProperty(Property.RECURRENCE_ID); if (ridp != null) { testXparams(ridp, hasXparams); ridObj = BwDateTime.makeBwDateTime(ridp); if (ridObj.getRange() != null) { /* XXX What do I do with it? */ logger.warn("TRANS-TO_EVENT: Got a recurrence id range"); } rid = ridObj.getDate(); } EventInfo masterEI = null; EventInfo evinfo = null; final BwEvent ev; /* If we have a recurrence id see if we already have the master (we should * get a master + all its overrides). * * If so find the override and use the annnotation or if no override, * make one. * * If no override retrieve the event, add it to our table and then locate the * annotation. * * If there is no annotation, create one. * * It's possible we have been sent 'detached' instances of a recurring * event. This may happen if we are invited to one or more instances of a * meeting. In this case we try to retrieve the master and if it doesn't * exist we manufacture one. We consider such an instance an update to * that instance only and leave the others alone. */ /* We need this in a couple of places */ final DtStart dtStart = pl.getProperty(Property.DTSTART); /* if (rid != null) { // See if we have a new master event. If so create a proxy to that event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI == null) { masterEI = makeNewEvent(cb, chg, entityType, guid, cal); BwEvent e = masterEI.getEvent(); // XXX This seems bogus DtStart mdtStart; String bogusDate = "19980118T230000"; if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + "Z"); } else if (dtStart.getTimeZone() == null) { mdtStart = new DtStart(bogusDate); } else { mdtStart = new DtStart(bogusDate + "Z", dtStart.getTimeZone()); } setDates(e, mdtStart, null, null, chg); e.setRecurring(true); e.addRdate(ridObj); e.setSuppressed(true); ical.addComponent(masterEI); } if (masterEI != null) { evinfo = masterEI.findOverride(rid); } } */ /* If this is a recurrence instance see if we can find the master We only need this because the master may follow the overrides. */ if (rid != null) { // See if we have a new master event. If so create a proxy to this event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI != null) { evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; } } if ((evinfo == null) && (cal != null) && (cal.getCalType() != BwCalendar.calTypeInbox) && (cal.getCalType() != BwCalendar.calTypePendingInbox) && (cal.getCalType() != BwCalendar.calTypeOutbox)) { if (logger.debug()) { logger.debug("TRANS-TO_EVENT: try to fetch event with guid=" + guid); } final GetEntitiesResponse<EventInfo> eisResp = cb.getEvent(colPath, guid); if (eisResp.isError()) { return Response.fromResponse(resp, eisResp); } final var eis = eisResp.getEntities(); if (!Util.isEmpty(eis)) { if (eis.size() > 1) { // DORECUR - wrong again return Response.notOk(resp, failed, "More than one event returned for guid."); } evinfo = eis.iterator().next(); } if (logger.debug()) { if (evinfo != null) { logger.debug("TRANS-TO_EVENT: fetched event with guid"); } else { logger.debug("TRANS-TO_EVENT: did not find event with guid"); } } if (evinfo != null) { if (rid != null) { // We just retrieved it's master masterEI = evinfo; masterEI.setInstanceOnly(true); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; ical.addComponent(masterEI); } else if (methodType == ScheduleMethods.methodTypeCancel) { // This should never have an rid for cancel of entire event. evinfo.setInstanceOnly(evinfo.getEvent().getSuppressed()); } else { // Presumably sent an update for the entire event. No longer suppressed master evinfo.getEvent().setSuppressed(false); } } else if (rid != null) { /* Manufacture a master for the instance */ masterEI = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); final BwEvent e = masterEI.getEvent(); // XXX This seems bogus final DtStart mdtStart; final String bogusDate = "19980118"; final String bogusTime = "T230000"; // Base dtstart on the recurrence id. final boolean isDateType = ridObj.getDateType(); if (isDateType) { mdtStart = new DtStart(new Date(bogusDate)); } else if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + bogusTime + "Z"); } else if (ridObj.getTzid() == null) { mdtStart = new DtStart(bogusDate + bogusTime); } else { mdtStart = new DtStart(bogusDate + bogusTime, Timezones.getTz(ridObj.getTzid())); } IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), masterEI, mdtStart, null, null); e.setRecurring(true); // e.addRdate(ridObj); final var sum = (Summary)pl.getProperty(Property.SUMMARY); e.setSummary(sum.getValue()); e.setSuppressed(true); ical.addComponent(masterEI); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; masterEI.setInstanceOnly(rid != null); } } if (evinfo == null) { evinfo = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); } else if (evinfo.getEvent().getEntityType() != entityType) { return Response.notOk(resp, failed, "org.bedework.mismatched.entity.type: " + val); } final ChangeTable chg = evinfo.getChangeset( cb.getPrincipal().getPrincipalRef()); if (rid != null) { final String evrid = evinfo.getEvent().getRecurrenceId(); if ((evrid == null) || (!evrid.equals(rid))) { logger. warn("Mismatched rid ev=" + evrid + " expected " + rid); chg.changed(PropertyInfoIndex.RECURRENCE_ID, evrid, rid); // XXX spurious??? } if (masterEI.getEvent().getSuppressed()) { masterEI.getEvent().addRdate(ridObj); } } ev = evinfo.getEvent(); ev.setScheduleMethod(methodType); DtEnd dtEnd = null; if (entityType == IcalDefs.entityTypeTodo) { final Due due = pl.getProperty(Property.DUE); if (due != null ) { dtEnd = new DtEnd(due.getParameters(), due.getValue()); } } else { dtEnd = pl.getProperty(Property.DTEND); } final Duration duration = pl.getProperty(Property.DURATION); IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), evinfo, dtStart, dtEnd, duration); for (final Property prop: pl) { testXparams(prop, hasXparams); //debug("ical prop " + prop.getClass().getName()); String pval = prop.getValue(); if ((pval != null) && (pval.length() == 0)) { pval = null; } final PropertyInfoIndex pi; if (prop instanceof XProperty) { pi = PropertyInfoIndex.XPROP; } else { pi = PropertyInfoIndex.fromName(prop.getName()); } if (pi == null) { logger.debug("Unknown property with name " + prop.getName() + " class " + prop.getClass() + " and value " + pval); continue; } chg.present(pi); switch (pi) { case ACCEPT_RESPONSE: /* ------------------- Accept Response -------------------- */ String sval = prop.getValue(); if (chg.changed(pi, ev.getPollAcceptResponse(), sval)) { ev.setPollAcceptResponse(sval); } break; case ATTACH: /* ------------------- Attachment -------------------- */ chg.addValue(pi, IcalUtil.getAttachment((Attach)prop)); break; case ATTENDEE: /* ------------------- Attendee -------------------- */ if (methodType == ScheduleMethods.methodTypePublish) { if (cb.getStrictness() == IcalCallback.conformanceStrict) { return Response.notOk(resp, failed, CalFacadeException.attendeesInPublish); } //if (cb.getStrictness() == IcalCallback.conformanceWarn) { // warn("Had attendees for PUBLISH"); //} } final Attendee attPr = (Attendee)prop; if (evinfo.getNewEvent() || !mergeAttendees) { chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { final String pUri = cb.getCaladdr(attPr.getValue()); if (pUri.equals(attUri)) { /* Only update for our own attendee * We're doing a PUT and this must be the attendee updating their * partstat. We don't allow them to change other attendees * whatever the PUT content says. */ chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { // Use the value we currently have boolean found = false; for (final BwAttendee att: ev.getAttendees()) { if (pUri.equals(att.getAttendeeUri())) { chg.addValue(pi, att.clone()); found = true; break; } } if (!found) { // An added attendee final BwAttendee att = IcalUtil .getAttendee(cb, attPr); att.setPartstat(IcalDefs.partstatValNeedsAction); chg.addValue(pi, att); } } } break; case BUSYTYPE: final int ibt = BwEvent.fromBusyTypeString(pval); if (chg.changed(pi, ev.getBusyType(), ibt)) { ev.setBusyType(ibt); } break; case CATEGORIES: /* ------------------- Categories -------------------- */ final Categories cats = (Categories)prop; final TextList cl = cats.getCategories(); String lang = IcalUtil.getLang(cats); if (cl != null) { /* Got some categories */ for (final String wd: cl) { if (wd == null) { continue; } final BwString key = new BwString(lang, wd); final var fcResp = cb.findCategory(key); final BwCategory cat; if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isNotFound()) { cat = BwCategory.makeCategory(); cat.setWord(key); cb.addCategory(cat); } else { cat = fcResp.getEntity(); } chg.addValue(pi, cat); } } break; case CLASS: /* ------------------- Class -------------------- */ if (chg.changed(pi, ev.getClassification(), pval)) { ev.setClassification(pval); } break; case COMMENT: /* ------------------- Comment -------------------- */ chg.addValue(pi, new BwString(null, pval)); break; case COMPLETED: /* ------------------- Completed -------------------- */ if (chg.changed(pi, ev.getCompleted(), pval)) { ev.setCompleted(pval); } break; case CONCEPT: /* ------------------- Concept -------------------- */ final Concept c = (Concept)prop; final String cval = c.getValue(); if (cval != null) { /* Got a concept */ chg.addValue(PropertyInfoIndex.XPROP, BwXproperty.makeIcalProperty("CONCEPT", null, cval)); } break; case CONTACT: /* ------------------- Contact -------------------- */ final String altrep = getAltRepPar(prop); lang = IcalUtil.getLang(prop); final String uid = getUidPar(prop); final BwString nm = new BwString(lang, pval); BwContact contact = null; if (uid != null) { final var fcResp = cb.getContact(uid); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { final var fcResp = cb.findContact(nm); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { contact = BwContact.makeContact(); contact.setCn(nm); contact.setLink(altrep); cb.addContact(contact); } else { contact.setCn(nm); contact.setLink(altrep); } chg.addValue(pi, contact); break; case CREATED: /* ------------------- Created -------------------- */ if (chg.changed(pi, ev.getCreated(), pval)) { ev.setCreated(pval); } break; case DESCRIPTION: /* ------------------- Description -------------------- */ if (chg.changed(pi, ev.getDescription(), pval)) { ev.setDescription(pval); } break; case DTEND: /* ------------------- DtEnd -------------------- */ break; case DTSTAMP: /* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval); break; case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE: /* -------------------- Due ------------------------ */ break; case DURATION: /* ------------------- Duration -------------------- */ break; case EXDATE: /* ------------------- ExDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case EXRULE: /* ------------------- ExRule -------------------- */ chg.addValue(pi, pval); break; case FREEBUSY: /* ------------------- freebusy -------------------- */ final FreeBusy fbusy = (FreeBusy)prop; final PeriodList perpl = fbusy.getPeriods(); final Parameter par = IcalUtil.getParameter(fbusy, "FBTYPE"); final int fbtype; if (par == null) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY)) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY_TENTATIVE)) { fbtype = BwFreeBusyComponent.typeBusyTentative; } else if (par.equals(FbType.BUSY_UNAVAILABLE)) { fbtype = BwFreeBusyComponent.typeBusyUnavailable; } else if (par.equals(FbType.FREE)) { fbtype = BwFreeBusyComponent.typeFree; } else { if (logger.debug()) { logger.debug("Unsupported parameter " + par.getName()); } return Response.notOk(resp, failed, "Unsupported parameter " + par.getName()); } final BwFreeBusyComponent fbc = new BwFreeBusyComponent(); fbc.setType(fbtype); for (final Period per : perpl) { fbc.addPeriod(per); } ev.addFreeBusyPeriod(fbc); break; case GEO: /* ------------------- Geo -------------------- */ final Geo g = (Geo)prop; final BwGeo geo = new BwGeo(g.getLatitude(), g.getLongitude()); if (chg.changed(pi, ev.getGeo(), geo)) { ev.setGeo(geo); } break; case LAST_MODIFIED: /* ------------------- LastModified -------------------- */ if (chg.changed(pi, ev.getLastmod(), pval)) { ev.setLastmod(pval); } break; case LOCATION: /* ------------------- Location -------------------- */ BwLocation loc = null; //String uid = getUidPar(prop); /* At the moment Mozilla lightning is broken and this leads to all * sorts of problems. if (uid != null) { loc = cb.getLocation(uid); } */ lang = IcalUtil.getLang(prop); BwString addr = null; if (pval != null) { if (loc == null) { addr = new BwString(lang, pval); final var fcResp = cb.findLocation(addr); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { loc = fcResp.getEntity(); } } if (loc == null) { loc = BwLocation.makeLocation(); loc.setAddress(addr); cb.addLocation(loc); } } final BwLocation evloc = ev.getLocation(); if (chg.changed(pi, evloc, loc)) { // CHGTBL - this only shows that it's a different location object ev.setLocation(loc); } else if ((loc != null) && (evloc != null)) { // See if the value is changed final String evval = evloc.getAddress().getValue(); final String inval = loc.getAddress().getValue(); if (!evval.equals(inval)) { chg.changed(pi, evval, inval); evloc.getAddress().setValue(inval); } } break; case ORGANIZER: /* ------------------- Organizer -------------------- */ final BwOrganizer org = IcalUtil.getOrganizer(cb, (Organizer)prop); final BwOrganizer evorg = ev.getOrganizer(); final BwOrganizer evorgCopy; if (evorg == null) { evorgCopy = null; } else { evorgCopy = (BwOrganizer)evorg.clone(); } if (chg.changed(pi, evorgCopy, org)) { if (evorg == null) { ev.setOrganizer(org); } else { evorg.update(org); } } break; case PERCENT_COMPLETE: /* ------------------- PercentComplete -------------------- */ Integer ival = ((PercentComplete)prop).getPercentage(); if (chg.changed(pi, ev.getPercentComplete(), ival)) { ev.setPercentComplete(ival); } break; case POLL_MODE: /* ------------------- Poll mode -------------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollMode(), sval)) { ev.setPollMode(sval); } break; case POLL_PROPERTIES: /* ------------------- Poll properties ---------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollProperties(), sval)) { ev.setPollProperties(sval); } break; case POLL_WINNER: /* ------------------- Poll winner -------------------- */ ival = ((PollWinner)prop).getPollwinner(); if (chg.changed(pi, ev.getPollWinner(), ival)) { ev.setPollWinner(ival); } break; case PRIORITY: /* ------------------- Priority -------------------- */ ival = ((Priority)prop).getLevel(); if (chg.changed(pi, ev.getPriority(), ival)) { ev.setPriority(ival); } break; case RDATE: /* ------------------- RDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case RECURRENCE_ID: /* ------------------- RecurrenceID -------------------- */ // Done above break; case RELATED_TO: /* ------------------- RelatedTo -------------------- */ final RelatedTo irelto = (RelatedTo)prop; final BwRelatedTo relto = new BwRelatedTo(); final String parval = IcalUtil.getParameterVal(irelto, "RELTYPE"); if (parval != null) { relto.setRelType(parval); } relto.setValue(irelto.getValue()); if (chg.changed(pi, ev.getRelatedTo(), relto)) { ev.setRelatedTo(relto); } break; case REQUEST_STATUS: /* ------------------- RequestStatus -------------------- */ final BwRequestStatus rs = BwRequestStatus .fromRequestStatus((RequestStatus)prop); chg.addValue(pi, rs); break; case RESOURCES: /* ------------------- Resources -------------------- */ final TextList rl = ((Resources)prop).getResources(); if (rl != null) { /* Got some resources */ lang = IcalUtil.getLang(prop); for (final String s: rl) { final BwString rsrc = new BwString(lang, s); chg.addValue(pi, rsrc); } } break; case RRULE: /* ------------------- RRule -------------------- */ chg.addValue(pi, pval); break; case SEQUENCE: /* ------------------- Sequence -------------------- */ final int seq = ((Sequence)prop).getSequenceNo(); if (seq != ev.getSequence()) { chg.changed(pi, ev.getSequence(), seq); ev.setSequence(seq); } break; case STATUS: /* ------------------- Status -------------------- */ if (chg.changed(pi, ev.getStatus(), pval)) { ev.setStatus(pval); } break; case SUMMARY: /* ------------------- Summary -------------------- */ if (chg.changed(pi, ev.getSummary(), pval)) { ev.setSummary(pval); } break; case TRANSP: /* ------------------- Transp -------------------- */ if (chg.changed(pi, ev.getPeruserTransparency( cb.getPrincipal() .getPrincipalRef()), pval)) { final BwXproperty pu = ev.setPeruserTransparency( cb.getPrincipal().getPrincipalRef(), pval); if (pu != null) { chg.addValue(PropertyInfoIndex.XPROP, pu); } } break; case UID: /* ------------------- Uid -------------------- */ /* We did this above */ break; case URL: /* ------------------- Url -------------------- */ if (chg.changed(pi, ev.getLink(), pval)) { ev.setLink(pval); } break; case XPROP: /* ------------------------- x-property --------------------------- */ final String name = prop.getName(); if (name.equalsIgnoreCase(BwXproperty.bedeworkCost)) { if (chg.changed(PropertyInfoIndex.COST, ev.getCost(), pval)) { ev.setCost(pval); } break; } if (name.equalsIgnoreCase(BwXproperty.xBedeworkCategories)) { if (checkCategory(cb, chg, ev, null, pval)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkLocation)) { if (checkLocation(cb, chg, ev, prop)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkContact)) { if (checkContact(cb, chg, ev, null, pval)) { break; } } /* See if this is an x-category that can be converted to a real category */ final XProperty xp = (XProperty)prop; chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(name, xp.getParameters() .toString(), pval)); break; default: if (logger.debug()) { logger.debug("Unsupported property with index " + pi + "; class " + prop.getClass() + " and value " + pval); } } } /* =================== Process sub-components =============== */ final ComponentList<Component> subComps; if (val instanceof ComponentContainer) { subComps = ((ComponentContainer<Component>)val).getComponents(); } else { subComps = null; } final Set<Integer> pids; if (vpoll) { pids = new TreeSet<>(); final BwEvent vp = evinfo.getEvent(); if (!Util.isEmpty(vp.getPollItems())) { vp.clearPollItems(); } } else { pids = null; } if (!Util.isEmpty(subComps)) { for (final var subComp: subComps) { if (subComp instanceof Available) { if (!(val instanceof VAvailability)) { return Response.error(resp, "AVAILABLE only valid in VAVAILABLE"); } final var avlResp = processAvailable(cb, cal, ical, (VAvailability)val, (Available)subComp, evinfo); if (!avlResp.isOk()) { return Response.fromResponse(resp, avlResp); } continue; } if (subComp instanceof Participant) { if (vpoll) { final var vresp = processVoter(cb, (VPoll)val, (Participant)subComp, evinfo, chg, mergeAttendees); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Participant object"); continue; } if (subComp instanceof VResource) { logger.warn("Unimplemented VResource object"); continue; } if (subComp instanceof VLocation) { logger.warn("Unimplemented VLocation object"); continue; } if (subComp instanceof VAlarm) { final var aresp = VAlarmUtil.processAlarm(cb, val, (VAlarm)subComp, ev, currentPrincipal, chg); if (!aresp.isOk()) { return Response.fromResponse(resp, aresp); } continue; } if (vpoll && (event || task)) { final var vresp = processCandidate((VPoll)val, subComp, evinfo, pids, chg); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Component object: " + subComp); } } /* Fix up timestamps. */ if (ev.getCreated() == null) { if (ev.getLastmod() != null) { ev.setCreated(ev.getLastmod()); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); } else { ev.updateDtstamp(); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } } if (ev.getLastmod() == null) { // created cannot be null now ev.setLastmod(ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } processTimezones(ev, ical, chg); /* Remove any recipients and originator */ if (ev.getRecipients() != null) { ev.getRecipients().clear(); } ev.setOriginator(null); if (hasXparams.value) { /* Save a text copy of the entire event as an x-property */ final Component valCopy = val.copy(); /* Remove potentially large values */ final Description desp = valCopy.getProperty(Property.DESCRIPTION); if (desp != null) { desp.setValue(null); } final Attach attachp = valCopy.getProperty(Property.ATTACH); // Don't store the entire attachment - we just need the parameters. if (attachp != null) { final Value v = attachp.getParameter(Parameter.VALUE); if (v != null) { attachp.setValue(String.valueOf(attachp.getValue().hashCode())); } } chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(BwXproperty.bedeworkIcal, null, valCopy.toString())); } chg.processChanges(ev, true, false); ev.setRecurring(ev.isRecurringEntity()); if (logger.debug()) { logger.debug(chg.toString()); logger.debug(ev.toString()); } if (masterEI != null) { // Just return notfound as this event is on its override list return Response.notFound(resp); } resp.setEntity(evinfo); return resp; } catch (final Throwable t) { if (logger.debug()) { logger.error(t); } return Response.error(resp, t); } }
NONSATD
true
final String cval = c.getValue(); if (cval != null) { /* Got a concept */ chg.addValue(PropertyInfoIndex.XPROP, BwXproperty.makeIcalProperty("CONCEPT",
/* ------------------- Completed -------------------- */ if (chg.changed(pi, ev.getCompleted(), pval)) { ev.setCompleted(pval); } break; case CONCEPT: /* ------------------- Concept -------------------- */ final Concept c = (Concept)prop; final String cval = c.getValue(); if (cval != null) { /* Got a concept */ chg.addValue(PropertyInfoIndex.XPROP, BwXproperty.makeIcalProperty("CONCEPT", null, cval)); } break; case CONTACT: /* ------------------- Contact -------------------- */ final String altrep = getAltRepPar(prop); lang = IcalUtil.getLang(prop);
if (chg.changed(pi, ev.getClassification(), pval)) { ev.setClassification(pval); } break; case COMMENT: /* ------------------- Comment -------------------- */ chg.addValue(pi, new BwString(null, pval)); break; case COMPLETED: /* ------------------- Completed -------------------- */ if (chg.changed(pi, ev.getCompleted(), pval)) { ev.setCompleted(pval); } break; case CONCEPT: /* ------------------- Concept -------------------- */ final Concept c = (Concept)prop; final String cval = c.getValue(); if (cval != null) { /* Got a concept */ chg.addValue(PropertyInfoIndex.XPROP, BwXproperty.makeIcalProperty("CONCEPT", null, cval)); } break; case CONTACT: /* ------------------- Contact -------------------- */ final String altrep = getAltRepPar(prop); lang = IcalUtil.getLang(prop); final String uid = getUidPar(prop); final BwString nm = new BwString(lang, pval); BwContact contact = null; if (uid != null) { final var fcResp = cb.getContact(uid); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity();
7,893
36
/* ------------------- Contact -------------------- */
public static GetEntityResponse<EventInfo> toEvent( final IcalCallback cb, final BwCalendar cal, final Icalendar ical, final Component val, final boolean mergeAttendees) { final var resp = new GetEntityResponse<EventInfo>(); if (val == null) { return Response.notOk(resp, failed, "No component supplied"); } String currentPrincipal = null; final BwPrincipal principal = cb.getPrincipal(); if (principal != null) { currentPrincipal = principal.getPrincipalRef(); } final Holder<Boolean> hasXparams = new Holder<>(Boolean.FALSE); final int methodType = ical.getMethodType(); String attUri = null; if (mergeAttendees) { // We'll need this later. attUri = cb.getCaladdr(cb.getPrincipal().getPrincipalRef()); } final String colPath; if (cal == null) { colPath = null; } else { colPath = cal.getPath(); } try { final PropertyList<Property> pl = val.getProperties(); boolean vpoll = false; boolean event = false; boolean task = false; if (pl == null) { // Empty component return Response.notOk(resp, failed, "Empty component"); } final int entityType; if (val instanceof VEvent) { entityType = IcalDefs.entityTypeEvent; event = true; } else if (val instanceof VToDo) { entityType = IcalDefs.entityTypeTodo; task = true; } else if (val instanceof VJournal) { entityType = IcalDefs.entityTypeJournal; } else if (val instanceof VFreeBusy) { entityType = IcalDefs.entityTypeFreeAndBusy; } else if (val instanceof VAvailability) { entityType = IcalDefs.entityTypeVavailability; } else if (val instanceof Available) { entityType = IcalDefs.entityTypeAvailable; } else if (val instanceof VPoll) { entityType = IcalDefs.entityTypeVpoll; vpoll = true; } else { return Response.error(resp, "org.bedework.invalid.component.type: " + val.getName()); } // Get the guid from the component String guid = null; final Uid uidp = pl.getProperty(Property.UID); if (uidp != null) { testXparams(uidp, hasXparams); guid = uidp.getValue(); } if (guid == null) { /* XXX A guid is required - but are there devices out there without a * guid - and if so how do we handle it? */ return Response.notOk(resp, failed, CalFacadeException.noGuid); } /* See if we have a recurrence id */ BwDateTime ridObj = null; String rid = null; TimeZone ridTz = null; final RecurrenceId ridp = pl.getProperty(Property.RECURRENCE_ID); if (ridp != null) { testXparams(ridp, hasXparams); ridObj = BwDateTime.makeBwDateTime(ridp); if (ridObj.getRange() != null) { /* XXX What do I do with it? */ logger.warn("TRANS-TO_EVENT: Got a recurrence id range"); } rid = ridObj.getDate(); } EventInfo masterEI = null; EventInfo evinfo = null; final BwEvent ev; /* If we have a recurrence id see if we already have the master (we should * get a master + all its overrides). * * If so find the override and use the annnotation or if no override, * make one. * * If no override retrieve the event, add it to our table and then locate the * annotation. * * If there is no annotation, create one. * * It's possible we have been sent 'detached' instances of a recurring * event. This may happen if we are invited to one or more instances of a * meeting. In this case we try to retrieve the master and if it doesn't * exist we manufacture one. We consider such an instance an update to * that instance only and leave the others alone. */ /* We need this in a couple of places */ final DtStart dtStart = pl.getProperty(Property.DTSTART); /* if (rid != null) { // See if we have a new master event. If so create a proxy to that event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI == null) { masterEI = makeNewEvent(cb, chg, entityType, guid, cal); BwEvent e = masterEI.getEvent(); // XXX This seems bogus DtStart mdtStart; String bogusDate = "19980118T230000"; if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + "Z"); } else if (dtStart.getTimeZone() == null) { mdtStart = new DtStart(bogusDate); } else { mdtStart = new DtStart(bogusDate + "Z", dtStart.getTimeZone()); } setDates(e, mdtStart, null, null, chg); e.setRecurring(true); e.addRdate(ridObj); e.setSuppressed(true); ical.addComponent(masterEI); } if (masterEI != null) { evinfo = masterEI.findOverride(rid); } } */ /* If this is a recurrence instance see if we can find the master We only need this because the master may follow the overrides. */ if (rid != null) { // See if we have a new master event. If so create a proxy to this event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI != null) { evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; } } if ((evinfo == null) && (cal != null) && (cal.getCalType() != BwCalendar.calTypeInbox) && (cal.getCalType() != BwCalendar.calTypePendingInbox) && (cal.getCalType() != BwCalendar.calTypeOutbox)) { if (logger.debug()) { logger.debug("TRANS-TO_EVENT: try to fetch event with guid=" + guid); } final GetEntitiesResponse<EventInfo> eisResp = cb.getEvent(colPath, guid); if (eisResp.isError()) { return Response.fromResponse(resp, eisResp); } final var eis = eisResp.getEntities(); if (!Util.isEmpty(eis)) { if (eis.size() > 1) { // DORECUR - wrong again return Response.notOk(resp, failed, "More than one event returned for guid."); } evinfo = eis.iterator().next(); } if (logger.debug()) { if (evinfo != null) { logger.debug("TRANS-TO_EVENT: fetched event with guid"); } else { logger.debug("TRANS-TO_EVENT: did not find event with guid"); } } if (evinfo != null) { if (rid != null) { // We just retrieved it's master masterEI = evinfo; masterEI.setInstanceOnly(true); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; ical.addComponent(masterEI); } else if (methodType == ScheduleMethods.methodTypeCancel) { // This should never have an rid for cancel of entire event. evinfo.setInstanceOnly(evinfo.getEvent().getSuppressed()); } else { // Presumably sent an update for the entire event. No longer suppressed master evinfo.getEvent().setSuppressed(false); } } else if (rid != null) { /* Manufacture a master for the instance */ masterEI = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); final BwEvent e = masterEI.getEvent(); // XXX This seems bogus final DtStart mdtStart; final String bogusDate = "19980118"; final String bogusTime = "T230000"; // Base dtstart on the recurrence id. final boolean isDateType = ridObj.getDateType(); if (isDateType) { mdtStart = new DtStart(new Date(bogusDate)); } else if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + bogusTime + "Z"); } else if (ridObj.getTzid() == null) { mdtStart = new DtStart(bogusDate + bogusTime); } else { mdtStart = new DtStart(bogusDate + bogusTime, Timezones.getTz(ridObj.getTzid())); } IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), masterEI, mdtStart, null, null); e.setRecurring(true); // e.addRdate(ridObj); final var sum = (Summary)pl.getProperty(Property.SUMMARY); e.setSummary(sum.getValue()); e.setSuppressed(true); ical.addComponent(masterEI); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; masterEI.setInstanceOnly(rid != null); } } if (evinfo == null) { evinfo = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); } else if (evinfo.getEvent().getEntityType() != entityType) { return Response.notOk(resp, failed, "org.bedework.mismatched.entity.type: " + val); } final ChangeTable chg = evinfo.getChangeset( cb.getPrincipal().getPrincipalRef()); if (rid != null) { final String evrid = evinfo.getEvent().getRecurrenceId(); if ((evrid == null) || (!evrid.equals(rid))) { logger. warn("Mismatched rid ev=" + evrid + " expected " + rid); chg.changed(PropertyInfoIndex.RECURRENCE_ID, evrid, rid); // XXX spurious??? } if (masterEI.getEvent().getSuppressed()) { masterEI.getEvent().addRdate(ridObj); } } ev = evinfo.getEvent(); ev.setScheduleMethod(methodType); DtEnd dtEnd = null; if (entityType == IcalDefs.entityTypeTodo) { final Due due = pl.getProperty(Property.DUE); if (due != null ) { dtEnd = new DtEnd(due.getParameters(), due.getValue()); } } else { dtEnd = pl.getProperty(Property.DTEND); } final Duration duration = pl.getProperty(Property.DURATION); IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), evinfo, dtStart, dtEnd, duration); for (final Property prop: pl) { testXparams(prop, hasXparams); //debug("ical prop " + prop.getClass().getName()); String pval = prop.getValue(); if ((pval != null) && (pval.length() == 0)) { pval = null; } final PropertyInfoIndex pi; if (prop instanceof XProperty) { pi = PropertyInfoIndex.XPROP; } else { pi = PropertyInfoIndex.fromName(prop.getName()); } if (pi == null) { logger.debug("Unknown property with name " + prop.getName() + " class " + prop.getClass() + " and value " + pval); continue; } chg.present(pi); switch (pi) { case ACCEPT_RESPONSE: /* ------------------- Accept Response -------------------- */ String sval = prop.getValue(); if (chg.changed(pi, ev.getPollAcceptResponse(), sval)) { ev.setPollAcceptResponse(sval); } break; case ATTACH: /* ------------------- Attachment -------------------- */ chg.addValue(pi, IcalUtil.getAttachment((Attach)prop)); break; case ATTENDEE: /* ------------------- Attendee -------------------- */ if (methodType == ScheduleMethods.methodTypePublish) { if (cb.getStrictness() == IcalCallback.conformanceStrict) { return Response.notOk(resp, failed, CalFacadeException.attendeesInPublish); } //if (cb.getStrictness() == IcalCallback.conformanceWarn) { // warn("Had attendees for PUBLISH"); //} } final Attendee attPr = (Attendee)prop; if (evinfo.getNewEvent() || !mergeAttendees) { chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { final String pUri = cb.getCaladdr(attPr.getValue()); if (pUri.equals(attUri)) { /* Only update for our own attendee * We're doing a PUT and this must be the attendee updating their * partstat. We don't allow them to change other attendees * whatever the PUT content says. */ chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { // Use the value we currently have boolean found = false; for (final BwAttendee att: ev.getAttendees()) { if (pUri.equals(att.getAttendeeUri())) { chg.addValue(pi, att.clone()); found = true; break; } } if (!found) { // An added attendee final BwAttendee att = IcalUtil .getAttendee(cb, attPr); att.setPartstat(IcalDefs.partstatValNeedsAction); chg.addValue(pi, att); } } } break; case BUSYTYPE: final int ibt = BwEvent.fromBusyTypeString(pval); if (chg.changed(pi, ev.getBusyType(), ibt)) { ev.setBusyType(ibt); } break; case CATEGORIES: /* ------------------- Categories -------------------- */ final Categories cats = (Categories)prop; final TextList cl = cats.getCategories(); String lang = IcalUtil.getLang(cats); if (cl != null) { /* Got some categories */ for (final String wd: cl) { if (wd == null) { continue; } final BwString key = new BwString(lang, wd); final var fcResp = cb.findCategory(key); final BwCategory cat; if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isNotFound()) { cat = BwCategory.makeCategory(); cat.setWord(key); cb.addCategory(cat); } else { cat = fcResp.getEntity(); } chg.addValue(pi, cat); } } break; case CLASS: /* ------------------- Class -------------------- */ if (chg.changed(pi, ev.getClassification(), pval)) { ev.setClassification(pval); } break; case COMMENT: /* ------------------- Comment -------------------- */ chg.addValue(pi, new BwString(null, pval)); break; case COMPLETED: /* ------------------- Completed -------------------- */ if (chg.changed(pi, ev.getCompleted(), pval)) { ev.setCompleted(pval); } break; case CONCEPT: /* ------------------- Concept -------------------- */ final Concept c = (Concept)prop; final String cval = c.getValue(); if (cval != null) { /* Got a concept */ chg.addValue(PropertyInfoIndex.XPROP, BwXproperty.makeIcalProperty("CONCEPT", null, cval)); } break; case CONTACT: /* ------------------- Contact -------------------- */ final String altrep = getAltRepPar(prop); lang = IcalUtil.getLang(prop); final String uid = getUidPar(prop); final BwString nm = new BwString(lang, pval); BwContact contact = null; if (uid != null) { final var fcResp = cb.getContact(uid); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { final var fcResp = cb.findContact(nm); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { contact = BwContact.makeContact(); contact.setCn(nm); contact.setLink(altrep); cb.addContact(contact); } else { contact.setCn(nm); contact.setLink(altrep); } chg.addValue(pi, contact); break; case CREATED: /* ------------------- Created -------------------- */ if (chg.changed(pi, ev.getCreated(), pval)) { ev.setCreated(pval); } break; case DESCRIPTION: /* ------------------- Description -------------------- */ if (chg.changed(pi, ev.getDescription(), pval)) { ev.setDescription(pval); } break; case DTEND: /* ------------------- DtEnd -------------------- */ break; case DTSTAMP: /* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval); break; case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE: /* -------------------- Due ------------------------ */ break; case DURATION: /* ------------------- Duration -------------------- */ break; case EXDATE: /* ------------------- ExDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case EXRULE: /* ------------------- ExRule -------------------- */ chg.addValue(pi, pval); break; case FREEBUSY: /* ------------------- freebusy -------------------- */ final FreeBusy fbusy = (FreeBusy)prop; final PeriodList perpl = fbusy.getPeriods(); final Parameter par = IcalUtil.getParameter(fbusy, "FBTYPE"); final int fbtype; if (par == null) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY)) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY_TENTATIVE)) { fbtype = BwFreeBusyComponent.typeBusyTentative; } else if (par.equals(FbType.BUSY_UNAVAILABLE)) { fbtype = BwFreeBusyComponent.typeBusyUnavailable; } else if (par.equals(FbType.FREE)) { fbtype = BwFreeBusyComponent.typeFree; } else { if (logger.debug()) { logger.debug("Unsupported parameter " + par.getName()); } return Response.notOk(resp, failed, "Unsupported parameter " + par.getName()); } final BwFreeBusyComponent fbc = new BwFreeBusyComponent(); fbc.setType(fbtype); for (final Period per : perpl) { fbc.addPeriod(per); } ev.addFreeBusyPeriod(fbc); break; case GEO: /* ------------------- Geo -------------------- */ final Geo g = (Geo)prop; final BwGeo geo = new BwGeo(g.getLatitude(), g.getLongitude()); if (chg.changed(pi, ev.getGeo(), geo)) { ev.setGeo(geo); } break; case LAST_MODIFIED: /* ------------------- LastModified -------------------- */ if (chg.changed(pi, ev.getLastmod(), pval)) { ev.setLastmod(pval); } break; case LOCATION: /* ------------------- Location -------------------- */ BwLocation loc = null; //String uid = getUidPar(prop); /* At the moment Mozilla lightning is broken and this leads to all * sorts of problems. if (uid != null) { loc = cb.getLocation(uid); } */ lang = IcalUtil.getLang(prop); BwString addr = null; if (pval != null) { if (loc == null) { addr = new BwString(lang, pval); final var fcResp = cb.findLocation(addr); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { loc = fcResp.getEntity(); } } if (loc == null) { loc = BwLocation.makeLocation(); loc.setAddress(addr); cb.addLocation(loc); } } final BwLocation evloc = ev.getLocation(); if (chg.changed(pi, evloc, loc)) { // CHGTBL - this only shows that it's a different location object ev.setLocation(loc); } else if ((loc != null) && (evloc != null)) { // See if the value is changed final String evval = evloc.getAddress().getValue(); final String inval = loc.getAddress().getValue(); if (!evval.equals(inval)) { chg.changed(pi, evval, inval); evloc.getAddress().setValue(inval); } } break; case ORGANIZER: /* ------------------- Organizer -------------------- */ final BwOrganizer org = IcalUtil.getOrganizer(cb, (Organizer)prop); final BwOrganizer evorg = ev.getOrganizer(); final BwOrganizer evorgCopy; if (evorg == null) { evorgCopy = null; } else { evorgCopy = (BwOrganizer)evorg.clone(); } if (chg.changed(pi, evorgCopy, org)) { if (evorg == null) { ev.setOrganizer(org); } else { evorg.update(org); } } break; case PERCENT_COMPLETE: /* ------------------- PercentComplete -------------------- */ Integer ival = ((PercentComplete)prop).getPercentage(); if (chg.changed(pi, ev.getPercentComplete(), ival)) { ev.setPercentComplete(ival); } break; case POLL_MODE: /* ------------------- Poll mode -------------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollMode(), sval)) { ev.setPollMode(sval); } break; case POLL_PROPERTIES: /* ------------------- Poll properties ---------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollProperties(), sval)) { ev.setPollProperties(sval); } break; case POLL_WINNER: /* ------------------- Poll winner -------------------- */ ival = ((PollWinner)prop).getPollwinner(); if (chg.changed(pi, ev.getPollWinner(), ival)) { ev.setPollWinner(ival); } break; case PRIORITY: /* ------------------- Priority -------------------- */ ival = ((Priority)prop).getLevel(); if (chg.changed(pi, ev.getPriority(), ival)) { ev.setPriority(ival); } break; case RDATE: /* ------------------- RDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case RECURRENCE_ID: /* ------------------- RecurrenceID -------------------- */ // Done above break; case RELATED_TO: /* ------------------- RelatedTo -------------------- */ final RelatedTo irelto = (RelatedTo)prop; final BwRelatedTo relto = new BwRelatedTo(); final String parval = IcalUtil.getParameterVal(irelto, "RELTYPE"); if (parval != null) { relto.setRelType(parval); } relto.setValue(irelto.getValue()); if (chg.changed(pi, ev.getRelatedTo(), relto)) { ev.setRelatedTo(relto); } break; case REQUEST_STATUS: /* ------------------- RequestStatus -------------------- */ final BwRequestStatus rs = BwRequestStatus .fromRequestStatus((RequestStatus)prop); chg.addValue(pi, rs); break; case RESOURCES: /* ------------------- Resources -------------------- */ final TextList rl = ((Resources)prop).getResources(); if (rl != null) { /* Got some resources */ lang = IcalUtil.getLang(prop); for (final String s: rl) { final BwString rsrc = new BwString(lang, s); chg.addValue(pi, rsrc); } } break; case RRULE: /* ------------------- RRule -------------------- */ chg.addValue(pi, pval); break; case SEQUENCE: /* ------------------- Sequence -------------------- */ final int seq = ((Sequence)prop).getSequenceNo(); if (seq != ev.getSequence()) { chg.changed(pi, ev.getSequence(), seq); ev.setSequence(seq); } break; case STATUS: /* ------------------- Status -------------------- */ if (chg.changed(pi, ev.getStatus(), pval)) { ev.setStatus(pval); } break; case SUMMARY: /* ------------------- Summary -------------------- */ if (chg.changed(pi, ev.getSummary(), pval)) { ev.setSummary(pval); } break; case TRANSP: /* ------------------- Transp -------------------- */ if (chg.changed(pi, ev.getPeruserTransparency( cb.getPrincipal() .getPrincipalRef()), pval)) { final BwXproperty pu = ev.setPeruserTransparency( cb.getPrincipal().getPrincipalRef(), pval); if (pu != null) { chg.addValue(PropertyInfoIndex.XPROP, pu); } } break; case UID: /* ------------------- Uid -------------------- */ /* We did this above */ break; case URL: /* ------------------- Url -------------------- */ if (chg.changed(pi, ev.getLink(), pval)) { ev.setLink(pval); } break; case XPROP: /* ------------------------- x-property --------------------------- */ final String name = prop.getName(); if (name.equalsIgnoreCase(BwXproperty.bedeworkCost)) { if (chg.changed(PropertyInfoIndex.COST, ev.getCost(), pval)) { ev.setCost(pval); } break; } if (name.equalsIgnoreCase(BwXproperty.xBedeworkCategories)) { if (checkCategory(cb, chg, ev, null, pval)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkLocation)) { if (checkLocation(cb, chg, ev, prop)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkContact)) { if (checkContact(cb, chg, ev, null, pval)) { break; } } /* See if this is an x-category that can be converted to a real category */ final XProperty xp = (XProperty)prop; chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(name, xp.getParameters() .toString(), pval)); break; default: if (logger.debug()) { logger.debug("Unsupported property with index " + pi + "; class " + prop.getClass() + " and value " + pval); } } } /* =================== Process sub-components =============== */ final ComponentList<Component> subComps; if (val instanceof ComponentContainer) { subComps = ((ComponentContainer<Component>)val).getComponents(); } else { subComps = null; } final Set<Integer> pids; if (vpoll) { pids = new TreeSet<>(); final BwEvent vp = evinfo.getEvent(); if (!Util.isEmpty(vp.getPollItems())) { vp.clearPollItems(); } } else { pids = null; } if (!Util.isEmpty(subComps)) { for (final var subComp: subComps) { if (subComp instanceof Available) { if (!(val instanceof VAvailability)) { return Response.error(resp, "AVAILABLE only valid in VAVAILABLE"); } final var avlResp = processAvailable(cb, cal, ical, (VAvailability)val, (Available)subComp, evinfo); if (!avlResp.isOk()) { return Response.fromResponse(resp, avlResp); } continue; } if (subComp instanceof Participant) { if (vpoll) { final var vresp = processVoter(cb, (VPoll)val, (Participant)subComp, evinfo, chg, mergeAttendees); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Participant object"); continue; } if (subComp instanceof VResource) { logger.warn("Unimplemented VResource object"); continue; } if (subComp instanceof VLocation) { logger.warn("Unimplemented VLocation object"); continue; } if (subComp instanceof VAlarm) { final var aresp = VAlarmUtil.processAlarm(cb, val, (VAlarm)subComp, ev, currentPrincipal, chg); if (!aresp.isOk()) { return Response.fromResponse(resp, aresp); } continue; } if (vpoll && (event || task)) { final var vresp = processCandidate((VPoll)val, subComp, evinfo, pids, chg); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Component object: " + subComp); } } /* Fix up timestamps. */ if (ev.getCreated() == null) { if (ev.getLastmod() != null) { ev.setCreated(ev.getLastmod()); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); } else { ev.updateDtstamp(); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } } if (ev.getLastmod() == null) { // created cannot be null now ev.setLastmod(ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } processTimezones(ev, ical, chg); /* Remove any recipients and originator */ if (ev.getRecipients() != null) { ev.getRecipients().clear(); } ev.setOriginator(null); if (hasXparams.value) { /* Save a text copy of the entire event as an x-property */ final Component valCopy = val.copy(); /* Remove potentially large values */ final Description desp = valCopy.getProperty(Property.DESCRIPTION); if (desp != null) { desp.setValue(null); } final Attach attachp = valCopy.getProperty(Property.ATTACH); // Don't store the entire attachment - we just need the parameters. if (attachp != null) { final Value v = attachp.getParameter(Parameter.VALUE); if (v != null) { attachp.setValue(String.valueOf(attachp.getValue().hashCode())); } } chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(BwXproperty.bedeworkIcal, null, valCopy.toString())); } chg.processChanges(ev, true, false); ev.setRecurring(ev.isRecurringEntity()); if (logger.debug()) { logger.debug(chg.toString()); logger.debug(ev.toString()); } if (masterEI != null) { // Just return notfound as this event is on its override list return Response.notFound(resp); } resp.setEntity(evinfo); return resp; } catch (final Throwable t) { if (logger.debug()) { logger.error(t); } return Response.error(resp, t); } }
NONSATD
true
break; case CONTACT: /* ------------------- Contact -------------------- */ final String altrep = getAltRepPar(prop); lang = IcalUtil.getLang(prop);
final String cval = c.getValue(); if (cval != null) { /* Got a concept */ chg.addValue(PropertyInfoIndex.XPROP, BwXproperty.makeIcalProperty("CONCEPT", null, cval)); } break; case CONTACT: /* ------------------- Contact -------------------- */ final String altrep = getAltRepPar(prop); lang = IcalUtil.getLang(prop); final String uid = getUidPar(prop); final BwString nm = new BwString(lang, pval); BwContact contact = null; if (uid != null) { final var fcResp = cb.getContact(uid); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); }
break; case COMPLETED: /* ------------------- Completed -------------------- */ if (chg.changed(pi, ev.getCompleted(), pval)) { ev.setCompleted(pval); } break; case CONCEPT: /* ------------------- Concept -------------------- */ final Concept c = (Concept)prop; final String cval = c.getValue(); if (cval != null) { /* Got a concept */ chg.addValue(PropertyInfoIndex.XPROP, BwXproperty.makeIcalProperty("CONCEPT", null, cval)); } break; case CONTACT: /* ------------------- Contact -------------------- */ final String altrep = getAltRepPar(prop); lang = IcalUtil.getLang(prop); final String uid = getUidPar(prop); final BwString nm = new BwString(lang, pval); BwContact contact = null; if (uid != null) { final var fcResp = cb.getContact(uid); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { final var fcResp = cb.findContact(nm); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) {
7,893
37
/* ------------------- Created -------------------- */
public static GetEntityResponse<EventInfo> toEvent( final IcalCallback cb, final BwCalendar cal, final Icalendar ical, final Component val, final boolean mergeAttendees) { final var resp = new GetEntityResponse<EventInfo>(); if (val == null) { return Response.notOk(resp, failed, "No component supplied"); } String currentPrincipal = null; final BwPrincipal principal = cb.getPrincipal(); if (principal != null) { currentPrincipal = principal.getPrincipalRef(); } final Holder<Boolean> hasXparams = new Holder<>(Boolean.FALSE); final int methodType = ical.getMethodType(); String attUri = null; if (mergeAttendees) { // We'll need this later. attUri = cb.getCaladdr(cb.getPrincipal().getPrincipalRef()); } final String colPath; if (cal == null) { colPath = null; } else { colPath = cal.getPath(); } try { final PropertyList<Property> pl = val.getProperties(); boolean vpoll = false; boolean event = false; boolean task = false; if (pl == null) { // Empty component return Response.notOk(resp, failed, "Empty component"); } final int entityType; if (val instanceof VEvent) { entityType = IcalDefs.entityTypeEvent; event = true; } else if (val instanceof VToDo) { entityType = IcalDefs.entityTypeTodo; task = true; } else if (val instanceof VJournal) { entityType = IcalDefs.entityTypeJournal; } else if (val instanceof VFreeBusy) { entityType = IcalDefs.entityTypeFreeAndBusy; } else if (val instanceof VAvailability) { entityType = IcalDefs.entityTypeVavailability; } else if (val instanceof Available) { entityType = IcalDefs.entityTypeAvailable; } else if (val instanceof VPoll) { entityType = IcalDefs.entityTypeVpoll; vpoll = true; } else { return Response.error(resp, "org.bedework.invalid.component.type: " + val.getName()); } // Get the guid from the component String guid = null; final Uid uidp = pl.getProperty(Property.UID); if (uidp != null) { testXparams(uidp, hasXparams); guid = uidp.getValue(); } if (guid == null) { /* XXX A guid is required - but are there devices out there without a * guid - and if so how do we handle it? */ return Response.notOk(resp, failed, CalFacadeException.noGuid); } /* See if we have a recurrence id */ BwDateTime ridObj = null; String rid = null; TimeZone ridTz = null; final RecurrenceId ridp = pl.getProperty(Property.RECURRENCE_ID); if (ridp != null) { testXparams(ridp, hasXparams); ridObj = BwDateTime.makeBwDateTime(ridp); if (ridObj.getRange() != null) { /* XXX What do I do with it? */ logger.warn("TRANS-TO_EVENT: Got a recurrence id range"); } rid = ridObj.getDate(); } EventInfo masterEI = null; EventInfo evinfo = null; final BwEvent ev; /* If we have a recurrence id see if we already have the master (we should * get a master + all its overrides). * * If so find the override and use the annnotation or if no override, * make one. * * If no override retrieve the event, add it to our table and then locate the * annotation. * * If there is no annotation, create one. * * It's possible we have been sent 'detached' instances of a recurring * event. This may happen if we are invited to one or more instances of a * meeting. In this case we try to retrieve the master and if it doesn't * exist we manufacture one. We consider such an instance an update to * that instance only and leave the others alone. */ /* We need this in a couple of places */ final DtStart dtStart = pl.getProperty(Property.DTSTART); /* if (rid != null) { // See if we have a new master event. If so create a proxy to that event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI == null) { masterEI = makeNewEvent(cb, chg, entityType, guid, cal); BwEvent e = masterEI.getEvent(); // XXX This seems bogus DtStart mdtStart; String bogusDate = "19980118T230000"; if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + "Z"); } else if (dtStart.getTimeZone() == null) { mdtStart = new DtStart(bogusDate); } else { mdtStart = new DtStart(bogusDate + "Z", dtStart.getTimeZone()); } setDates(e, mdtStart, null, null, chg); e.setRecurring(true); e.addRdate(ridObj); e.setSuppressed(true); ical.addComponent(masterEI); } if (masterEI != null) { evinfo = masterEI.findOverride(rid); } } */ /* If this is a recurrence instance see if we can find the master We only need this because the master may follow the overrides. */ if (rid != null) { // See if we have a new master event. If so create a proxy to this event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI != null) { evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; } } if ((evinfo == null) && (cal != null) && (cal.getCalType() != BwCalendar.calTypeInbox) && (cal.getCalType() != BwCalendar.calTypePendingInbox) && (cal.getCalType() != BwCalendar.calTypeOutbox)) { if (logger.debug()) { logger.debug("TRANS-TO_EVENT: try to fetch event with guid=" + guid); } final GetEntitiesResponse<EventInfo> eisResp = cb.getEvent(colPath, guid); if (eisResp.isError()) { return Response.fromResponse(resp, eisResp); } final var eis = eisResp.getEntities(); if (!Util.isEmpty(eis)) { if (eis.size() > 1) { // DORECUR - wrong again return Response.notOk(resp, failed, "More than one event returned for guid."); } evinfo = eis.iterator().next(); } if (logger.debug()) { if (evinfo != null) { logger.debug("TRANS-TO_EVENT: fetched event with guid"); } else { logger.debug("TRANS-TO_EVENT: did not find event with guid"); } } if (evinfo != null) { if (rid != null) { // We just retrieved it's master masterEI = evinfo; masterEI.setInstanceOnly(true); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; ical.addComponent(masterEI); } else if (methodType == ScheduleMethods.methodTypeCancel) { // This should never have an rid for cancel of entire event. evinfo.setInstanceOnly(evinfo.getEvent().getSuppressed()); } else { // Presumably sent an update for the entire event. No longer suppressed master evinfo.getEvent().setSuppressed(false); } } else if (rid != null) { /* Manufacture a master for the instance */ masterEI = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); final BwEvent e = masterEI.getEvent(); // XXX This seems bogus final DtStart mdtStart; final String bogusDate = "19980118"; final String bogusTime = "T230000"; // Base dtstart on the recurrence id. final boolean isDateType = ridObj.getDateType(); if (isDateType) { mdtStart = new DtStart(new Date(bogusDate)); } else if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + bogusTime + "Z"); } else if (ridObj.getTzid() == null) { mdtStart = new DtStart(bogusDate + bogusTime); } else { mdtStart = new DtStart(bogusDate + bogusTime, Timezones.getTz(ridObj.getTzid())); } IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), masterEI, mdtStart, null, null); e.setRecurring(true); // e.addRdate(ridObj); final var sum = (Summary)pl.getProperty(Property.SUMMARY); e.setSummary(sum.getValue()); e.setSuppressed(true); ical.addComponent(masterEI); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; masterEI.setInstanceOnly(rid != null); } } if (evinfo == null) { evinfo = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); } else if (evinfo.getEvent().getEntityType() != entityType) { return Response.notOk(resp, failed, "org.bedework.mismatched.entity.type: " + val); } final ChangeTable chg = evinfo.getChangeset( cb.getPrincipal().getPrincipalRef()); if (rid != null) { final String evrid = evinfo.getEvent().getRecurrenceId(); if ((evrid == null) || (!evrid.equals(rid))) { logger. warn("Mismatched rid ev=" + evrid + " expected " + rid); chg.changed(PropertyInfoIndex.RECURRENCE_ID, evrid, rid); // XXX spurious??? } if (masterEI.getEvent().getSuppressed()) { masterEI.getEvent().addRdate(ridObj); } } ev = evinfo.getEvent(); ev.setScheduleMethod(methodType); DtEnd dtEnd = null; if (entityType == IcalDefs.entityTypeTodo) { final Due due = pl.getProperty(Property.DUE); if (due != null ) { dtEnd = new DtEnd(due.getParameters(), due.getValue()); } } else { dtEnd = pl.getProperty(Property.DTEND); } final Duration duration = pl.getProperty(Property.DURATION); IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), evinfo, dtStart, dtEnd, duration); for (final Property prop: pl) { testXparams(prop, hasXparams); //debug("ical prop " + prop.getClass().getName()); String pval = prop.getValue(); if ((pval != null) && (pval.length() == 0)) { pval = null; } final PropertyInfoIndex pi; if (prop instanceof XProperty) { pi = PropertyInfoIndex.XPROP; } else { pi = PropertyInfoIndex.fromName(prop.getName()); } if (pi == null) { logger.debug("Unknown property with name " + prop.getName() + " class " + prop.getClass() + " and value " + pval); continue; } chg.present(pi); switch (pi) { case ACCEPT_RESPONSE: /* ------------------- Accept Response -------------------- */ String sval = prop.getValue(); if (chg.changed(pi, ev.getPollAcceptResponse(), sval)) { ev.setPollAcceptResponse(sval); } break; case ATTACH: /* ------------------- Attachment -------------------- */ chg.addValue(pi, IcalUtil.getAttachment((Attach)prop)); break; case ATTENDEE: /* ------------------- Attendee -------------------- */ if (methodType == ScheduleMethods.methodTypePublish) { if (cb.getStrictness() == IcalCallback.conformanceStrict) { return Response.notOk(resp, failed, CalFacadeException.attendeesInPublish); } //if (cb.getStrictness() == IcalCallback.conformanceWarn) { // warn("Had attendees for PUBLISH"); //} } final Attendee attPr = (Attendee)prop; if (evinfo.getNewEvent() || !mergeAttendees) { chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { final String pUri = cb.getCaladdr(attPr.getValue()); if (pUri.equals(attUri)) { /* Only update for our own attendee * We're doing a PUT and this must be the attendee updating their * partstat. We don't allow them to change other attendees * whatever the PUT content says. */ chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { // Use the value we currently have boolean found = false; for (final BwAttendee att: ev.getAttendees()) { if (pUri.equals(att.getAttendeeUri())) { chg.addValue(pi, att.clone()); found = true; break; } } if (!found) { // An added attendee final BwAttendee att = IcalUtil .getAttendee(cb, attPr); att.setPartstat(IcalDefs.partstatValNeedsAction); chg.addValue(pi, att); } } } break; case BUSYTYPE: final int ibt = BwEvent.fromBusyTypeString(pval); if (chg.changed(pi, ev.getBusyType(), ibt)) { ev.setBusyType(ibt); } break; case CATEGORIES: /* ------------------- Categories -------------------- */ final Categories cats = (Categories)prop; final TextList cl = cats.getCategories(); String lang = IcalUtil.getLang(cats); if (cl != null) { /* Got some categories */ for (final String wd: cl) { if (wd == null) { continue; } final BwString key = new BwString(lang, wd); final var fcResp = cb.findCategory(key); final BwCategory cat; if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isNotFound()) { cat = BwCategory.makeCategory(); cat.setWord(key); cb.addCategory(cat); } else { cat = fcResp.getEntity(); } chg.addValue(pi, cat); } } break; case CLASS: /* ------------------- Class -------------------- */ if (chg.changed(pi, ev.getClassification(), pval)) { ev.setClassification(pval); } break; case COMMENT: /* ------------------- Comment -------------------- */ chg.addValue(pi, new BwString(null, pval)); break; case COMPLETED: /* ------------------- Completed -------------------- */ if (chg.changed(pi, ev.getCompleted(), pval)) { ev.setCompleted(pval); } break; case CONCEPT: /* ------------------- Concept -------------------- */ final Concept c = (Concept)prop; final String cval = c.getValue(); if (cval != null) { /* Got a concept */ chg.addValue(PropertyInfoIndex.XPROP, BwXproperty.makeIcalProperty("CONCEPT", null, cval)); } break; case CONTACT: /* ------------------- Contact -------------------- */ final String altrep = getAltRepPar(prop); lang = IcalUtil.getLang(prop); final String uid = getUidPar(prop); final BwString nm = new BwString(lang, pval); BwContact contact = null; if (uid != null) { final var fcResp = cb.getContact(uid); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { final var fcResp = cb.findContact(nm); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { contact = BwContact.makeContact(); contact.setCn(nm); contact.setLink(altrep); cb.addContact(contact); } else { contact.setCn(nm); contact.setLink(altrep); } chg.addValue(pi, contact); break; case CREATED: /* ------------------- Created -------------------- */ if (chg.changed(pi, ev.getCreated(), pval)) { ev.setCreated(pval); } break; case DESCRIPTION: /* ------------------- Description -------------------- */ if (chg.changed(pi, ev.getDescription(), pval)) { ev.setDescription(pval); } break; case DTEND: /* ------------------- DtEnd -------------------- */ break; case DTSTAMP: /* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval); break; case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE: /* -------------------- Due ------------------------ */ break; case DURATION: /* ------------------- Duration -------------------- */ break; case EXDATE: /* ------------------- ExDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case EXRULE: /* ------------------- ExRule -------------------- */ chg.addValue(pi, pval); break; case FREEBUSY: /* ------------------- freebusy -------------------- */ final FreeBusy fbusy = (FreeBusy)prop; final PeriodList perpl = fbusy.getPeriods(); final Parameter par = IcalUtil.getParameter(fbusy, "FBTYPE"); final int fbtype; if (par == null) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY)) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY_TENTATIVE)) { fbtype = BwFreeBusyComponent.typeBusyTentative; } else if (par.equals(FbType.BUSY_UNAVAILABLE)) { fbtype = BwFreeBusyComponent.typeBusyUnavailable; } else if (par.equals(FbType.FREE)) { fbtype = BwFreeBusyComponent.typeFree; } else { if (logger.debug()) { logger.debug("Unsupported parameter " + par.getName()); } return Response.notOk(resp, failed, "Unsupported parameter " + par.getName()); } final BwFreeBusyComponent fbc = new BwFreeBusyComponent(); fbc.setType(fbtype); for (final Period per : perpl) { fbc.addPeriod(per); } ev.addFreeBusyPeriod(fbc); break; case GEO: /* ------------------- Geo -------------------- */ final Geo g = (Geo)prop; final BwGeo geo = new BwGeo(g.getLatitude(), g.getLongitude()); if (chg.changed(pi, ev.getGeo(), geo)) { ev.setGeo(geo); } break; case LAST_MODIFIED: /* ------------------- LastModified -------------------- */ if (chg.changed(pi, ev.getLastmod(), pval)) { ev.setLastmod(pval); } break; case LOCATION: /* ------------------- Location -------------------- */ BwLocation loc = null; //String uid = getUidPar(prop); /* At the moment Mozilla lightning is broken and this leads to all * sorts of problems. if (uid != null) { loc = cb.getLocation(uid); } */ lang = IcalUtil.getLang(prop); BwString addr = null; if (pval != null) { if (loc == null) { addr = new BwString(lang, pval); final var fcResp = cb.findLocation(addr); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { loc = fcResp.getEntity(); } } if (loc == null) { loc = BwLocation.makeLocation(); loc.setAddress(addr); cb.addLocation(loc); } } final BwLocation evloc = ev.getLocation(); if (chg.changed(pi, evloc, loc)) { // CHGTBL - this only shows that it's a different location object ev.setLocation(loc); } else if ((loc != null) && (evloc != null)) { // See if the value is changed final String evval = evloc.getAddress().getValue(); final String inval = loc.getAddress().getValue(); if (!evval.equals(inval)) { chg.changed(pi, evval, inval); evloc.getAddress().setValue(inval); } } break; case ORGANIZER: /* ------------------- Organizer -------------------- */ final BwOrganizer org = IcalUtil.getOrganizer(cb, (Organizer)prop); final BwOrganizer evorg = ev.getOrganizer(); final BwOrganizer evorgCopy; if (evorg == null) { evorgCopy = null; } else { evorgCopy = (BwOrganizer)evorg.clone(); } if (chg.changed(pi, evorgCopy, org)) { if (evorg == null) { ev.setOrganizer(org); } else { evorg.update(org); } } break; case PERCENT_COMPLETE: /* ------------------- PercentComplete -------------------- */ Integer ival = ((PercentComplete)prop).getPercentage(); if (chg.changed(pi, ev.getPercentComplete(), ival)) { ev.setPercentComplete(ival); } break; case POLL_MODE: /* ------------------- Poll mode -------------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollMode(), sval)) { ev.setPollMode(sval); } break; case POLL_PROPERTIES: /* ------------------- Poll properties ---------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollProperties(), sval)) { ev.setPollProperties(sval); } break; case POLL_WINNER: /* ------------------- Poll winner -------------------- */ ival = ((PollWinner)prop).getPollwinner(); if (chg.changed(pi, ev.getPollWinner(), ival)) { ev.setPollWinner(ival); } break; case PRIORITY: /* ------------------- Priority -------------------- */ ival = ((Priority)prop).getLevel(); if (chg.changed(pi, ev.getPriority(), ival)) { ev.setPriority(ival); } break; case RDATE: /* ------------------- RDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case RECURRENCE_ID: /* ------------------- RecurrenceID -------------------- */ // Done above break; case RELATED_TO: /* ------------------- RelatedTo -------------------- */ final RelatedTo irelto = (RelatedTo)prop; final BwRelatedTo relto = new BwRelatedTo(); final String parval = IcalUtil.getParameterVal(irelto, "RELTYPE"); if (parval != null) { relto.setRelType(parval); } relto.setValue(irelto.getValue()); if (chg.changed(pi, ev.getRelatedTo(), relto)) { ev.setRelatedTo(relto); } break; case REQUEST_STATUS: /* ------------------- RequestStatus -------------------- */ final BwRequestStatus rs = BwRequestStatus .fromRequestStatus((RequestStatus)prop); chg.addValue(pi, rs); break; case RESOURCES: /* ------------------- Resources -------------------- */ final TextList rl = ((Resources)prop).getResources(); if (rl != null) { /* Got some resources */ lang = IcalUtil.getLang(prop); for (final String s: rl) { final BwString rsrc = new BwString(lang, s); chg.addValue(pi, rsrc); } } break; case RRULE: /* ------------------- RRule -------------------- */ chg.addValue(pi, pval); break; case SEQUENCE: /* ------------------- Sequence -------------------- */ final int seq = ((Sequence)prop).getSequenceNo(); if (seq != ev.getSequence()) { chg.changed(pi, ev.getSequence(), seq); ev.setSequence(seq); } break; case STATUS: /* ------------------- Status -------------------- */ if (chg.changed(pi, ev.getStatus(), pval)) { ev.setStatus(pval); } break; case SUMMARY: /* ------------------- Summary -------------------- */ if (chg.changed(pi, ev.getSummary(), pval)) { ev.setSummary(pval); } break; case TRANSP: /* ------------------- Transp -------------------- */ if (chg.changed(pi, ev.getPeruserTransparency( cb.getPrincipal() .getPrincipalRef()), pval)) { final BwXproperty pu = ev.setPeruserTransparency( cb.getPrincipal().getPrincipalRef(), pval); if (pu != null) { chg.addValue(PropertyInfoIndex.XPROP, pu); } } break; case UID: /* ------------------- Uid -------------------- */ /* We did this above */ break; case URL: /* ------------------- Url -------------------- */ if (chg.changed(pi, ev.getLink(), pval)) { ev.setLink(pval); } break; case XPROP: /* ------------------------- x-property --------------------------- */ final String name = prop.getName(); if (name.equalsIgnoreCase(BwXproperty.bedeworkCost)) { if (chg.changed(PropertyInfoIndex.COST, ev.getCost(), pval)) { ev.setCost(pval); } break; } if (name.equalsIgnoreCase(BwXproperty.xBedeworkCategories)) { if (checkCategory(cb, chg, ev, null, pval)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkLocation)) { if (checkLocation(cb, chg, ev, prop)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkContact)) { if (checkContact(cb, chg, ev, null, pval)) { break; } } /* See if this is an x-category that can be converted to a real category */ final XProperty xp = (XProperty)prop; chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(name, xp.getParameters() .toString(), pval)); break; default: if (logger.debug()) { logger.debug("Unsupported property with index " + pi + "; class " + prop.getClass() + " and value " + pval); } } } /* =================== Process sub-components =============== */ final ComponentList<Component> subComps; if (val instanceof ComponentContainer) { subComps = ((ComponentContainer<Component>)val).getComponents(); } else { subComps = null; } final Set<Integer> pids; if (vpoll) { pids = new TreeSet<>(); final BwEvent vp = evinfo.getEvent(); if (!Util.isEmpty(vp.getPollItems())) { vp.clearPollItems(); } } else { pids = null; } if (!Util.isEmpty(subComps)) { for (final var subComp: subComps) { if (subComp instanceof Available) { if (!(val instanceof VAvailability)) { return Response.error(resp, "AVAILABLE only valid in VAVAILABLE"); } final var avlResp = processAvailable(cb, cal, ical, (VAvailability)val, (Available)subComp, evinfo); if (!avlResp.isOk()) { return Response.fromResponse(resp, avlResp); } continue; } if (subComp instanceof Participant) { if (vpoll) { final var vresp = processVoter(cb, (VPoll)val, (Participant)subComp, evinfo, chg, mergeAttendees); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Participant object"); continue; } if (subComp instanceof VResource) { logger.warn("Unimplemented VResource object"); continue; } if (subComp instanceof VLocation) { logger.warn("Unimplemented VLocation object"); continue; } if (subComp instanceof VAlarm) { final var aresp = VAlarmUtil.processAlarm(cb, val, (VAlarm)subComp, ev, currentPrincipal, chg); if (!aresp.isOk()) { return Response.fromResponse(resp, aresp); } continue; } if (vpoll && (event || task)) { final var vresp = processCandidate((VPoll)val, subComp, evinfo, pids, chg); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Component object: " + subComp); } } /* Fix up timestamps. */ if (ev.getCreated() == null) { if (ev.getLastmod() != null) { ev.setCreated(ev.getLastmod()); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); } else { ev.updateDtstamp(); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } } if (ev.getLastmod() == null) { // created cannot be null now ev.setLastmod(ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } processTimezones(ev, ical, chg); /* Remove any recipients and originator */ if (ev.getRecipients() != null) { ev.getRecipients().clear(); } ev.setOriginator(null); if (hasXparams.value) { /* Save a text copy of the entire event as an x-property */ final Component valCopy = val.copy(); /* Remove potentially large values */ final Description desp = valCopy.getProperty(Property.DESCRIPTION); if (desp != null) { desp.setValue(null); } final Attach attachp = valCopy.getProperty(Property.ATTACH); // Don't store the entire attachment - we just need the parameters. if (attachp != null) { final Value v = attachp.getParameter(Parameter.VALUE); if (v != null) { attachp.setValue(String.valueOf(attachp.getValue().hashCode())); } } chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(BwXproperty.bedeworkIcal, null, valCopy.toString())); } chg.processChanges(ev, true, false); ev.setRecurring(ev.isRecurringEntity()); if (logger.debug()) { logger.debug(chg.toString()); logger.debug(ev.toString()); } if (masterEI != null) { // Just return notfound as this event is on its override list return Response.notFound(resp); } resp.setEntity(evinfo); return resp; } catch (final Throwable t) { if (logger.debug()) { logger.error(t); } return Response.error(resp, t); } }
NONSATD
true
break; case CREATED: /* ------------------- Created -------------------- */ if (chg.changed(pi, ev.getCreated(), pval)) { ev.setCreated(pval);
contact.setCn(nm); contact.setLink(altrep); cb.addContact(contact); } else { contact.setCn(nm); contact.setLink(altrep); } chg.addValue(pi, contact); break; case CREATED: /* ------------------- Created -------------------- */ if (chg.changed(pi, ev.getCreated(), pval)) { ev.setCreated(pval); } break; case DESCRIPTION: /* ------------------- Description -------------------- */ if (chg.changed(pi, ev.getDescription(), pval)) { ev.setDescription(pval); } break;
final var fcResp = cb.findContact(nm); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { contact = BwContact.makeContact(); contact.setCn(nm); contact.setLink(altrep); cb.addContact(contact); } else { contact.setCn(nm); contact.setLink(altrep); } chg.addValue(pi, contact); break; case CREATED: /* ------------------- Created -------------------- */ if (chg.changed(pi, ev.getCreated(), pval)) { ev.setCreated(pval); } break; case DESCRIPTION: /* ------------------- Description -------------------- */ if (chg.changed(pi, ev.getDescription(), pval)) { ev.setDescription(pval); } break; case DTEND: /* ------------------- DtEnd -------------------- */ break; case DTSTAMP: /* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval); break; case DTSTART: /* ------------------- DtStart -------------------- */ break;
7,893
38
/* ------------------- Description -------------------- */
public static GetEntityResponse<EventInfo> toEvent( final IcalCallback cb, final BwCalendar cal, final Icalendar ical, final Component val, final boolean mergeAttendees) { final var resp = new GetEntityResponse<EventInfo>(); if (val == null) { return Response.notOk(resp, failed, "No component supplied"); } String currentPrincipal = null; final BwPrincipal principal = cb.getPrincipal(); if (principal != null) { currentPrincipal = principal.getPrincipalRef(); } final Holder<Boolean> hasXparams = new Holder<>(Boolean.FALSE); final int methodType = ical.getMethodType(); String attUri = null; if (mergeAttendees) { // We'll need this later. attUri = cb.getCaladdr(cb.getPrincipal().getPrincipalRef()); } final String colPath; if (cal == null) { colPath = null; } else { colPath = cal.getPath(); } try { final PropertyList<Property> pl = val.getProperties(); boolean vpoll = false; boolean event = false; boolean task = false; if (pl == null) { // Empty component return Response.notOk(resp, failed, "Empty component"); } final int entityType; if (val instanceof VEvent) { entityType = IcalDefs.entityTypeEvent; event = true; } else if (val instanceof VToDo) { entityType = IcalDefs.entityTypeTodo; task = true; } else if (val instanceof VJournal) { entityType = IcalDefs.entityTypeJournal; } else if (val instanceof VFreeBusy) { entityType = IcalDefs.entityTypeFreeAndBusy; } else if (val instanceof VAvailability) { entityType = IcalDefs.entityTypeVavailability; } else if (val instanceof Available) { entityType = IcalDefs.entityTypeAvailable; } else if (val instanceof VPoll) { entityType = IcalDefs.entityTypeVpoll; vpoll = true; } else { return Response.error(resp, "org.bedework.invalid.component.type: " + val.getName()); } // Get the guid from the component String guid = null; final Uid uidp = pl.getProperty(Property.UID); if (uidp != null) { testXparams(uidp, hasXparams); guid = uidp.getValue(); } if (guid == null) { /* XXX A guid is required - but are there devices out there without a * guid - and if so how do we handle it? */ return Response.notOk(resp, failed, CalFacadeException.noGuid); } /* See if we have a recurrence id */ BwDateTime ridObj = null; String rid = null; TimeZone ridTz = null; final RecurrenceId ridp = pl.getProperty(Property.RECURRENCE_ID); if (ridp != null) { testXparams(ridp, hasXparams); ridObj = BwDateTime.makeBwDateTime(ridp); if (ridObj.getRange() != null) { /* XXX What do I do with it? */ logger.warn("TRANS-TO_EVENT: Got a recurrence id range"); } rid = ridObj.getDate(); } EventInfo masterEI = null; EventInfo evinfo = null; final BwEvent ev; /* If we have a recurrence id see if we already have the master (we should * get a master + all its overrides). * * If so find the override and use the annnotation or if no override, * make one. * * If no override retrieve the event, add it to our table and then locate the * annotation. * * If there is no annotation, create one. * * It's possible we have been sent 'detached' instances of a recurring * event. This may happen if we are invited to one or more instances of a * meeting. In this case we try to retrieve the master and if it doesn't * exist we manufacture one. We consider such an instance an update to * that instance only and leave the others alone. */ /* We need this in a couple of places */ final DtStart dtStart = pl.getProperty(Property.DTSTART); /* if (rid != null) { // See if we have a new master event. If so create a proxy to that event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI == null) { masterEI = makeNewEvent(cb, chg, entityType, guid, cal); BwEvent e = masterEI.getEvent(); // XXX This seems bogus DtStart mdtStart; String bogusDate = "19980118T230000"; if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + "Z"); } else if (dtStart.getTimeZone() == null) { mdtStart = new DtStart(bogusDate); } else { mdtStart = new DtStart(bogusDate + "Z", dtStart.getTimeZone()); } setDates(e, mdtStart, null, null, chg); e.setRecurring(true); e.addRdate(ridObj); e.setSuppressed(true); ical.addComponent(masterEI); } if (masterEI != null) { evinfo = masterEI.findOverride(rid); } } */ /* If this is a recurrence instance see if we can find the master We only need this because the master may follow the overrides. */ if (rid != null) { // See if we have a new master event. If so create a proxy to this event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI != null) { evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; } } if ((evinfo == null) && (cal != null) && (cal.getCalType() != BwCalendar.calTypeInbox) && (cal.getCalType() != BwCalendar.calTypePendingInbox) && (cal.getCalType() != BwCalendar.calTypeOutbox)) { if (logger.debug()) { logger.debug("TRANS-TO_EVENT: try to fetch event with guid=" + guid); } final GetEntitiesResponse<EventInfo> eisResp = cb.getEvent(colPath, guid); if (eisResp.isError()) { return Response.fromResponse(resp, eisResp); } final var eis = eisResp.getEntities(); if (!Util.isEmpty(eis)) { if (eis.size() > 1) { // DORECUR - wrong again return Response.notOk(resp, failed, "More than one event returned for guid."); } evinfo = eis.iterator().next(); } if (logger.debug()) { if (evinfo != null) { logger.debug("TRANS-TO_EVENT: fetched event with guid"); } else { logger.debug("TRANS-TO_EVENT: did not find event with guid"); } } if (evinfo != null) { if (rid != null) { // We just retrieved it's master masterEI = evinfo; masterEI.setInstanceOnly(true); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; ical.addComponent(masterEI); } else if (methodType == ScheduleMethods.methodTypeCancel) { // This should never have an rid for cancel of entire event. evinfo.setInstanceOnly(evinfo.getEvent().getSuppressed()); } else { // Presumably sent an update for the entire event. No longer suppressed master evinfo.getEvent().setSuppressed(false); } } else if (rid != null) { /* Manufacture a master for the instance */ masterEI = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); final BwEvent e = masterEI.getEvent(); // XXX This seems bogus final DtStart mdtStart; final String bogusDate = "19980118"; final String bogusTime = "T230000"; // Base dtstart on the recurrence id. final boolean isDateType = ridObj.getDateType(); if (isDateType) { mdtStart = new DtStart(new Date(bogusDate)); } else if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + bogusTime + "Z"); } else if (ridObj.getTzid() == null) { mdtStart = new DtStart(bogusDate + bogusTime); } else { mdtStart = new DtStart(bogusDate + bogusTime, Timezones.getTz(ridObj.getTzid())); } IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), masterEI, mdtStart, null, null); e.setRecurring(true); // e.addRdate(ridObj); final var sum = (Summary)pl.getProperty(Property.SUMMARY); e.setSummary(sum.getValue()); e.setSuppressed(true); ical.addComponent(masterEI); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; masterEI.setInstanceOnly(rid != null); } } if (evinfo == null) { evinfo = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); } else if (evinfo.getEvent().getEntityType() != entityType) { return Response.notOk(resp, failed, "org.bedework.mismatched.entity.type: " + val); } final ChangeTable chg = evinfo.getChangeset( cb.getPrincipal().getPrincipalRef()); if (rid != null) { final String evrid = evinfo.getEvent().getRecurrenceId(); if ((evrid == null) || (!evrid.equals(rid))) { logger. warn("Mismatched rid ev=" + evrid + " expected " + rid); chg.changed(PropertyInfoIndex.RECURRENCE_ID, evrid, rid); // XXX spurious??? } if (masterEI.getEvent().getSuppressed()) { masterEI.getEvent().addRdate(ridObj); } } ev = evinfo.getEvent(); ev.setScheduleMethod(methodType); DtEnd dtEnd = null; if (entityType == IcalDefs.entityTypeTodo) { final Due due = pl.getProperty(Property.DUE); if (due != null ) { dtEnd = new DtEnd(due.getParameters(), due.getValue()); } } else { dtEnd = pl.getProperty(Property.DTEND); } final Duration duration = pl.getProperty(Property.DURATION); IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), evinfo, dtStart, dtEnd, duration); for (final Property prop: pl) { testXparams(prop, hasXparams); //debug("ical prop " + prop.getClass().getName()); String pval = prop.getValue(); if ((pval != null) && (pval.length() == 0)) { pval = null; } final PropertyInfoIndex pi; if (prop instanceof XProperty) { pi = PropertyInfoIndex.XPROP; } else { pi = PropertyInfoIndex.fromName(prop.getName()); } if (pi == null) { logger.debug("Unknown property with name " + prop.getName() + " class " + prop.getClass() + " and value " + pval); continue; } chg.present(pi); switch (pi) { case ACCEPT_RESPONSE: /* ------------------- Accept Response -------------------- */ String sval = prop.getValue(); if (chg.changed(pi, ev.getPollAcceptResponse(), sval)) { ev.setPollAcceptResponse(sval); } break; case ATTACH: /* ------------------- Attachment -------------------- */ chg.addValue(pi, IcalUtil.getAttachment((Attach)prop)); break; case ATTENDEE: /* ------------------- Attendee -------------------- */ if (methodType == ScheduleMethods.methodTypePublish) { if (cb.getStrictness() == IcalCallback.conformanceStrict) { return Response.notOk(resp, failed, CalFacadeException.attendeesInPublish); } //if (cb.getStrictness() == IcalCallback.conformanceWarn) { // warn("Had attendees for PUBLISH"); //} } final Attendee attPr = (Attendee)prop; if (evinfo.getNewEvent() || !mergeAttendees) { chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { final String pUri = cb.getCaladdr(attPr.getValue()); if (pUri.equals(attUri)) { /* Only update for our own attendee * We're doing a PUT and this must be the attendee updating their * partstat. We don't allow them to change other attendees * whatever the PUT content says. */ chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { // Use the value we currently have boolean found = false; for (final BwAttendee att: ev.getAttendees()) { if (pUri.equals(att.getAttendeeUri())) { chg.addValue(pi, att.clone()); found = true; break; } } if (!found) { // An added attendee final BwAttendee att = IcalUtil .getAttendee(cb, attPr); att.setPartstat(IcalDefs.partstatValNeedsAction); chg.addValue(pi, att); } } } break; case BUSYTYPE: final int ibt = BwEvent.fromBusyTypeString(pval); if (chg.changed(pi, ev.getBusyType(), ibt)) { ev.setBusyType(ibt); } break; case CATEGORIES: /* ------------------- Categories -------------------- */ final Categories cats = (Categories)prop; final TextList cl = cats.getCategories(); String lang = IcalUtil.getLang(cats); if (cl != null) { /* Got some categories */ for (final String wd: cl) { if (wd == null) { continue; } final BwString key = new BwString(lang, wd); final var fcResp = cb.findCategory(key); final BwCategory cat; if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isNotFound()) { cat = BwCategory.makeCategory(); cat.setWord(key); cb.addCategory(cat); } else { cat = fcResp.getEntity(); } chg.addValue(pi, cat); } } break; case CLASS: /* ------------------- Class -------------------- */ if (chg.changed(pi, ev.getClassification(), pval)) { ev.setClassification(pval); } break; case COMMENT: /* ------------------- Comment -------------------- */ chg.addValue(pi, new BwString(null, pval)); break; case COMPLETED: /* ------------------- Completed -------------------- */ if (chg.changed(pi, ev.getCompleted(), pval)) { ev.setCompleted(pval); } break; case CONCEPT: /* ------------------- Concept -------------------- */ final Concept c = (Concept)prop; final String cval = c.getValue(); if (cval != null) { /* Got a concept */ chg.addValue(PropertyInfoIndex.XPROP, BwXproperty.makeIcalProperty("CONCEPT", null, cval)); } break; case CONTACT: /* ------------------- Contact -------------------- */ final String altrep = getAltRepPar(prop); lang = IcalUtil.getLang(prop); final String uid = getUidPar(prop); final BwString nm = new BwString(lang, pval); BwContact contact = null; if (uid != null) { final var fcResp = cb.getContact(uid); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { final var fcResp = cb.findContact(nm); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { contact = BwContact.makeContact(); contact.setCn(nm); contact.setLink(altrep); cb.addContact(contact); } else { contact.setCn(nm); contact.setLink(altrep); } chg.addValue(pi, contact); break; case CREATED: /* ------------------- Created -------------------- */ if (chg.changed(pi, ev.getCreated(), pval)) { ev.setCreated(pval); } break; case DESCRIPTION: /* ------------------- Description -------------------- */ if (chg.changed(pi, ev.getDescription(), pval)) { ev.setDescription(pval); } break; case DTEND: /* ------------------- DtEnd -------------------- */ break; case DTSTAMP: /* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval); break; case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE: /* -------------------- Due ------------------------ */ break; case DURATION: /* ------------------- Duration -------------------- */ break; case EXDATE: /* ------------------- ExDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case EXRULE: /* ------------------- ExRule -------------------- */ chg.addValue(pi, pval); break; case FREEBUSY: /* ------------------- freebusy -------------------- */ final FreeBusy fbusy = (FreeBusy)prop; final PeriodList perpl = fbusy.getPeriods(); final Parameter par = IcalUtil.getParameter(fbusy, "FBTYPE"); final int fbtype; if (par == null) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY)) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY_TENTATIVE)) { fbtype = BwFreeBusyComponent.typeBusyTentative; } else if (par.equals(FbType.BUSY_UNAVAILABLE)) { fbtype = BwFreeBusyComponent.typeBusyUnavailable; } else if (par.equals(FbType.FREE)) { fbtype = BwFreeBusyComponent.typeFree; } else { if (logger.debug()) { logger.debug("Unsupported parameter " + par.getName()); } return Response.notOk(resp, failed, "Unsupported parameter " + par.getName()); } final BwFreeBusyComponent fbc = new BwFreeBusyComponent(); fbc.setType(fbtype); for (final Period per : perpl) { fbc.addPeriod(per); } ev.addFreeBusyPeriod(fbc); break; case GEO: /* ------------------- Geo -------------------- */ final Geo g = (Geo)prop; final BwGeo geo = new BwGeo(g.getLatitude(), g.getLongitude()); if (chg.changed(pi, ev.getGeo(), geo)) { ev.setGeo(geo); } break; case LAST_MODIFIED: /* ------------------- LastModified -------------------- */ if (chg.changed(pi, ev.getLastmod(), pval)) { ev.setLastmod(pval); } break; case LOCATION: /* ------------------- Location -------------------- */ BwLocation loc = null; //String uid = getUidPar(prop); /* At the moment Mozilla lightning is broken and this leads to all * sorts of problems. if (uid != null) { loc = cb.getLocation(uid); } */ lang = IcalUtil.getLang(prop); BwString addr = null; if (pval != null) { if (loc == null) { addr = new BwString(lang, pval); final var fcResp = cb.findLocation(addr); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { loc = fcResp.getEntity(); } } if (loc == null) { loc = BwLocation.makeLocation(); loc.setAddress(addr); cb.addLocation(loc); } } final BwLocation evloc = ev.getLocation(); if (chg.changed(pi, evloc, loc)) { // CHGTBL - this only shows that it's a different location object ev.setLocation(loc); } else if ((loc != null) && (evloc != null)) { // See if the value is changed final String evval = evloc.getAddress().getValue(); final String inval = loc.getAddress().getValue(); if (!evval.equals(inval)) { chg.changed(pi, evval, inval); evloc.getAddress().setValue(inval); } } break; case ORGANIZER: /* ------------------- Organizer -------------------- */ final BwOrganizer org = IcalUtil.getOrganizer(cb, (Organizer)prop); final BwOrganizer evorg = ev.getOrganizer(); final BwOrganizer evorgCopy; if (evorg == null) { evorgCopy = null; } else { evorgCopy = (BwOrganizer)evorg.clone(); } if (chg.changed(pi, evorgCopy, org)) { if (evorg == null) { ev.setOrganizer(org); } else { evorg.update(org); } } break; case PERCENT_COMPLETE: /* ------------------- PercentComplete -------------------- */ Integer ival = ((PercentComplete)prop).getPercentage(); if (chg.changed(pi, ev.getPercentComplete(), ival)) { ev.setPercentComplete(ival); } break; case POLL_MODE: /* ------------------- Poll mode -------------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollMode(), sval)) { ev.setPollMode(sval); } break; case POLL_PROPERTIES: /* ------------------- Poll properties ---------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollProperties(), sval)) { ev.setPollProperties(sval); } break; case POLL_WINNER: /* ------------------- Poll winner -------------------- */ ival = ((PollWinner)prop).getPollwinner(); if (chg.changed(pi, ev.getPollWinner(), ival)) { ev.setPollWinner(ival); } break; case PRIORITY: /* ------------------- Priority -------------------- */ ival = ((Priority)prop).getLevel(); if (chg.changed(pi, ev.getPriority(), ival)) { ev.setPriority(ival); } break; case RDATE: /* ------------------- RDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case RECURRENCE_ID: /* ------------------- RecurrenceID -------------------- */ // Done above break; case RELATED_TO: /* ------------------- RelatedTo -------------------- */ final RelatedTo irelto = (RelatedTo)prop; final BwRelatedTo relto = new BwRelatedTo(); final String parval = IcalUtil.getParameterVal(irelto, "RELTYPE"); if (parval != null) { relto.setRelType(parval); } relto.setValue(irelto.getValue()); if (chg.changed(pi, ev.getRelatedTo(), relto)) { ev.setRelatedTo(relto); } break; case REQUEST_STATUS: /* ------------------- RequestStatus -------------------- */ final BwRequestStatus rs = BwRequestStatus .fromRequestStatus((RequestStatus)prop); chg.addValue(pi, rs); break; case RESOURCES: /* ------------------- Resources -------------------- */ final TextList rl = ((Resources)prop).getResources(); if (rl != null) { /* Got some resources */ lang = IcalUtil.getLang(prop); for (final String s: rl) { final BwString rsrc = new BwString(lang, s); chg.addValue(pi, rsrc); } } break; case RRULE: /* ------------------- RRule -------------------- */ chg.addValue(pi, pval); break; case SEQUENCE: /* ------------------- Sequence -------------------- */ final int seq = ((Sequence)prop).getSequenceNo(); if (seq != ev.getSequence()) { chg.changed(pi, ev.getSequence(), seq); ev.setSequence(seq); } break; case STATUS: /* ------------------- Status -------------------- */ if (chg.changed(pi, ev.getStatus(), pval)) { ev.setStatus(pval); } break; case SUMMARY: /* ------------------- Summary -------------------- */ if (chg.changed(pi, ev.getSummary(), pval)) { ev.setSummary(pval); } break; case TRANSP: /* ------------------- Transp -------------------- */ if (chg.changed(pi, ev.getPeruserTransparency( cb.getPrincipal() .getPrincipalRef()), pval)) { final BwXproperty pu = ev.setPeruserTransparency( cb.getPrincipal().getPrincipalRef(), pval); if (pu != null) { chg.addValue(PropertyInfoIndex.XPROP, pu); } } break; case UID: /* ------------------- Uid -------------------- */ /* We did this above */ break; case URL: /* ------------------- Url -------------------- */ if (chg.changed(pi, ev.getLink(), pval)) { ev.setLink(pval); } break; case XPROP: /* ------------------------- x-property --------------------------- */ final String name = prop.getName(); if (name.equalsIgnoreCase(BwXproperty.bedeworkCost)) { if (chg.changed(PropertyInfoIndex.COST, ev.getCost(), pval)) { ev.setCost(pval); } break; } if (name.equalsIgnoreCase(BwXproperty.xBedeworkCategories)) { if (checkCategory(cb, chg, ev, null, pval)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkLocation)) { if (checkLocation(cb, chg, ev, prop)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkContact)) { if (checkContact(cb, chg, ev, null, pval)) { break; } } /* See if this is an x-category that can be converted to a real category */ final XProperty xp = (XProperty)prop; chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(name, xp.getParameters() .toString(), pval)); break; default: if (logger.debug()) { logger.debug("Unsupported property with index " + pi + "; class " + prop.getClass() + " and value " + pval); } } } /* =================== Process sub-components =============== */ final ComponentList<Component> subComps; if (val instanceof ComponentContainer) { subComps = ((ComponentContainer<Component>)val).getComponents(); } else { subComps = null; } final Set<Integer> pids; if (vpoll) { pids = new TreeSet<>(); final BwEvent vp = evinfo.getEvent(); if (!Util.isEmpty(vp.getPollItems())) { vp.clearPollItems(); } } else { pids = null; } if (!Util.isEmpty(subComps)) { for (final var subComp: subComps) { if (subComp instanceof Available) { if (!(val instanceof VAvailability)) { return Response.error(resp, "AVAILABLE only valid in VAVAILABLE"); } final var avlResp = processAvailable(cb, cal, ical, (VAvailability)val, (Available)subComp, evinfo); if (!avlResp.isOk()) { return Response.fromResponse(resp, avlResp); } continue; } if (subComp instanceof Participant) { if (vpoll) { final var vresp = processVoter(cb, (VPoll)val, (Participant)subComp, evinfo, chg, mergeAttendees); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Participant object"); continue; } if (subComp instanceof VResource) { logger.warn("Unimplemented VResource object"); continue; } if (subComp instanceof VLocation) { logger.warn("Unimplemented VLocation object"); continue; } if (subComp instanceof VAlarm) { final var aresp = VAlarmUtil.processAlarm(cb, val, (VAlarm)subComp, ev, currentPrincipal, chg); if (!aresp.isOk()) { return Response.fromResponse(resp, aresp); } continue; } if (vpoll && (event || task)) { final var vresp = processCandidate((VPoll)val, subComp, evinfo, pids, chg); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Component object: " + subComp); } } /* Fix up timestamps. */ if (ev.getCreated() == null) { if (ev.getLastmod() != null) { ev.setCreated(ev.getLastmod()); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); } else { ev.updateDtstamp(); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } } if (ev.getLastmod() == null) { // created cannot be null now ev.setLastmod(ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } processTimezones(ev, ical, chg); /* Remove any recipients and originator */ if (ev.getRecipients() != null) { ev.getRecipients().clear(); } ev.setOriginator(null); if (hasXparams.value) { /* Save a text copy of the entire event as an x-property */ final Component valCopy = val.copy(); /* Remove potentially large values */ final Description desp = valCopy.getProperty(Property.DESCRIPTION); if (desp != null) { desp.setValue(null); } final Attach attachp = valCopy.getProperty(Property.ATTACH); // Don't store the entire attachment - we just need the parameters. if (attachp != null) { final Value v = attachp.getParameter(Parameter.VALUE); if (v != null) { attachp.setValue(String.valueOf(attachp.getValue().hashCode())); } } chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(BwXproperty.bedeworkIcal, null, valCopy.toString())); } chg.processChanges(ev, true, false); ev.setRecurring(ev.isRecurringEntity()); if (logger.debug()) { logger.debug(chg.toString()); logger.debug(ev.toString()); } if (masterEI != null) { // Just return notfound as this event is on its override list return Response.notFound(resp); } resp.setEntity(evinfo); return resp; } catch (final Throwable t) { if (logger.debug()) { logger.error(t); } return Response.error(resp, t); } }
NONSATD
true
break; case DESCRIPTION: /* ------------------- Description -------------------- */ if (chg.changed(pi, ev.getDescription(), pval)) { ev.setDescription(pval);
} chg.addValue(pi, contact); break; case CREATED: /* ------------------- Created -------------------- */ if (chg.changed(pi, ev.getCreated(), pval)) { ev.setCreated(pval); } break; case DESCRIPTION: /* ------------------- Description -------------------- */ if (chg.changed(pi, ev.getDescription(), pval)) { ev.setDescription(pval); } break; case DTEND: /* ------------------- DtEnd -------------------- */ break; case DTSTAMP: /* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval);
} } if (contact == null) { contact = BwContact.makeContact(); contact.setCn(nm); contact.setLink(altrep); cb.addContact(contact); } else { contact.setCn(nm); contact.setLink(altrep); } chg.addValue(pi, contact); break; case CREATED: /* ------------------- Created -------------------- */ if (chg.changed(pi, ev.getCreated(), pval)) { ev.setCreated(pval); } break; case DESCRIPTION: /* ------------------- Description -------------------- */ if (chg.changed(pi, ev.getDescription(), pval)) { ev.setDescription(pval); } break; case DTEND: /* ------------------- DtEnd -------------------- */ break; case DTSTAMP: /* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval); break; case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE: /* -------------------- Due ------------------------ */ break; case DURATION: /* ------------------- Duration -------------------- */ break;
7,893
39
/* ------------------- DtEnd -------------------- */
public static GetEntityResponse<EventInfo> toEvent( final IcalCallback cb, final BwCalendar cal, final Icalendar ical, final Component val, final boolean mergeAttendees) { final var resp = new GetEntityResponse<EventInfo>(); if (val == null) { return Response.notOk(resp, failed, "No component supplied"); } String currentPrincipal = null; final BwPrincipal principal = cb.getPrincipal(); if (principal != null) { currentPrincipal = principal.getPrincipalRef(); } final Holder<Boolean> hasXparams = new Holder<>(Boolean.FALSE); final int methodType = ical.getMethodType(); String attUri = null; if (mergeAttendees) { // We'll need this later. attUri = cb.getCaladdr(cb.getPrincipal().getPrincipalRef()); } final String colPath; if (cal == null) { colPath = null; } else { colPath = cal.getPath(); } try { final PropertyList<Property> pl = val.getProperties(); boolean vpoll = false; boolean event = false; boolean task = false; if (pl == null) { // Empty component return Response.notOk(resp, failed, "Empty component"); } final int entityType; if (val instanceof VEvent) { entityType = IcalDefs.entityTypeEvent; event = true; } else if (val instanceof VToDo) { entityType = IcalDefs.entityTypeTodo; task = true; } else if (val instanceof VJournal) { entityType = IcalDefs.entityTypeJournal; } else if (val instanceof VFreeBusy) { entityType = IcalDefs.entityTypeFreeAndBusy; } else if (val instanceof VAvailability) { entityType = IcalDefs.entityTypeVavailability; } else if (val instanceof Available) { entityType = IcalDefs.entityTypeAvailable; } else if (val instanceof VPoll) { entityType = IcalDefs.entityTypeVpoll; vpoll = true; } else { return Response.error(resp, "org.bedework.invalid.component.type: " + val.getName()); } // Get the guid from the component String guid = null; final Uid uidp = pl.getProperty(Property.UID); if (uidp != null) { testXparams(uidp, hasXparams); guid = uidp.getValue(); } if (guid == null) { /* XXX A guid is required - but are there devices out there without a * guid - and if so how do we handle it? */ return Response.notOk(resp, failed, CalFacadeException.noGuid); } /* See if we have a recurrence id */ BwDateTime ridObj = null; String rid = null; TimeZone ridTz = null; final RecurrenceId ridp = pl.getProperty(Property.RECURRENCE_ID); if (ridp != null) { testXparams(ridp, hasXparams); ridObj = BwDateTime.makeBwDateTime(ridp); if (ridObj.getRange() != null) { /* XXX What do I do with it? */ logger.warn("TRANS-TO_EVENT: Got a recurrence id range"); } rid = ridObj.getDate(); } EventInfo masterEI = null; EventInfo evinfo = null; final BwEvent ev; /* If we have a recurrence id see if we already have the master (we should * get a master + all its overrides). * * If so find the override and use the annnotation or if no override, * make one. * * If no override retrieve the event, add it to our table and then locate the * annotation. * * If there is no annotation, create one. * * It's possible we have been sent 'detached' instances of a recurring * event. This may happen if we are invited to one or more instances of a * meeting. In this case we try to retrieve the master and if it doesn't * exist we manufacture one. We consider such an instance an update to * that instance only and leave the others alone. */ /* We need this in a couple of places */ final DtStart dtStart = pl.getProperty(Property.DTSTART); /* if (rid != null) { // See if we have a new master event. If so create a proxy to that event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI == null) { masterEI = makeNewEvent(cb, chg, entityType, guid, cal); BwEvent e = masterEI.getEvent(); // XXX This seems bogus DtStart mdtStart; String bogusDate = "19980118T230000"; if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + "Z"); } else if (dtStart.getTimeZone() == null) { mdtStart = new DtStart(bogusDate); } else { mdtStart = new DtStart(bogusDate + "Z", dtStart.getTimeZone()); } setDates(e, mdtStart, null, null, chg); e.setRecurring(true); e.addRdate(ridObj); e.setSuppressed(true); ical.addComponent(masterEI); } if (masterEI != null) { evinfo = masterEI.findOverride(rid); } } */ /* If this is a recurrence instance see if we can find the master We only need this because the master may follow the overrides. */ if (rid != null) { // See if we have a new master event. If so create a proxy to this event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI != null) { evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; } } if ((evinfo == null) && (cal != null) && (cal.getCalType() != BwCalendar.calTypeInbox) && (cal.getCalType() != BwCalendar.calTypePendingInbox) && (cal.getCalType() != BwCalendar.calTypeOutbox)) { if (logger.debug()) { logger.debug("TRANS-TO_EVENT: try to fetch event with guid=" + guid); } final GetEntitiesResponse<EventInfo> eisResp = cb.getEvent(colPath, guid); if (eisResp.isError()) { return Response.fromResponse(resp, eisResp); } final var eis = eisResp.getEntities(); if (!Util.isEmpty(eis)) { if (eis.size() > 1) { // DORECUR - wrong again return Response.notOk(resp, failed, "More than one event returned for guid."); } evinfo = eis.iterator().next(); } if (logger.debug()) { if (evinfo != null) { logger.debug("TRANS-TO_EVENT: fetched event with guid"); } else { logger.debug("TRANS-TO_EVENT: did not find event with guid"); } } if (evinfo != null) { if (rid != null) { // We just retrieved it's master masterEI = evinfo; masterEI.setInstanceOnly(true); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; ical.addComponent(masterEI); } else if (methodType == ScheduleMethods.methodTypeCancel) { // This should never have an rid for cancel of entire event. evinfo.setInstanceOnly(evinfo.getEvent().getSuppressed()); } else { // Presumably sent an update for the entire event. No longer suppressed master evinfo.getEvent().setSuppressed(false); } } else if (rid != null) { /* Manufacture a master for the instance */ masterEI = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); final BwEvent e = masterEI.getEvent(); // XXX This seems bogus final DtStart mdtStart; final String bogusDate = "19980118"; final String bogusTime = "T230000"; // Base dtstart on the recurrence id. final boolean isDateType = ridObj.getDateType(); if (isDateType) { mdtStart = new DtStart(new Date(bogusDate)); } else if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + bogusTime + "Z"); } else if (ridObj.getTzid() == null) { mdtStart = new DtStart(bogusDate + bogusTime); } else { mdtStart = new DtStart(bogusDate + bogusTime, Timezones.getTz(ridObj.getTzid())); } IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), masterEI, mdtStart, null, null); e.setRecurring(true); // e.addRdate(ridObj); final var sum = (Summary)pl.getProperty(Property.SUMMARY); e.setSummary(sum.getValue()); e.setSuppressed(true); ical.addComponent(masterEI); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; masterEI.setInstanceOnly(rid != null); } } if (evinfo == null) { evinfo = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); } else if (evinfo.getEvent().getEntityType() != entityType) { return Response.notOk(resp, failed, "org.bedework.mismatched.entity.type: " + val); } final ChangeTable chg = evinfo.getChangeset( cb.getPrincipal().getPrincipalRef()); if (rid != null) { final String evrid = evinfo.getEvent().getRecurrenceId(); if ((evrid == null) || (!evrid.equals(rid))) { logger. warn("Mismatched rid ev=" + evrid + " expected " + rid); chg.changed(PropertyInfoIndex.RECURRENCE_ID, evrid, rid); // XXX spurious??? } if (masterEI.getEvent().getSuppressed()) { masterEI.getEvent().addRdate(ridObj); } } ev = evinfo.getEvent(); ev.setScheduleMethod(methodType); DtEnd dtEnd = null; if (entityType == IcalDefs.entityTypeTodo) { final Due due = pl.getProperty(Property.DUE); if (due != null ) { dtEnd = new DtEnd(due.getParameters(), due.getValue()); } } else { dtEnd = pl.getProperty(Property.DTEND); } final Duration duration = pl.getProperty(Property.DURATION); IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), evinfo, dtStart, dtEnd, duration); for (final Property prop: pl) { testXparams(prop, hasXparams); //debug("ical prop " + prop.getClass().getName()); String pval = prop.getValue(); if ((pval != null) && (pval.length() == 0)) { pval = null; } final PropertyInfoIndex pi; if (prop instanceof XProperty) { pi = PropertyInfoIndex.XPROP; } else { pi = PropertyInfoIndex.fromName(prop.getName()); } if (pi == null) { logger.debug("Unknown property with name " + prop.getName() + " class " + prop.getClass() + " and value " + pval); continue; } chg.present(pi); switch (pi) { case ACCEPT_RESPONSE: /* ------------------- Accept Response -------------------- */ String sval = prop.getValue(); if (chg.changed(pi, ev.getPollAcceptResponse(), sval)) { ev.setPollAcceptResponse(sval); } break; case ATTACH: /* ------------------- Attachment -------------------- */ chg.addValue(pi, IcalUtil.getAttachment((Attach)prop)); break; case ATTENDEE: /* ------------------- Attendee -------------------- */ if (methodType == ScheduleMethods.methodTypePublish) { if (cb.getStrictness() == IcalCallback.conformanceStrict) { return Response.notOk(resp, failed, CalFacadeException.attendeesInPublish); } //if (cb.getStrictness() == IcalCallback.conformanceWarn) { // warn("Had attendees for PUBLISH"); //} } final Attendee attPr = (Attendee)prop; if (evinfo.getNewEvent() || !mergeAttendees) { chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { final String pUri = cb.getCaladdr(attPr.getValue()); if (pUri.equals(attUri)) { /* Only update for our own attendee * We're doing a PUT and this must be the attendee updating their * partstat. We don't allow them to change other attendees * whatever the PUT content says. */ chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { // Use the value we currently have boolean found = false; for (final BwAttendee att: ev.getAttendees()) { if (pUri.equals(att.getAttendeeUri())) { chg.addValue(pi, att.clone()); found = true; break; } } if (!found) { // An added attendee final BwAttendee att = IcalUtil .getAttendee(cb, attPr); att.setPartstat(IcalDefs.partstatValNeedsAction); chg.addValue(pi, att); } } } break; case BUSYTYPE: final int ibt = BwEvent.fromBusyTypeString(pval); if (chg.changed(pi, ev.getBusyType(), ibt)) { ev.setBusyType(ibt); } break; case CATEGORIES: /* ------------------- Categories -------------------- */ final Categories cats = (Categories)prop; final TextList cl = cats.getCategories(); String lang = IcalUtil.getLang(cats); if (cl != null) { /* Got some categories */ for (final String wd: cl) { if (wd == null) { continue; } final BwString key = new BwString(lang, wd); final var fcResp = cb.findCategory(key); final BwCategory cat; if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isNotFound()) { cat = BwCategory.makeCategory(); cat.setWord(key); cb.addCategory(cat); } else { cat = fcResp.getEntity(); } chg.addValue(pi, cat); } } break; case CLASS: /* ------------------- Class -------------------- */ if (chg.changed(pi, ev.getClassification(), pval)) { ev.setClassification(pval); } break; case COMMENT: /* ------------------- Comment -------------------- */ chg.addValue(pi, new BwString(null, pval)); break; case COMPLETED: /* ------------------- Completed -------------------- */ if (chg.changed(pi, ev.getCompleted(), pval)) { ev.setCompleted(pval); } break; case CONCEPT: /* ------------------- Concept -------------------- */ final Concept c = (Concept)prop; final String cval = c.getValue(); if (cval != null) { /* Got a concept */ chg.addValue(PropertyInfoIndex.XPROP, BwXproperty.makeIcalProperty("CONCEPT", null, cval)); } break; case CONTACT: /* ------------------- Contact -------------------- */ final String altrep = getAltRepPar(prop); lang = IcalUtil.getLang(prop); final String uid = getUidPar(prop); final BwString nm = new BwString(lang, pval); BwContact contact = null; if (uid != null) { final var fcResp = cb.getContact(uid); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { final var fcResp = cb.findContact(nm); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { contact = BwContact.makeContact(); contact.setCn(nm); contact.setLink(altrep); cb.addContact(contact); } else { contact.setCn(nm); contact.setLink(altrep); } chg.addValue(pi, contact); break; case CREATED: /* ------------------- Created -------------------- */ if (chg.changed(pi, ev.getCreated(), pval)) { ev.setCreated(pval); } break; case DESCRIPTION: /* ------------------- Description -------------------- */ if (chg.changed(pi, ev.getDescription(), pval)) { ev.setDescription(pval); } break; case DTEND: /* ------------------- DtEnd -------------------- */ break; case DTSTAMP: /* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval); break; case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE: /* -------------------- Due ------------------------ */ break; case DURATION: /* ------------------- Duration -------------------- */ break; case EXDATE: /* ------------------- ExDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case EXRULE: /* ------------------- ExRule -------------------- */ chg.addValue(pi, pval); break; case FREEBUSY: /* ------------------- freebusy -------------------- */ final FreeBusy fbusy = (FreeBusy)prop; final PeriodList perpl = fbusy.getPeriods(); final Parameter par = IcalUtil.getParameter(fbusy, "FBTYPE"); final int fbtype; if (par == null) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY)) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY_TENTATIVE)) { fbtype = BwFreeBusyComponent.typeBusyTentative; } else if (par.equals(FbType.BUSY_UNAVAILABLE)) { fbtype = BwFreeBusyComponent.typeBusyUnavailable; } else if (par.equals(FbType.FREE)) { fbtype = BwFreeBusyComponent.typeFree; } else { if (logger.debug()) { logger.debug("Unsupported parameter " + par.getName()); } return Response.notOk(resp, failed, "Unsupported parameter " + par.getName()); } final BwFreeBusyComponent fbc = new BwFreeBusyComponent(); fbc.setType(fbtype); for (final Period per : perpl) { fbc.addPeriod(per); } ev.addFreeBusyPeriod(fbc); break; case GEO: /* ------------------- Geo -------------------- */ final Geo g = (Geo)prop; final BwGeo geo = new BwGeo(g.getLatitude(), g.getLongitude()); if (chg.changed(pi, ev.getGeo(), geo)) { ev.setGeo(geo); } break; case LAST_MODIFIED: /* ------------------- LastModified -------------------- */ if (chg.changed(pi, ev.getLastmod(), pval)) { ev.setLastmod(pval); } break; case LOCATION: /* ------------------- Location -------------------- */ BwLocation loc = null; //String uid = getUidPar(prop); /* At the moment Mozilla lightning is broken and this leads to all * sorts of problems. if (uid != null) { loc = cb.getLocation(uid); } */ lang = IcalUtil.getLang(prop); BwString addr = null; if (pval != null) { if (loc == null) { addr = new BwString(lang, pval); final var fcResp = cb.findLocation(addr); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { loc = fcResp.getEntity(); } } if (loc == null) { loc = BwLocation.makeLocation(); loc.setAddress(addr); cb.addLocation(loc); } } final BwLocation evloc = ev.getLocation(); if (chg.changed(pi, evloc, loc)) { // CHGTBL - this only shows that it's a different location object ev.setLocation(loc); } else if ((loc != null) && (evloc != null)) { // See if the value is changed final String evval = evloc.getAddress().getValue(); final String inval = loc.getAddress().getValue(); if (!evval.equals(inval)) { chg.changed(pi, evval, inval); evloc.getAddress().setValue(inval); } } break; case ORGANIZER: /* ------------------- Organizer -------------------- */ final BwOrganizer org = IcalUtil.getOrganizer(cb, (Organizer)prop); final BwOrganizer evorg = ev.getOrganizer(); final BwOrganizer evorgCopy; if (evorg == null) { evorgCopy = null; } else { evorgCopy = (BwOrganizer)evorg.clone(); } if (chg.changed(pi, evorgCopy, org)) { if (evorg == null) { ev.setOrganizer(org); } else { evorg.update(org); } } break; case PERCENT_COMPLETE: /* ------------------- PercentComplete -------------------- */ Integer ival = ((PercentComplete)prop).getPercentage(); if (chg.changed(pi, ev.getPercentComplete(), ival)) { ev.setPercentComplete(ival); } break; case POLL_MODE: /* ------------------- Poll mode -------------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollMode(), sval)) { ev.setPollMode(sval); } break; case POLL_PROPERTIES: /* ------------------- Poll properties ---------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollProperties(), sval)) { ev.setPollProperties(sval); } break; case POLL_WINNER: /* ------------------- Poll winner -------------------- */ ival = ((PollWinner)prop).getPollwinner(); if (chg.changed(pi, ev.getPollWinner(), ival)) { ev.setPollWinner(ival); } break; case PRIORITY: /* ------------------- Priority -------------------- */ ival = ((Priority)prop).getLevel(); if (chg.changed(pi, ev.getPriority(), ival)) { ev.setPriority(ival); } break; case RDATE: /* ------------------- RDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case RECURRENCE_ID: /* ------------------- RecurrenceID -------------------- */ // Done above break; case RELATED_TO: /* ------------------- RelatedTo -------------------- */ final RelatedTo irelto = (RelatedTo)prop; final BwRelatedTo relto = new BwRelatedTo(); final String parval = IcalUtil.getParameterVal(irelto, "RELTYPE"); if (parval != null) { relto.setRelType(parval); } relto.setValue(irelto.getValue()); if (chg.changed(pi, ev.getRelatedTo(), relto)) { ev.setRelatedTo(relto); } break; case REQUEST_STATUS: /* ------------------- RequestStatus -------------------- */ final BwRequestStatus rs = BwRequestStatus .fromRequestStatus((RequestStatus)prop); chg.addValue(pi, rs); break; case RESOURCES: /* ------------------- Resources -------------------- */ final TextList rl = ((Resources)prop).getResources(); if (rl != null) { /* Got some resources */ lang = IcalUtil.getLang(prop); for (final String s: rl) { final BwString rsrc = new BwString(lang, s); chg.addValue(pi, rsrc); } } break; case RRULE: /* ------------------- RRule -------------------- */ chg.addValue(pi, pval); break; case SEQUENCE: /* ------------------- Sequence -------------------- */ final int seq = ((Sequence)prop).getSequenceNo(); if (seq != ev.getSequence()) { chg.changed(pi, ev.getSequence(), seq); ev.setSequence(seq); } break; case STATUS: /* ------------------- Status -------------------- */ if (chg.changed(pi, ev.getStatus(), pval)) { ev.setStatus(pval); } break; case SUMMARY: /* ------------------- Summary -------------------- */ if (chg.changed(pi, ev.getSummary(), pval)) { ev.setSummary(pval); } break; case TRANSP: /* ------------------- Transp -------------------- */ if (chg.changed(pi, ev.getPeruserTransparency( cb.getPrincipal() .getPrincipalRef()), pval)) { final BwXproperty pu = ev.setPeruserTransparency( cb.getPrincipal().getPrincipalRef(), pval); if (pu != null) { chg.addValue(PropertyInfoIndex.XPROP, pu); } } break; case UID: /* ------------------- Uid -------------------- */ /* We did this above */ break; case URL: /* ------------------- Url -------------------- */ if (chg.changed(pi, ev.getLink(), pval)) { ev.setLink(pval); } break; case XPROP: /* ------------------------- x-property --------------------------- */ final String name = prop.getName(); if (name.equalsIgnoreCase(BwXproperty.bedeworkCost)) { if (chg.changed(PropertyInfoIndex.COST, ev.getCost(), pval)) { ev.setCost(pval); } break; } if (name.equalsIgnoreCase(BwXproperty.xBedeworkCategories)) { if (checkCategory(cb, chg, ev, null, pval)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkLocation)) { if (checkLocation(cb, chg, ev, prop)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkContact)) { if (checkContact(cb, chg, ev, null, pval)) { break; } } /* See if this is an x-category that can be converted to a real category */ final XProperty xp = (XProperty)prop; chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(name, xp.getParameters() .toString(), pval)); break; default: if (logger.debug()) { logger.debug("Unsupported property with index " + pi + "; class " + prop.getClass() + " and value " + pval); } } } /* =================== Process sub-components =============== */ final ComponentList<Component> subComps; if (val instanceof ComponentContainer) { subComps = ((ComponentContainer<Component>)val).getComponents(); } else { subComps = null; } final Set<Integer> pids; if (vpoll) { pids = new TreeSet<>(); final BwEvent vp = evinfo.getEvent(); if (!Util.isEmpty(vp.getPollItems())) { vp.clearPollItems(); } } else { pids = null; } if (!Util.isEmpty(subComps)) { for (final var subComp: subComps) { if (subComp instanceof Available) { if (!(val instanceof VAvailability)) { return Response.error(resp, "AVAILABLE only valid in VAVAILABLE"); } final var avlResp = processAvailable(cb, cal, ical, (VAvailability)val, (Available)subComp, evinfo); if (!avlResp.isOk()) { return Response.fromResponse(resp, avlResp); } continue; } if (subComp instanceof Participant) { if (vpoll) { final var vresp = processVoter(cb, (VPoll)val, (Participant)subComp, evinfo, chg, mergeAttendees); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Participant object"); continue; } if (subComp instanceof VResource) { logger.warn("Unimplemented VResource object"); continue; } if (subComp instanceof VLocation) { logger.warn("Unimplemented VLocation object"); continue; } if (subComp instanceof VAlarm) { final var aresp = VAlarmUtil.processAlarm(cb, val, (VAlarm)subComp, ev, currentPrincipal, chg); if (!aresp.isOk()) { return Response.fromResponse(resp, aresp); } continue; } if (vpoll && (event || task)) { final var vresp = processCandidate((VPoll)val, subComp, evinfo, pids, chg); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Component object: " + subComp); } } /* Fix up timestamps. */ if (ev.getCreated() == null) { if (ev.getLastmod() != null) { ev.setCreated(ev.getLastmod()); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); } else { ev.updateDtstamp(); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } } if (ev.getLastmod() == null) { // created cannot be null now ev.setLastmod(ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } processTimezones(ev, ical, chg); /* Remove any recipients and originator */ if (ev.getRecipients() != null) { ev.getRecipients().clear(); } ev.setOriginator(null); if (hasXparams.value) { /* Save a text copy of the entire event as an x-property */ final Component valCopy = val.copy(); /* Remove potentially large values */ final Description desp = valCopy.getProperty(Property.DESCRIPTION); if (desp != null) { desp.setValue(null); } final Attach attachp = valCopy.getProperty(Property.ATTACH); // Don't store the entire attachment - we just need the parameters. if (attachp != null) { final Value v = attachp.getParameter(Parameter.VALUE); if (v != null) { attachp.setValue(String.valueOf(attachp.getValue().hashCode())); } } chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(BwXproperty.bedeworkIcal, null, valCopy.toString())); } chg.processChanges(ev, true, false); ev.setRecurring(ev.isRecurringEntity()); if (logger.debug()) { logger.debug(chg.toString()); logger.debug(ev.toString()); } if (masterEI != null) { // Just return notfound as this event is on its override list return Response.notFound(resp); } resp.setEntity(evinfo); return resp; } catch (final Throwable t) { if (logger.debug()) { logger.error(t); } return Response.error(resp, t); } }
NONSATD
true
break; case DTEND: /* ------------------- DtEnd -------------------- */ break; case DTSTAMP:
ev.setCreated(pval); } break; case DESCRIPTION: /* ------------------- Description -------------------- */ if (chg.changed(pi, ev.getDescription(), pval)) { ev.setDescription(pval); } break; case DTEND: /* ------------------- DtEnd -------------------- */ break; case DTSTAMP: /* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval); break; case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE: /* -------------------- Due ------------------------ */
cb.addContact(contact); } else { contact.setCn(nm); contact.setLink(altrep); } chg.addValue(pi, contact); break; case CREATED: /* ------------------- Created -------------------- */ if (chg.changed(pi, ev.getCreated(), pval)) { ev.setCreated(pval); } break; case DESCRIPTION: /* ------------------- Description -------------------- */ if (chg.changed(pi, ev.getDescription(), pval)) { ev.setDescription(pval); } break; case DTEND: /* ------------------- DtEnd -------------------- */ break; case DTSTAMP: /* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval); break; case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE: /* -------------------- Due ------------------------ */ break; case DURATION: /* ------------------- Duration -------------------- */ break; case EXDATE: /* ------------------- ExDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case EXRULE:
7,893
40
/* ------------------- DtStamp -------------------- */
public static GetEntityResponse<EventInfo> toEvent( final IcalCallback cb, final BwCalendar cal, final Icalendar ical, final Component val, final boolean mergeAttendees) { final var resp = new GetEntityResponse<EventInfo>(); if (val == null) { return Response.notOk(resp, failed, "No component supplied"); } String currentPrincipal = null; final BwPrincipal principal = cb.getPrincipal(); if (principal != null) { currentPrincipal = principal.getPrincipalRef(); } final Holder<Boolean> hasXparams = new Holder<>(Boolean.FALSE); final int methodType = ical.getMethodType(); String attUri = null; if (mergeAttendees) { // We'll need this later. attUri = cb.getCaladdr(cb.getPrincipal().getPrincipalRef()); } final String colPath; if (cal == null) { colPath = null; } else { colPath = cal.getPath(); } try { final PropertyList<Property> pl = val.getProperties(); boolean vpoll = false; boolean event = false; boolean task = false; if (pl == null) { // Empty component return Response.notOk(resp, failed, "Empty component"); } final int entityType; if (val instanceof VEvent) { entityType = IcalDefs.entityTypeEvent; event = true; } else if (val instanceof VToDo) { entityType = IcalDefs.entityTypeTodo; task = true; } else if (val instanceof VJournal) { entityType = IcalDefs.entityTypeJournal; } else if (val instanceof VFreeBusy) { entityType = IcalDefs.entityTypeFreeAndBusy; } else if (val instanceof VAvailability) { entityType = IcalDefs.entityTypeVavailability; } else if (val instanceof Available) { entityType = IcalDefs.entityTypeAvailable; } else if (val instanceof VPoll) { entityType = IcalDefs.entityTypeVpoll; vpoll = true; } else { return Response.error(resp, "org.bedework.invalid.component.type: " + val.getName()); } // Get the guid from the component String guid = null; final Uid uidp = pl.getProperty(Property.UID); if (uidp != null) { testXparams(uidp, hasXparams); guid = uidp.getValue(); } if (guid == null) { /* XXX A guid is required - but are there devices out there without a * guid - and if so how do we handle it? */ return Response.notOk(resp, failed, CalFacadeException.noGuid); } /* See if we have a recurrence id */ BwDateTime ridObj = null; String rid = null; TimeZone ridTz = null; final RecurrenceId ridp = pl.getProperty(Property.RECURRENCE_ID); if (ridp != null) { testXparams(ridp, hasXparams); ridObj = BwDateTime.makeBwDateTime(ridp); if (ridObj.getRange() != null) { /* XXX What do I do with it? */ logger.warn("TRANS-TO_EVENT: Got a recurrence id range"); } rid = ridObj.getDate(); } EventInfo masterEI = null; EventInfo evinfo = null; final BwEvent ev; /* If we have a recurrence id see if we already have the master (we should * get a master + all its overrides). * * If so find the override and use the annnotation or if no override, * make one. * * If no override retrieve the event, add it to our table and then locate the * annotation. * * If there is no annotation, create one. * * It's possible we have been sent 'detached' instances of a recurring * event. This may happen if we are invited to one or more instances of a * meeting. In this case we try to retrieve the master and if it doesn't * exist we manufacture one. We consider such an instance an update to * that instance only and leave the others alone. */ /* We need this in a couple of places */ final DtStart dtStart = pl.getProperty(Property.DTSTART); /* if (rid != null) { // See if we have a new master event. If so create a proxy to that event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI == null) { masterEI = makeNewEvent(cb, chg, entityType, guid, cal); BwEvent e = masterEI.getEvent(); // XXX This seems bogus DtStart mdtStart; String bogusDate = "19980118T230000"; if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + "Z"); } else if (dtStart.getTimeZone() == null) { mdtStart = new DtStart(bogusDate); } else { mdtStart = new DtStart(bogusDate + "Z", dtStart.getTimeZone()); } setDates(e, mdtStart, null, null, chg); e.setRecurring(true); e.addRdate(ridObj); e.setSuppressed(true); ical.addComponent(masterEI); } if (masterEI != null) { evinfo = masterEI.findOverride(rid); } } */ /* If this is a recurrence instance see if we can find the master We only need this because the master may follow the overrides. */ if (rid != null) { // See if we have a new master event. If so create a proxy to this event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI != null) { evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; } } if ((evinfo == null) && (cal != null) && (cal.getCalType() != BwCalendar.calTypeInbox) && (cal.getCalType() != BwCalendar.calTypePendingInbox) && (cal.getCalType() != BwCalendar.calTypeOutbox)) { if (logger.debug()) { logger.debug("TRANS-TO_EVENT: try to fetch event with guid=" + guid); } final GetEntitiesResponse<EventInfo> eisResp = cb.getEvent(colPath, guid); if (eisResp.isError()) { return Response.fromResponse(resp, eisResp); } final var eis = eisResp.getEntities(); if (!Util.isEmpty(eis)) { if (eis.size() > 1) { // DORECUR - wrong again return Response.notOk(resp, failed, "More than one event returned for guid."); } evinfo = eis.iterator().next(); } if (logger.debug()) { if (evinfo != null) { logger.debug("TRANS-TO_EVENT: fetched event with guid"); } else { logger.debug("TRANS-TO_EVENT: did not find event with guid"); } } if (evinfo != null) { if (rid != null) { // We just retrieved it's master masterEI = evinfo; masterEI.setInstanceOnly(true); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; ical.addComponent(masterEI); } else if (methodType == ScheduleMethods.methodTypeCancel) { // This should never have an rid for cancel of entire event. evinfo.setInstanceOnly(evinfo.getEvent().getSuppressed()); } else { // Presumably sent an update for the entire event. No longer suppressed master evinfo.getEvent().setSuppressed(false); } } else if (rid != null) { /* Manufacture a master for the instance */ masterEI = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); final BwEvent e = masterEI.getEvent(); // XXX This seems bogus final DtStart mdtStart; final String bogusDate = "19980118"; final String bogusTime = "T230000"; // Base dtstart on the recurrence id. final boolean isDateType = ridObj.getDateType(); if (isDateType) { mdtStart = new DtStart(new Date(bogusDate)); } else if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + bogusTime + "Z"); } else if (ridObj.getTzid() == null) { mdtStart = new DtStart(bogusDate + bogusTime); } else { mdtStart = new DtStart(bogusDate + bogusTime, Timezones.getTz(ridObj.getTzid())); } IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), masterEI, mdtStart, null, null); e.setRecurring(true); // e.addRdate(ridObj); final var sum = (Summary)pl.getProperty(Property.SUMMARY); e.setSummary(sum.getValue()); e.setSuppressed(true); ical.addComponent(masterEI); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; masterEI.setInstanceOnly(rid != null); } } if (evinfo == null) { evinfo = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); } else if (evinfo.getEvent().getEntityType() != entityType) { return Response.notOk(resp, failed, "org.bedework.mismatched.entity.type: " + val); } final ChangeTable chg = evinfo.getChangeset( cb.getPrincipal().getPrincipalRef()); if (rid != null) { final String evrid = evinfo.getEvent().getRecurrenceId(); if ((evrid == null) || (!evrid.equals(rid))) { logger. warn("Mismatched rid ev=" + evrid + " expected " + rid); chg.changed(PropertyInfoIndex.RECURRENCE_ID, evrid, rid); // XXX spurious??? } if (masterEI.getEvent().getSuppressed()) { masterEI.getEvent().addRdate(ridObj); } } ev = evinfo.getEvent(); ev.setScheduleMethod(methodType); DtEnd dtEnd = null; if (entityType == IcalDefs.entityTypeTodo) { final Due due = pl.getProperty(Property.DUE); if (due != null ) { dtEnd = new DtEnd(due.getParameters(), due.getValue()); } } else { dtEnd = pl.getProperty(Property.DTEND); } final Duration duration = pl.getProperty(Property.DURATION); IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), evinfo, dtStart, dtEnd, duration); for (final Property prop: pl) { testXparams(prop, hasXparams); //debug("ical prop " + prop.getClass().getName()); String pval = prop.getValue(); if ((pval != null) && (pval.length() == 0)) { pval = null; } final PropertyInfoIndex pi; if (prop instanceof XProperty) { pi = PropertyInfoIndex.XPROP; } else { pi = PropertyInfoIndex.fromName(prop.getName()); } if (pi == null) { logger.debug("Unknown property with name " + prop.getName() + " class " + prop.getClass() + " and value " + pval); continue; } chg.present(pi); switch (pi) { case ACCEPT_RESPONSE: /* ------------------- Accept Response -------------------- */ String sval = prop.getValue(); if (chg.changed(pi, ev.getPollAcceptResponse(), sval)) { ev.setPollAcceptResponse(sval); } break; case ATTACH: /* ------------------- Attachment -------------------- */ chg.addValue(pi, IcalUtil.getAttachment((Attach)prop)); break; case ATTENDEE: /* ------------------- Attendee -------------------- */ if (methodType == ScheduleMethods.methodTypePublish) { if (cb.getStrictness() == IcalCallback.conformanceStrict) { return Response.notOk(resp, failed, CalFacadeException.attendeesInPublish); } //if (cb.getStrictness() == IcalCallback.conformanceWarn) { // warn("Had attendees for PUBLISH"); //} } final Attendee attPr = (Attendee)prop; if (evinfo.getNewEvent() || !mergeAttendees) { chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { final String pUri = cb.getCaladdr(attPr.getValue()); if (pUri.equals(attUri)) { /* Only update for our own attendee * We're doing a PUT and this must be the attendee updating their * partstat. We don't allow them to change other attendees * whatever the PUT content says. */ chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { // Use the value we currently have boolean found = false; for (final BwAttendee att: ev.getAttendees()) { if (pUri.equals(att.getAttendeeUri())) { chg.addValue(pi, att.clone()); found = true; break; } } if (!found) { // An added attendee final BwAttendee att = IcalUtil .getAttendee(cb, attPr); att.setPartstat(IcalDefs.partstatValNeedsAction); chg.addValue(pi, att); } } } break; case BUSYTYPE: final int ibt = BwEvent.fromBusyTypeString(pval); if (chg.changed(pi, ev.getBusyType(), ibt)) { ev.setBusyType(ibt); } break; case CATEGORIES: /* ------------------- Categories -------------------- */ final Categories cats = (Categories)prop; final TextList cl = cats.getCategories(); String lang = IcalUtil.getLang(cats); if (cl != null) { /* Got some categories */ for (final String wd: cl) { if (wd == null) { continue; } final BwString key = new BwString(lang, wd); final var fcResp = cb.findCategory(key); final BwCategory cat; if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isNotFound()) { cat = BwCategory.makeCategory(); cat.setWord(key); cb.addCategory(cat); } else { cat = fcResp.getEntity(); } chg.addValue(pi, cat); } } break; case CLASS: /* ------------------- Class -------------------- */ if (chg.changed(pi, ev.getClassification(), pval)) { ev.setClassification(pval); } break; case COMMENT: /* ------------------- Comment -------------------- */ chg.addValue(pi, new BwString(null, pval)); break; case COMPLETED: /* ------------------- Completed -------------------- */ if (chg.changed(pi, ev.getCompleted(), pval)) { ev.setCompleted(pval); } break; case CONCEPT: /* ------------------- Concept -------------------- */ final Concept c = (Concept)prop; final String cval = c.getValue(); if (cval != null) { /* Got a concept */ chg.addValue(PropertyInfoIndex.XPROP, BwXproperty.makeIcalProperty("CONCEPT", null, cval)); } break; case CONTACT: /* ------------------- Contact -------------------- */ final String altrep = getAltRepPar(prop); lang = IcalUtil.getLang(prop); final String uid = getUidPar(prop); final BwString nm = new BwString(lang, pval); BwContact contact = null; if (uid != null) { final var fcResp = cb.getContact(uid); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { final var fcResp = cb.findContact(nm); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { contact = BwContact.makeContact(); contact.setCn(nm); contact.setLink(altrep); cb.addContact(contact); } else { contact.setCn(nm); contact.setLink(altrep); } chg.addValue(pi, contact); break; case CREATED: /* ------------------- Created -------------------- */ if (chg.changed(pi, ev.getCreated(), pval)) { ev.setCreated(pval); } break; case DESCRIPTION: /* ------------------- Description -------------------- */ if (chg.changed(pi, ev.getDescription(), pval)) { ev.setDescription(pval); } break; case DTEND: /* ------------------- DtEnd -------------------- */ break; case DTSTAMP: /* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval); break; case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE: /* -------------------- Due ------------------------ */ break; case DURATION: /* ------------------- Duration -------------------- */ break; case EXDATE: /* ------------------- ExDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case EXRULE: /* ------------------- ExRule -------------------- */ chg.addValue(pi, pval); break; case FREEBUSY: /* ------------------- freebusy -------------------- */ final FreeBusy fbusy = (FreeBusy)prop; final PeriodList perpl = fbusy.getPeriods(); final Parameter par = IcalUtil.getParameter(fbusy, "FBTYPE"); final int fbtype; if (par == null) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY)) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY_TENTATIVE)) { fbtype = BwFreeBusyComponent.typeBusyTentative; } else if (par.equals(FbType.BUSY_UNAVAILABLE)) { fbtype = BwFreeBusyComponent.typeBusyUnavailable; } else if (par.equals(FbType.FREE)) { fbtype = BwFreeBusyComponent.typeFree; } else { if (logger.debug()) { logger.debug("Unsupported parameter " + par.getName()); } return Response.notOk(resp, failed, "Unsupported parameter " + par.getName()); } final BwFreeBusyComponent fbc = new BwFreeBusyComponent(); fbc.setType(fbtype); for (final Period per : perpl) { fbc.addPeriod(per); } ev.addFreeBusyPeriod(fbc); break; case GEO: /* ------------------- Geo -------------------- */ final Geo g = (Geo)prop; final BwGeo geo = new BwGeo(g.getLatitude(), g.getLongitude()); if (chg.changed(pi, ev.getGeo(), geo)) { ev.setGeo(geo); } break; case LAST_MODIFIED: /* ------------------- LastModified -------------------- */ if (chg.changed(pi, ev.getLastmod(), pval)) { ev.setLastmod(pval); } break; case LOCATION: /* ------------------- Location -------------------- */ BwLocation loc = null; //String uid = getUidPar(prop); /* At the moment Mozilla lightning is broken and this leads to all * sorts of problems. if (uid != null) { loc = cb.getLocation(uid); } */ lang = IcalUtil.getLang(prop); BwString addr = null; if (pval != null) { if (loc == null) { addr = new BwString(lang, pval); final var fcResp = cb.findLocation(addr); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { loc = fcResp.getEntity(); } } if (loc == null) { loc = BwLocation.makeLocation(); loc.setAddress(addr); cb.addLocation(loc); } } final BwLocation evloc = ev.getLocation(); if (chg.changed(pi, evloc, loc)) { // CHGTBL - this only shows that it's a different location object ev.setLocation(loc); } else if ((loc != null) && (evloc != null)) { // See if the value is changed final String evval = evloc.getAddress().getValue(); final String inval = loc.getAddress().getValue(); if (!evval.equals(inval)) { chg.changed(pi, evval, inval); evloc.getAddress().setValue(inval); } } break; case ORGANIZER: /* ------------------- Organizer -------------------- */ final BwOrganizer org = IcalUtil.getOrganizer(cb, (Organizer)prop); final BwOrganizer evorg = ev.getOrganizer(); final BwOrganizer evorgCopy; if (evorg == null) { evorgCopy = null; } else { evorgCopy = (BwOrganizer)evorg.clone(); } if (chg.changed(pi, evorgCopy, org)) { if (evorg == null) { ev.setOrganizer(org); } else { evorg.update(org); } } break; case PERCENT_COMPLETE: /* ------------------- PercentComplete -------------------- */ Integer ival = ((PercentComplete)prop).getPercentage(); if (chg.changed(pi, ev.getPercentComplete(), ival)) { ev.setPercentComplete(ival); } break; case POLL_MODE: /* ------------------- Poll mode -------------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollMode(), sval)) { ev.setPollMode(sval); } break; case POLL_PROPERTIES: /* ------------------- Poll properties ---------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollProperties(), sval)) { ev.setPollProperties(sval); } break; case POLL_WINNER: /* ------------------- Poll winner -------------------- */ ival = ((PollWinner)prop).getPollwinner(); if (chg.changed(pi, ev.getPollWinner(), ival)) { ev.setPollWinner(ival); } break; case PRIORITY: /* ------------------- Priority -------------------- */ ival = ((Priority)prop).getLevel(); if (chg.changed(pi, ev.getPriority(), ival)) { ev.setPriority(ival); } break; case RDATE: /* ------------------- RDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case RECURRENCE_ID: /* ------------------- RecurrenceID -------------------- */ // Done above break; case RELATED_TO: /* ------------------- RelatedTo -------------------- */ final RelatedTo irelto = (RelatedTo)prop; final BwRelatedTo relto = new BwRelatedTo(); final String parval = IcalUtil.getParameterVal(irelto, "RELTYPE"); if (parval != null) { relto.setRelType(parval); } relto.setValue(irelto.getValue()); if (chg.changed(pi, ev.getRelatedTo(), relto)) { ev.setRelatedTo(relto); } break; case REQUEST_STATUS: /* ------------------- RequestStatus -------------------- */ final BwRequestStatus rs = BwRequestStatus .fromRequestStatus((RequestStatus)prop); chg.addValue(pi, rs); break; case RESOURCES: /* ------------------- Resources -------------------- */ final TextList rl = ((Resources)prop).getResources(); if (rl != null) { /* Got some resources */ lang = IcalUtil.getLang(prop); for (final String s: rl) { final BwString rsrc = new BwString(lang, s); chg.addValue(pi, rsrc); } } break; case RRULE: /* ------------------- RRule -------------------- */ chg.addValue(pi, pval); break; case SEQUENCE: /* ------------------- Sequence -------------------- */ final int seq = ((Sequence)prop).getSequenceNo(); if (seq != ev.getSequence()) { chg.changed(pi, ev.getSequence(), seq); ev.setSequence(seq); } break; case STATUS: /* ------------------- Status -------------------- */ if (chg.changed(pi, ev.getStatus(), pval)) { ev.setStatus(pval); } break; case SUMMARY: /* ------------------- Summary -------------------- */ if (chg.changed(pi, ev.getSummary(), pval)) { ev.setSummary(pval); } break; case TRANSP: /* ------------------- Transp -------------------- */ if (chg.changed(pi, ev.getPeruserTransparency( cb.getPrincipal() .getPrincipalRef()), pval)) { final BwXproperty pu = ev.setPeruserTransparency( cb.getPrincipal().getPrincipalRef(), pval); if (pu != null) { chg.addValue(PropertyInfoIndex.XPROP, pu); } } break; case UID: /* ------------------- Uid -------------------- */ /* We did this above */ break; case URL: /* ------------------- Url -------------------- */ if (chg.changed(pi, ev.getLink(), pval)) { ev.setLink(pval); } break; case XPROP: /* ------------------------- x-property --------------------------- */ final String name = prop.getName(); if (name.equalsIgnoreCase(BwXproperty.bedeworkCost)) { if (chg.changed(PropertyInfoIndex.COST, ev.getCost(), pval)) { ev.setCost(pval); } break; } if (name.equalsIgnoreCase(BwXproperty.xBedeworkCategories)) { if (checkCategory(cb, chg, ev, null, pval)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkLocation)) { if (checkLocation(cb, chg, ev, prop)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkContact)) { if (checkContact(cb, chg, ev, null, pval)) { break; } } /* See if this is an x-category that can be converted to a real category */ final XProperty xp = (XProperty)prop; chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(name, xp.getParameters() .toString(), pval)); break; default: if (logger.debug()) { logger.debug("Unsupported property with index " + pi + "; class " + prop.getClass() + " and value " + pval); } } } /* =================== Process sub-components =============== */ final ComponentList<Component> subComps; if (val instanceof ComponentContainer) { subComps = ((ComponentContainer<Component>)val).getComponents(); } else { subComps = null; } final Set<Integer> pids; if (vpoll) { pids = new TreeSet<>(); final BwEvent vp = evinfo.getEvent(); if (!Util.isEmpty(vp.getPollItems())) { vp.clearPollItems(); } } else { pids = null; } if (!Util.isEmpty(subComps)) { for (final var subComp: subComps) { if (subComp instanceof Available) { if (!(val instanceof VAvailability)) { return Response.error(resp, "AVAILABLE only valid in VAVAILABLE"); } final var avlResp = processAvailable(cb, cal, ical, (VAvailability)val, (Available)subComp, evinfo); if (!avlResp.isOk()) { return Response.fromResponse(resp, avlResp); } continue; } if (subComp instanceof Participant) { if (vpoll) { final var vresp = processVoter(cb, (VPoll)val, (Participant)subComp, evinfo, chg, mergeAttendees); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Participant object"); continue; } if (subComp instanceof VResource) { logger.warn("Unimplemented VResource object"); continue; } if (subComp instanceof VLocation) { logger.warn("Unimplemented VLocation object"); continue; } if (subComp instanceof VAlarm) { final var aresp = VAlarmUtil.processAlarm(cb, val, (VAlarm)subComp, ev, currentPrincipal, chg); if (!aresp.isOk()) { return Response.fromResponse(resp, aresp); } continue; } if (vpoll && (event || task)) { final var vresp = processCandidate((VPoll)val, subComp, evinfo, pids, chg); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Component object: " + subComp); } } /* Fix up timestamps. */ if (ev.getCreated() == null) { if (ev.getLastmod() != null) { ev.setCreated(ev.getLastmod()); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); } else { ev.updateDtstamp(); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } } if (ev.getLastmod() == null) { // created cannot be null now ev.setLastmod(ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } processTimezones(ev, ical, chg); /* Remove any recipients and originator */ if (ev.getRecipients() != null) { ev.getRecipients().clear(); } ev.setOriginator(null); if (hasXparams.value) { /* Save a text copy of the entire event as an x-property */ final Component valCopy = val.copy(); /* Remove potentially large values */ final Description desp = valCopy.getProperty(Property.DESCRIPTION); if (desp != null) { desp.setValue(null); } final Attach attachp = valCopy.getProperty(Property.ATTACH); // Don't store the entire attachment - we just need the parameters. if (attachp != null) { final Value v = attachp.getParameter(Parameter.VALUE); if (v != null) { attachp.setValue(String.valueOf(attachp.getValue().hashCode())); } } chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(BwXproperty.bedeworkIcal, null, valCopy.toString())); } chg.processChanges(ev, true, false); ev.setRecurring(ev.isRecurringEntity()); if (logger.debug()) { logger.debug(chg.toString()); logger.debug(ev.toString()); } if (masterEI != null) { // Just return notfound as this event is on its override list return Response.notFound(resp); } resp.setEntity(evinfo); return resp; } catch (final Throwable t) { if (logger.debug()) { logger.error(t); } return Response.error(resp, t); } }
NONSATD
true
break; case DTSTAMP: /* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval); break;
case DESCRIPTION: /* ------------------- Description -------------------- */ if (chg.changed(pi, ev.getDescription(), pval)) { ev.setDescription(pval); } break; case DTEND: /* ------------------- DtEnd -------------------- */ break; case DTSTAMP: /* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval); break; case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE: /* -------------------- Due ------------------------ */ break; case DURATION: /* ------------------- Duration -------------------- */
contact.setLink(altrep); } chg.addValue(pi, contact); break; case CREATED: /* ------------------- Created -------------------- */ if (chg.changed(pi, ev.getCreated(), pval)) { ev.setCreated(pval); } break; case DESCRIPTION: /* ------------------- Description -------------------- */ if (chg.changed(pi, ev.getDescription(), pval)) { ev.setDescription(pval); } break; case DTEND: /* ------------------- DtEnd -------------------- */ break; case DTSTAMP: /* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval); break; case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE: /* -------------------- Due ------------------------ */ break; case DURATION: /* ------------------- Duration -------------------- */ break; case EXDATE: /* ------------------- ExDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case EXRULE: /* ------------------- ExRule -------------------- */ chg.addValue(pi, pval); break;
7,893
41
/* ------------------- DtStart -------------------- */
public static GetEntityResponse<EventInfo> toEvent( final IcalCallback cb, final BwCalendar cal, final Icalendar ical, final Component val, final boolean mergeAttendees) { final var resp = new GetEntityResponse<EventInfo>(); if (val == null) { return Response.notOk(resp, failed, "No component supplied"); } String currentPrincipal = null; final BwPrincipal principal = cb.getPrincipal(); if (principal != null) { currentPrincipal = principal.getPrincipalRef(); } final Holder<Boolean> hasXparams = new Holder<>(Boolean.FALSE); final int methodType = ical.getMethodType(); String attUri = null; if (mergeAttendees) { // We'll need this later. attUri = cb.getCaladdr(cb.getPrincipal().getPrincipalRef()); } final String colPath; if (cal == null) { colPath = null; } else { colPath = cal.getPath(); } try { final PropertyList<Property> pl = val.getProperties(); boolean vpoll = false; boolean event = false; boolean task = false; if (pl == null) { // Empty component return Response.notOk(resp, failed, "Empty component"); } final int entityType; if (val instanceof VEvent) { entityType = IcalDefs.entityTypeEvent; event = true; } else if (val instanceof VToDo) { entityType = IcalDefs.entityTypeTodo; task = true; } else if (val instanceof VJournal) { entityType = IcalDefs.entityTypeJournal; } else if (val instanceof VFreeBusy) { entityType = IcalDefs.entityTypeFreeAndBusy; } else if (val instanceof VAvailability) { entityType = IcalDefs.entityTypeVavailability; } else if (val instanceof Available) { entityType = IcalDefs.entityTypeAvailable; } else if (val instanceof VPoll) { entityType = IcalDefs.entityTypeVpoll; vpoll = true; } else { return Response.error(resp, "org.bedework.invalid.component.type: " + val.getName()); } // Get the guid from the component String guid = null; final Uid uidp = pl.getProperty(Property.UID); if (uidp != null) { testXparams(uidp, hasXparams); guid = uidp.getValue(); } if (guid == null) { /* XXX A guid is required - but are there devices out there without a * guid - and if so how do we handle it? */ return Response.notOk(resp, failed, CalFacadeException.noGuid); } /* See if we have a recurrence id */ BwDateTime ridObj = null; String rid = null; TimeZone ridTz = null; final RecurrenceId ridp = pl.getProperty(Property.RECURRENCE_ID); if (ridp != null) { testXparams(ridp, hasXparams); ridObj = BwDateTime.makeBwDateTime(ridp); if (ridObj.getRange() != null) { /* XXX What do I do with it? */ logger.warn("TRANS-TO_EVENT: Got a recurrence id range"); } rid = ridObj.getDate(); } EventInfo masterEI = null; EventInfo evinfo = null; final BwEvent ev; /* If we have a recurrence id see if we already have the master (we should * get a master + all its overrides). * * If so find the override and use the annnotation or if no override, * make one. * * If no override retrieve the event, add it to our table and then locate the * annotation. * * If there is no annotation, create one. * * It's possible we have been sent 'detached' instances of a recurring * event. This may happen if we are invited to one or more instances of a * meeting. In this case we try to retrieve the master and if it doesn't * exist we manufacture one. We consider such an instance an update to * that instance only and leave the others alone. */ /* We need this in a couple of places */ final DtStart dtStart = pl.getProperty(Property.DTSTART); /* if (rid != null) { // See if we have a new master event. If so create a proxy to that event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI == null) { masterEI = makeNewEvent(cb, chg, entityType, guid, cal); BwEvent e = masterEI.getEvent(); // XXX This seems bogus DtStart mdtStart; String bogusDate = "19980118T230000"; if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + "Z"); } else if (dtStart.getTimeZone() == null) { mdtStart = new DtStart(bogusDate); } else { mdtStart = new DtStart(bogusDate + "Z", dtStart.getTimeZone()); } setDates(e, mdtStart, null, null, chg); e.setRecurring(true); e.addRdate(ridObj); e.setSuppressed(true); ical.addComponent(masterEI); } if (masterEI != null) { evinfo = masterEI.findOverride(rid); } } */ /* If this is a recurrence instance see if we can find the master We only need this because the master may follow the overrides. */ if (rid != null) { // See if we have a new master event. If so create a proxy to this event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI != null) { evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; } } if ((evinfo == null) && (cal != null) && (cal.getCalType() != BwCalendar.calTypeInbox) && (cal.getCalType() != BwCalendar.calTypePendingInbox) && (cal.getCalType() != BwCalendar.calTypeOutbox)) { if (logger.debug()) { logger.debug("TRANS-TO_EVENT: try to fetch event with guid=" + guid); } final GetEntitiesResponse<EventInfo> eisResp = cb.getEvent(colPath, guid); if (eisResp.isError()) { return Response.fromResponse(resp, eisResp); } final var eis = eisResp.getEntities(); if (!Util.isEmpty(eis)) { if (eis.size() > 1) { // DORECUR - wrong again return Response.notOk(resp, failed, "More than one event returned for guid."); } evinfo = eis.iterator().next(); } if (logger.debug()) { if (evinfo != null) { logger.debug("TRANS-TO_EVENT: fetched event with guid"); } else { logger.debug("TRANS-TO_EVENT: did not find event with guid"); } } if (evinfo != null) { if (rid != null) { // We just retrieved it's master masterEI = evinfo; masterEI.setInstanceOnly(true); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; ical.addComponent(masterEI); } else if (methodType == ScheduleMethods.methodTypeCancel) { // This should never have an rid for cancel of entire event. evinfo.setInstanceOnly(evinfo.getEvent().getSuppressed()); } else { // Presumably sent an update for the entire event. No longer suppressed master evinfo.getEvent().setSuppressed(false); } } else if (rid != null) { /* Manufacture a master for the instance */ masterEI = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); final BwEvent e = masterEI.getEvent(); // XXX This seems bogus final DtStart mdtStart; final String bogusDate = "19980118"; final String bogusTime = "T230000"; // Base dtstart on the recurrence id. final boolean isDateType = ridObj.getDateType(); if (isDateType) { mdtStart = new DtStart(new Date(bogusDate)); } else if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + bogusTime + "Z"); } else if (ridObj.getTzid() == null) { mdtStart = new DtStart(bogusDate + bogusTime); } else { mdtStart = new DtStart(bogusDate + bogusTime, Timezones.getTz(ridObj.getTzid())); } IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), masterEI, mdtStart, null, null); e.setRecurring(true); // e.addRdate(ridObj); final var sum = (Summary)pl.getProperty(Property.SUMMARY); e.setSummary(sum.getValue()); e.setSuppressed(true); ical.addComponent(masterEI); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; masterEI.setInstanceOnly(rid != null); } } if (evinfo == null) { evinfo = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); } else if (evinfo.getEvent().getEntityType() != entityType) { return Response.notOk(resp, failed, "org.bedework.mismatched.entity.type: " + val); } final ChangeTable chg = evinfo.getChangeset( cb.getPrincipal().getPrincipalRef()); if (rid != null) { final String evrid = evinfo.getEvent().getRecurrenceId(); if ((evrid == null) || (!evrid.equals(rid))) { logger. warn("Mismatched rid ev=" + evrid + " expected " + rid); chg.changed(PropertyInfoIndex.RECURRENCE_ID, evrid, rid); // XXX spurious??? } if (masterEI.getEvent().getSuppressed()) { masterEI.getEvent().addRdate(ridObj); } } ev = evinfo.getEvent(); ev.setScheduleMethod(methodType); DtEnd dtEnd = null; if (entityType == IcalDefs.entityTypeTodo) { final Due due = pl.getProperty(Property.DUE); if (due != null ) { dtEnd = new DtEnd(due.getParameters(), due.getValue()); } } else { dtEnd = pl.getProperty(Property.DTEND); } final Duration duration = pl.getProperty(Property.DURATION); IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), evinfo, dtStart, dtEnd, duration); for (final Property prop: pl) { testXparams(prop, hasXparams); //debug("ical prop " + prop.getClass().getName()); String pval = prop.getValue(); if ((pval != null) && (pval.length() == 0)) { pval = null; } final PropertyInfoIndex pi; if (prop instanceof XProperty) { pi = PropertyInfoIndex.XPROP; } else { pi = PropertyInfoIndex.fromName(prop.getName()); } if (pi == null) { logger.debug("Unknown property with name " + prop.getName() + " class " + prop.getClass() + " and value " + pval); continue; } chg.present(pi); switch (pi) { case ACCEPT_RESPONSE: /* ------------------- Accept Response -------------------- */ String sval = prop.getValue(); if (chg.changed(pi, ev.getPollAcceptResponse(), sval)) { ev.setPollAcceptResponse(sval); } break; case ATTACH: /* ------------------- Attachment -------------------- */ chg.addValue(pi, IcalUtil.getAttachment((Attach)prop)); break; case ATTENDEE: /* ------------------- Attendee -------------------- */ if (methodType == ScheduleMethods.methodTypePublish) { if (cb.getStrictness() == IcalCallback.conformanceStrict) { return Response.notOk(resp, failed, CalFacadeException.attendeesInPublish); } //if (cb.getStrictness() == IcalCallback.conformanceWarn) { // warn("Had attendees for PUBLISH"); //} } final Attendee attPr = (Attendee)prop; if (evinfo.getNewEvent() || !mergeAttendees) { chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { final String pUri = cb.getCaladdr(attPr.getValue()); if (pUri.equals(attUri)) { /* Only update for our own attendee * We're doing a PUT and this must be the attendee updating their * partstat. We don't allow them to change other attendees * whatever the PUT content says. */ chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { // Use the value we currently have boolean found = false; for (final BwAttendee att: ev.getAttendees()) { if (pUri.equals(att.getAttendeeUri())) { chg.addValue(pi, att.clone()); found = true; break; } } if (!found) { // An added attendee final BwAttendee att = IcalUtil .getAttendee(cb, attPr); att.setPartstat(IcalDefs.partstatValNeedsAction); chg.addValue(pi, att); } } } break; case BUSYTYPE: final int ibt = BwEvent.fromBusyTypeString(pval); if (chg.changed(pi, ev.getBusyType(), ibt)) { ev.setBusyType(ibt); } break; case CATEGORIES: /* ------------------- Categories -------------------- */ final Categories cats = (Categories)prop; final TextList cl = cats.getCategories(); String lang = IcalUtil.getLang(cats); if (cl != null) { /* Got some categories */ for (final String wd: cl) { if (wd == null) { continue; } final BwString key = new BwString(lang, wd); final var fcResp = cb.findCategory(key); final BwCategory cat; if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isNotFound()) { cat = BwCategory.makeCategory(); cat.setWord(key); cb.addCategory(cat); } else { cat = fcResp.getEntity(); } chg.addValue(pi, cat); } } break; case CLASS: /* ------------------- Class -------------------- */ if (chg.changed(pi, ev.getClassification(), pval)) { ev.setClassification(pval); } break; case COMMENT: /* ------------------- Comment -------------------- */ chg.addValue(pi, new BwString(null, pval)); break; case COMPLETED: /* ------------------- Completed -------------------- */ if (chg.changed(pi, ev.getCompleted(), pval)) { ev.setCompleted(pval); } break; case CONCEPT: /* ------------------- Concept -------------------- */ final Concept c = (Concept)prop; final String cval = c.getValue(); if (cval != null) { /* Got a concept */ chg.addValue(PropertyInfoIndex.XPROP, BwXproperty.makeIcalProperty("CONCEPT", null, cval)); } break; case CONTACT: /* ------------------- Contact -------------------- */ final String altrep = getAltRepPar(prop); lang = IcalUtil.getLang(prop); final String uid = getUidPar(prop); final BwString nm = new BwString(lang, pval); BwContact contact = null; if (uid != null) { final var fcResp = cb.getContact(uid); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { final var fcResp = cb.findContact(nm); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { contact = BwContact.makeContact(); contact.setCn(nm); contact.setLink(altrep); cb.addContact(contact); } else { contact.setCn(nm); contact.setLink(altrep); } chg.addValue(pi, contact); break; case CREATED: /* ------------------- Created -------------------- */ if (chg.changed(pi, ev.getCreated(), pval)) { ev.setCreated(pval); } break; case DESCRIPTION: /* ------------------- Description -------------------- */ if (chg.changed(pi, ev.getDescription(), pval)) { ev.setDescription(pval); } break; case DTEND: /* ------------------- DtEnd -------------------- */ break; case DTSTAMP: /* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval); break; case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE: /* -------------------- Due ------------------------ */ break; case DURATION: /* ------------------- Duration -------------------- */ break; case EXDATE: /* ------------------- ExDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case EXRULE: /* ------------------- ExRule -------------------- */ chg.addValue(pi, pval); break; case FREEBUSY: /* ------------------- freebusy -------------------- */ final FreeBusy fbusy = (FreeBusy)prop; final PeriodList perpl = fbusy.getPeriods(); final Parameter par = IcalUtil.getParameter(fbusy, "FBTYPE"); final int fbtype; if (par == null) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY)) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY_TENTATIVE)) { fbtype = BwFreeBusyComponent.typeBusyTentative; } else if (par.equals(FbType.BUSY_UNAVAILABLE)) { fbtype = BwFreeBusyComponent.typeBusyUnavailable; } else if (par.equals(FbType.FREE)) { fbtype = BwFreeBusyComponent.typeFree; } else { if (logger.debug()) { logger.debug("Unsupported parameter " + par.getName()); } return Response.notOk(resp, failed, "Unsupported parameter " + par.getName()); } final BwFreeBusyComponent fbc = new BwFreeBusyComponent(); fbc.setType(fbtype); for (final Period per : perpl) { fbc.addPeriod(per); } ev.addFreeBusyPeriod(fbc); break; case GEO: /* ------------------- Geo -------------------- */ final Geo g = (Geo)prop; final BwGeo geo = new BwGeo(g.getLatitude(), g.getLongitude()); if (chg.changed(pi, ev.getGeo(), geo)) { ev.setGeo(geo); } break; case LAST_MODIFIED: /* ------------------- LastModified -------------------- */ if (chg.changed(pi, ev.getLastmod(), pval)) { ev.setLastmod(pval); } break; case LOCATION: /* ------------------- Location -------------------- */ BwLocation loc = null; //String uid = getUidPar(prop); /* At the moment Mozilla lightning is broken and this leads to all * sorts of problems. if (uid != null) { loc = cb.getLocation(uid); } */ lang = IcalUtil.getLang(prop); BwString addr = null; if (pval != null) { if (loc == null) { addr = new BwString(lang, pval); final var fcResp = cb.findLocation(addr); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { loc = fcResp.getEntity(); } } if (loc == null) { loc = BwLocation.makeLocation(); loc.setAddress(addr); cb.addLocation(loc); } } final BwLocation evloc = ev.getLocation(); if (chg.changed(pi, evloc, loc)) { // CHGTBL - this only shows that it's a different location object ev.setLocation(loc); } else if ((loc != null) && (evloc != null)) { // See if the value is changed final String evval = evloc.getAddress().getValue(); final String inval = loc.getAddress().getValue(); if (!evval.equals(inval)) { chg.changed(pi, evval, inval); evloc.getAddress().setValue(inval); } } break; case ORGANIZER: /* ------------------- Organizer -------------------- */ final BwOrganizer org = IcalUtil.getOrganizer(cb, (Organizer)prop); final BwOrganizer evorg = ev.getOrganizer(); final BwOrganizer evorgCopy; if (evorg == null) { evorgCopy = null; } else { evorgCopy = (BwOrganizer)evorg.clone(); } if (chg.changed(pi, evorgCopy, org)) { if (evorg == null) { ev.setOrganizer(org); } else { evorg.update(org); } } break; case PERCENT_COMPLETE: /* ------------------- PercentComplete -------------------- */ Integer ival = ((PercentComplete)prop).getPercentage(); if (chg.changed(pi, ev.getPercentComplete(), ival)) { ev.setPercentComplete(ival); } break; case POLL_MODE: /* ------------------- Poll mode -------------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollMode(), sval)) { ev.setPollMode(sval); } break; case POLL_PROPERTIES: /* ------------------- Poll properties ---------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollProperties(), sval)) { ev.setPollProperties(sval); } break; case POLL_WINNER: /* ------------------- Poll winner -------------------- */ ival = ((PollWinner)prop).getPollwinner(); if (chg.changed(pi, ev.getPollWinner(), ival)) { ev.setPollWinner(ival); } break; case PRIORITY: /* ------------------- Priority -------------------- */ ival = ((Priority)prop).getLevel(); if (chg.changed(pi, ev.getPriority(), ival)) { ev.setPriority(ival); } break; case RDATE: /* ------------------- RDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case RECURRENCE_ID: /* ------------------- RecurrenceID -------------------- */ // Done above break; case RELATED_TO: /* ------------------- RelatedTo -------------------- */ final RelatedTo irelto = (RelatedTo)prop; final BwRelatedTo relto = new BwRelatedTo(); final String parval = IcalUtil.getParameterVal(irelto, "RELTYPE"); if (parval != null) { relto.setRelType(parval); } relto.setValue(irelto.getValue()); if (chg.changed(pi, ev.getRelatedTo(), relto)) { ev.setRelatedTo(relto); } break; case REQUEST_STATUS: /* ------------------- RequestStatus -------------------- */ final BwRequestStatus rs = BwRequestStatus .fromRequestStatus((RequestStatus)prop); chg.addValue(pi, rs); break; case RESOURCES: /* ------------------- Resources -------------------- */ final TextList rl = ((Resources)prop).getResources(); if (rl != null) { /* Got some resources */ lang = IcalUtil.getLang(prop); for (final String s: rl) { final BwString rsrc = new BwString(lang, s); chg.addValue(pi, rsrc); } } break; case RRULE: /* ------------------- RRule -------------------- */ chg.addValue(pi, pval); break; case SEQUENCE: /* ------------------- Sequence -------------------- */ final int seq = ((Sequence)prop).getSequenceNo(); if (seq != ev.getSequence()) { chg.changed(pi, ev.getSequence(), seq); ev.setSequence(seq); } break; case STATUS: /* ------------------- Status -------------------- */ if (chg.changed(pi, ev.getStatus(), pval)) { ev.setStatus(pval); } break; case SUMMARY: /* ------------------- Summary -------------------- */ if (chg.changed(pi, ev.getSummary(), pval)) { ev.setSummary(pval); } break; case TRANSP: /* ------------------- Transp -------------------- */ if (chg.changed(pi, ev.getPeruserTransparency( cb.getPrincipal() .getPrincipalRef()), pval)) { final BwXproperty pu = ev.setPeruserTransparency( cb.getPrincipal().getPrincipalRef(), pval); if (pu != null) { chg.addValue(PropertyInfoIndex.XPROP, pu); } } break; case UID: /* ------------------- Uid -------------------- */ /* We did this above */ break; case URL: /* ------------------- Url -------------------- */ if (chg.changed(pi, ev.getLink(), pval)) { ev.setLink(pval); } break; case XPROP: /* ------------------------- x-property --------------------------- */ final String name = prop.getName(); if (name.equalsIgnoreCase(BwXproperty.bedeworkCost)) { if (chg.changed(PropertyInfoIndex.COST, ev.getCost(), pval)) { ev.setCost(pval); } break; } if (name.equalsIgnoreCase(BwXproperty.xBedeworkCategories)) { if (checkCategory(cb, chg, ev, null, pval)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkLocation)) { if (checkLocation(cb, chg, ev, prop)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkContact)) { if (checkContact(cb, chg, ev, null, pval)) { break; } } /* See if this is an x-category that can be converted to a real category */ final XProperty xp = (XProperty)prop; chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(name, xp.getParameters() .toString(), pval)); break; default: if (logger.debug()) { logger.debug("Unsupported property with index " + pi + "; class " + prop.getClass() + " and value " + pval); } } } /* =================== Process sub-components =============== */ final ComponentList<Component> subComps; if (val instanceof ComponentContainer) { subComps = ((ComponentContainer<Component>)val).getComponents(); } else { subComps = null; } final Set<Integer> pids; if (vpoll) { pids = new TreeSet<>(); final BwEvent vp = evinfo.getEvent(); if (!Util.isEmpty(vp.getPollItems())) { vp.clearPollItems(); } } else { pids = null; } if (!Util.isEmpty(subComps)) { for (final var subComp: subComps) { if (subComp instanceof Available) { if (!(val instanceof VAvailability)) { return Response.error(resp, "AVAILABLE only valid in VAVAILABLE"); } final var avlResp = processAvailable(cb, cal, ical, (VAvailability)val, (Available)subComp, evinfo); if (!avlResp.isOk()) { return Response.fromResponse(resp, avlResp); } continue; } if (subComp instanceof Participant) { if (vpoll) { final var vresp = processVoter(cb, (VPoll)val, (Participant)subComp, evinfo, chg, mergeAttendees); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Participant object"); continue; } if (subComp instanceof VResource) { logger.warn("Unimplemented VResource object"); continue; } if (subComp instanceof VLocation) { logger.warn("Unimplemented VLocation object"); continue; } if (subComp instanceof VAlarm) { final var aresp = VAlarmUtil.processAlarm(cb, val, (VAlarm)subComp, ev, currentPrincipal, chg); if (!aresp.isOk()) { return Response.fromResponse(resp, aresp); } continue; } if (vpoll && (event || task)) { final var vresp = processCandidate((VPoll)val, subComp, evinfo, pids, chg); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Component object: " + subComp); } } /* Fix up timestamps. */ if (ev.getCreated() == null) { if (ev.getLastmod() != null) { ev.setCreated(ev.getLastmod()); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); } else { ev.updateDtstamp(); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } } if (ev.getLastmod() == null) { // created cannot be null now ev.setLastmod(ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } processTimezones(ev, ical, chg); /* Remove any recipients and originator */ if (ev.getRecipients() != null) { ev.getRecipients().clear(); } ev.setOriginator(null); if (hasXparams.value) { /* Save a text copy of the entire event as an x-property */ final Component valCopy = val.copy(); /* Remove potentially large values */ final Description desp = valCopy.getProperty(Property.DESCRIPTION); if (desp != null) { desp.setValue(null); } final Attach attachp = valCopy.getProperty(Property.ATTACH); // Don't store the entire attachment - we just need the parameters. if (attachp != null) { final Value v = attachp.getParameter(Parameter.VALUE); if (v != null) { attachp.setValue(String.valueOf(attachp.getValue().hashCode())); } } chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(BwXproperty.bedeworkIcal, null, valCopy.toString())); } chg.processChanges(ev, true, false); ev.setRecurring(ev.isRecurringEntity()); if (logger.debug()) { logger.debug(chg.toString()); logger.debug(ev.toString()); } if (masterEI != null) { // Just return notfound as this event is on its override list return Response.notFound(resp); } resp.setEntity(evinfo); return resp; } catch (final Throwable t) { if (logger.debug()) { logger.error(t); } return Response.error(resp, t); } }
NONSATD
true
break; case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE:
} break; case DTEND: /* ------------------- DtEnd -------------------- */ break; case DTSTAMP: /* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval); break; case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE: /* -------------------- Due ------------------------ */ break; case DURATION: /* ------------------- Duration -------------------- */ break; case EXDATE: /* ------------------- ExDate -------------------- */ chg.addValues(pi,
case CREATED: /* ------------------- Created -------------------- */ if (chg.changed(pi, ev.getCreated(), pval)) { ev.setCreated(pval); } break; case DESCRIPTION: /* ------------------- Description -------------------- */ if (chg.changed(pi, ev.getDescription(), pval)) { ev.setDescription(pval); } break; case DTEND: /* ------------------- DtEnd -------------------- */ break; case DTSTAMP: /* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval); break; case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE: /* -------------------- Due ------------------------ */ break; case DURATION: /* ------------------- Duration -------------------- */ break; case EXDATE: /* ------------------- ExDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case EXRULE: /* ------------------- ExRule -------------------- */ chg.addValue(pi, pval); break; case FREEBUSY: /* ------------------- freebusy -------------------- */ final FreeBusy fbusy = (FreeBusy)prop; final PeriodList perpl = fbusy.getPeriods();
7,893
42
/* -------------------- Due ------------------------ */
public static GetEntityResponse<EventInfo> toEvent( final IcalCallback cb, final BwCalendar cal, final Icalendar ical, final Component val, final boolean mergeAttendees) { final var resp = new GetEntityResponse<EventInfo>(); if (val == null) { return Response.notOk(resp, failed, "No component supplied"); } String currentPrincipal = null; final BwPrincipal principal = cb.getPrincipal(); if (principal != null) { currentPrincipal = principal.getPrincipalRef(); } final Holder<Boolean> hasXparams = new Holder<>(Boolean.FALSE); final int methodType = ical.getMethodType(); String attUri = null; if (mergeAttendees) { // We'll need this later. attUri = cb.getCaladdr(cb.getPrincipal().getPrincipalRef()); } final String colPath; if (cal == null) { colPath = null; } else { colPath = cal.getPath(); } try { final PropertyList<Property> pl = val.getProperties(); boolean vpoll = false; boolean event = false; boolean task = false; if (pl == null) { // Empty component return Response.notOk(resp, failed, "Empty component"); } final int entityType; if (val instanceof VEvent) { entityType = IcalDefs.entityTypeEvent; event = true; } else if (val instanceof VToDo) { entityType = IcalDefs.entityTypeTodo; task = true; } else if (val instanceof VJournal) { entityType = IcalDefs.entityTypeJournal; } else if (val instanceof VFreeBusy) { entityType = IcalDefs.entityTypeFreeAndBusy; } else if (val instanceof VAvailability) { entityType = IcalDefs.entityTypeVavailability; } else if (val instanceof Available) { entityType = IcalDefs.entityTypeAvailable; } else if (val instanceof VPoll) { entityType = IcalDefs.entityTypeVpoll; vpoll = true; } else { return Response.error(resp, "org.bedework.invalid.component.type: " + val.getName()); } // Get the guid from the component String guid = null; final Uid uidp = pl.getProperty(Property.UID); if (uidp != null) { testXparams(uidp, hasXparams); guid = uidp.getValue(); } if (guid == null) { /* XXX A guid is required - but are there devices out there without a * guid - and if so how do we handle it? */ return Response.notOk(resp, failed, CalFacadeException.noGuid); } /* See if we have a recurrence id */ BwDateTime ridObj = null; String rid = null; TimeZone ridTz = null; final RecurrenceId ridp = pl.getProperty(Property.RECURRENCE_ID); if (ridp != null) { testXparams(ridp, hasXparams); ridObj = BwDateTime.makeBwDateTime(ridp); if (ridObj.getRange() != null) { /* XXX What do I do with it? */ logger.warn("TRANS-TO_EVENT: Got a recurrence id range"); } rid = ridObj.getDate(); } EventInfo masterEI = null; EventInfo evinfo = null; final BwEvent ev; /* If we have a recurrence id see if we already have the master (we should * get a master + all its overrides). * * If so find the override and use the annnotation or if no override, * make one. * * If no override retrieve the event, add it to our table and then locate the * annotation. * * If there is no annotation, create one. * * It's possible we have been sent 'detached' instances of a recurring * event. This may happen if we are invited to one or more instances of a * meeting. In this case we try to retrieve the master and if it doesn't * exist we manufacture one. We consider such an instance an update to * that instance only and leave the others alone. */ /* We need this in a couple of places */ final DtStart dtStart = pl.getProperty(Property.DTSTART); /* if (rid != null) { // See if we have a new master event. If so create a proxy to that event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI == null) { masterEI = makeNewEvent(cb, chg, entityType, guid, cal); BwEvent e = masterEI.getEvent(); // XXX This seems bogus DtStart mdtStart; String bogusDate = "19980118T230000"; if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + "Z"); } else if (dtStart.getTimeZone() == null) { mdtStart = new DtStart(bogusDate); } else { mdtStart = new DtStart(bogusDate + "Z", dtStart.getTimeZone()); } setDates(e, mdtStart, null, null, chg); e.setRecurring(true); e.addRdate(ridObj); e.setSuppressed(true); ical.addComponent(masterEI); } if (masterEI != null) { evinfo = masterEI.findOverride(rid); } } */ /* If this is a recurrence instance see if we can find the master We only need this because the master may follow the overrides. */ if (rid != null) { // See if we have a new master event. If so create a proxy to this event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI != null) { evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; } } if ((evinfo == null) && (cal != null) && (cal.getCalType() != BwCalendar.calTypeInbox) && (cal.getCalType() != BwCalendar.calTypePendingInbox) && (cal.getCalType() != BwCalendar.calTypeOutbox)) { if (logger.debug()) { logger.debug("TRANS-TO_EVENT: try to fetch event with guid=" + guid); } final GetEntitiesResponse<EventInfo> eisResp = cb.getEvent(colPath, guid); if (eisResp.isError()) { return Response.fromResponse(resp, eisResp); } final var eis = eisResp.getEntities(); if (!Util.isEmpty(eis)) { if (eis.size() > 1) { // DORECUR - wrong again return Response.notOk(resp, failed, "More than one event returned for guid."); } evinfo = eis.iterator().next(); } if (logger.debug()) { if (evinfo != null) { logger.debug("TRANS-TO_EVENT: fetched event with guid"); } else { logger.debug("TRANS-TO_EVENT: did not find event with guid"); } } if (evinfo != null) { if (rid != null) { // We just retrieved it's master masterEI = evinfo; masterEI.setInstanceOnly(true); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; ical.addComponent(masterEI); } else if (methodType == ScheduleMethods.methodTypeCancel) { // This should never have an rid for cancel of entire event. evinfo.setInstanceOnly(evinfo.getEvent().getSuppressed()); } else { // Presumably sent an update for the entire event. No longer suppressed master evinfo.getEvent().setSuppressed(false); } } else if (rid != null) { /* Manufacture a master for the instance */ masterEI = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); final BwEvent e = masterEI.getEvent(); // XXX This seems bogus final DtStart mdtStart; final String bogusDate = "19980118"; final String bogusTime = "T230000"; // Base dtstart on the recurrence id. final boolean isDateType = ridObj.getDateType(); if (isDateType) { mdtStart = new DtStart(new Date(bogusDate)); } else if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + bogusTime + "Z"); } else if (ridObj.getTzid() == null) { mdtStart = new DtStart(bogusDate + bogusTime); } else { mdtStart = new DtStart(bogusDate + bogusTime, Timezones.getTz(ridObj.getTzid())); } IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), masterEI, mdtStart, null, null); e.setRecurring(true); // e.addRdate(ridObj); final var sum = (Summary)pl.getProperty(Property.SUMMARY); e.setSummary(sum.getValue()); e.setSuppressed(true); ical.addComponent(masterEI); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; masterEI.setInstanceOnly(rid != null); } } if (evinfo == null) { evinfo = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); } else if (evinfo.getEvent().getEntityType() != entityType) { return Response.notOk(resp, failed, "org.bedework.mismatched.entity.type: " + val); } final ChangeTable chg = evinfo.getChangeset( cb.getPrincipal().getPrincipalRef()); if (rid != null) { final String evrid = evinfo.getEvent().getRecurrenceId(); if ((evrid == null) || (!evrid.equals(rid))) { logger. warn("Mismatched rid ev=" + evrid + " expected " + rid); chg.changed(PropertyInfoIndex.RECURRENCE_ID, evrid, rid); // XXX spurious??? } if (masterEI.getEvent().getSuppressed()) { masterEI.getEvent().addRdate(ridObj); } } ev = evinfo.getEvent(); ev.setScheduleMethod(methodType); DtEnd dtEnd = null; if (entityType == IcalDefs.entityTypeTodo) { final Due due = pl.getProperty(Property.DUE); if (due != null ) { dtEnd = new DtEnd(due.getParameters(), due.getValue()); } } else { dtEnd = pl.getProperty(Property.DTEND); } final Duration duration = pl.getProperty(Property.DURATION); IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), evinfo, dtStart, dtEnd, duration); for (final Property prop: pl) { testXparams(prop, hasXparams); //debug("ical prop " + prop.getClass().getName()); String pval = prop.getValue(); if ((pval != null) && (pval.length() == 0)) { pval = null; } final PropertyInfoIndex pi; if (prop instanceof XProperty) { pi = PropertyInfoIndex.XPROP; } else { pi = PropertyInfoIndex.fromName(prop.getName()); } if (pi == null) { logger.debug("Unknown property with name " + prop.getName() + " class " + prop.getClass() + " and value " + pval); continue; } chg.present(pi); switch (pi) { case ACCEPT_RESPONSE: /* ------------------- Accept Response -------------------- */ String sval = prop.getValue(); if (chg.changed(pi, ev.getPollAcceptResponse(), sval)) { ev.setPollAcceptResponse(sval); } break; case ATTACH: /* ------------------- Attachment -------------------- */ chg.addValue(pi, IcalUtil.getAttachment((Attach)prop)); break; case ATTENDEE: /* ------------------- Attendee -------------------- */ if (methodType == ScheduleMethods.methodTypePublish) { if (cb.getStrictness() == IcalCallback.conformanceStrict) { return Response.notOk(resp, failed, CalFacadeException.attendeesInPublish); } //if (cb.getStrictness() == IcalCallback.conformanceWarn) { // warn("Had attendees for PUBLISH"); //} } final Attendee attPr = (Attendee)prop; if (evinfo.getNewEvent() || !mergeAttendees) { chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { final String pUri = cb.getCaladdr(attPr.getValue()); if (pUri.equals(attUri)) { /* Only update for our own attendee * We're doing a PUT and this must be the attendee updating their * partstat. We don't allow them to change other attendees * whatever the PUT content says. */ chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { // Use the value we currently have boolean found = false; for (final BwAttendee att: ev.getAttendees()) { if (pUri.equals(att.getAttendeeUri())) { chg.addValue(pi, att.clone()); found = true; break; } } if (!found) { // An added attendee final BwAttendee att = IcalUtil .getAttendee(cb, attPr); att.setPartstat(IcalDefs.partstatValNeedsAction); chg.addValue(pi, att); } } } break; case BUSYTYPE: final int ibt = BwEvent.fromBusyTypeString(pval); if (chg.changed(pi, ev.getBusyType(), ibt)) { ev.setBusyType(ibt); } break; case CATEGORIES: /* ------------------- Categories -------------------- */ final Categories cats = (Categories)prop; final TextList cl = cats.getCategories(); String lang = IcalUtil.getLang(cats); if (cl != null) { /* Got some categories */ for (final String wd: cl) { if (wd == null) { continue; } final BwString key = new BwString(lang, wd); final var fcResp = cb.findCategory(key); final BwCategory cat; if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isNotFound()) { cat = BwCategory.makeCategory(); cat.setWord(key); cb.addCategory(cat); } else { cat = fcResp.getEntity(); } chg.addValue(pi, cat); } } break; case CLASS: /* ------------------- Class -------------------- */ if (chg.changed(pi, ev.getClassification(), pval)) { ev.setClassification(pval); } break; case COMMENT: /* ------------------- Comment -------------------- */ chg.addValue(pi, new BwString(null, pval)); break; case COMPLETED: /* ------------------- Completed -------------------- */ if (chg.changed(pi, ev.getCompleted(), pval)) { ev.setCompleted(pval); } break; case CONCEPT: /* ------------------- Concept -------------------- */ final Concept c = (Concept)prop; final String cval = c.getValue(); if (cval != null) { /* Got a concept */ chg.addValue(PropertyInfoIndex.XPROP, BwXproperty.makeIcalProperty("CONCEPT", null, cval)); } break; case CONTACT: /* ------------------- Contact -------------------- */ final String altrep = getAltRepPar(prop); lang = IcalUtil.getLang(prop); final String uid = getUidPar(prop); final BwString nm = new BwString(lang, pval); BwContact contact = null; if (uid != null) { final var fcResp = cb.getContact(uid); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { final var fcResp = cb.findContact(nm); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { contact = BwContact.makeContact(); contact.setCn(nm); contact.setLink(altrep); cb.addContact(contact); } else { contact.setCn(nm); contact.setLink(altrep); } chg.addValue(pi, contact); break; case CREATED: /* ------------------- Created -------------------- */ if (chg.changed(pi, ev.getCreated(), pval)) { ev.setCreated(pval); } break; case DESCRIPTION: /* ------------------- Description -------------------- */ if (chg.changed(pi, ev.getDescription(), pval)) { ev.setDescription(pval); } break; case DTEND: /* ------------------- DtEnd -------------------- */ break; case DTSTAMP: /* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval); break; case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE: /* -------------------- Due ------------------------ */ break; case DURATION: /* ------------------- Duration -------------------- */ break; case EXDATE: /* ------------------- ExDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case EXRULE: /* ------------------- ExRule -------------------- */ chg.addValue(pi, pval); break; case FREEBUSY: /* ------------------- freebusy -------------------- */ final FreeBusy fbusy = (FreeBusy)prop; final PeriodList perpl = fbusy.getPeriods(); final Parameter par = IcalUtil.getParameter(fbusy, "FBTYPE"); final int fbtype; if (par == null) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY)) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY_TENTATIVE)) { fbtype = BwFreeBusyComponent.typeBusyTentative; } else if (par.equals(FbType.BUSY_UNAVAILABLE)) { fbtype = BwFreeBusyComponent.typeBusyUnavailable; } else if (par.equals(FbType.FREE)) { fbtype = BwFreeBusyComponent.typeFree; } else { if (logger.debug()) { logger.debug("Unsupported parameter " + par.getName()); } return Response.notOk(resp, failed, "Unsupported parameter " + par.getName()); } final BwFreeBusyComponent fbc = new BwFreeBusyComponent(); fbc.setType(fbtype); for (final Period per : perpl) { fbc.addPeriod(per); } ev.addFreeBusyPeriod(fbc); break; case GEO: /* ------------------- Geo -------------------- */ final Geo g = (Geo)prop; final BwGeo geo = new BwGeo(g.getLatitude(), g.getLongitude()); if (chg.changed(pi, ev.getGeo(), geo)) { ev.setGeo(geo); } break; case LAST_MODIFIED: /* ------------------- LastModified -------------------- */ if (chg.changed(pi, ev.getLastmod(), pval)) { ev.setLastmod(pval); } break; case LOCATION: /* ------------------- Location -------------------- */ BwLocation loc = null; //String uid = getUidPar(prop); /* At the moment Mozilla lightning is broken and this leads to all * sorts of problems. if (uid != null) { loc = cb.getLocation(uid); } */ lang = IcalUtil.getLang(prop); BwString addr = null; if (pval != null) { if (loc == null) { addr = new BwString(lang, pval); final var fcResp = cb.findLocation(addr); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { loc = fcResp.getEntity(); } } if (loc == null) { loc = BwLocation.makeLocation(); loc.setAddress(addr); cb.addLocation(loc); } } final BwLocation evloc = ev.getLocation(); if (chg.changed(pi, evloc, loc)) { // CHGTBL - this only shows that it's a different location object ev.setLocation(loc); } else if ((loc != null) && (evloc != null)) { // See if the value is changed final String evval = evloc.getAddress().getValue(); final String inval = loc.getAddress().getValue(); if (!evval.equals(inval)) { chg.changed(pi, evval, inval); evloc.getAddress().setValue(inval); } } break; case ORGANIZER: /* ------------------- Organizer -------------------- */ final BwOrganizer org = IcalUtil.getOrganizer(cb, (Organizer)prop); final BwOrganizer evorg = ev.getOrganizer(); final BwOrganizer evorgCopy; if (evorg == null) { evorgCopy = null; } else { evorgCopy = (BwOrganizer)evorg.clone(); } if (chg.changed(pi, evorgCopy, org)) { if (evorg == null) { ev.setOrganizer(org); } else { evorg.update(org); } } break; case PERCENT_COMPLETE: /* ------------------- PercentComplete -------------------- */ Integer ival = ((PercentComplete)prop).getPercentage(); if (chg.changed(pi, ev.getPercentComplete(), ival)) { ev.setPercentComplete(ival); } break; case POLL_MODE: /* ------------------- Poll mode -------------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollMode(), sval)) { ev.setPollMode(sval); } break; case POLL_PROPERTIES: /* ------------------- Poll properties ---------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollProperties(), sval)) { ev.setPollProperties(sval); } break; case POLL_WINNER: /* ------------------- Poll winner -------------------- */ ival = ((PollWinner)prop).getPollwinner(); if (chg.changed(pi, ev.getPollWinner(), ival)) { ev.setPollWinner(ival); } break; case PRIORITY: /* ------------------- Priority -------------------- */ ival = ((Priority)prop).getLevel(); if (chg.changed(pi, ev.getPriority(), ival)) { ev.setPriority(ival); } break; case RDATE: /* ------------------- RDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case RECURRENCE_ID: /* ------------------- RecurrenceID -------------------- */ // Done above break; case RELATED_TO: /* ------------------- RelatedTo -------------------- */ final RelatedTo irelto = (RelatedTo)prop; final BwRelatedTo relto = new BwRelatedTo(); final String parval = IcalUtil.getParameterVal(irelto, "RELTYPE"); if (parval != null) { relto.setRelType(parval); } relto.setValue(irelto.getValue()); if (chg.changed(pi, ev.getRelatedTo(), relto)) { ev.setRelatedTo(relto); } break; case REQUEST_STATUS: /* ------------------- RequestStatus -------------------- */ final BwRequestStatus rs = BwRequestStatus .fromRequestStatus((RequestStatus)prop); chg.addValue(pi, rs); break; case RESOURCES: /* ------------------- Resources -------------------- */ final TextList rl = ((Resources)prop).getResources(); if (rl != null) { /* Got some resources */ lang = IcalUtil.getLang(prop); for (final String s: rl) { final BwString rsrc = new BwString(lang, s); chg.addValue(pi, rsrc); } } break; case RRULE: /* ------------------- RRule -------------------- */ chg.addValue(pi, pval); break; case SEQUENCE: /* ------------------- Sequence -------------------- */ final int seq = ((Sequence)prop).getSequenceNo(); if (seq != ev.getSequence()) { chg.changed(pi, ev.getSequence(), seq); ev.setSequence(seq); } break; case STATUS: /* ------------------- Status -------------------- */ if (chg.changed(pi, ev.getStatus(), pval)) { ev.setStatus(pval); } break; case SUMMARY: /* ------------------- Summary -------------------- */ if (chg.changed(pi, ev.getSummary(), pval)) { ev.setSummary(pval); } break; case TRANSP: /* ------------------- Transp -------------------- */ if (chg.changed(pi, ev.getPeruserTransparency( cb.getPrincipal() .getPrincipalRef()), pval)) { final BwXproperty pu = ev.setPeruserTransparency( cb.getPrincipal().getPrincipalRef(), pval); if (pu != null) { chg.addValue(PropertyInfoIndex.XPROP, pu); } } break; case UID: /* ------------------- Uid -------------------- */ /* We did this above */ break; case URL: /* ------------------- Url -------------------- */ if (chg.changed(pi, ev.getLink(), pval)) { ev.setLink(pval); } break; case XPROP: /* ------------------------- x-property --------------------------- */ final String name = prop.getName(); if (name.equalsIgnoreCase(BwXproperty.bedeworkCost)) { if (chg.changed(PropertyInfoIndex.COST, ev.getCost(), pval)) { ev.setCost(pval); } break; } if (name.equalsIgnoreCase(BwXproperty.xBedeworkCategories)) { if (checkCategory(cb, chg, ev, null, pval)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkLocation)) { if (checkLocation(cb, chg, ev, prop)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkContact)) { if (checkContact(cb, chg, ev, null, pval)) { break; } } /* See if this is an x-category that can be converted to a real category */ final XProperty xp = (XProperty)prop; chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(name, xp.getParameters() .toString(), pval)); break; default: if (logger.debug()) { logger.debug("Unsupported property with index " + pi + "; class " + prop.getClass() + " and value " + pval); } } } /* =================== Process sub-components =============== */ final ComponentList<Component> subComps; if (val instanceof ComponentContainer) { subComps = ((ComponentContainer<Component>)val).getComponents(); } else { subComps = null; } final Set<Integer> pids; if (vpoll) { pids = new TreeSet<>(); final BwEvent vp = evinfo.getEvent(); if (!Util.isEmpty(vp.getPollItems())) { vp.clearPollItems(); } } else { pids = null; } if (!Util.isEmpty(subComps)) { for (final var subComp: subComps) { if (subComp instanceof Available) { if (!(val instanceof VAvailability)) { return Response.error(resp, "AVAILABLE only valid in VAVAILABLE"); } final var avlResp = processAvailable(cb, cal, ical, (VAvailability)val, (Available)subComp, evinfo); if (!avlResp.isOk()) { return Response.fromResponse(resp, avlResp); } continue; } if (subComp instanceof Participant) { if (vpoll) { final var vresp = processVoter(cb, (VPoll)val, (Participant)subComp, evinfo, chg, mergeAttendees); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Participant object"); continue; } if (subComp instanceof VResource) { logger.warn("Unimplemented VResource object"); continue; } if (subComp instanceof VLocation) { logger.warn("Unimplemented VLocation object"); continue; } if (subComp instanceof VAlarm) { final var aresp = VAlarmUtil.processAlarm(cb, val, (VAlarm)subComp, ev, currentPrincipal, chg); if (!aresp.isOk()) { return Response.fromResponse(resp, aresp); } continue; } if (vpoll && (event || task)) { final var vresp = processCandidate((VPoll)val, subComp, evinfo, pids, chg); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Component object: " + subComp); } } /* Fix up timestamps. */ if (ev.getCreated() == null) { if (ev.getLastmod() != null) { ev.setCreated(ev.getLastmod()); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); } else { ev.updateDtstamp(); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } } if (ev.getLastmod() == null) { // created cannot be null now ev.setLastmod(ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } processTimezones(ev, ical, chg); /* Remove any recipients and originator */ if (ev.getRecipients() != null) { ev.getRecipients().clear(); } ev.setOriginator(null); if (hasXparams.value) { /* Save a text copy of the entire event as an x-property */ final Component valCopy = val.copy(); /* Remove potentially large values */ final Description desp = valCopy.getProperty(Property.DESCRIPTION); if (desp != null) { desp.setValue(null); } final Attach attachp = valCopy.getProperty(Property.ATTACH); // Don't store the entire attachment - we just need the parameters. if (attachp != null) { final Value v = attachp.getParameter(Parameter.VALUE); if (v != null) { attachp.setValue(String.valueOf(attachp.getValue().hashCode())); } } chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(BwXproperty.bedeworkIcal, null, valCopy.toString())); } chg.processChanges(ev, true, false); ev.setRecurring(ev.isRecurringEntity()); if (logger.debug()) { logger.debug(chg.toString()); logger.debug(ev.toString()); } if (masterEI != null) { // Just return notfound as this event is on its override list return Response.notFound(resp); } resp.setEntity(evinfo); return resp; } catch (final Throwable t) { if (logger.debug()) { logger.error(t); } return Response.error(resp, t); } }
NONSATD
true
break; case DUE: /* -------------------- Due ------------------------ */ break; case DURATION:
/* ------------------- DtEnd -------------------- */ break; case DTSTAMP: /* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval); break; case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE: /* -------------------- Due ------------------------ */ break; case DURATION: /* ------------------- Duration -------------------- */ break; case EXDATE: /* ------------------- ExDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case EXRULE:
ev.setCreated(pval); } break; case DESCRIPTION: /* ------------------- Description -------------------- */ if (chg.changed(pi, ev.getDescription(), pval)) { ev.setDescription(pval); } break; case DTEND: /* ------------------- DtEnd -------------------- */ break; case DTSTAMP: /* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval); break; case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE: /* -------------------- Due ------------------------ */ break; case DURATION: /* ------------------- Duration -------------------- */ break; case EXDATE: /* ------------------- ExDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case EXRULE: /* ------------------- ExRule -------------------- */ chg.addValue(pi, pval); break; case FREEBUSY: /* ------------------- freebusy -------------------- */ final FreeBusy fbusy = (FreeBusy)prop; final PeriodList perpl = fbusy.getPeriods(); final Parameter par = IcalUtil.getParameter(fbusy, "FBTYPE"); final int fbtype; if (par == null) {
7,893
43
/* ------------------- Duration -------------------- */
public static GetEntityResponse<EventInfo> toEvent( final IcalCallback cb, final BwCalendar cal, final Icalendar ical, final Component val, final boolean mergeAttendees) { final var resp = new GetEntityResponse<EventInfo>(); if (val == null) { return Response.notOk(resp, failed, "No component supplied"); } String currentPrincipal = null; final BwPrincipal principal = cb.getPrincipal(); if (principal != null) { currentPrincipal = principal.getPrincipalRef(); } final Holder<Boolean> hasXparams = new Holder<>(Boolean.FALSE); final int methodType = ical.getMethodType(); String attUri = null; if (mergeAttendees) { // We'll need this later. attUri = cb.getCaladdr(cb.getPrincipal().getPrincipalRef()); } final String colPath; if (cal == null) { colPath = null; } else { colPath = cal.getPath(); } try { final PropertyList<Property> pl = val.getProperties(); boolean vpoll = false; boolean event = false; boolean task = false; if (pl == null) { // Empty component return Response.notOk(resp, failed, "Empty component"); } final int entityType; if (val instanceof VEvent) { entityType = IcalDefs.entityTypeEvent; event = true; } else if (val instanceof VToDo) { entityType = IcalDefs.entityTypeTodo; task = true; } else if (val instanceof VJournal) { entityType = IcalDefs.entityTypeJournal; } else if (val instanceof VFreeBusy) { entityType = IcalDefs.entityTypeFreeAndBusy; } else if (val instanceof VAvailability) { entityType = IcalDefs.entityTypeVavailability; } else if (val instanceof Available) { entityType = IcalDefs.entityTypeAvailable; } else if (val instanceof VPoll) { entityType = IcalDefs.entityTypeVpoll; vpoll = true; } else { return Response.error(resp, "org.bedework.invalid.component.type: " + val.getName()); } // Get the guid from the component String guid = null; final Uid uidp = pl.getProperty(Property.UID); if (uidp != null) { testXparams(uidp, hasXparams); guid = uidp.getValue(); } if (guid == null) { /* XXX A guid is required - but are there devices out there without a * guid - and if so how do we handle it? */ return Response.notOk(resp, failed, CalFacadeException.noGuid); } /* See if we have a recurrence id */ BwDateTime ridObj = null; String rid = null; TimeZone ridTz = null; final RecurrenceId ridp = pl.getProperty(Property.RECURRENCE_ID); if (ridp != null) { testXparams(ridp, hasXparams); ridObj = BwDateTime.makeBwDateTime(ridp); if (ridObj.getRange() != null) { /* XXX What do I do with it? */ logger.warn("TRANS-TO_EVENT: Got a recurrence id range"); } rid = ridObj.getDate(); } EventInfo masterEI = null; EventInfo evinfo = null; final BwEvent ev; /* If we have a recurrence id see if we already have the master (we should * get a master + all its overrides). * * If so find the override and use the annnotation or if no override, * make one. * * If no override retrieve the event, add it to our table and then locate the * annotation. * * If there is no annotation, create one. * * It's possible we have been sent 'detached' instances of a recurring * event. This may happen if we are invited to one or more instances of a * meeting. In this case we try to retrieve the master and if it doesn't * exist we manufacture one. We consider such an instance an update to * that instance only and leave the others alone. */ /* We need this in a couple of places */ final DtStart dtStart = pl.getProperty(Property.DTSTART); /* if (rid != null) { // See if we have a new master event. If so create a proxy to that event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI == null) { masterEI = makeNewEvent(cb, chg, entityType, guid, cal); BwEvent e = masterEI.getEvent(); // XXX This seems bogus DtStart mdtStart; String bogusDate = "19980118T230000"; if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + "Z"); } else if (dtStart.getTimeZone() == null) { mdtStart = new DtStart(bogusDate); } else { mdtStart = new DtStart(bogusDate + "Z", dtStart.getTimeZone()); } setDates(e, mdtStart, null, null, chg); e.setRecurring(true); e.addRdate(ridObj); e.setSuppressed(true); ical.addComponent(masterEI); } if (masterEI != null) { evinfo = masterEI.findOverride(rid); } } */ /* If this is a recurrence instance see if we can find the master We only need this because the master may follow the overrides. */ if (rid != null) { // See if we have a new master event. If so create a proxy to this event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI != null) { evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; } } if ((evinfo == null) && (cal != null) && (cal.getCalType() != BwCalendar.calTypeInbox) && (cal.getCalType() != BwCalendar.calTypePendingInbox) && (cal.getCalType() != BwCalendar.calTypeOutbox)) { if (logger.debug()) { logger.debug("TRANS-TO_EVENT: try to fetch event with guid=" + guid); } final GetEntitiesResponse<EventInfo> eisResp = cb.getEvent(colPath, guid); if (eisResp.isError()) { return Response.fromResponse(resp, eisResp); } final var eis = eisResp.getEntities(); if (!Util.isEmpty(eis)) { if (eis.size() > 1) { // DORECUR - wrong again return Response.notOk(resp, failed, "More than one event returned for guid."); } evinfo = eis.iterator().next(); } if (logger.debug()) { if (evinfo != null) { logger.debug("TRANS-TO_EVENT: fetched event with guid"); } else { logger.debug("TRANS-TO_EVENT: did not find event with guid"); } } if (evinfo != null) { if (rid != null) { // We just retrieved it's master masterEI = evinfo; masterEI.setInstanceOnly(true); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; ical.addComponent(masterEI); } else if (methodType == ScheduleMethods.methodTypeCancel) { // This should never have an rid for cancel of entire event. evinfo.setInstanceOnly(evinfo.getEvent().getSuppressed()); } else { // Presumably sent an update for the entire event. No longer suppressed master evinfo.getEvent().setSuppressed(false); } } else if (rid != null) { /* Manufacture a master for the instance */ masterEI = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); final BwEvent e = masterEI.getEvent(); // XXX This seems bogus final DtStart mdtStart; final String bogusDate = "19980118"; final String bogusTime = "T230000"; // Base dtstart on the recurrence id. final boolean isDateType = ridObj.getDateType(); if (isDateType) { mdtStart = new DtStart(new Date(bogusDate)); } else if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + bogusTime + "Z"); } else if (ridObj.getTzid() == null) { mdtStart = new DtStart(bogusDate + bogusTime); } else { mdtStart = new DtStart(bogusDate + bogusTime, Timezones.getTz(ridObj.getTzid())); } IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), masterEI, mdtStart, null, null); e.setRecurring(true); // e.addRdate(ridObj); final var sum = (Summary)pl.getProperty(Property.SUMMARY); e.setSummary(sum.getValue()); e.setSuppressed(true); ical.addComponent(masterEI); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; masterEI.setInstanceOnly(rid != null); } } if (evinfo == null) { evinfo = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); } else if (evinfo.getEvent().getEntityType() != entityType) { return Response.notOk(resp, failed, "org.bedework.mismatched.entity.type: " + val); } final ChangeTable chg = evinfo.getChangeset( cb.getPrincipal().getPrincipalRef()); if (rid != null) { final String evrid = evinfo.getEvent().getRecurrenceId(); if ((evrid == null) || (!evrid.equals(rid))) { logger. warn("Mismatched rid ev=" + evrid + " expected " + rid); chg.changed(PropertyInfoIndex.RECURRENCE_ID, evrid, rid); // XXX spurious??? } if (masterEI.getEvent().getSuppressed()) { masterEI.getEvent().addRdate(ridObj); } } ev = evinfo.getEvent(); ev.setScheduleMethod(methodType); DtEnd dtEnd = null; if (entityType == IcalDefs.entityTypeTodo) { final Due due = pl.getProperty(Property.DUE); if (due != null ) { dtEnd = new DtEnd(due.getParameters(), due.getValue()); } } else { dtEnd = pl.getProperty(Property.DTEND); } final Duration duration = pl.getProperty(Property.DURATION); IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), evinfo, dtStart, dtEnd, duration); for (final Property prop: pl) { testXparams(prop, hasXparams); //debug("ical prop " + prop.getClass().getName()); String pval = prop.getValue(); if ((pval != null) && (pval.length() == 0)) { pval = null; } final PropertyInfoIndex pi; if (prop instanceof XProperty) { pi = PropertyInfoIndex.XPROP; } else { pi = PropertyInfoIndex.fromName(prop.getName()); } if (pi == null) { logger.debug("Unknown property with name " + prop.getName() + " class " + prop.getClass() + " and value " + pval); continue; } chg.present(pi); switch (pi) { case ACCEPT_RESPONSE: /* ------------------- Accept Response -------------------- */ String sval = prop.getValue(); if (chg.changed(pi, ev.getPollAcceptResponse(), sval)) { ev.setPollAcceptResponse(sval); } break; case ATTACH: /* ------------------- Attachment -------------------- */ chg.addValue(pi, IcalUtil.getAttachment((Attach)prop)); break; case ATTENDEE: /* ------------------- Attendee -------------------- */ if (methodType == ScheduleMethods.methodTypePublish) { if (cb.getStrictness() == IcalCallback.conformanceStrict) { return Response.notOk(resp, failed, CalFacadeException.attendeesInPublish); } //if (cb.getStrictness() == IcalCallback.conformanceWarn) { // warn("Had attendees for PUBLISH"); //} } final Attendee attPr = (Attendee)prop; if (evinfo.getNewEvent() || !mergeAttendees) { chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { final String pUri = cb.getCaladdr(attPr.getValue()); if (pUri.equals(attUri)) { /* Only update for our own attendee * We're doing a PUT and this must be the attendee updating their * partstat. We don't allow them to change other attendees * whatever the PUT content says. */ chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { // Use the value we currently have boolean found = false; for (final BwAttendee att: ev.getAttendees()) { if (pUri.equals(att.getAttendeeUri())) { chg.addValue(pi, att.clone()); found = true; break; } } if (!found) { // An added attendee final BwAttendee att = IcalUtil .getAttendee(cb, attPr); att.setPartstat(IcalDefs.partstatValNeedsAction); chg.addValue(pi, att); } } } break; case BUSYTYPE: final int ibt = BwEvent.fromBusyTypeString(pval); if (chg.changed(pi, ev.getBusyType(), ibt)) { ev.setBusyType(ibt); } break; case CATEGORIES: /* ------------------- Categories -------------------- */ final Categories cats = (Categories)prop; final TextList cl = cats.getCategories(); String lang = IcalUtil.getLang(cats); if (cl != null) { /* Got some categories */ for (final String wd: cl) { if (wd == null) { continue; } final BwString key = new BwString(lang, wd); final var fcResp = cb.findCategory(key); final BwCategory cat; if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isNotFound()) { cat = BwCategory.makeCategory(); cat.setWord(key); cb.addCategory(cat); } else { cat = fcResp.getEntity(); } chg.addValue(pi, cat); } } break; case CLASS: /* ------------------- Class -------------------- */ if (chg.changed(pi, ev.getClassification(), pval)) { ev.setClassification(pval); } break; case COMMENT: /* ------------------- Comment -------------------- */ chg.addValue(pi, new BwString(null, pval)); break; case COMPLETED: /* ------------------- Completed -------------------- */ if (chg.changed(pi, ev.getCompleted(), pval)) { ev.setCompleted(pval); } break; case CONCEPT: /* ------------------- Concept -------------------- */ final Concept c = (Concept)prop; final String cval = c.getValue(); if (cval != null) { /* Got a concept */ chg.addValue(PropertyInfoIndex.XPROP, BwXproperty.makeIcalProperty("CONCEPT", null, cval)); } break; case CONTACT: /* ------------------- Contact -------------------- */ final String altrep = getAltRepPar(prop); lang = IcalUtil.getLang(prop); final String uid = getUidPar(prop); final BwString nm = new BwString(lang, pval); BwContact contact = null; if (uid != null) { final var fcResp = cb.getContact(uid); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { final var fcResp = cb.findContact(nm); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { contact = BwContact.makeContact(); contact.setCn(nm); contact.setLink(altrep); cb.addContact(contact); } else { contact.setCn(nm); contact.setLink(altrep); } chg.addValue(pi, contact); break; case CREATED: /* ------------------- Created -------------------- */ if (chg.changed(pi, ev.getCreated(), pval)) { ev.setCreated(pval); } break; case DESCRIPTION: /* ------------------- Description -------------------- */ if (chg.changed(pi, ev.getDescription(), pval)) { ev.setDescription(pval); } break; case DTEND: /* ------------------- DtEnd -------------------- */ break; case DTSTAMP: /* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval); break; case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE: /* -------------------- Due ------------------------ */ break; case DURATION: /* ------------------- Duration -------------------- */ break; case EXDATE: /* ------------------- ExDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case EXRULE: /* ------------------- ExRule -------------------- */ chg.addValue(pi, pval); break; case FREEBUSY: /* ------------------- freebusy -------------------- */ final FreeBusy fbusy = (FreeBusy)prop; final PeriodList perpl = fbusy.getPeriods(); final Parameter par = IcalUtil.getParameter(fbusy, "FBTYPE"); final int fbtype; if (par == null) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY)) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY_TENTATIVE)) { fbtype = BwFreeBusyComponent.typeBusyTentative; } else if (par.equals(FbType.BUSY_UNAVAILABLE)) { fbtype = BwFreeBusyComponent.typeBusyUnavailable; } else if (par.equals(FbType.FREE)) { fbtype = BwFreeBusyComponent.typeFree; } else { if (logger.debug()) { logger.debug("Unsupported parameter " + par.getName()); } return Response.notOk(resp, failed, "Unsupported parameter " + par.getName()); } final BwFreeBusyComponent fbc = new BwFreeBusyComponent(); fbc.setType(fbtype); for (final Period per : perpl) { fbc.addPeriod(per); } ev.addFreeBusyPeriod(fbc); break; case GEO: /* ------------------- Geo -------------------- */ final Geo g = (Geo)prop; final BwGeo geo = new BwGeo(g.getLatitude(), g.getLongitude()); if (chg.changed(pi, ev.getGeo(), geo)) { ev.setGeo(geo); } break; case LAST_MODIFIED: /* ------------------- LastModified -------------------- */ if (chg.changed(pi, ev.getLastmod(), pval)) { ev.setLastmod(pval); } break; case LOCATION: /* ------------------- Location -------------------- */ BwLocation loc = null; //String uid = getUidPar(prop); /* At the moment Mozilla lightning is broken and this leads to all * sorts of problems. if (uid != null) { loc = cb.getLocation(uid); } */ lang = IcalUtil.getLang(prop); BwString addr = null; if (pval != null) { if (loc == null) { addr = new BwString(lang, pval); final var fcResp = cb.findLocation(addr); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { loc = fcResp.getEntity(); } } if (loc == null) { loc = BwLocation.makeLocation(); loc.setAddress(addr); cb.addLocation(loc); } } final BwLocation evloc = ev.getLocation(); if (chg.changed(pi, evloc, loc)) { // CHGTBL - this only shows that it's a different location object ev.setLocation(loc); } else if ((loc != null) && (evloc != null)) { // See if the value is changed final String evval = evloc.getAddress().getValue(); final String inval = loc.getAddress().getValue(); if (!evval.equals(inval)) { chg.changed(pi, evval, inval); evloc.getAddress().setValue(inval); } } break; case ORGANIZER: /* ------------------- Organizer -------------------- */ final BwOrganizer org = IcalUtil.getOrganizer(cb, (Organizer)prop); final BwOrganizer evorg = ev.getOrganizer(); final BwOrganizer evorgCopy; if (evorg == null) { evorgCopy = null; } else { evorgCopy = (BwOrganizer)evorg.clone(); } if (chg.changed(pi, evorgCopy, org)) { if (evorg == null) { ev.setOrganizer(org); } else { evorg.update(org); } } break; case PERCENT_COMPLETE: /* ------------------- PercentComplete -------------------- */ Integer ival = ((PercentComplete)prop).getPercentage(); if (chg.changed(pi, ev.getPercentComplete(), ival)) { ev.setPercentComplete(ival); } break; case POLL_MODE: /* ------------------- Poll mode -------------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollMode(), sval)) { ev.setPollMode(sval); } break; case POLL_PROPERTIES: /* ------------------- Poll properties ---------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollProperties(), sval)) { ev.setPollProperties(sval); } break; case POLL_WINNER: /* ------------------- Poll winner -------------------- */ ival = ((PollWinner)prop).getPollwinner(); if (chg.changed(pi, ev.getPollWinner(), ival)) { ev.setPollWinner(ival); } break; case PRIORITY: /* ------------------- Priority -------------------- */ ival = ((Priority)prop).getLevel(); if (chg.changed(pi, ev.getPriority(), ival)) { ev.setPriority(ival); } break; case RDATE: /* ------------------- RDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case RECURRENCE_ID: /* ------------------- RecurrenceID -------------------- */ // Done above break; case RELATED_TO: /* ------------------- RelatedTo -------------------- */ final RelatedTo irelto = (RelatedTo)prop; final BwRelatedTo relto = new BwRelatedTo(); final String parval = IcalUtil.getParameterVal(irelto, "RELTYPE"); if (parval != null) { relto.setRelType(parval); } relto.setValue(irelto.getValue()); if (chg.changed(pi, ev.getRelatedTo(), relto)) { ev.setRelatedTo(relto); } break; case REQUEST_STATUS: /* ------------------- RequestStatus -------------------- */ final BwRequestStatus rs = BwRequestStatus .fromRequestStatus((RequestStatus)prop); chg.addValue(pi, rs); break; case RESOURCES: /* ------------------- Resources -------------------- */ final TextList rl = ((Resources)prop).getResources(); if (rl != null) { /* Got some resources */ lang = IcalUtil.getLang(prop); for (final String s: rl) { final BwString rsrc = new BwString(lang, s); chg.addValue(pi, rsrc); } } break; case RRULE: /* ------------------- RRule -------------------- */ chg.addValue(pi, pval); break; case SEQUENCE: /* ------------------- Sequence -------------------- */ final int seq = ((Sequence)prop).getSequenceNo(); if (seq != ev.getSequence()) { chg.changed(pi, ev.getSequence(), seq); ev.setSequence(seq); } break; case STATUS: /* ------------------- Status -------------------- */ if (chg.changed(pi, ev.getStatus(), pval)) { ev.setStatus(pval); } break; case SUMMARY: /* ------------------- Summary -------------------- */ if (chg.changed(pi, ev.getSummary(), pval)) { ev.setSummary(pval); } break; case TRANSP: /* ------------------- Transp -------------------- */ if (chg.changed(pi, ev.getPeruserTransparency( cb.getPrincipal() .getPrincipalRef()), pval)) { final BwXproperty pu = ev.setPeruserTransparency( cb.getPrincipal().getPrincipalRef(), pval); if (pu != null) { chg.addValue(PropertyInfoIndex.XPROP, pu); } } break; case UID: /* ------------------- Uid -------------------- */ /* We did this above */ break; case URL: /* ------------------- Url -------------------- */ if (chg.changed(pi, ev.getLink(), pval)) { ev.setLink(pval); } break; case XPROP: /* ------------------------- x-property --------------------------- */ final String name = prop.getName(); if (name.equalsIgnoreCase(BwXproperty.bedeworkCost)) { if (chg.changed(PropertyInfoIndex.COST, ev.getCost(), pval)) { ev.setCost(pval); } break; } if (name.equalsIgnoreCase(BwXproperty.xBedeworkCategories)) { if (checkCategory(cb, chg, ev, null, pval)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkLocation)) { if (checkLocation(cb, chg, ev, prop)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkContact)) { if (checkContact(cb, chg, ev, null, pval)) { break; } } /* See if this is an x-category that can be converted to a real category */ final XProperty xp = (XProperty)prop; chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(name, xp.getParameters() .toString(), pval)); break; default: if (logger.debug()) { logger.debug("Unsupported property with index " + pi + "; class " + prop.getClass() + " and value " + pval); } } } /* =================== Process sub-components =============== */ final ComponentList<Component> subComps; if (val instanceof ComponentContainer) { subComps = ((ComponentContainer<Component>)val).getComponents(); } else { subComps = null; } final Set<Integer> pids; if (vpoll) { pids = new TreeSet<>(); final BwEvent vp = evinfo.getEvent(); if (!Util.isEmpty(vp.getPollItems())) { vp.clearPollItems(); } } else { pids = null; } if (!Util.isEmpty(subComps)) { for (final var subComp: subComps) { if (subComp instanceof Available) { if (!(val instanceof VAvailability)) { return Response.error(resp, "AVAILABLE only valid in VAVAILABLE"); } final var avlResp = processAvailable(cb, cal, ical, (VAvailability)val, (Available)subComp, evinfo); if (!avlResp.isOk()) { return Response.fromResponse(resp, avlResp); } continue; } if (subComp instanceof Participant) { if (vpoll) { final var vresp = processVoter(cb, (VPoll)val, (Participant)subComp, evinfo, chg, mergeAttendees); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Participant object"); continue; } if (subComp instanceof VResource) { logger.warn("Unimplemented VResource object"); continue; } if (subComp instanceof VLocation) { logger.warn("Unimplemented VLocation object"); continue; } if (subComp instanceof VAlarm) { final var aresp = VAlarmUtil.processAlarm(cb, val, (VAlarm)subComp, ev, currentPrincipal, chg); if (!aresp.isOk()) { return Response.fromResponse(resp, aresp); } continue; } if (vpoll && (event || task)) { final var vresp = processCandidate((VPoll)val, subComp, evinfo, pids, chg); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Component object: " + subComp); } } /* Fix up timestamps. */ if (ev.getCreated() == null) { if (ev.getLastmod() != null) { ev.setCreated(ev.getLastmod()); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); } else { ev.updateDtstamp(); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } } if (ev.getLastmod() == null) { // created cannot be null now ev.setLastmod(ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } processTimezones(ev, ical, chg); /* Remove any recipients and originator */ if (ev.getRecipients() != null) { ev.getRecipients().clear(); } ev.setOriginator(null); if (hasXparams.value) { /* Save a text copy of the entire event as an x-property */ final Component valCopy = val.copy(); /* Remove potentially large values */ final Description desp = valCopy.getProperty(Property.DESCRIPTION); if (desp != null) { desp.setValue(null); } final Attach attachp = valCopy.getProperty(Property.ATTACH); // Don't store the entire attachment - we just need the parameters. if (attachp != null) { final Value v = attachp.getParameter(Parameter.VALUE); if (v != null) { attachp.setValue(String.valueOf(attachp.getValue().hashCode())); } } chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(BwXproperty.bedeworkIcal, null, valCopy.toString())); } chg.processChanges(ev, true, false); ev.setRecurring(ev.isRecurringEntity()); if (logger.debug()) { logger.debug(chg.toString()); logger.debug(ev.toString()); } if (masterEI != null) { // Just return notfound as this event is on its override list return Response.notFound(resp); } resp.setEntity(evinfo); return resp; } catch (final Throwable t) { if (logger.debug()) { logger.error(t); } return Response.error(resp, t); } }
NONSATD
true
break; case DURATION: /* ------------------- Duration -------------------- */ break; case EXDATE:
/* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval); break; case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE: /* -------------------- Due ------------------------ */ break; case DURATION: /* ------------------- Duration -------------------- */ break; case EXDATE: /* ------------------- ExDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case EXRULE: /* ------------------- ExRule -------------------- */ chg.addValue(pi, pval); break;
case DESCRIPTION: /* ------------------- Description -------------------- */ if (chg.changed(pi, ev.getDescription(), pval)) { ev.setDescription(pval); } break; case DTEND: /* ------------------- DtEnd -------------------- */ break; case DTSTAMP: /* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval); break; case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE: /* -------------------- Due ------------------------ */ break; case DURATION: /* ------------------- Duration -------------------- */ break; case EXDATE: /* ------------------- ExDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case EXRULE: /* ------------------- ExRule -------------------- */ chg.addValue(pi, pval); break; case FREEBUSY: /* ------------------- freebusy -------------------- */ final FreeBusy fbusy = (FreeBusy)prop; final PeriodList perpl = fbusy.getPeriods(); final Parameter par = IcalUtil.getParameter(fbusy, "FBTYPE"); final int fbtype; if (par == null) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY)) { fbtype = BwFreeBusyComponent.typeBusy;
7,893
44
/* ------------------- ExDate -------------------- */
public static GetEntityResponse<EventInfo> toEvent( final IcalCallback cb, final BwCalendar cal, final Icalendar ical, final Component val, final boolean mergeAttendees) { final var resp = new GetEntityResponse<EventInfo>(); if (val == null) { return Response.notOk(resp, failed, "No component supplied"); } String currentPrincipal = null; final BwPrincipal principal = cb.getPrincipal(); if (principal != null) { currentPrincipal = principal.getPrincipalRef(); } final Holder<Boolean> hasXparams = new Holder<>(Boolean.FALSE); final int methodType = ical.getMethodType(); String attUri = null; if (mergeAttendees) { // We'll need this later. attUri = cb.getCaladdr(cb.getPrincipal().getPrincipalRef()); } final String colPath; if (cal == null) { colPath = null; } else { colPath = cal.getPath(); } try { final PropertyList<Property> pl = val.getProperties(); boolean vpoll = false; boolean event = false; boolean task = false; if (pl == null) { // Empty component return Response.notOk(resp, failed, "Empty component"); } final int entityType; if (val instanceof VEvent) { entityType = IcalDefs.entityTypeEvent; event = true; } else if (val instanceof VToDo) { entityType = IcalDefs.entityTypeTodo; task = true; } else if (val instanceof VJournal) { entityType = IcalDefs.entityTypeJournal; } else if (val instanceof VFreeBusy) { entityType = IcalDefs.entityTypeFreeAndBusy; } else if (val instanceof VAvailability) { entityType = IcalDefs.entityTypeVavailability; } else if (val instanceof Available) { entityType = IcalDefs.entityTypeAvailable; } else if (val instanceof VPoll) { entityType = IcalDefs.entityTypeVpoll; vpoll = true; } else { return Response.error(resp, "org.bedework.invalid.component.type: " + val.getName()); } // Get the guid from the component String guid = null; final Uid uidp = pl.getProperty(Property.UID); if (uidp != null) { testXparams(uidp, hasXparams); guid = uidp.getValue(); } if (guid == null) { /* XXX A guid is required - but are there devices out there without a * guid - and if so how do we handle it? */ return Response.notOk(resp, failed, CalFacadeException.noGuid); } /* See if we have a recurrence id */ BwDateTime ridObj = null; String rid = null; TimeZone ridTz = null; final RecurrenceId ridp = pl.getProperty(Property.RECURRENCE_ID); if (ridp != null) { testXparams(ridp, hasXparams); ridObj = BwDateTime.makeBwDateTime(ridp); if (ridObj.getRange() != null) { /* XXX What do I do with it? */ logger.warn("TRANS-TO_EVENT: Got a recurrence id range"); } rid = ridObj.getDate(); } EventInfo masterEI = null; EventInfo evinfo = null; final BwEvent ev; /* If we have a recurrence id see if we already have the master (we should * get a master + all its overrides). * * If so find the override and use the annnotation or if no override, * make one. * * If no override retrieve the event, add it to our table and then locate the * annotation. * * If there is no annotation, create one. * * It's possible we have been sent 'detached' instances of a recurring * event. This may happen if we are invited to one or more instances of a * meeting. In this case we try to retrieve the master and if it doesn't * exist we manufacture one. We consider such an instance an update to * that instance only and leave the others alone. */ /* We need this in a couple of places */ final DtStart dtStart = pl.getProperty(Property.DTSTART); /* if (rid != null) { // See if we have a new master event. If so create a proxy to that event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI == null) { masterEI = makeNewEvent(cb, chg, entityType, guid, cal); BwEvent e = masterEI.getEvent(); // XXX This seems bogus DtStart mdtStart; String bogusDate = "19980118T230000"; if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + "Z"); } else if (dtStart.getTimeZone() == null) { mdtStart = new DtStart(bogusDate); } else { mdtStart = new DtStart(bogusDate + "Z", dtStart.getTimeZone()); } setDates(e, mdtStart, null, null, chg); e.setRecurring(true); e.addRdate(ridObj); e.setSuppressed(true); ical.addComponent(masterEI); } if (masterEI != null) { evinfo = masterEI.findOverride(rid); } } */ /* If this is a recurrence instance see if we can find the master We only need this because the master may follow the overrides. */ if (rid != null) { // See if we have a new master event. If so create a proxy to this event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI != null) { evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; } } if ((evinfo == null) && (cal != null) && (cal.getCalType() != BwCalendar.calTypeInbox) && (cal.getCalType() != BwCalendar.calTypePendingInbox) && (cal.getCalType() != BwCalendar.calTypeOutbox)) { if (logger.debug()) { logger.debug("TRANS-TO_EVENT: try to fetch event with guid=" + guid); } final GetEntitiesResponse<EventInfo> eisResp = cb.getEvent(colPath, guid); if (eisResp.isError()) { return Response.fromResponse(resp, eisResp); } final var eis = eisResp.getEntities(); if (!Util.isEmpty(eis)) { if (eis.size() > 1) { // DORECUR - wrong again return Response.notOk(resp, failed, "More than one event returned for guid."); } evinfo = eis.iterator().next(); } if (logger.debug()) { if (evinfo != null) { logger.debug("TRANS-TO_EVENT: fetched event with guid"); } else { logger.debug("TRANS-TO_EVENT: did not find event with guid"); } } if (evinfo != null) { if (rid != null) { // We just retrieved it's master masterEI = evinfo; masterEI.setInstanceOnly(true); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; ical.addComponent(masterEI); } else if (methodType == ScheduleMethods.methodTypeCancel) { // This should never have an rid for cancel of entire event. evinfo.setInstanceOnly(evinfo.getEvent().getSuppressed()); } else { // Presumably sent an update for the entire event. No longer suppressed master evinfo.getEvent().setSuppressed(false); } } else if (rid != null) { /* Manufacture a master for the instance */ masterEI = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); final BwEvent e = masterEI.getEvent(); // XXX This seems bogus final DtStart mdtStart; final String bogusDate = "19980118"; final String bogusTime = "T230000"; // Base dtstart on the recurrence id. final boolean isDateType = ridObj.getDateType(); if (isDateType) { mdtStart = new DtStart(new Date(bogusDate)); } else if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + bogusTime + "Z"); } else if (ridObj.getTzid() == null) { mdtStart = new DtStart(bogusDate + bogusTime); } else { mdtStart = new DtStart(bogusDate + bogusTime, Timezones.getTz(ridObj.getTzid())); } IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), masterEI, mdtStart, null, null); e.setRecurring(true); // e.addRdate(ridObj); final var sum = (Summary)pl.getProperty(Property.SUMMARY); e.setSummary(sum.getValue()); e.setSuppressed(true); ical.addComponent(masterEI); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; masterEI.setInstanceOnly(rid != null); } } if (evinfo == null) { evinfo = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); } else if (evinfo.getEvent().getEntityType() != entityType) { return Response.notOk(resp, failed, "org.bedework.mismatched.entity.type: " + val); } final ChangeTable chg = evinfo.getChangeset( cb.getPrincipal().getPrincipalRef()); if (rid != null) { final String evrid = evinfo.getEvent().getRecurrenceId(); if ((evrid == null) || (!evrid.equals(rid))) { logger. warn("Mismatched rid ev=" + evrid + " expected " + rid); chg.changed(PropertyInfoIndex.RECURRENCE_ID, evrid, rid); // XXX spurious??? } if (masterEI.getEvent().getSuppressed()) { masterEI.getEvent().addRdate(ridObj); } } ev = evinfo.getEvent(); ev.setScheduleMethod(methodType); DtEnd dtEnd = null; if (entityType == IcalDefs.entityTypeTodo) { final Due due = pl.getProperty(Property.DUE); if (due != null ) { dtEnd = new DtEnd(due.getParameters(), due.getValue()); } } else { dtEnd = pl.getProperty(Property.DTEND); } final Duration duration = pl.getProperty(Property.DURATION); IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), evinfo, dtStart, dtEnd, duration); for (final Property prop: pl) { testXparams(prop, hasXparams); //debug("ical prop " + prop.getClass().getName()); String pval = prop.getValue(); if ((pval != null) && (pval.length() == 0)) { pval = null; } final PropertyInfoIndex pi; if (prop instanceof XProperty) { pi = PropertyInfoIndex.XPROP; } else { pi = PropertyInfoIndex.fromName(prop.getName()); } if (pi == null) { logger.debug("Unknown property with name " + prop.getName() + " class " + prop.getClass() + " and value " + pval); continue; } chg.present(pi); switch (pi) { case ACCEPT_RESPONSE: /* ------------------- Accept Response -------------------- */ String sval = prop.getValue(); if (chg.changed(pi, ev.getPollAcceptResponse(), sval)) { ev.setPollAcceptResponse(sval); } break; case ATTACH: /* ------------------- Attachment -------------------- */ chg.addValue(pi, IcalUtil.getAttachment((Attach)prop)); break; case ATTENDEE: /* ------------------- Attendee -------------------- */ if (methodType == ScheduleMethods.methodTypePublish) { if (cb.getStrictness() == IcalCallback.conformanceStrict) { return Response.notOk(resp, failed, CalFacadeException.attendeesInPublish); } //if (cb.getStrictness() == IcalCallback.conformanceWarn) { // warn("Had attendees for PUBLISH"); //} } final Attendee attPr = (Attendee)prop; if (evinfo.getNewEvent() || !mergeAttendees) { chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { final String pUri = cb.getCaladdr(attPr.getValue()); if (pUri.equals(attUri)) { /* Only update for our own attendee * We're doing a PUT and this must be the attendee updating their * partstat. We don't allow them to change other attendees * whatever the PUT content says. */ chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { // Use the value we currently have boolean found = false; for (final BwAttendee att: ev.getAttendees()) { if (pUri.equals(att.getAttendeeUri())) { chg.addValue(pi, att.clone()); found = true; break; } } if (!found) { // An added attendee final BwAttendee att = IcalUtil .getAttendee(cb, attPr); att.setPartstat(IcalDefs.partstatValNeedsAction); chg.addValue(pi, att); } } } break; case BUSYTYPE: final int ibt = BwEvent.fromBusyTypeString(pval); if (chg.changed(pi, ev.getBusyType(), ibt)) { ev.setBusyType(ibt); } break; case CATEGORIES: /* ------------------- Categories -------------------- */ final Categories cats = (Categories)prop; final TextList cl = cats.getCategories(); String lang = IcalUtil.getLang(cats); if (cl != null) { /* Got some categories */ for (final String wd: cl) { if (wd == null) { continue; } final BwString key = new BwString(lang, wd); final var fcResp = cb.findCategory(key); final BwCategory cat; if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isNotFound()) { cat = BwCategory.makeCategory(); cat.setWord(key); cb.addCategory(cat); } else { cat = fcResp.getEntity(); } chg.addValue(pi, cat); } } break; case CLASS: /* ------------------- Class -------------------- */ if (chg.changed(pi, ev.getClassification(), pval)) { ev.setClassification(pval); } break; case COMMENT: /* ------------------- Comment -------------------- */ chg.addValue(pi, new BwString(null, pval)); break; case COMPLETED: /* ------------------- Completed -------------------- */ if (chg.changed(pi, ev.getCompleted(), pval)) { ev.setCompleted(pval); } break; case CONCEPT: /* ------------------- Concept -------------------- */ final Concept c = (Concept)prop; final String cval = c.getValue(); if (cval != null) { /* Got a concept */ chg.addValue(PropertyInfoIndex.XPROP, BwXproperty.makeIcalProperty("CONCEPT", null, cval)); } break; case CONTACT: /* ------------------- Contact -------------------- */ final String altrep = getAltRepPar(prop); lang = IcalUtil.getLang(prop); final String uid = getUidPar(prop); final BwString nm = new BwString(lang, pval); BwContact contact = null; if (uid != null) { final var fcResp = cb.getContact(uid); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { final var fcResp = cb.findContact(nm); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { contact = BwContact.makeContact(); contact.setCn(nm); contact.setLink(altrep); cb.addContact(contact); } else { contact.setCn(nm); contact.setLink(altrep); } chg.addValue(pi, contact); break; case CREATED: /* ------------------- Created -------------------- */ if (chg.changed(pi, ev.getCreated(), pval)) { ev.setCreated(pval); } break; case DESCRIPTION: /* ------------------- Description -------------------- */ if (chg.changed(pi, ev.getDescription(), pval)) { ev.setDescription(pval); } break; case DTEND: /* ------------------- DtEnd -------------------- */ break; case DTSTAMP: /* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval); break; case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE: /* -------------------- Due ------------------------ */ break; case DURATION: /* ------------------- Duration -------------------- */ break; case EXDATE: /* ------------------- ExDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case EXRULE: /* ------------------- ExRule -------------------- */ chg.addValue(pi, pval); break; case FREEBUSY: /* ------------------- freebusy -------------------- */ final FreeBusy fbusy = (FreeBusy)prop; final PeriodList perpl = fbusy.getPeriods(); final Parameter par = IcalUtil.getParameter(fbusy, "FBTYPE"); final int fbtype; if (par == null) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY)) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY_TENTATIVE)) { fbtype = BwFreeBusyComponent.typeBusyTentative; } else if (par.equals(FbType.BUSY_UNAVAILABLE)) { fbtype = BwFreeBusyComponent.typeBusyUnavailable; } else if (par.equals(FbType.FREE)) { fbtype = BwFreeBusyComponent.typeFree; } else { if (logger.debug()) { logger.debug("Unsupported parameter " + par.getName()); } return Response.notOk(resp, failed, "Unsupported parameter " + par.getName()); } final BwFreeBusyComponent fbc = new BwFreeBusyComponent(); fbc.setType(fbtype); for (final Period per : perpl) { fbc.addPeriod(per); } ev.addFreeBusyPeriod(fbc); break; case GEO: /* ------------------- Geo -------------------- */ final Geo g = (Geo)prop; final BwGeo geo = new BwGeo(g.getLatitude(), g.getLongitude()); if (chg.changed(pi, ev.getGeo(), geo)) { ev.setGeo(geo); } break; case LAST_MODIFIED: /* ------------------- LastModified -------------------- */ if (chg.changed(pi, ev.getLastmod(), pval)) { ev.setLastmod(pval); } break; case LOCATION: /* ------------------- Location -------------------- */ BwLocation loc = null; //String uid = getUidPar(prop); /* At the moment Mozilla lightning is broken and this leads to all * sorts of problems. if (uid != null) { loc = cb.getLocation(uid); } */ lang = IcalUtil.getLang(prop); BwString addr = null; if (pval != null) { if (loc == null) { addr = new BwString(lang, pval); final var fcResp = cb.findLocation(addr); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { loc = fcResp.getEntity(); } } if (loc == null) { loc = BwLocation.makeLocation(); loc.setAddress(addr); cb.addLocation(loc); } } final BwLocation evloc = ev.getLocation(); if (chg.changed(pi, evloc, loc)) { // CHGTBL - this only shows that it's a different location object ev.setLocation(loc); } else if ((loc != null) && (evloc != null)) { // See if the value is changed final String evval = evloc.getAddress().getValue(); final String inval = loc.getAddress().getValue(); if (!evval.equals(inval)) { chg.changed(pi, evval, inval); evloc.getAddress().setValue(inval); } } break; case ORGANIZER: /* ------------------- Organizer -------------------- */ final BwOrganizer org = IcalUtil.getOrganizer(cb, (Organizer)prop); final BwOrganizer evorg = ev.getOrganizer(); final BwOrganizer evorgCopy; if (evorg == null) { evorgCopy = null; } else { evorgCopy = (BwOrganizer)evorg.clone(); } if (chg.changed(pi, evorgCopy, org)) { if (evorg == null) { ev.setOrganizer(org); } else { evorg.update(org); } } break; case PERCENT_COMPLETE: /* ------------------- PercentComplete -------------------- */ Integer ival = ((PercentComplete)prop).getPercentage(); if (chg.changed(pi, ev.getPercentComplete(), ival)) { ev.setPercentComplete(ival); } break; case POLL_MODE: /* ------------------- Poll mode -------------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollMode(), sval)) { ev.setPollMode(sval); } break; case POLL_PROPERTIES: /* ------------------- Poll properties ---------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollProperties(), sval)) { ev.setPollProperties(sval); } break; case POLL_WINNER: /* ------------------- Poll winner -------------------- */ ival = ((PollWinner)prop).getPollwinner(); if (chg.changed(pi, ev.getPollWinner(), ival)) { ev.setPollWinner(ival); } break; case PRIORITY: /* ------------------- Priority -------------------- */ ival = ((Priority)prop).getLevel(); if (chg.changed(pi, ev.getPriority(), ival)) { ev.setPriority(ival); } break; case RDATE: /* ------------------- RDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case RECURRENCE_ID: /* ------------------- RecurrenceID -------------------- */ // Done above break; case RELATED_TO: /* ------------------- RelatedTo -------------------- */ final RelatedTo irelto = (RelatedTo)prop; final BwRelatedTo relto = new BwRelatedTo(); final String parval = IcalUtil.getParameterVal(irelto, "RELTYPE"); if (parval != null) { relto.setRelType(parval); } relto.setValue(irelto.getValue()); if (chg.changed(pi, ev.getRelatedTo(), relto)) { ev.setRelatedTo(relto); } break; case REQUEST_STATUS: /* ------------------- RequestStatus -------------------- */ final BwRequestStatus rs = BwRequestStatus .fromRequestStatus((RequestStatus)prop); chg.addValue(pi, rs); break; case RESOURCES: /* ------------------- Resources -------------------- */ final TextList rl = ((Resources)prop).getResources(); if (rl != null) { /* Got some resources */ lang = IcalUtil.getLang(prop); for (final String s: rl) { final BwString rsrc = new BwString(lang, s); chg.addValue(pi, rsrc); } } break; case RRULE: /* ------------------- RRule -------------------- */ chg.addValue(pi, pval); break; case SEQUENCE: /* ------------------- Sequence -------------------- */ final int seq = ((Sequence)prop).getSequenceNo(); if (seq != ev.getSequence()) { chg.changed(pi, ev.getSequence(), seq); ev.setSequence(seq); } break; case STATUS: /* ------------------- Status -------------------- */ if (chg.changed(pi, ev.getStatus(), pval)) { ev.setStatus(pval); } break; case SUMMARY: /* ------------------- Summary -------------------- */ if (chg.changed(pi, ev.getSummary(), pval)) { ev.setSummary(pval); } break; case TRANSP: /* ------------------- Transp -------------------- */ if (chg.changed(pi, ev.getPeruserTransparency( cb.getPrincipal() .getPrincipalRef()), pval)) { final BwXproperty pu = ev.setPeruserTransparency( cb.getPrincipal().getPrincipalRef(), pval); if (pu != null) { chg.addValue(PropertyInfoIndex.XPROP, pu); } } break; case UID: /* ------------------- Uid -------------------- */ /* We did this above */ break; case URL: /* ------------------- Url -------------------- */ if (chg.changed(pi, ev.getLink(), pval)) { ev.setLink(pval); } break; case XPROP: /* ------------------------- x-property --------------------------- */ final String name = prop.getName(); if (name.equalsIgnoreCase(BwXproperty.bedeworkCost)) { if (chg.changed(PropertyInfoIndex.COST, ev.getCost(), pval)) { ev.setCost(pval); } break; } if (name.equalsIgnoreCase(BwXproperty.xBedeworkCategories)) { if (checkCategory(cb, chg, ev, null, pval)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkLocation)) { if (checkLocation(cb, chg, ev, prop)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkContact)) { if (checkContact(cb, chg, ev, null, pval)) { break; } } /* See if this is an x-category that can be converted to a real category */ final XProperty xp = (XProperty)prop; chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(name, xp.getParameters() .toString(), pval)); break; default: if (logger.debug()) { logger.debug("Unsupported property with index " + pi + "; class " + prop.getClass() + " and value " + pval); } } } /* =================== Process sub-components =============== */ final ComponentList<Component> subComps; if (val instanceof ComponentContainer) { subComps = ((ComponentContainer<Component>)val).getComponents(); } else { subComps = null; } final Set<Integer> pids; if (vpoll) { pids = new TreeSet<>(); final BwEvent vp = evinfo.getEvent(); if (!Util.isEmpty(vp.getPollItems())) { vp.clearPollItems(); } } else { pids = null; } if (!Util.isEmpty(subComps)) { for (final var subComp: subComps) { if (subComp instanceof Available) { if (!(val instanceof VAvailability)) { return Response.error(resp, "AVAILABLE only valid in VAVAILABLE"); } final var avlResp = processAvailable(cb, cal, ical, (VAvailability)val, (Available)subComp, evinfo); if (!avlResp.isOk()) { return Response.fromResponse(resp, avlResp); } continue; } if (subComp instanceof Participant) { if (vpoll) { final var vresp = processVoter(cb, (VPoll)val, (Participant)subComp, evinfo, chg, mergeAttendees); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Participant object"); continue; } if (subComp instanceof VResource) { logger.warn("Unimplemented VResource object"); continue; } if (subComp instanceof VLocation) { logger.warn("Unimplemented VLocation object"); continue; } if (subComp instanceof VAlarm) { final var aresp = VAlarmUtil.processAlarm(cb, val, (VAlarm)subComp, ev, currentPrincipal, chg); if (!aresp.isOk()) { return Response.fromResponse(resp, aresp); } continue; } if (vpoll && (event || task)) { final var vresp = processCandidate((VPoll)val, subComp, evinfo, pids, chg); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Component object: " + subComp); } } /* Fix up timestamps. */ if (ev.getCreated() == null) { if (ev.getLastmod() != null) { ev.setCreated(ev.getLastmod()); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); } else { ev.updateDtstamp(); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } } if (ev.getLastmod() == null) { // created cannot be null now ev.setLastmod(ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } processTimezones(ev, ical, chg); /* Remove any recipients and originator */ if (ev.getRecipients() != null) { ev.getRecipients().clear(); } ev.setOriginator(null); if (hasXparams.value) { /* Save a text copy of the entire event as an x-property */ final Component valCopy = val.copy(); /* Remove potentially large values */ final Description desp = valCopy.getProperty(Property.DESCRIPTION); if (desp != null) { desp.setValue(null); } final Attach attachp = valCopy.getProperty(Property.ATTACH); // Don't store the entire attachment - we just need the parameters. if (attachp != null) { final Value v = attachp.getParameter(Parameter.VALUE); if (v != null) { attachp.setValue(String.valueOf(attachp.getValue().hashCode())); } } chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(BwXproperty.bedeworkIcal, null, valCopy.toString())); } chg.processChanges(ev, true, false); ev.setRecurring(ev.isRecurringEntity()); if (logger.debug()) { logger.debug(chg.toString()); logger.debug(ev.toString()); } if (masterEI != null) { // Just return notfound as this event is on its override list return Response.notFound(resp); } resp.setEntity(evinfo); return resp; } catch (final Throwable t) { if (logger.debug()) { logger.error(t); } return Response.error(resp, t); } }
NONSATD
true
break; case EXDATE: /* ------------------- ExDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop));
case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE: /* -------------------- Due ------------------------ */ break; case DURATION: /* ------------------- Duration -------------------- */ break; case EXDATE: /* ------------------- ExDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case EXRULE: /* ------------------- ExRule -------------------- */ chg.addValue(pi, pval); break; case FREEBUSY: /* ------------------- freebusy -------------------- */ final FreeBusy fbusy = (FreeBusy)prop;
ev.setDescription(pval); } break; case DTEND: /* ------------------- DtEnd -------------------- */ break; case DTSTAMP: /* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval); break; case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE: /* -------------------- Due ------------------------ */ break; case DURATION: /* ------------------- Duration -------------------- */ break; case EXDATE: /* ------------------- ExDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case EXRULE: /* ------------------- ExRule -------------------- */ chg.addValue(pi, pval); break; case FREEBUSY: /* ------------------- freebusy -------------------- */ final FreeBusy fbusy = (FreeBusy)prop; final PeriodList perpl = fbusy.getPeriods(); final Parameter par = IcalUtil.getParameter(fbusy, "FBTYPE"); final int fbtype; if (par == null) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY)) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY_TENTATIVE)) { fbtype = BwFreeBusyComponent.typeBusyTentative; } else if (par.equals(FbType.BUSY_UNAVAILABLE)) {
7,893
45
/* ------------------- ExRule -------------------- */
public static GetEntityResponse<EventInfo> toEvent( final IcalCallback cb, final BwCalendar cal, final Icalendar ical, final Component val, final boolean mergeAttendees) { final var resp = new GetEntityResponse<EventInfo>(); if (val == null) { return Response.notOk(resp, failed, "No component supplied"); } String currentPrincipal = null; final BwPrincipal principal = cb.getPrincipal(); if (principal != null) { currentPrincipal = principal.getPrincipalRef(); } final Holder<Boolean> hasXparams = new Holder<>(Boolean.FALSE); final int methodType = ical.getMethodType(); String attUri = null; if (mergeAttendees) { // We'll need this later. attUri = cb.getCaladdr(cb.getPrincipal().getPrincipalRef()); } final String colPath; if (cal == null) { colPath = null; } else { colPath = cal.getPath(); } try { final PropertyList<Property> pl = val.getProperties(); boolean vpoll = false; boolean event = false; boolean task = false; if (pl == null) { // Empty component return Response.notOk(resp, failed, "Empty component"); } final int entityType; if (val instanceof VEvent) { entityType = IcalDefs.entityTypeEvent; event = true; } else if (val instanceof VToDo) { entityType = IcalDefs.entityTypeTodo; task = true; } else if (val instanceof VJournal) { entityType = IcalDefs.entityTypeJournal; } else if (val instanceof VFreeBusy) { entityType = IcalDefs.entityTypeFreeAndBusy; } else if (val instanceof VAvailability) { entityType = IcalDefs.entityTypeVavailability; } else if (val instanceof Available) { entityType = IcalDefs.entityTypeAvailable; } else if (val instanceof VPoll) { entityType = IcalDefs.entityTypeVpoll; vpoll = true; } else { return Response.error(resp, "org.bedework.invalid.component.type: " + val.getName()); } // Get the guid from the component String guid = null; final Uid uidp = pl.getProperty(Property.UID); if (uidp != null) { testXparams(uidp, hasXparams); guid = uidp.getValue(); } if (guid == null) { /* XXX A guid is required - but are there devices out there without a * guid - and if so how do we handle it? */ return Response.notOk(resp, failed, CalFacadeException.noGuid); } /* See if we have a recurrence id */ BwDateTime ridObj = null; String rid = null; TimeZone ridTz = null; final RecurrenceId ridp = pl.getProperty(Property.RECURRENCE_ID); if (ridp != null) { testXparams(ridp, hasXparams); ridObj = BwDateTime.makeBwDateTime(ridp); if (ridObj.getRange() != null) { /* XXX What do I do with it? */ logger.warn("TRANS-TO_EVENT: Got a recurrence id range"); } rid = ridObj.getDate(); } EventInfo masterEI = null; EventInfo evinfo = null; final BwEvent ev; /* If we have a recurrence id see if we already have the master (we should * get a master + all its overrides). * * If so find the override and use the annnotation or if no override, * make one. * * If no override retrieve the event, add it to our table and then locate the * annotation. * * If there is no annotation, create one. * * It's possible we have been sent 'detached' instances of a recurring * event. This may happen if we are invited to one or more instances of a * meeting. In this case we try to retrieve the master and if it doesn't * exist we manufacture one. We consider such an instance an update to * that instance only and leave the others alone. */ /* We need this in a couple of places */ final DtStart dtStart = pl.getProperty(Property.DTSTART); /* if (rid != null) { // See if we have a new master event. If so create a proxy to that event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI == null) { masterEI = makeNewEvent(cb, chg, entityType, guid, cal); BwEvent e = masterEI.getEvent(); // XXX This seems bogus DtStart mdtStart; String bogusDate = "19980118T230000"; if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + "Z"); } else if (dtStart.getTimeZone() == null) { mdtStart = new DtStart(bogusDate); } else { mdtStart = new DtStart(bogusDate + "Z", dtStart.getTimeZone()); } setDates(e, mdtStart, null, null, chg); e.setRecurring(true); e.addRdate(ridObj); e.setSuppressed(true); ical.addComponent(masterEI); } if (masterEI != null) { evinfo = masterEI.findOverride(rid); } } */ /* If this is a recurrence instance see if we can find the master We only need this because the master may follow the overrides. */ if (rid != null) { // See if we have a new master event. If so create a proxy to this event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI != null) { evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; } } if ((evinfo == null) && (cal != null) && (cal.getCalType() != BwCalendar.calTypeInbox) && (cal.getCalType() != BwCalendar.calTypePendingInbox) && (cal.getCalType() != BwCalendar.calTypeOutbox)) { if (logger.debug()) { logger.debug("TRANS-TO_EVENT: try to fetch event with guid=" + guid); } final GetEntitiesResponse<EventInfo> eisResp = cb.getEvent(colPath, guid); if (eisResp.isError()) { return Response.fromResponse(resp, eisResp); } final var eis = eisResp.getEntities(); if (!Util.isEmpty(eis)) { if (eis.size() > 1) { // DORECUR - wrong again return Response.notOk(resp, failed, "More than one event returned for guid."); } evinfo = eis.iterator().next(); } if (logger.debug()) { if (evinfo != null) { logger.debug("TRANS-TO_EVENT: fetched event with guid"); } else { logger.debug("TRANS-TO_EVENT: did not find event with guid"); } } if (evinfo != null) { if (rid != null) { // We just retrieved it's master masterEI = evinfo; masterEI.setInstanceOnly(true); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; ical.addComponent(masterEI); } else if (methodType == ScheduleMethods.methodTypeCancel) { // This should never have an rid for cancel of entire event. evinfo.setInstanceOnly(evinfo.getEvent().getSuppressed()); } else { // Presumably sent an update for the entire event. No longer suppressed master evinfo.getEvent().setSuppressed(false); } } else if (rid != null) { /* Manufacture a master for the instance */ masterEI = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); final BwEvent e = masterEI.getEvent(); // XXX This seems bogus final DtStart mdtStart; final String bogusDate = "19980118"; final String bogusTime = "T230000"; // Base dtstart on the recurrence id. final boolean isDateType = ridObj.getDateType(); if (isDateType) { mdtStart = new DtStart(new Date(bogusDate)); } else if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + bogusTime + "Z"); } else if (ridObj.getTzid() == null) { mdtStart = new DtStart(bogusDate + bogusTime); } else { mdtStart = new DtStart(bogusDate + bogusTime, Timezones.getTz(ridObj.getTzid())); } IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), masterEI, mdtStart, null, null); e.setRecurring(true); // e.addRdate(ridObj); final var sum = (Summary)pl.getProperty(Property.SUMMARY); e.setSummary(sum.getValue()); e.setSuppressed(true); ical.addComponent(masterEI); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; masterEI.setInstanceOnly(rid != null); } } if (evinfo == null) { evinfo = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); } else if (evinfo.getEvent().getEntityType() != entityType) { return Response.notOk(resp, failed, "org.bedework.mismatched.entity.type: " + val); } final ChangeTable chg = evinfo.getChangeset( cb.getPrincipal().getPrincipalRef()); if (rid != null) { final String evrid = evinfo.getEvent().getRecurrenceId(); if ((evrid == null) || (!evrid.equals(rid))) { logger. warn("Mismatched rid ev=" + evrid + " expected " + rid); chg.changed(PropertyInfoIndex.RECURRENCE_ID, evrid, rid); // XXX spurious??? } if (masterEI.getEvent().getSuppressed()) { masterEI.getEvent().addRdate(ridObj); } } ev = evinfo.getEvent(); ev.setScheduleMethod(methodType); DtEnd dtEnd = null; if (entityType == IcalDefs.entityTypeTodo) { final Due due = pl.getProperty(Property.DUE); if (due != null ) { dtEnd = new DtEnd(due.getParameters(), due.getValue()); } } else { dtEnd = pl.getProperty(Property.DTEND); } final Duration duration = pl.getProperty(Property.DURATION); IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), evinfo, dtStart, dtEnd, duration); for (final Property prop: pl) { testXparams(prop, hasXparams); //debug("ical prop " + prop.getClass().getName()); String pval = prop.getValue(); if ((pval != null) && (pval.length() == 0)) { pval = null; } final PropertyInfoIndex pi; if (prop instanceof XProperty) { pi = PropertyInfoIndex.XPROP; } else { pi = PropertyInfoIndex.fromName(prop.getName()); } if (pi == null) { logger.debug("Unknown property with name " + prop.getName() + " class " + prop.getClass() + " and value " + pval); continue; } chg.present(pi); switch (pi) { case ACCEPT_RESPONSE: /* ------------------- Accept Response -------------------- */ String sval = prop.getValue(); if (chg.changed(pi, ev.getPollAcceptResponse(), sval)) { ev.setPollAcceptResponse(sval); } break; case ATTACH: /* ------------------- Attachment -------------------- */ chg.addValue(pi, IcalUtil.getAttachment((Attach)prop)); break; case ATTENDEE: /* ------------------- Attendee -------------------- */ if (methodType == ScheduleMethods.methodTypePublish) { if (cb.getStrictness() == IcalCallback.conformanceStrict) { return Response.notOk(resp, failed, CalFacadeException.attendeesInPublish); } //if (cb.getStrictness() == IcalCallback.conformanceWarn) { // warn("Had attendees for PUBLISH"); //} } final Attendee attPr = (Attendee)prop; if (evinfo.getNewEvent() || !mergeAttendees) { chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { final String pUri = cb.getCaladdr(attPr.getValue()); if (pUri.equals(attUri)) { /* Only update for our own attendee * We're doing a PUT and this must be the attendee updating their * partstat. We don't allow them to change other attendees * whatever the PUT content says. */ chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { // Use the value we currently have boolean found = false; for (final BwAttendee att: ev.getAttendees()) { if (pUri.equals(att.getAttendeeUri())) { chg.addValue(pi, att.clone()); found = true; break; } } if (!found) { // An added attendee final BwAttendee att = IcalUtil .getAttendee(cb, attPr); att.setPartstat(IcalDefs.partstatValNeedsAction); chg.addValue(pi, att); } } } break; case BUSYTYPE: final int ibt = BwEvent.fromBusyTypeString(pval); if (chg.changed(pi, ev.getBusyType(), ibt)) { ev.setBusyType(ibt); } break; case CATEGORIES: /* ------------------- Categories -------------------- */ final Categories cats = (Categories)prop; final TextList cl = cats.getCategories(); String lang = IcalUtil.getLang(cats); if (cl != null) { /* Got some categories */ for (final String wd: cl) { if (wd == null) { continue; } final BwString key = new BwString(lang, wd); final var fcResp = cb.findCategory(key); final BwCategory cat; if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isNotFound()) { cat = BwCategory.makeCategory(); cat.setWord(key); cb.addCategory(cat); } else { cat = fcResp.getEntity(); } chg.addValue(pi, cat); } } break; case CLASS: /* ------------------- Class -------------------- */ if (chg.changed(pi, ev.getClassification(), pval)) { ev.setClassification(pval); } break; case COMMENT: /* ------------------- Comment -------------------- */ chg.addValue(pi, new BwString(null, pval)); break; case COMPLETED: /* ------------------- Completed -------------------- */ if (chg.changed(pi, ev.getCompleted(), pval)) { ev.setCompleted(pval); } break; case CONCEPT: /* ------------------- Concept -------------------- */ final Concept c = (Concept)prop; final String cval = c.getValue(); if (cval != null) { /* Got a concept */ chg.addValue(PropertyInfoIndex.XPROP, BwXproperty.makeIcalProperty("CONCEPT", null, cval)); } break; case CONTACT: /* ------------------- Contact -------------------- */ final String altrep = getAltRepPar(prop); lang = IcalUtil.getLang(prop); final String uid = getUidPar(prop); final BwString nm = new BwString(lang, pval); BwContact contact = null; if (uid != null) { final var fcResp = cb.getContact(uid); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { final var fcResp = cb.findContact(nm); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { contact = BwContact.makeContact(); contact.setCn(nm); contact.setLink(altrep); cb.addContact(contact); } else { contact.setCn(nm); contact.setLink(altrep); } chg.addValue(pi, contact); break; case CREATED: /* ------------------- Created -------------------- */ if (chg.changed(pi, ev.getCreated(), pval)) { ev.setCreated(pval); } break; case DESCRIPTION: /* ------------------- Description -------------------- */ if (chg.changed(pi, ev.getDescription(), pval)) { ev.setDescription(pval); } break; case DTEND: /* ------------------- DtEnd -------------------- */ break; case DTSTAMP: /* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval); break; case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE: /* -------------------- Due ------------------------ */ break; case DURATION: /* ------------------- Duration -------------------- */ break; case EXDATE: /* ------------------- ExDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case EXRULE: /* ------------------- ExRule -------------------- */ chg.addValue(pi, pval); break; case FREEBUSY: /* ------------------- freebusy -------------------- */ final FreeBusy fbusy = (FreeBusy)prop; final PeriodList perpl = fbusy.getPeriods(); final Parameter par = IcalUtil.getParameter(fbusy, "FBTYPE"); final int fbtype; if (par == null) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY)) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY_TENTATIVE)) { fbtype = BwFreeBusyComponent.typeBusyTentative; } else if (par.equals(FbType.BUSY_UNAVAILABLE)) { fbtype = BwFreeBusyComponent.typeBusyUnavailable; } else if (par.equals(FbType.FREE)) { fbtype = BwFreeBusyComponent.typeFree; } else { if (logger.debug()) { logger.debug("Unsupported parameter " + par.getName()); } return Response.notOk(resp, failed, "Unsupported parameter " + par.getName()); } final BwFreeBusyComponent fbc = new BwFreeBusyComponent(); fbc.setType(fbtype); for (final Period per : perpl) { fbc.addPeriod(per); } ev.addFreeBusyPeriod(fbc); break; case GEO: /* ------------------- Geo -------------------- */ final Geo g = (Geo)prop; final BwGeo geo = new BwGeo(g.getLatitude(), g.getLongitude()); if (chg.changed(pi, ev.getGeo(), geo)) { ev.setGeo(geo); } break; case LAST_MODIFIED: /* ------------------- LastModified -------------------- */ if (chg.changed(pi, ev.getLastmod(), pval)) { ev.setLastmod(pval); } break; case LOCATION: /* ------------------- Location -------------------- */ BwLocation loc = null; //String uid = getUidPar(prop); /* At the moment Mozilla lightning is broken and this leads to all * sorts of problems. if (uid != null) { loc = cb.getLocation(uid); } */ lang = IcalUtil.getLang(prop); BwString addr = null; if (pval != null) { if (loc == null) { addr = new BwString(lang, pval); final var fcResp = cb.findLocation(addr); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { loc = fcResp.getEntity(); } } if (loc == null) { loc = BwLocation.makeLocation(); loc.setAddress(addr); cb.addLocation(loc); } } final BwLocation evloc = ev.getLocation(); if (chg.changed(pi, evloc, loc)) { // CHGTBL - this only shows that it's a different location object ev.setLocation(loc); } else if ((loc != null) && (evloc != null)) { // See if the value is changed final String evval = evloc.getAddress().getValue(); final String inval = loc.getAddress().getValue(); if (!evval.equals(inval)) { chg.changed(pi, evval, inval); evloc.getAddress().setValue(inval); } } break; case ORGANIZER: /* ------------------- Organizer -------------------- */ final BwOrganizer org = IcalUtil.getOrganizer(cb, (Organizer)prop); final BwOrganizer evorg = ev.getOrganizer(); final BwOrganizer evorgCopy; if (evorg == null) { evorgCopy = null; } else { evorgCopy = (BwOrganizer)evorg.clone(); } if (chg.changed(pi, evorgCopy, org)) { if (evorg == null) { ev.setOrganizer(org); } else { evorg.update(org); } } break; case PERCENT_COMPLETE: /* ------------------- PercentComplete -------------------- */ Integer ival = ((PercentComplete)prop).getPercentage(); if (chg.changed(pi, ev.getPercentComplete(), ival)) { ev.setPercentComplete(ival); } break; case POLL_MODE: /* ------------------- Poll mode -------------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollMode(), sval)) { ev.setPollMode(sval); } break; case POLL_PROPERTIES: /* ------------------- Poll properties ---------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollProperties(), sval)) { ev.setPollProperties(sval); } break; case POLL_WINNER: /* ------------------- Poll winner -------------------- */ ival = ((PollWinner)prop).getPollwinner(); if (chg.changed(pi, ev.getPollWinner(), ival)) { ev.setPollWinner(ival); } break; case PRIORITY: /* ------------------- Priority -------------------- */ ival = ((Priority)prop).getLevel(); if (chg.changed(pi, ev.getPriority(), ival)) { ev.setPriority(ival); } break; case RDATE: /* ------------------- RDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case RECURRENCE_ID: /* ------------------- RecurrenceID -------------------- */ // Done above break; case RELATED_TO: /* ------------------- RelatedTo -------------------- */ final RelatedTo irelto = (RelatedTo)prop; final BwRelatedTo relto = new BwRelatedTo(); final String parval = IcalUtil.getParameterVal(irelto, "RELTYPE"); if (parval != null) { relto.setRelType(parval); } relto.setValue(irelto.getValue()); if (chg.changed(pi, ev.getRelatedTo(), relto)) { ev.setRelatedTo(relto); } break; case REQUEST_STATUS: /* ------------------- RequestStatus -------------------- */ final BwRequestStatus rs = BwRequestStatus .fromRequestStatus((RequestStatus)prop); chg.addValue(pi, rs); break; case RESOURCES: /* ------------------- Resources -------------------- */ final TextList rl = ((Resources)prop).getResources(); if (rl != null) { /* Got some resources */ lang = IcalUtil.getLang(prop); for (final String s: rl) { final BwString rsrc = new BwString(lang, s); chg.addValue(pi, rsrc); } } break; case RRULE: /* ------------------- RRule -------------------- */ chg.addValue(pi, pval); break; case SEQUENCE: /* ------------------- Sequence -------------------- */ final int seq = ((Sequence)prop).getSequenceNo(); if (seq != ev.getSequence()) { chg.changed(pi, ev.getSequence(), seq); ev.setSequence(seq); } break; case STATUS: /* ------------------- Status -------------------- */ if (chg.changed(pi, ev.getStatus(), pval)) { ev.setStatus(pval); } break; case SUMMARY: /* ------------------- Summary -------------------- */ if (chg.changed(pi, ev.getSummary(), pval)) { ev.setSummary(pval); } break; case TRANSP: /* ------------------- Transp -------------------- */ if (chg.changed(pi, ev.getPeruserTransparency( cb.getPrincipal() .getPrincipalRef()), pval)) { final BwXproperty pu = ev.setPeruserTransparency( cb.getPrincipal().getPrincipalRef(), pval); if (pu != null) { chg.addValue(PropertyInfoIndex.XPROP, pu); } } break; case UID: /* ------------------- Uid -------------------- */ /* We did this above */ break; case URL: /* ------------------- Url -------------------- */ if (chg.changed(pi, ev.getLink(), pval)) { ev.setLink(pval); } break; case XPROP: /* ------------------------- x-property --------------------------- */ final String name = prop.getName(); if (name.equalsIgnoreCase(BwXproperty.bedeworkCost)) { if (chg.changed(PropertyInfoIndex.COST, ev.getCost(), pval)) { ev.setCost(pval); } break; } if (name.equalsIgnoreCase(BwXproperty.xBedeworkCategories)) { if (checkCategory(cb, chg, ev, null, pval)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkLocation)) { if (checkLocation(cb, chg, ev, prop)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkContact)) { if (checkContact(cb, chg, ev, null, pval)) { break; } } /* See if this is an x-category that can be converted to a real category */ final XProperty xp = (XProperty)prop; chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(name, xp.getParameters() .toString(), pval)); break; default: if (logger.debug()) { logger.debug("Unsupported property with index " + pi + "; class " + prop.getClass() + " and value " + pval); } } } /* =================== Process sub-components =============== */ final ComponentList<Component> subComps; if (val instanceof ComponentContainer) { subComps = ((ComponentContainer<Component>)val).getComponents(); } else { subComps = null; } final Set<Integer> pids; if (vpoll) { pids = new TreeSet<>(); final BwEvent vp = evinfo.getEvent(); if (!Util.isEmpty(vp.getPollItems())) { vp.clearPollItems(); } } else { pids = null; } if (!Util.isEmpty(subComps)) { for (final var subComp: subComps) { if (subComp instanceof Available) { if (!(val instanceof VAvailability)) { return Response.error(resp, "AVAILABLE only valid in VAVAILABLE"); } final var avlResp = processAvailable(cb, cal, ical, (VAvailability)val, (Available)subComp, evinfo); if (!avlResp.isOk()) { return Response.fromResponse(resp, avlResp); } continue; } if (subComp instanceof Participant) { if (vpoll) { final var vresp = processVoter(cb, (VPoll)val, (Participant)subComp, evinfo, chg, mergeAttendees); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Participant object"); continue; } if (subComp instanceof VResource) { logger.warn("Unimplemented VResource object"); continue; } if (subComp instanceof VLocation) { logger.warn("Unimplemented VLocation object"); continue; } if (subComp instanceof VAlarm) { final var aresp = VAlarmUtil.processAlarm(cb, val, (VAlarm)subComp, ev, currentPrincipal, chg); if (!aresp.isOk()) { return Response.fromResponse(resp, aresp); } continue; } if (vpoll && (event || task)) { final var vresp = processCandidate((VPoll)val, subComp, evinfo, pids, chg); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Component object: " + subComp); } } /* Fix up timestamps. */ if (ev.getCreated() == null) { if (ev.getLastmod() != null) { ev.setCreated(ev.getLastmod()); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); } else { ev.updateDtstamp(); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } } if (ev.getLastmod() == null) { // created cannot be null now ev.setLastmod(ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } processTimezones(ev, ical, chg); /* Remove any recipients and originator */ if (ev.getRecipients() != null) { ev.getRecipients().clear(); } ev.setOriginator(null); if (hasXparams.value) { /* Save a text copy of the entire event as an x-property */ final Component valCopy = val.copy(); /* Remove potentially large values */ final Description desp = valCopy.getProperty(Property.DESCRIPTION); if (desp != null) { desp.setValue(null); } final Attach attachp = valCopy.getProperty(Property.ATTACH); // Don't store the entire attachment - we just need the parameters. if (attachp != null) { final Value v = attachp.getParameter(Parameter.VALUE); if (v != null) { attachp.setValue(String.valueOf(attachp.getValue().hashCode())); } } chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(BwXproperty.bedeworkIcal, null, valCopy.toString())); } chg.processChanges(ev, true, false); ev.setRecurring(ev.isRecurringEntity()); if (logger.debug()) { logger.debug(chg.toString()); logger.debug(ev.toString()); } if (masterEI != null) { // Just return notfound as this event is on its override list return Response.notFound(resp); } resp.setEntity(evinfo); return resp; } catch (final Throwable t) { if (logger.debug()) { logger.error(t); } return Response.error(resp, t); } }
NONSATD
true
break; case EXRULE: /* ------------------- ExRule -------------------- */ chg.addValue(pi, pval); break;
break; case DURATION: /* ------------------- Duration -------------------- */ break; case EXDATE: /* ------------------- ExDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case EXRULE: /* ------------------- ExRule -------------------- */ chg.addValue(pi, pval); break; case FREEBUSY: /* ------------------- freebusy -------------------- */ final FreeBusy fbusy = (FreeBusy)prop; final PeriodList perpl = fbusy.getPeriods(); final Parameter par = IcalUtil.getParameter(fbusy, "FBTYPE"); final int fbtype; if (par == null) { fbtype = BwFreeBusyComponent.typeBusy;
break; case DTSTAMP: /* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval); break; case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE: /* -------------------- Due ------------------------ */ break; case DURATION: /* ------------------- Duration -------------------- */ break; case EXDATE: /* ------------------- ExDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case EXRULE: /* ------------------- ExRule -------------------- */ chg.addValue(pi, pval); break; case FREEBUSY: /* ------------------- freebusy -------------------- */ final FreeBusy fbusy = (FreeBusy)prop; final PeriodList perpl = fbusy.getPeriods(); final Parameter par = IcalUtil.getParameter(fbusy, "FBTYPE"); final int fbtype; if (par == null) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY)) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY_TENTATIVE)) { fbtype = BwFreeBusyComponent.typeBusyTentative; } else if (par.equals(FbType.BUSY_UNAVAILABLE)) { fbtype = BwFreeBusyComponent.typeBusyUnavailable; } else if (par.equals(FbType.FREE)) { fbtype = BwFreeBusyComponent.typeFree; } else { if (logger.debug()) {
7,893
46
/* ------------------- freebusy -------------------- */
public static GetEntityResponse<EventInfo> toEvent( final IcalCallback cb, final BwCalendar cal, final Icalendar ical, final Component val, final boolean mergeAttendees) { final var resp = new GetEntityResponse<EventInfo>(); if (val == null) { return Response.notOk(resp, failed, "No component supplied"); } String currentPrincipal = null; final BwPrincipal principal = cb.getPrincipal(); if (principal != null) { currentPrincipal = principal.getPrincipalRef(); } final Holder<Boolean> hasXparams = new Holder<>(Boolean.FALSE); final int methodType = ical.getMethodType(); String attUri = null; if (mergeAttendees) { // We'll need this later. attUri = cb.getCaladdr(cb.getPrincipal().getPrincipalRef()); } final String colPath; if (cal == null) { colPath = null; } else { colPath = cal.getPath(); } try { final PropertyList<Property> pl = val.getProperties(); boolean vpoll = false; boolean event = false; boolean task = false; if (pl == null) { // Empty component return Response.notOk(resp, failed, "Empty component"); } final int entityType; if (val instanceof VEvent) { entityType = IcalDefs.entityTypeEvent; event = true; } else if (val instanceof VToDo) { entityType = IcalDefs.entityTypeTodo; task = true; } else if (val instanceof VJournal) { entityType = IcalDefs.entityTypeJournal; } else if (val instanceof VFreeBusy) { entityType = IcalDefs.entityTypeFreeAndBusy; } else if (val instanceof VAvailability) { entityType = IcalDefs.entityTypeVavailability; } else if (val instanceof Available) { entityType = IcalDefs.entityTypeAvailable; } else if (val instanceof VPoll) { entityType = IcalDefs.entityTypeVpoll; vpoll = true; } else { return Response.error(resp, "org.bedework.invalid.component.type: " + val.getName()); } // Get the guid from the component String guid = null; final Uid uidp = pl.getProperty(Property.UID); if (uidp != null) { testXparams(uidp, hasXparams); guid = uidp.getValue(); } if (guid == null) { /* XXX A guid is required - but are there devices out there without a * guid - and if so how do we handle it? */ return Response.notOk(resp, failed, CalFacadeException.noGuid); } /* See if we have a recurrence id */ BwDateTime ridObj = null; String rid = null; TimeZone ridTz = null; final RecurrenceId ridp = pl.getProperty(Property.RECURRENCE_ID); if (ridp != null) { testXparams(ridp, hasXparams); ridObj = BwDateTime.makeBwDateTime(ridp); if (ridObj.getRange() != null) { /* XXX What do I do with it? */ logger.warn("TRANS-TO_EVENT: Got a recurrence id range"); } rid = ridObj.getDate(); } EventInfo masterEI = null; EventInfo evinfo = null; final BwEvent ev; /* If we have a recurrence id see if we already have the master (we should * get a master + all its overrides). * * If so find the override and use the annnotation or if no override, * make one. * * If no override retrieve the event, add it to our table and then locate the * annotation. * * If there is no annotation, create one. * * It's possible we have been sent 'detached' instances of a recurring * event. This may happen if we are invited to one or more instances of a * meeting. In this case we try to retrieve the master and if it doesn't * exist we manufacture one. We consider such an instance an update to * that instance only and leave the others alone. */ /* We need this in a couple of places */ final DtStart dtStart = pl.getProperty(Property.DTSTART); /* if (rid != null) { // See if we have a new master event. If so create a proxy to that event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI == null) { masterEI = makeNewEvent(cb, chg, entityType, guid, cal); BwEvent e = masterEI.getEvent(); // XXX This seems bogus DtStart mdtStart; String bogusDate = "19980118T230000"; if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + "Z"); } else if (dtStart.getTimeZone() == null) { mdtStart = new DtStart(bogusDate); } else { mdtStart = new DtStart(bogusDate + "Z", dtStart.getTimeZone()); } setDates(e, mdtStart, null, null, chg); e.setRecurring(true); e.addRdate(ridObj); e.setSuppressed(true); ical.addComponent(masterEI); } if (masterEI != null) { evinfo = masterEI.findOverride(rid); } } */ /* If this is a recurrence instance see if we can find the master We only need this because the master may follow the overrides. */ if (rid != null) { // See if we have a new master event. If so create a proxy to this event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI != null) { evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; } } if ((evinfo == null) && (cal != null) && (cal.getCalType() != BwCalendar.calTypeInbox) && (cal.getCalType() != BwCalendar.calTypePendingInbox) && (cal.getCalType() != BwCalendar.calTypeOutbox)) { if (logger.debug()) { logger.debug("TRANS-TO_EVENT: try to fetch event with guid=" + guid); } final GetEntitiesResponse<EventInfo> eisResp = cb.getEvent(colPath, guid); if (eisResp.isError()) { return Response.fromResponse(resp, eisResp); } final var eis = eisResp.getEntities(); if (!Util.isEmpty(eis)) { if (eis.size() > 1) { // DORECUR - wrong again return Response.notOk(resp, failed, "More than one event returned for guid."); } evinfo = eis.iterator().next(); } if (logger.debug()) { if (evinfo != null) { logger.debug("TRANS-TO_EVENT: fetched event with guid"); } else { logger.debug("TRANS-TO_EVENT: did not find event with guid"); } } if (evinfo != null) { if (rid != null) { // We just retrieved it's master masterEI = evinfo; masterEI.setInstanceOnly(true); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; ical.addComponent(masterEI); } else if (methodType == ScheduleMethods.methodTypeCancel) { // This should never have an rid for cancel of entire event. evinfo.setInstanceOnly(evinfo.getEvent().getSuppressed()); } else { // Presumably sent an update for the entire event. No longer suppressed master evinfo.getEvent().setSuppressed(false); } } else if (rid != null) { /* Manufacture a master for the instance */ masterEI = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); final BwEvent e = masterEI.getEvent(); // XXX This seems bogus final DtStart mdtStart; final String bogusDate = "19980118"; final String bogusTime = "T230000"; // Base dtstart on the recurrence id. final boolean isDateType = ridObj.getDateType(); if (isDateType) { mdtStart = new DtStart(new Date(bogusDate)); } else if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + bogusTime + "Z"); } else if (ridObj.getTzid() == null) { mdtStart = new DtStart(bogusDate + bogusTime); } else { mdtStart = new DtStart(bogusDate + bogusTime, Timezones.getTz(ridObj.getTzid())); } IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), masterEI, mdtStart, null, null); e.setRecurring(true); // e.addRdate(ridObj); final var sum = (Summary)pl.getProperty(Property.SUMMARY); e.setSummary(sum.getValue()); e.setSuppressed(true); ical.addComponent(masterEI); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; masterEI.setInstanceOnly(rid != null); } } if (evinfo == null) { evinfo = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); } else if (evinfo.getEvent().getEntityType() != entityType) { return Response.notOk(resp, failed, "org.bedework.mismatched.entity.type: " + val); } final ChangeTable chg = evinfo.getChangeset( cb.getPrincipal().getPrincipalRef()); if (rid != null) { final String evrid = evinfo.getEvent().getRecurrenceId(); if ((evrid == null) || (!evrid.equals(rid))) { logger. warn("Mismatched rid ev=" + evrid + " expected " + rid); chg.changed(PropertyInfoIndex.RECURRENCE_ID, evrid, rid); // XXX spurious??? } if (masterEI.getEvent().getSuppressed()) { masterEI.getEvent().addRdate(ridObj); } } ev = evinfo.getEvent(); ev.setScheduleMethod(methodType); DtEnd dtEnd = null; if (entityType == IcalDefs.entityTypeTodo) { final Due due = pl.getProperty(Property.DUE); if (due != null ) { dtEnd = new DtEnd(due.getParameters(), due.getValue()); } } else { dtEnd = pl.getProperty(Property.DTEND); } final Duration duration = pl.getProperty(Property.DURATION); IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), evinfo, dtStart, dtEnd, duration); for (final Property prop: pl) { testXparams(prop, hasXparams); //debug("ical prop " + prop.getClass().getName()); String pval = prop.getValue(); if ((pval != null) && (pval.length() == 0)) { pval = null; } final PropertyInfoIndex pi; if (prop instanceof XProperty) { pi = PropertyInfoIndex.XPROP; } else { pi = PropertyInfoIndex.fromName(prop.getName()); } if (pi == null) { logger.debug("Unknown property with name " + prop.getName() + " class " + prop.getClass() + " and value " + pval); continue; } chg.present(pi); switch (pi) { case ACCEPT_RESPONSE: /* ------------------- Accept Response -------------------- */ String sval = prop.getValue(); if (chg.changed(pi, ev.getPollAcceptResponse(), sval)) { ev.setPollAcceptResponse(sval); } break; case ATTACH: /* ------------------- Attachment -------------------- */ chg.addValue(pi, IcalUtil.getAttachment((Attach)prop)); break; case ATTENDEE: /* ------------------- Attendee -------------------- */ if (methodType == ScheduleMethods.methodTypePublish) { if (cb.getStrictness() == IcalCallback.conformanceStrict) { return Response.notOk(resp, failed, CalFacadeException.attendeesInPublish); } //if (cb.getStrictness() == IcalCallback.conformanceWarn) { // warn("Had attendees for PUBLISH"); //} } final Attendee attPr = (Attendee)prop; if (evinfo.getNewEvent() || !mergeAttendees) { chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { final String pUri = cb.getCaladdr(attPr.getValue()); if (pUri.equals(attUri)) { /* Only update for our own attendee * We're doing a PUT and this must be the attendee updating their * partstat. We don't allow them to change other attendees * whatever the PUT content says. */ chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { // Use the value we currently have boolean found = false; for (final BwAttendee att: ev.getAttendees()) { if (pUri.equals(att.getAttendeeUri())) { chg.addValue(pi, att.clone()); found = true; break; } } if (!found) { // An added attendee final BwAttendee att = IcalUtil .getAttendee(cb, attPr); att.setPartstat(IcalDefs.partstatValNeedsAction); chg.addValue(pi, att); } } } break; case BUSYTYPE: final int ibt = BwEvent.fromBusyTypeString(pval); if (chg.changed(pi, ev.getBusyType(), ibt)) { ev.setBusyType(ibt); } break; case CATEGORIES: /* ------------------- Categories -------------------- */ final Categories cats = (Categories)prop; final TextList cl = cats.getCategories(); String lang = IcalUtil.getLang(cats); if (cl != null) { /* Got some categories */ for (final String wd: cl) { if (wd == null) { continue; } final BwString key = new BwString(lang, wd); final var fcResp = cb.findCategory(key); final BwCategory cat; if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isNotFound()) { cat = BwCategory.makeCategory(); cat.setWord(key); cb.addCategory(cat); } else { cat = fcResp.getEntity(); } chg.addValue(pi, cat); } } break; case CLASS: /* ------------------- Class -------------------- */ if (chg.changed(pi, ev.getClassification(), pval)) { ev.setClassification(pval); } break; case COMMENT: /* ------------------- Comment -------------------- */ chg.addValue(pi, new BwString(null, pval)); break; case COMPLETED: /* ------------------- Completed -------------------- */ if (chg.changed(pi, ev.getCompleted(), pval)) { ev.setCompleted(pval); } break; case CONCEPT: /* ------------------- Concept -------------------- */ final Concept c = (Concept)prop; final String cval = c.getValue(); if (cval != null) { /* Got a concept */ chg.addValue(PropertyInfoIndex.XPROP, BwXproperty.makeIcalProperty("CONCEPT", null, cval)); } break; case CONTACT: /* ------------------- Contact -------------------- */ final String altrep = getAltRepPar(prop); lang = IcalUtil.getLang(prop); final String uid = getUidPar(prop); final BwString nm = new BwString(lang, pval); BwContact contact = null; if (uid != null) { final var fcResp = cb.getContact(uid); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { final var fcResp = cb.findContact(nm); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { contact = BwContact.makeContact(); contact.setCn(nm); contact.setLink(altrep); cb.addContact(contact); } else { contact.setCn(nm); contact.setLink(altrep); } chg.addValue(pi, contact); break; case CREATED: /* ------------------- Created -------------------- */ if (chg.changed(pi, ev.getCreated(), pval)) { ev.setCreated(pval); } break; case DESCRIPTION: /* ------------------- Description -------------------- */ if (chg.changed(pi, ev.getDescription(), pval)) { ev.setDescription(pval); } break; case DTEND: /* ------------------- DtEnd -------------------- */ break; case DTSTAMP: /* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval); break; case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE: /* -------------------- Due ------------------------ */ break; case DURATION: /* ------------------- Duration -------------------- */ break; case EXDATE: /* ------------------- ExDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case EXRULE: /* ------------------- ExRule -------------------- */ chg.addValue(pi, pval); break; case FREEBUSY: /* ------------------- freebusy -------------------- */ final FreeBusy fbusy = (FreeBusy)prop; final PeriodList perpl = fbusy.getPeriods(); final Parameter par = IcalUtil.getParameter(fbusy, "FBTYPE"); final int fbtype; if (par == null) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY)) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY_TENTATIVE)) { fbtype = BwFreeBusyComponent.typeBusyTentative; } else if (par.equals(FbType.BUSY_UNAVAILABLE)) { fbtype = BwFreeBusyComponent.typeBusyUnavailable; } else if (par.equals(FbType.FREE)) { fbtype = BwFreeBusyComponent.typeFree; } else { if (logger.debug()) { logger.debug("Unsupported parameter " + par.getName()); } return Response.notOk(resp, failed, "Unsupported parameter " + par.getName()); } final BwFreeBusyComponent fbc = new BwFreeBusyComponent(); fbc.setType(fbtype); for (final Period per : perpl) { fbc.addPeriod(per); } ev.addFreeBusyPeriod(fbc); break; case GEO: /* ------------------- Geo -------------------- */ final Geo g = (Geo)prop; final BwGeo geo = new BwGeo(g.getLatitude(), g.getLongitude()); if (chg.changed(pi, ev.getGeo(), geo)) { ev.setGeo(geo); } break; case LAST_MODIFIED: /* ------------------- LastModified -------------------- */ if (chg.changed(pi, ev.getLastmod(), pval)) { ev.setLastmod(pval); } break; case LOCATION: /* ------------------- Location -------------------- */ BwLocation loc = null; //String uid = getUidPar(prop); /* At the moment Mozilla lightning is broken and this leads to all * sorts of problems. if (uid != null) { loc = cb.getLocation(uid); } */ lang = IcalUtil.getLang(prop); BwString addr = null; if (pval != null) { if (loc == null) { addr = new BwString(lang, pval); final var fcResp = cb.findLocation(addr); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { loc = fcResp.getEntity(); } } if (loc == null) { loc = BwLocation.makeLocation(); loc.setAddress(addr); cb.addLocation(loc); } } final BwLocation evloc = ev.getLocation(); if (chg.changed(pi, evloc, loc)) { // CHGTBL - this only shows that it's a different location object ev.setLocation(loc); } else if ((loc != null) && (evloc != null)) { // See if the value is changed final String evval = evloc.getAddress().getValue(); final String inval = loc.getAddress().getValue(); if (!evval.equals(inval)) { chg.changed(pi, evval, inval); evloc.getAddress().setValue(inval); } } break; case ORGANIZER: /* ------------------- Organizer -------------------- */ final BwOrganizer org = IcalUtil.getOrganizer(cb, (Organizer)prop); final BwOrganizer evorg = ev.getOrganizer(); final BwOrganizer evorgCopy; if (evorg == null) { evorgCopy = null; } else { evorgCopy = (BwOrganizer)evorg.clone(); } if (chg.changed(pi, evorgCopy, org)) { if (evorg == null) { ev.setOrganizer(org); } else { evorg.update(org); } } break; case PERCENT_COMPLETE: /* ------------------- PercentComplete -------------------- */ Integer ival = ((PercentComplete)prop).getPercentage(); if (chg.changed(pi, ev.getPercentComplete(), ival)) { ev.setPercentComplete(ival); } break; case POLL_MODE: /* ------------------- Poll mode -------------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollMode(), sval)) { ev.setPollMode(sval); } break; case POLL_PROPERTIES: /* ------------------- Poll properties ---------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollProperties(), sval)) { ev.setPollProperties(sval); } break; case POLL_WINNER: /* ------------------- Poll winner -------------------- */ ival = ((PollWinner)prop).getPollwinner(); if (chg.changed(pi, ev.getPollWinner(), ival)) { ev.setPollWinner(ival); } break; case PRIORITY: /* ------------------- Priority -------------------- */ ival = ((Priority)prop).getLevel(); if (chg.changed(pi, ev.getPriority(), ival)) { ev.setPriority(ival); } break; case RDATE: /* ------------------- RDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case RECURRENCE_ID: /* ------------------- RecurrenceID -------------------- */ // Done above break; case RELATED_TO: /* ------------------- RelatedTo -------------------- */ final RelatedTo irelto = (RelatedTo)prop; final BwRelatedTo relto = new BwRelatedTo(); final String parval = IcalUtil.getParameterVal(irelto, "RELTYPE"); if (parval != null) { relto.setRelType(parval); } relto.setValue(irelto.getValue()); if (chg.changed(pi, ev.getRelatedTo(), relto)) { ev.setRelatedTo(relto); } break; case REQUEST_STATUS: /* ------------------- RequestStatus -------------------- */ final BwRequestStatus rs = BwRequestStatus .fromRequestStatus((RequestStatus)prop); chg.addValue(pi, rs); break; case RESOURCES: /* ------------------- Resources -------------------- */ final TextList rl = ((Resources)prop).getResources(); if (rl != null) { /* Got some resources */ lang = IcalUtil.getLang(prop); for (final String s: rl) { final BwString rsrc = new BwString(lang, s); chg.addValue(pi, rsrc); } } break; case RRULE: /* ------------------- RRule -------------------- */ chg.addValue(pi, pval); break; case SEQUENCE: /* ------------------- Sequence -------------------- */ final int seq = ((Sequence)prop).getSequenceNo(); if (seq != ev.getSequence()) { chg.changed(pi, ev.getSequence(), seq); ev.setSequence(seq); } break; case STATUS: /* ------------------- Status -------------------- */ if (chg.changed(pi, ev.getStatus(), pval)) { ev.setStatus(pval); } break; case SUMMARY: /* ------------------- Summary -------------------- */ if (chg.changed(pi, ev.getSummary(), pval)) { ev.setSummary(pval); } break; case TRANSP: /* ------------------- Transp -------------------- */ if (chg.changed(pi, ev.getPeruserTransparency( cb.getPrincipal() .getPrincipalRef()), pval)) { final BwXproperty pu = ev.setPeruserTransparency( cb.getPrincipal().getPrincipalRef(), pval); if (pu != null) { chg.addValue(PropertyInfoIndex.XPROP, pu); } } break; case UID: /* ------------------- Uid -------------------- */ /* We did this above */ break; case URL: /* ------------------- Url -------------------- */ if (chg.changed(pi, ev.getLink(), pval)) { ev.setLink(pval); } break; case XPROP: /* ------------------------- x-property --------------------------- */ final String name = prop.getName(); if (name.equalsIgnoreCase(BwXproperty.bedeworkCost)) { if (chg.changed(PropertyInfoIndex.COST, ev.getCost(), pval)) { ev.setCost(pval); } break; } if (name.equalsIgnoreCase(BwXproperty.xBedeworkCategories)) { if (checkCategory(cb, chg, ev, null, pval)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkLocation)) { if (checkLocation(cb, chg, ev, prop)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkContact)) { if (checkContact(cb, chg, ev, null, pval)) { break; } } /* See if this is an x-category that can be converted to a real category */ final XProperty xp = (XProperty)prop; chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(name, xp.getParameters() .toString(), pval)); break; default: if (logger.debug()) { logger.debug("Unsupported property with index " + pi + "; class " + prop.getClass() + " and value " + pval); } } } /* =================== Process sub-components =============== */ final ComponentList<Component> subComps; if (val instanceof ComponentContainer) { subComps = ((ComponentContainer<Component>)val).getComponents(); } else { subComps = null; } final Set<Integer> pids; if (vpoll) { pids = new TreeSet<>(); final BwEvent vp = evinfo.getEvent(); if (!Util.isEmpty(vp.getPollItems())) { vp.clearPollItems(); } } else { pids = null; } if (!Util.isEmpty(subComps)) { for (final var subComp: subComps) { if (subComp instanceof Available) { if (!(val instanceof VAvailability)) { return Response.error(resp, "AVAILABLE only valid in VAVAILABLE"); } final var avlResp = processAvailable(cb, cal, ical, (VAvailability)val, (Available)subComp, evinfo); if (!avlResp.isOk()) { return Response.fromResponse(resp, avlResp); } continue; } if (subComp instanceof Participant) { if (vpoll) { final var vresp = processVoter(cb, (VPoll)val, (Participant)subComp, evinfo, chg, mergeAttendees); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Participant object"); continue; } if (subComp instanceof VResource) { logger.warn("Unimplemented VResource object"); continue; } if (subComp instanceof VLocation) { logger.warn("Unimplemented VLocation object"); continue; } if (subComp instanceof VAlarm) { final var aresp = VAlarmUtil.processAlarm(cb, val, (VAlarm)subComp, ev, currentPrincipal, chg); if (!aresp.isOk()) { return Response.fromResponse(resp, aresp); } continue; } if (vpoll && (event || task)) { final var vresp = processCandidate((VPoll)val, subComp, evinfo, pids, chg); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Component object: " + subComp); } } /* Fix up timestamps. */ if (ev.getCreated() == null) { if (ev.getLastmod() != null) { ev.setCreated(ev.getLastmod()); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); } else { ev.updateDtstamp(); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } } if (ev.getLastmod() == null) { // created cannot be null now ev.setLastmod(ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } processTimezones(ev, ical, chg); /* Remove any recipients and originator */ if (ev.getRecipients() != null) { ev.getRecipients().clear(); } ev.setOriginator(null); if (hasXparams.value) { /* Save a text copy of the entire event as an x-property */ final Component valCopy = val.copy(); /* Remove potentially large values */ final Description desp = valCopy.getProperty(Property.DESCRIPTION); if (desp != null) { desp.setValue(null); } final Attach attachp = valCopy.getProperty(Property.ATTACH); // Don't store the entire attachment - we just need the parameters. if (attachp != null) { final Value v = attachp.getParameter(Parameter.VALUE); if (v != null) { attachp.setValue(String.valueOf(attachp.getValue().hashCode())); } } chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(BwXproperty.bedeworkIcal, null, valCopy.toString())); } chg.processChanges(ev, true, false); ev.setRecurring(ev.isRecurringEntity()); if (logger.debug()) { logger.debug(chg.toString()); logger.debug(ev.toString()); } if (masterEI != null) { // Just return notfound as this event is on its override list return Response.notFound(resp); } resp.setEntity(evinfo); return resp; } catch (final Throwable t) { if (logger.debug()) { logger.error(t); } return Response.error(resp, t); } }
NONSATD
true
break; case FREEBUSY: /* ------------------- freebusy -------------------- */ final FreeBusy fbusy = (FreeBusy)prop; final PeriodList perpl = fbusy.getPeriods();
case EXDATE: /* ------------------- ExDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case EXRULE: /* ------------------- ExRule -------------------- */ chg.addValue(pi, pval); break; case FREEBUSY: /* ------------------- freebusy -------------------- */ final FreeBusy fbusy = (FreeBusy)prop; final PeriodList perpl = fbusy.getPeriods(); final Parameter par = IcalUtil.getParameter(fbusy, "FBTYPE"); final int fbtype; if (par == null) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY)) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY_TENTATIVE)) { fbtype = BwFreeBusyComponent.typeBusyTentative;
break; case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE: /* -------------------- Due ------------------------ */ break; case DURATION: /* ------------------- Duration -------------------- */ break; case EXDATE: /* ------------------- ExDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case EXRULE: /* ------------------- ExRule -------------------- */ chg.addValue(pi, pval); break; case FREEBUSY: /* ------------------- freebusy -------------------- */ final FreeBusy fbusy = (FreeBusy)prop; final PeriodList perpl = fbusy.getPeriods(); final Parameter par = IcalUtil.getParameter(fbusy, "FBTYPE"); final int fbtype; if (par == null) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY)) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY_TENTATIVE)) { fbtype = BwFreeBusyComponent.typeBusyTentative; } else if (par.equals(FbType.BUSY_UNAVAILABLE)) { fbtype = BwFreeBusyComponent.typeBusyUnavailable; } else if (par.equals(FbType.FREE)) { fbtype = BwFreeBusyComponent.typeFree; } else { if (logger.debug()) { logger.debug("Unsupported parameter " + par.getName()); } return Response.notOk(resp, failed, "Unsupported parameter " +
7,893
47
/* ------------------- Geo -------------------- */
public static GetEntityResponse<EventInfo> toEvent( final IcalCallback cb, final BwCalendar cal, final Icalendar ical, final Component val, final boolean mergeAttendees) { final var resp = new GetEntityResponse<EventInfo>(); if (val == null) { return Response.notOk(resp, failed, "No component supplied"); } String currentPrincipal = null; final BwPrincipal principal = cb.getPrincipal(); if (principal != null) { currentPrincipal = principal.getPrincipalRef(); } final Holder<Boolean> hasXparams = new Holder<>(Boolean.FALSE); final int methodType = ical.getMethodType(); String attUri = null; if (mergeAttendees) { // We'll need this later. attUri = cb.getCaladdr(cb.getPrincipal().getPrincipalRef()); } final String colPath; if (cal == null) { colPath = null; } else { colPath = cal.getPath(); } try { final PropertyList<Property> pl = val.getProperties(); boolean vpoll = false; boolean event = false; boolean task = false; if (pl == null) { // Empty component return Response.notOk(resp, failed, "Empty component"); } final int entityType; if (val instanceof VEvent) { entityType = IcalDefs.entityTypeEvent; event = true; } else if (val instanceof VToDo) { entityType = IcalDefs.entityTypeTodo; task = true; } else if (val instanceof VJournal) { entityType = IcalDefs.entityTypeJournal; } else if (val instanceof VFreeBusy) { entityType = IcalDefs.entityTypeFreeAndBusy; } else if (val instanceof VAvailability) { entityType = IcalDefs.entityTypeVavailability; } else if (val instanceof Available) { entityType = IcalDefs.entityTypeAvailable; } else if (val instanceof VPoll) { entityType = IcalDefs.entityTypeVpoll; vpoll = true; } else { return Response.error(resp, "org.bedework.invalid.component.type: " + val.getName()); } // Get the guid from the component String guid = null; final Uid uidp = pl.getProperty(Property.UID); if (uidp != null) { testXparams(uidp, hasXparams); guid = uidp.getValue(); } if (guid == null) { /* XXX A guid is required - but are there devices out there without a * guid - and if so how do we handle it? */ return Response.notOk(resp, failed, CalFacadeException.noGuid); } /* See if we have a recurrence id */ BwDateTime ridObj = null; String rid = null; TimeZone ridTz = null; final RecurrenceId ridp = pl.getProperty(Property.RECURRENCE_ID); if (ridp != null) { testXparams(ridp, hasXparams); ridObj = BwDateTime.makeBwDateTime(ridp); if (ridObj.getRange() != null) { /* XXX What do I do with it? */ logger.warn("TRANS-TO_EVENT: Got a recurrence id range"); } rid = ridObj.getDate(); } EventInfo masterEI = null; EventInfo evinfo = null; final BwEvent ev; /* If we have a recurrence id see if we already have the master (we should * get a master + all its overrides). * * If so find the override and use the annnotation or if no override, * make one. * * If no override retrieve the event, add it to our table and then locate the * annotation. * * If there is no annotation, create one. * * It's possible we have been sent 'detached' instances of a recurring * event. This may happen if we are invited to one or more instances of a * meeting. In this case we try to retrieve the master and if it doesn't * exist we manufacture one. We consider such an instance an update to * that instance only and leave the others alone. */ /* We need this in a couple of places */ final DtStart dtStart = pl.getProperty(Property.DTSTART); /* if (rid != null) { // See if we have a new master event. If so create a proxy to that event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI == null) { masterEI = makeNewEvent(cb, chg, entityType, guid, cal); BwEvent e = masterEI.getEvent(); // XXX This seems bogus DtStart mdtStart; String bogusDate = "19980118T230000"; if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + "Z"); } else if (dtStart.getTimeZone() == null) { mdtStart = new DtStart(bogusDate); } else { mdtStart = new DtStart(bogusDate + "Z", dtStart.getTimeZone()); } setDates(e, mdtStart, null, null, chg); e.setRecurring(true); e.addRdate(ridObj); e.setSuppressed(true); ical.addComponent(masterEI); } if (masterEI != null) { evinfo = masterEI.findOverride(rid); } } */ /* If this is a recurrence instance see if we can find the master We only need this because the master may follow the overrides. */ if (rid != null) { // See if we have a new master event. If so create a proxy to this event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI != null) { evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; } } if ((evinfo == null) && (cal != null) && (cal.getCalType() != BwCalendar.calTypeInbox) && (cal.getCalType() != BwCalendar.calTypePendingInbox) && (cal.getCalType() != BwCalendar.calTypeOutbox)) { if (logger.debug()) { logger.debug("TRANS-TO_EVENT: try to fetch event with guid=" + guid); } final GetEntitiesResponse<EventInfo> eisResp = cb.getEvent(colPath, guid); if (eisResp.isError()) { return Response.fromResponse(resp, eisResp); } final var eis = eisResp.getEntities(); if (!Util.isEmpty(eis)) { if (eis.size() > 1) { // DORECUR - wrong again return Response.notOk(resp, failed, "More than one event returned for guid."); } evinfo = eis.iterator().next(); } if (logger.debug()) { if (evinfo != null) { logger.debug("TRANS-TO_EVENT: fetched event with guid"); } else { logger.debug("TRANS-TO_EVENT: did not find event with guid"); } } if (evinfo != null) { if (rid != null) { // We just retrieved it's master masterEI = evinfo; masterEI.setInstanceOnly(true); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; ical.addComponent(masterEI); } else if (methodType == ScheduleMethods.methodTypeCancel) { // This should never have an rid for cancel of entire event. evinfo.setInstanceOnly(evinfo.getEvent().getSuppressed()); } else { // Presumably sent an update for the entire event. No longer suppressed master evinfo.getEvent().setSuppressed(false); } } else if (rid != null) { /* Manufacture a master for the instance */ masterEI = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); final BwEvent e = masterEI.getEvent(); // XXX This seems bogus final DtStart mdtStart; final String bogusDate = "19980118"; final String bogusTime = "T230000"; // Base dtstart on the recurrence id. final boolean isDateType = ridObj.getDateType(); if (isDateType) { mdtStart = new DtStart(new Date(bogusDate)); } else if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + bogusTime + "Z"); } else if (ridObj.getTzid() == null) { mdtStart = new DtStart(bogusDate + bogusTime); } else { mdtStart = new DtStart(bogusDate + bogusTime, Timezones.getTz(ridObj.getTzid())); } IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), masterEI, mdtStart, null, null); e.setRecurring(true); // e.addRdate(ridObj); final var sum = (Summary)pl.getProperty(Property.SUMMARY); e.setSummary(sum.getValue()); e.setSuppressed(true); ical.addComponent(masterEI); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; masterEI.setInstanceOnly(rid != null); } } if (evinfo == null) { evinfo = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); } else if (evinfo.getEvent().getEntityType() != entityType) { return Response.notOk(resp, failed, "org.bedework.mismatched.entity.type: " + val); } final ChangeTable chg = evinfo.getChangeset( cb.getPrincipal().getPrincipalRef()); if (rid != null) { final String evrid = evinfo.getEvent().getRecurrenceId(); if ((evrid == null) || (!evrid.equals(rid))) { logger. warn("Mismatched rid ev=" + evrid + " expected " + rid); chg.changed(PropertyInfoIndex.RECURRENCE_ID, evrid, rid); // XXX spurious??? } if (masterEI.getEvent().getSuppressed()) { masterEI.getEvent().addRdate(ridObj); } } ev = evinfo.getEvent(); ev.setScheduleMethod(methodType); DtEnd dtEnd = null; if (entityType == IcalDefs.entityTypeTodo) { final Due due = pl.getProperty(Property.DUE); if (due != null ) { dtEnd = new DtEnd(due.getParameters(), due.getValue()); } } else { dtEnd = pl.getProperty(Property.DTEND); } final Duration duration = pl.getProperty(Property.DURATION); IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), evinfo, dtStart, dtEnd, duration); for (final Property prop: pl) { testXparams(prop, hasXparams); //debug("ical prop " + prop.getClass().getName()); String pval = prop.getValue(); if ((pval != null) && (pval.length() == 0)) { pval = null; } final PropertyInfoIndex pi; if (prop instanceof XProperty) { pi = PropertyInfoIndex.XPROP; } else { pi = PropertyInfoIndex.fromName(prop.getName()); } if (pi == null) { logger.debug("Unknown property with name " + prop.getName() + " class " + prop.getClass() + " and value " + pval); continue; } chg.present(pi); switch (pi) { case ACCEPT_RESPONSE: /* ------------------- Accept Response -------------------- */ String sval = prop.getValue(); if (chg.changed(pi, ev.getPollAcceptResponse(), sval)) { ev.setPollAcceptResponse(sval); } break; case ATTACH: /* ------------------- Attachment -------------------- */ chg.addValue(pi, IcalUtil.getAttachment((Attach)prop)); break; case ATTENDEE: /* ------------------- Attendee -------------------- */ if (methodType == ScheduleMethods.methodTypePublish) { if (cb.getStrictness() == IcalCallback.conformanceStrict) { return Response.notOk(resp, failed, CalFacadeException.attendeesInPublish); } //if (cb.getStrictness() == IcalCallback.conformanceWarn) { // warn("Had attendees for PUBLISH"); //} } final Attendee attPr = (Attendee)prop; if (evinfo.getNewEvent() || !mergeAttendees) { chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { final String pUri = cb.getCaladdr(attPr.getValue()); if (pUri.equals(attUri)) { /* Only update for our own attendee * We're doing a PUT and this must be the attendee updating their * partstat. We don't allow them to change other attendees * whatever the PUT content says. */ chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { // Use the value we currently have boolean found = false; for (final BwAttendee att: ev.getAttendees()) { if (pUri.equals(att.getAttendeeUri())) { chg.addValue(pi, att.clone()); found = true; break; } } if (!found) { // An added attendee final BwAttendee att = IcalUtil .getAttendee(cb, attPr); att.setPartstat(IcalDefs.partstatValNeedsAction); chg.addValue(pi, att); } } } break; case BUSYTYPE: final int ibt = BwEvent.fromBusyTypeString(pval); if (chg.changed(pi, ev.getBusyType(), ibt)) { ev.setBusyType(ibt); } break; case CATEGORIES: /* ------------------- Categories -------------------- */ final Categories cats = (Categories)prop; final TextList cl = cats.getCategories(); String lang = IcalUtil.getLang(cats); if (cl != null) { /* Got some categories */ for (final String wd: cl) { if (wd == null) { continue; } final BwString key = new BwString(lang, wd); final var fcResp = cb.findCategory(key); final BwCategory cat; if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isNotFound()) { cat = BwCategory.makeCategory(); cat.setWord(key); cb.addCategory(cat); } else { cat = fcResp.getEntity(); } chg.addValue(pi, cat); } } break; case CLASS: /* ------------------- Class -------------------- */ if (chg.changed(pi, ev.getClassification(), pval)) { ev.setClassification(pval); } break; case COMMENT: /* ------------------- Comment -------------------- */ chg.addValue(pi, new BwString(null, pval)); break; case COMPLETED: /* ------------------- Completed -------------------- */ if (chg.changed(pi, ev.getCompleted(), pval)) { ev.setCompleted(pval); } break; case CONCEPT: /* ------------------- Concept -------------------- */ final Concept c = (Concept)prop; final String cval = c.getValue(); if (cval != null) { /* Got a concept */ chg.addValue(PropertyInfoIndex.XPROP, BwXproperty.makeIcalProperty("CONCEPT", null, cval)); } break; case CONTACT: /* ------------------- Contact -------------------- */ final String altrep = getAltRepPar(prop); lang = IcalUtil.getLang(prop); final String uid = getUidPar(prop); final BwString nm = new BwString(lang, pval); BwContact contact = null; if (uid != null) { final var fcResp = cb.getContact(uid); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { final var fcResp = cb.findContact(nm); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { contact = BwContact.makeContact(); contact.setCn(nm); contact.setLink(altrep); cb.addContact(contact); } else { contact.setCn(nm); contact.setLink(altrep); } chg.addValue(pi, contact); break; case CREATED: /* ------------------- Created -------------------- */ if (chg.changed(pi, ev.getCreated(), pval)) { ev.setCreated(pval); } break; case DESCRIPTION: /* ------------------- Description -------------------- */ if (chg.changed(pi, ev.getDescription(), pval)) { ev.setDescription(pval); } break; case DTEND: /* ------------------- DtEnd -------------------- */ break; case DTSTAMP: /* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval); break; case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE: /* -------------------- Due ------------------------ */ break; case DURATION: /* ------------------- Duration -------------------- */ break; case EXDATE: /* ------------------- ExDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case EXRULE: /* ------------------- ExRule -------------------- */ chg.addValue(pi, pval); break; case FREEBUSY: /* ------------------- freebusy -------------------- */ final FreeBusy fbusy = (FreeBusy)prop; final PeriodList perpl = fbusy.getPeriods(); final Parameter par = IcalUtil.getParameter(fbusy, "FBTYPE"); final int fbtype; if (par == null) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY)) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY_TENTATIVE)) { fbtype = BwFreeBusyComponent.typeBusyTentative; } else if (par.equals(FbType.BUSY_UNAVAILABLE)) { fbtype = BwFreeBusyComponent.typeBusyUnavailable; } else if (par.equals(FbType.FREE)) { fbtype = BwFreeBusyComponent.typeFree; } else { if (logger.debug()) { logger.debug("Unsupported parameter " + par.getName()); } return Response.notOk(resp, failed, "Unsupported parameter " + par.getName()); } final BwFreeBusyComponent fbc = new BwFreeBusyComponent(); fbc.setType(fbtype); for (final Period per : perpl) { fbc.addPeriod(per); } ev.addFreeBusyPeriod(fbc); break; case GEO: /* ------------------- Geo -------------------- */ final Geo g = (Geo)prop; final BwGeo geo = new BwGeo(g.getLatitude(), g.getLongitude()); if (chg.changed(pi, ev.getGeo(), geo)) { ev.setGeo(geo); } break; case LAST_MODIFIED: /* ------------------- LastModified -------------------- */ if (chg.changed(pi, ev.getLastmod(), pval)) { ev.setLastmod(pval); } break; case LOCATION: /* ------------------- Location -------------------- */ BwLocation loc = null; //String uid = getUidPar(prop); /* At the moment Mozilla lightning is broken and this leads to all * sorts of problems. if (uid != null) { loc = cb.getLocation(uid); } */ lang = IcalUtil.getLang(prop); BwString addr = null; if (pval != null) { if (loc == null) { addr = new BwString(lang, pval); final var fcResp = cb.findLocation(addr); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { loc = fcResp.getEntity(); } } if (loc == null) { loc = BwLocation.makeLocation(); loc.setAddress(addr); cb.addLocation(loc); } } final BwLocation evloc = ev.getLocation(); if (chg.changed(pi, evloc, loc)) { // CHGTBL - this only shows that it's a different location object ev.setLocation(loc); } else if ((loc != null) && (evloc != null)) { // See if the value is changed final String evval = evloc.getAddress().getValue(); final String inval = loc.getAddress().getValue(); if (!evval.equals(inval)) { chg.changed(pi, evval, inval); evloc.getAddress().setValue(inval); } } break; case ORGANIZER: /* ------------------- Organizer -------------------- */ final BwOrganizer org = IcalUtil.getOrganizer(cb, (Organizer)prop); final BwOrganizer evorg = ev.getOrganizer(); final BwOrganizer evorgCopy; if (evorg == null) { evorgCopy = null; } else { evorgCopy = (BwOrganizer)evorg.clone(); } if (chg.changed(pi, evorgCopy, org)) { if (evorg == null) { ev.setOrganizer(org); } else { evorg.update(org); } } break; case PERCENT_COMPLETE: /* ------------------- PercentComplete -------------------- */ Integer ival = ((PercentComplete)prop).getPercentage(); if (chg.changed(pi, ev.getPercentComplete(), ival)) { ev.setPercentComplete(ival); } break; case POLL_MODE: /* ------------------- Poll mode -------------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollMode(), sval)) { ev.setPollMode(sval); } break; case POLL_PROPERTIES: /* ------------------- Poll properties ---------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollProperties(), sval)) { ev.setPollProperties(sval); } break; case POLL_WINNER: /* ------------------- Poll winner -------------------- */ ival = ((PollWinner)prop).getPollwinner(); if (chg.changed(pi, ev.getPollWinner(), ival)) { ev.setPollWinner(ival); } break; case PRIORITY: /* ------------------- Priority -------------------- */ ival = ((Priority)prop).getLevel(); if (chg.changed(pi, ev.getPriority(), ival)) { ev.setPriority(ival); } break; case RDATE: /* ------------------- RDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case RECURRENCE_ID: /* ------------------- RecurrenceID -------------------- */ // Done above break; case RELATED_TO: /* ------------------- RelatedTo -------------------- */ final RelatedTo irelto = (RelatedTo)prop; final BwRelatedTo relto = new BwRelatedTo(); final String parval = IcalUtil.getParameterVal(irelto, "RELTYPE"); if (parval != null) { relto.setRelType(parval); } relto.setValue(irelto.getValue()); if (chg.changed(pi, ev.getRelatedTo(), relto)) { ev.setRelatedTo(relto); } break; case REQUEST_STATUS: /* ------------------- RequestStatus -------------------- */ final BwRequestStatus rs = BwRequestStatus .fromRequestStatus((RequestStatus)prop); chg.addValue(pi, rs); break; case RESOURCES: /* ------------------- Resources -------------------- */ final TextList rl = ((Resources)prop).getResources(); if (rl != null) { /* Got some resources */ lang = IcalUtil.getLang(prop); for (final String s: rl) { final BwString rsrc = new BwString(lang, s); chg.addValue(pi, rsrc); } } break; case RRULE: /* ------------------- RRule -------------------- */ chg.addValue(pi, pval); break; case SEQUENCE: /* ------------------- Sequence -------------------- */ final int seq = ((Sequence)prop).getSequenceNo(); if (seq != ev.getSequence()) { chg.changed(pi, ev.getSequence(), seq); ev.setSequence(seq); } break; case STATUS: /* ------------------- Status -------------------- */ if (chg.changed(pi, ev.getStatus(), pval)) { ev.setStatus(pval); } break; case SUMMARY: /* ------------------- Summary -------------------- */ if (chg.changed(pi, ev.getSummary(), pval)) { ev.setSummary(pval); } break; case TRANSP: /* ------------------- Transp -------------------- */ if (chg.changed(pi, ev.getPeruserTransparency( cb.getPrincipal() .getPrincipalRef()), pval)) { final BwXproperty pu = ev.setPeruserTransparency( cb.getPrincipal().getPrincipalRef(), pval); if (pu != null) { chg.addValue(PropertyInfoIndex.XPROP, pu); } } break; case UID: /* ------------------- Uid -------------------- */ /* We did this above */ break; case URL: /* ------------------- Url -------------------- */ if (chg.changed(pi, ev.getLink(), pval)) { ev.setLink(pval); } break; case XPROP: /* ------------------------- x-property --------------------------- */ final String name = prop.getName(); if (name.equalsIgnoreCase(BwXproperty.bedeworkCost)) { if (chg.changed(PropertyInfoIndex.COST, ev.getCost(), pval)) { ev.setCost(pval); } break; } if (name.equalsIgnoreCase(BwXproperty.xBedeworkCategories)) { if (checkCategory(cb, chg, ev, null, pval)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkLocation)) { if (checkLocation(cb, chg, ev, prop)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkContact)) { if (checkContact(cb, chg, ev, null, pval)) { break; } } /* See if this is an x-category that can be converted to a real category */ final XProperty xp = (XProperty)prop; chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(name, xp.getParameters() .toString(), pval)); break; default: if (logger.debug()) { logger.debug("Unsupported property with index " + pi + "; class " + prop.getClass() + " and value " + pval); } } } /* =================== Process sub-components =============== */ final ComponentList<Component> subComps; if (val instanceof ComponentContainer) { subComps = ((ComponentContainer<Component>)val).getComponents(); } else { subComps = null; } final Set<Integer> pids; if (vpoll) { pids = new TreeSet<>(); final BwEvent vp = evinfo.getEvent(); if (!Util.isEmpty(vp.getPollItems())) { vp.clearPollItems(); } } else { pids = null; } if (!Util.isEmpty(subComps)) { for (final var subComp: subComps) { if (subComp instanceof Available) { if (!(val instanceof VAvailability)) { return Response.error(resp, "AVAILABLE only valid in VAVAILABLE"); } final var avlResp = processAvailable(cb, cal, ical, (VAvailability)val, (Available)subComp, evinfo); if (!avlResp.isOk()) { return Response.fromResponse(resp, avlResp); } continue; } if (subComp instanceof Participant) { if (vpoll) { final var vresp = processVoter(cb, (VPoll)val, (Participant)subComp, evinfo, chg, mergeAttendees); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Participant object"); continue; } if (subComp instanceof VResource) { logger.warn("Unimplemented VResource object"); continue; } if (subComp instanceof VLocation) { logger.warn("Unimplemented VLocation object"); continue; } if (subComp instanceof VAlarm) { final var aresp = VAlarmUtil.processAlarm(cb, val, (VAlarm)subComp, ev, currentPrincipal, chg); if (!aresp.isOk()) { return Response.fromResponse(resp, aresp); } continue; } if (vpoll && (event || task)) { final var vresp = processCandidate((VPoll)val, subComp, evinfo, pids, chg); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Component object: " + subComp); } } /* Fix up timestamps. */ if (ev.getCreated() == null) { if (ev.getLastmod() != null) { ev.setCreated(ev.getLastmod()); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); } else { ev.updateDtstamp(); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } } if (ev.getLastmod() == null) { // created cannot be null now ev.setLastmod(ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } processTimezones(ev, ical, chg); /* Remove any recipients and originator */ if (ev.getRecipients() != null) { ev.getRecipients().clear(); } ev.setOriginator(null); if (hasXparams.value) { /* Save a text copy of the entire event as an x-property */ final Component valCopy = val.copy(); /* Remove potentially large values */ final Description desp = valCopy.getProperty(Property.DESCRIPTION); if (desp != null) { desp.setValue(null); } final Attach attachp = valCopy.getProperty(Property.ATTACH); // Don't store the entire attachment - we just need the parameters. if (attachp != null) { final Value v = attachp.getParameter(Parameter.VALUE); if (v != null) { attachp.setValue(String.valueOf(attachp.getValue().hashCode())); } } chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(BwXproperty.bedeworkIcal, null, valCopy.toString())); } chg.processChanges(ev, true, false); ev.setRecurring(ev.isRecurringEntity()); if (logger.debug()) { logger.debug(chg.toString()); logger.debug(ev.toString()); } if (masterEI != null) { // Just return notfound as this event is on its override list return Response.notFound(resp); } resp.setEntity(evinfo); return resp; } catch (final Throwable t) { if (logger.debug()) { logger.error(t); } return Response.error(resp, t); } }
NONSATD
true
break; case GEO: /* ------------------- Geo -------------------- */ final Geo g = (Geo)prop; final BwGeo geo = new BwGeo(g.getLatitude(),
par.getName()); } final BwFreeBusyComponent fbc = new BwFreeBusyComponent(); fbc.setType(fbtype); for (final Period per : perpl) { fbc.addPeriod(per); } ev.addFreeBusyPeriod(fbc); break; case GEO: /* ------------------- Geo -------------------- */ final Geo g = (Geo)prop; final BwGeo geo = new BwGeo(g.getLatitude(), g.getLongitude()); if (chg.changed(pi, ev.getGeo(), geo)) { ev.setGeo(geo); } break; case LAST_MODIFIED: /* ------------------- LastModified -------------------- */ if (chg.changed(pi, ev.getLastmod(), pval)) {
} else if (par.equals(FbType.BUSY_UNAVAILABLE)) { fbtype = BwFreeBusyComponent.typeBusyUnavailable; } else if (par.equals(FbType.FREE)) { fbtype = BwFreeBusyComponent.typeFree; } else { if (logger.debug()) { logger.debug("Unsupported parameter " + par.getName()); } return Response.notOk(resp, failed, "Unsupported parameter " + par.getName()); } final BwFreeBusyComponent fbc = new BwFreeBusyComponent(); fbc.setType(fbtype); for (final Period per : perpl) { fbc.addPeriod(per); } ev.addFreeBusyPeriod(fbc); break; case GEO: /* ------------------- Geo -------------------- */ final Geo g = (Geo)prop; final BwGeo geo = new BwGeo(g.getLatitude(), g.getLongitude()); if (chg.changed(pi, ev.getGeo(), geo)) { ev.setGeo(geo); } break; case LAST_MODIFIED: /* ------------------- LastModified -------------------- */ if (chg.changed(pi, ev.getLastmod(), pval)) { ev.setLastmod(pval); } break; case LOCATION: /* ------------------- Location -------------------- */ BwLocation loc = null; //String uid = getUidPar(prop); /* At the moment Mozilla lightning is broken and this leads to all * sorts of problems. if (uid != null) {
7,893
48
/* ------------------- LastModified -------------------- */
public static GetEntityResponse<EventInfo> toEvent( final IcalCallback cb, final BwCalendar cal, final Icalendar ical, final Component val, final boolean mergeAttendees) { final var resp = new GetEntityResponse<EventInfo>(); if (val == null) { return Response.notOk(resp, failed, "No component supplied"); } String currentPrincipal = null; final BwPrincipal principal = cb.getPrincipal(); if (principal != null) { currentPrincipal = principal.getPrincipalRef(); } final Holder<Boolean> hasXparams = new Holder<>(Boolean.FALSE); final int methodType = ical.getMethodType(); String attUri = null; if (mergeAttendees) { // We'll need this later. attUri = cb.getCaladdr(cb.getPrincipal().getPrincipalRef()); } final String colPath; if (cal == null) { colPath = null; } else { colPath = cal.getPath(); } try { final PropertyList<Property> pl = val.getProperties(); boolean vpoll = false; boolean event = false; boolean task = false; if (pl == null) { // Empty component return Response.notOk(resp, failed, "Empty component"); } final int entityType; if (val instanceof VEvent) { entityType = IcalDefs.entityTypeEvent; event = true; } else if (val instanceof VToDo) { entityType = IcalDefs.entityTypeTodo; task = true; } else if (val instanceof VJournal) { entityType = IcalDefs.entityTypeJournal; } else if (val instanceof VFreeBusy) { entityType = IcalDefs.entityTypeFreeAndBusy; } else if (val instanceof VAvailability) { entityType = IcalDefs.entityTypeVavailability; } else if (val instanceof Available) { entityType = IcalDefs.entityTypeAvailable; } else if (val instanceof VPoll) { entityType = IcalDefs.entityTypeVpoll; vpoll = true; } else { return Response.error(resp, "org.bedework.invalid.component.type: " + val.getName()); } // Get the guid from the component String guid = null; final Uid uidp = pl.getProperty(Property.UID); if (uidp != null) { testXparams(uidp, hasXparams); guid = uidp.getValue(); } if (guid == null) { /* XXX A guid is required - but are there devices out there without a * guid - and if so how do we handle it? */ return Response.notOk(resp, failed, CalFacadeException.noGuid); } /* See if we have a recurrence id */ BwDateTime ridObj = null; String rid = null; TimeZone ridTz = null; final RecurrenceId ridp = pl.getProperty(Property.RECURRENCE_ID); if (ridp != null) { testXparams(ridp, hasXparams); ridObj = BwDateTime.makeBwDateTime(ridp); if (ridObj.getRange() != null) { /* XXX What do I do with it? */ logger.warn("TRANS-TO_EVENT: Got a recurrence id range"); } rid = ridObj.getDate(); } EventInfo masterEI = null; EventInfo evinfo = null; final BwEvent ev; /* If we have a recurrence id see if we already have the master (we should * get a master + all its overrides). * * If so find the override and use the annnotation or if no override, * make one. * * If no override retrieve the event, add it to our table and then locate the * annotation. * * If there is no annotation, create one. * * It's possible we have been sent 'detached' instances of a recurring * event. This may happen if we are invited to one or more instances of a * meeting. In this case we try to retrieve the master and if it doesn't * exist we manufacture one. We consider such an instance an update to * that instance only and leave the others alone. */ /* We need this in a couple of places */ final DtStart dtStart = pl.getProperty(Property.DTSTART); /* if (rid != null) { // See if we have a new master event. If so create a proxy to that event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI == null) { masterEI = makeNewEvent(cb, chg, entityType, guid, cal); BwEvent e = masterEI.getEvent(); // XXX This seems bogus DtStart mdtStart; String bogusDate = "19980118T230000"; if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + "Z"); } else if (dtStart.getTimeZone() == null) { mdtStart = new DtStart(bogusDate); } else { mdtStart = new DtStart(bogusDate + "Z", dtStart.getTimeZone()); } setDates(e, mdtStart, null, null, chg); e.setRecurring(true); e.addRdate(ridObj); e.setSuppressed(true); ical.addComponent(masterEI); } if (masterEI != null) { evinfo = masterEI.findOverride(rid); } } */ /* If this is a recurrence instance see if we can find the master We only need this because the master may follow the overrides. */ if (rid != null) { // See if we have a new master event. If so create a proxy to this event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI != null) { evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; } } if ((evinfo == null) && (cal != null) && (cal.getCalType() != BwCalendar.calTypeInbox) && (cal.getCalType() != BwCalendar.calTypePendingInbox) && (cal.getCalType() != BwCalendar.calTypeOutbox)) { if (logger.debug()) { logger.debug("TRANS-TO_EVENT: try to fetch event with guid=" + guid); } final GetEntitiesResponse<EventInfo> eisResp = cb.getEvent(colPath, guid); if (eisResp.isError()) { return Response.fromResponse(resp, eisResp); } final var eis = eisResp.getEntities(); if (!Util.isEmpty(eis)) { if (eis.size() > 1) { // DORECUR - wrong again return Response.notOk(resp, failed, "More than one event returned for guid."); } evinfo = eis.iterator().next(); } if (logger.debug()) { if (evinfo != null) { logger.debug("TRANS-TO_EVENT: fetched event with guid"); } else { logger.debug("TRANS-TO_EVENT: did not find event with guid"); } } if (evinfo != null) { if (rid != null) { // We just retrieved it's master masterEI = evinfo; masterEI.setInstanceOnly(true); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; ical.addComponent(masterEI); } else if (methodType == ScheduleMethods.methodTypeCancel) { // This should never have an rid for cancel of entire event. evinfo.setInstanceOnly(evinfo.getEvent().getSuppressed()); } else { // Presumably sent an update for the entire event. No longer suppressed master evinfo.getEvent().setSuppressed(false); } } else if (rid != null) { /* Manufacture a master for the instance */ masterEI = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); final BwEvent e = masterEI.getEvent(); // XXX This seems bogus final DtStart mdtStart; final String bogusDate = "19980118"; final String bogusTime = "T230000"; // Base dtstart on the recurrence id. final boolean isDateType = ridObj.getDateType(); if (isDateType) { mdtStart = new DtStart(new Date(bogusDate)); } else if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + bogusTime + "Z"); } else if (ridObj.getTzid() == null) { mdtStart = new DtStart(bogusDate + bogusTime); } else { mdtStart = new DtStart(bogusDate + bogusTime, Timezones.getTz(ridObj.getTzid())); } IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), masterEI, mdtStart, null, null); e.setRecurring(true); // e.addRdate(ridObj); final var sum = (Summary)pl.getProperty(Property.SUMMARY); e.setSummary(sum.getValue()); e.setSuppressed(true); ical.addComponent(masterEI); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; masterEI.setInstanceOnly(rid != null); } } if (evinfo == null) { evinfo = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); } else if (evinfo.getEvent().getEntityType() != entityType) { return Response.notOk(resp, failed, "org.bedework.mismatched.entity.type: " + val); } final ChangeTable chg = evinfo.getChangeset( cb.getPrincipal().getPrincipalRef()); if (rid != null) { final String evrid = evinfo.getEvent().getRecurrenceId(); if ((evrid == null) || (!evrid.equals(rid))) { logger. warn("Mismatched rid ev=" + evrid + " expected " + rid); chg.changed(PropertyInfoIndex.RECURRENCE_ID, evrid, rid); // XXX spurious??? } if (masterEI.getEvent().getSuppressed()) { masterEI.getEvent().addRdate(ridObj); } } ev = evinfo.getEvent(); ev.setScheduleMethod(methodType); DtEnd dtEnd = null; if (entityType == IcalDefs.entityTypeTodo) { final Due due = pl.getProperty(Property.DUE); if (due != null ) { dtEnd = new DtEnd(due.getParameters(), due.getValue()); } } else { dtEnd = pl.getProperty(Property.DTEND); } final Duration duration = pl.getProperty(Property.DURATION); IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), evinfo, dtStart, dtEnd, duration); for (final Property prop: pl) { testXparams(prop, hasXparams); //debug("ical prop " + prop.getClass().getName()); String pval = prop.getValue(); if ((pval != null) && (pval.length() == 0)) { pval = null; } final PropertyInfoIndex pi; if (prop instanceof XProperty) { pi = PropertyInfoIndex.XPROP; } else { pi = PropertyInfoIndex.fromName(prop.getName()); } if (pi == null) { logger.debug("Unknown property with name " + prop.getName() + " class " + prop.getClass() + " and value " + pval); continue; } chg.present(pi); switch (pi) { case ACCEPT_RESPONSE: /* ------------------- Accept Response -------------------- */ String sval = prop.getValue(); if (chg.changed(pi, ev.getPollAcceptResponse(), sval)) { ev.setPollAcceptResponse(sval); } break; case ATTACH: /* ------------------- Attachment -------------------- */ chg.addValue(pi, IcalUtil.getAttachment((Attach)prop)); break; case ATTENDEE: /* ------------------- Attendee -------------------- */ if (methodType == ScheduleMethods.methodTypePublish) { if (cb.getStrictness() == IcalCallback.conformanceStrict) { return Response.notOk(resp, failed, CalFacadeException.attendeesInPublish); } //if (cb.getStrictness() == IcalCallback.conformanceWarn) { // warn("Had attendees for PUBLISH"); //} } final Attendee attPr = (Attendee)prop; if (evinfo.getNewEvent() || !mergeAttendees) { chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { final String pUri = cb.getCaladdr(attPr.getValue()); if (pUri.equals(attUri)) { /* Only update for our own attendee * We're doing a PUT and this must be the attendee updating their * partstat. We don't allow them to change other attendees * whatever the PUT content says. */ chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { // Use the value we currently have boolean found = false; for (final BwAttendee att: ev.getAttendees()) { if (pUri.equals(att.getAttendeeUri())) { chg.addValue(pi, att.clone()); found = true; break; } } if (!found) { // An added attendee final BwAttendee att = IcalUtil .getAttendee(cb, attPr); att.setPartstat(IcalDefs.partstatValNeedsAction); chg.addValue(pi, att); } } } break; case BUSYTYPE: final int ibt = BwEvent.fromBusyTypeString(pval); if (chg.changed(pi, ev.getBusyType(), ibt)) { ev.setBusyType(ibt); } break; case CATEGORIES: /* ------------------- Categories -------------------- */ final Categories cats = (Categories)prop; final TextList cl = cats.getCategories(); String lang = IcalUtil.getLang(cats); if (cl != null) { /* Got some categories */ for (final String wd: cl) { if (wd == null) { continue; } final BwString key = new BwString(lang, wd); final var fcResp = cb.findCategory(key); final BwCategory cat; if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isNotFound()) { cat = BwCategory.makeCategory(); cat.setWord(key); cb.addCategory(cat); } else { cat = fcResp.getEntity(); } chg.addValue(pi, cat); } } break; case CLASS: /* ------------------- Class -------------------- */ if (chg.changed(pi, ev.getClassification(), pval)) { ev.setClassification(pval); } break; case COMMENT: /* ------------------- Comment -------------------- */ chg.addValue(pi, new BwString(null, pval)); break; case COMPLETED: /* ------------------- Completed -------------------- */ if (chg.changed(pi, ev.getCompleted(), pval)) { ev.setCompleted(pval); } break; case CONCEPT: /* ------------------- Concept -------------------- */ final Concept c = (Concept)prop; final String cval = c.getValue(); if (cval != null) { /* Got a concept */ chg.addValue(PropertyInfoIndex.XPROP, BwXproperty.makeIcalProperty("CONCEPT", null, cval)); } break; case CONTACT: /* ------------------- Contact -------------------- */ final String altrep = getAltRepPar(prop); lang = IcalUtil.getLang(prop); final String uid = getUidPar(prop); final BwString nm = new BwString(lang, pval); BwContact contact = null; if (uid != null) { final var fcResp = cb.getContact(uid); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { final var fcResp = cb.findContact(nm); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { contact = BwContact.makeContact(); contact.setCn(nm); contact.setLink(altrep); cb.addContact(contact); } else { contact.setCn(nm); contact.setLink(altrep); } chg.addValue(pi, contact); break; case CREATED: /* ------------------- Created -------------------- */ if (chg.changed(pi, ev.getCreated(), pval)) { ev.setCreated(pval); } break; case DESCRIPTION: /* ------------------- Description -------------------- */ if (chg.changed(pi, ev.getDescription(), pval)) { ev.setDescription(pval); } break; case DTEND: /* ------------------- DtEnd -------------------- */ break; case DTSTAMP: /* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval); break; case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE: /* -------------------- Due ------------------------ */ break; case DURATION: /* ------------------- Duration -------------------- */ break; case EXDATE: /* ------------------- ExDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case EXRULE: /* ------------------- ExRule -------------------- */ chg.addValue(pi, pval); break; case FREEBUSY: /* ------------------- freebusy -------------------- */ final FreeBusy fbusy = (FreeBusy)prop; final PeriodList perpl = fbusy.getPeriods(); final Parameter par = IcalUtil.getParameter(fbusy, "FBTYPE"); final int fbtype; if (par == null) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY)) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY_TENTATIVE)) { fbtype = BwFreeBusyComponent.typeBusyTentative; } else if (par.equals(FbType.BUSY_UNAVAILABLE)) { fbtype = BwFreeBusyComponent.typeBusyUnavailable; } else if (par.equals(FbType.FREE)) { fbtype = BwFreeBusyComponent.typeFree; } else { if (logger.debug()) { logger.debug("Unsupported parameter " + par.getName()); } return Response.notOk(resp, failed, "Unsupported parameter " + par.getName()); } final BwFreeBusyComponent fbc = new BwFreeBusyComponent(); fbc.setType(fbtype); for (final Period per : perpl) { fbc.addPeriod(per); } ev.addFreeBusyPeriod(fbc); break; case GEO: /* ------------------- Geo -------------------- */ final Geo g = (Geo)prop; final BwGeo geo = new BwGeo(g.getLatitude(), g.getLongitude()); if (chg.changed(pi, ev.getGeo(), geo)) { ev.setGeo(geo); } break; case LAST_MODIFIED: /* ------------------- LastModified -------------------- */ if (chg.changed(pi, ev.getLastmod(), pval)) { ev.setLastmod(pval); } break; case LOCATION: /* ------------------- Location -------------------- */ BwLocation loc = null; //String uid = getUidPar(prop); /* At the moment Mozilla lightning is broken and this leads to all * sorts of problems. if (uid != null) { loc = cb.getLocation(uid); } */ lang = IcalUtil.getLang(prop); BwString addr = null; if (pval != null) { if (loc == null) { addr = new BwString(lang, pval); final var fcResp = cb.findLocation(addr); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { loc = fcResp.getEntity(); } } if (loc == null) { loc = BwLocation.makeLocation(); loc.setAddress(addr); cb.addLocation(loc); } } final BwLocation evloc = ev.getLocation(); if (chg.changed(pi, evloc, loc)) { // CHGTBL - this only shows that it's a different location object ev.setLocation(loc); } else if ((loc != null) && (evloc != null)) { // See if the value is changed final String evval = evloc.getAddress().getValue(); final String inval = loc.getAddress().getValue(); if (!evval.equals(inval)) { chg.changed(pi, evval, inval); evloc.getAddress().setValue(inval); } } break; case ORGANIZER: /* ------------------- Organizer -------------------- */ final BwOrganizer org = IcalUtil.getOrganizer(cb, (Organizer)prop); final BwOrganizer evorg = ev.getOrganizer(); final BwOrganizer evorgCopy; if (evorg == null) { evorgCopy = null; } else { evorgCopy = (BwOrganizer)evorg.clone(); } if (chg.changed(pi, evorgCopy, org)) { if (evorg == null) { ev.setOrganizer(org); } else { evorg.update(org); } } break; case PERCENT_COMPLETE: /* ------------------- PercentComplete -------------------- */ Integer ival = ((PercentComplete)prop).getPercentage(); if (chg.changed(pi, ev.getPercentComplete(), ival)) { ev.setPercentComplete(ival); } break; case POLL_MODE: /* ------------------- Poll mode -------------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollMode(), sval)) { ev.setPollMode(sval); } break; case POLL_PROPERTIES: /* ------------------- Poll properties ---------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollProperties(), sval)) { ev.setPollProperties(sval); } break; case POLL_WINNER: /* ------------------- Poll winner -------------------- */ ival = ((PollWinner)prop).getPollwinner(); if (chg.changed(pi, ev.getPollWinner(), ival)) { ev.setPollWinner(ival); } break; case PRIORITY: /* ------------------- Priority -------------------- */ ival = ((Priority)prop).getLevel(); if (chg.changed(pi, ev.getPriority(), ival)) { ev.setPriority(ival); } break; case RDATE: /* ------------------- RDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case RECURRENCE_ID: /* ------------------- RecurrenceID -------------------- */ // Done above break; case RELATED_TO: /* ------------------- RelatedTo -------------------- */ final RelatedTo irelto = (RelatedTo)prop; final BwRelatedTo relto = new BwRelatedTo(); final String parval = IcalUtil.getParameterVal(irelto, "RELTYPE"); if (parval != null) { relto.setRelType(parval); } relto.setValue(irelto.getValue()); if (chg.changed(pi, ev.getRelatedTo(), relto)) { ev.setRelatedTo(relto); } break; case REQUEST_STATUS: /* ------------------- RequestStatus -------------------- */ final BwRequestStatus rs = BwRequestStatus .fromRequestStatus((RequestStatus)prop); chg.addValue(pi, rs); break; case RESOURCES: /* ------------------- Resources -------------------- */ final TextList rl = ((Resources)prop).getResources(); if (rl != null) { /* Got some resources */ lang = IcalUtil.getLang(prop); for (final String s: rl) { final BwString rsrc = new BwString(lang, s); chg.addValue(pi, rsrc); } } break; case RRULE: /* ------------------- RRule -------------------- */ chg.addValue(pi, pval); break; case SEQUENCE: /* ------------------- Sequence -------------------- */ final int seq = ((Sequence)prop).getSequenceNo(); if (seq != ev.getSequence()) { chg.changed(pi, ev.getSequence(), seq); ev.setSequence(seq); } break; case STATUS: /* ------------------- Status -------------------- */ if (chg.changed(pi, ev.getStatus(), pval)) { ev.setStatus(pval); } break; case SUMMARY: /* ------------------- Summary -------------------- */ if (chg.changed(pi, ev.getSummary(), pval)) { ev.setSummary(pval); } break; case TRANSP: /* ------------------- Transp -------------------- */ if (chg.changed(pi, ev.getPeruserTransparency( cb.getPrincipal() .getPrincipalRef()), pval)) { final BwXproperty pu = ev.setPeruserTransparency( cb.getPrincipal().getPrincipalRef(), pval); if (pu != null) { chg.addValue(PropertyInfoIndex.XPROP, pu); } } break; case UID: /* ------------------- Uid -------------------- */ /* We did this above */ break; case URL: /* ------------------- Url -------------------- */ if (chg.changed(pi, ev.getLink(), pval)) { ev.setLink(pval); } break; case XPROP: /* ------------------------- x-property --------------------------- */ final String name = prop.getName(); if (name.equalsIgnoreCase(BwXproperty.bedeworkCost)) { if (chg.changed(PropertyInfoIndex.COST, ev.getCost(), pval)) { ev.setCost(pval); } break; } if (name.equalsIgnoreCase(BwXproperty.xBedeworkCategories)) { if (checkCategory(cb, chg, ev, null, pval)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkLocation)) { if (checkLocation(cb, chg, ev, prop)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkContact)) { if (checkContact(cb, chg, ev, null, pval)) { break; } } /* See if this is an x-category that can be converted to a real category */ final XProperty xp = (XProperty)prop; chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(name, xp.getParameters() .toString(), pval)); break; default: if (logger.debug()) { logger.debug("Unsupported property with index " + pi + "; class " + prop.getClass() + " and value " + pval); } } } /* =================== Process sub-components =============== */ final ComponentList<Component> subComps; if (val instanceof ComponentContainer) { subComps = ((ComponentContainer<Component>)val).getComponents(); } else { subComps = null; } final Set<Integer> pids; if (vpoll) { pids = new TreeSet<>(); final BwEvent vp = evinfo.getEvent(); if (!Util.isEmpty(vp.getPollItems())) { vp.clearPollItems(); } } else { pids = null; } if (!Util.isEmpty(subComps)) { for (final var subComp: subComps) { if (subComp instanceof Available) { if (!(val instanceof VAvailability)) { return Response.error(resp, "AVAILABLE only valid in VAVAILABLE"); } final var avlResp = processAvailable(cb, cal, ical, (VAvailability)val, (Available)subComp, evinfo); if (!avlResp.isOk()) { return Response.fromResponse(resp, avlResp); } continue; } if (subComp instanceof Participant) { if (vpoll) { final var vresp = processVoter(cb, (VPoll)val, (Participant)subComp, evinfo, chg, mergeAttendees); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Participant object"); continue; } if (subComp instanceof VResource) { logger.warn("Unimplemented VResource object"); continue; } if (subComp instanceof VLocation) { logger.warn("Unimplemented VLocation object"); continue; } if (subComp instanceof VAlarm) { final var aresp = VAlarmUtil.processAlarm(cb, val, (VAlarm)subComp, ev, currentPrincipal, chg); if (!aresp.isOk()) { return Response.fromResponse(resp, aresp); } continue; } if (vpoll && (event || task)) { final var vresp = processCandidate((VPoll)val, subComp, evinfo, pids, chg); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Component object: " + subComp); } } /* Fix up timestamps. */ if (ev.getCreated() == null) { if (ev.getLastmod() != null) { ev.setCreated(ev.getLastmod()); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); } else { ev.updateDtstamp(); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } } if (ev.getLastmod() == null) { // created cannot be null now ev.setLastmod(ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } processTimezones(ev, ical, chg); /* Remove any recipients and originator */ if (ev.getRecipients() != null) { ev.getRecipients().clear(); } ev.setOriginator(null); if (hasXparams.value) { /* Save a text copy of the entire event as an x-property */ final Component valCopy = val.copy(); /* Remove potentially large values */ final Description desp = valCopy.getProperty(Property.DESCRIPTION); if (desp != null) { desp.setValue(null); } final Attach attachp = valCopy.getProperty(Property.ATTACH); // Don't store the entire attachment - we just need the parameters. if (attachp != null) { final Value v = attachp.getParameter(Parameter.VALUE); if (v != null) { attachp.setValue(String.valueOf(attachp.getValue().hashCode())); } } chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(BwXproperty.bedeworkIcal, null, valCopy.toString())); } chg.processChanges(ev, true, false); ev.setRecurring(ev.isRecurringEntity()); if (logger.debug()) { logger.debug(chg.toString()); logger.debug(ev.toString()); } if (masterEI != null) { // Just return notfound as this event is on its override list return Response.notFound(resp); } resp.setEntity(evinfo); return resp; } catch (final Throwable t) { if (logger.debug()) { logger.error(t); } return Response.error(resp, t); } }
NONSATD
true
break; case LAST_MODIFIED: /* ------------------- LastModified -------------------- */ if (chg.changed(pi, ev.getLastmod(), pval)) { ev.setLastmod(pval);
case GEO: /* ------------------- Geo -------------------- */ final Geo g = (Geo)prop; final BwGeo geo = new BwGeo(g.getLatitude(), g.getLongitude()); if (chg.changed(pi, ev.getGeo(), geo)) { ev.setGeo(geo); } break; case LAST_MODIFIED: /* ------------------- LastModified -------------------- */ if (chg.changed(pi, ev.getLastmod(), pval)) { ev.setLastmod(pval); } break; case LOCATION: /* ------------------- Location -------------------- */ BwLocation loc = null; //String uid = getUidPar(prop); /* At the moment Mozilla lightning is broken and this leads to all * sorts of problems.
"Unsupported parameter " + par.getName()); } final BwFreeBusyComponent fbc = new BwFreeBusyComponent(); fbc.setType(fbtype); for (final Period per : perpl) { fbc.addPeriod(per); } ev.addFreeBusyPeriod(fbc); break; case GEO: /* ------------------- Geo -------------------- */ final Geo g = (Geo)prop; final BwGeo geo = new BwGeo(g.getLatitude(), g.getLongitude()); if (chg.changed(pi, ev.getGeo(), geo)) { ev.setGeo(geo); } break; case LAST_MODIFIED: /* ------------------- LastModified -------------------- */ if (chg.changed(pi, ev.getLastmod(), pval)) { ev.setLastmod(pval); } break; case LOCATION: /* ------------------- Location -------------------- */ BwLocation loc = null; //String uid = getUidPar(prop); /* At the moment Mozilla lightning is broken and this leads to all * sorts of problems. if (uid != null) { loc = cb.getLocation(uid); } */ lang = IcalUtil.getLang(prop); BwString addr = null; if (pval != null) { if (loc == null) { addr = new BwString(lang, pval); final var fcResp = cb.findLocation(addr);
7,893
49
/* ------------------- Location -------------------- */
public static GetEntityResponse<EventInfo> toEvent( final IcalCallback cb, final BwCalendar cal, final Icalendar ical, final Component val, final boolean mergeAttendees) { final var resp = new GetEntityResponse<EventInfo>(); if (val == null) { return Response.notOk(resp, failed, "No component supplied"); } String currentPrincipal = null; final BwPrincipal principal = cb.getPrincipal(); if (principal != null) { currentPrincipal = principal.getPrincipalRef(); } final Holder<Boolean> hasXparams = new Holder<>(Boolean.FALSE); final int methodType = ical.getMethodType(); String attUri = null; if (mergeAttendees) { // We'll need this later. attUri = cb.getCaladdr(cb.getPrincipal().getPrincipalRef()); } final String colPath; if (cal == null) { colPath = null; } else { colPath = cal.getPath(); } try { final PropertyList<Property> pl = val.getProperties(); boolean vpoll = false; boolean event = false; boolean task = false; if (pl == null) { // Empty component return Response.notOk(resp, failed, "Empty component"); } final int entityType; if (val instanceof VEvent) { entityType = IcalDefs.entityTypeEvent; event = true; } else if (val instanceof VToDo) { entityType = IcalDefs.entityTypeTodo; task = true; } else if (val instanceof VJournal) { entityType = IcalDefs.entityTypeJournal; } else if (val instanceof VFreeBusy) { entityType = IcalDefs.entityTypeFreeAndBusy; } else if (val instanceof VAvailability) { entityType = IcalDefs.entityTypeVavailability; } else if (val instanceof Available) { entityType = IcalDefs.entityTypeAvailable; } else if (val instanceof VPoll) { entityType = IcalDefs.entityTypeVpoll; vpoll = true; } else { return Response.error(resp, "org.bedework.invalid.component.type: " + val.getName()); } // Get the guid from the component String guid = null; final Uid uidp = pl.getProperty(Property.UID); if (uidp != null) { testXparams(uidp, hasXparams); guid = uidp.getValue(); } if (guid == null) { /* XXX A guid is required - but are there devices out there without a * guid - and if so how do we handle it? */ return Response.notOk(resp, failed, CalFacadeException.noGuid); } /* See if we have a recurrence id */ BwDateTime ridObj = null; String rid = null; TimeZone ridTz = null; final RecurrenceId ridp = pl.getProperty(Property.RECURRENCE_ID); if (ridp != null) { testXparams(ridp, hasXparams); ridObj = BwDateTime.makeBwDateTime(ridp); if (ridObj.getRange() != null) { /* XXX What do I do with it? */ logger.warn("TRANS-TO_EVENT: Got a recurrence id range"); } rid = ridObj.getDate(); } EventInfo masterEI = null; EventInfo evinfo = null; final BwEvent ev; /* If we have a recurrence id see if we already have the master (we should * get a master + all its overrides). * * If so find the override and use the annnotation or if no override, * make one. * * If no override retrieve the event, add it to our table and then locate the * annotation. * * If there is no annotation, create one. * * It's possible we have been sent 'detached' instances of a recurring * event. This may happen if we are invited to one or more instances of a * meeting. In this case we try to retrieve the master and if it doesn't * exist we manufacture one. We consider such an instance an update to * that instance only and leave the others alone. */ /* We need this in a couple of places */ final DtStart dtStart = pl.getProperty(Property.DTSTART); /* if (rid != null) { // See if we have a new master event. If so create a proxy to that event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI == null) { masterEI = makeNewEvent(cb, chg, entityType, guid, cal); BwEvent e = masterEI.getEvent(); // XXX This seems bogus DtStart mdtStart; String bogusDate = "19980118T230000"; if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + "Z"); } else if (dtStart.getTimeZone() == null) { mdtStart = new DtStart(bogusDate); } else { mdtStart = new DtStart(bogusDate + "Z", dtStart.getTimeZone()); } setDates(e, mdtStart, null, null, chg); e.setRecurring(true); e.addRdate(ridObj); e.setSuppressed(true); ical.addComponent(masterEI); } if (masterEI != null) { evinfo = masterEI.findOverride(rid); } } */ /* If this is a recurrence instance see if we can find the master We only need this because the master may follow the overrides. */ if (rid != null) { // See if we have a new master event. If so create a proxy to this event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI != null) { evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; } } if ((evinfo == null) && (cal != null) && (cal.getCalType() != BwCalendar.calTypeInbox) && (cal.getCalType() != BwCalendar.calTypePendingInbox) && (cal.getCalType() != BwCalendar.calTypeOutbox)) { if (logger.debug()) { logger.debug("TRANS-TO_EVENT: try to fetch event with guid=" + guid); } final GetEntitiesResponse<EventInfo> eisResp = cb.getEvent(colPath, guid); if (eisResp.isError()) { return Response.fromResponse(resp, eisResp); } final var eis = eisResp.getEntities(); if (!Util.isEmpty(eis)) { if (eis.size() > 1) { // DORECUR - wrong again return Response.notOk(resp, failed, "More than one event returned for guid."); } evinfo = eis.iterator().next(); } if (logger.debug()) { if (evinfo != null) { logger.debug("TRANS-TO_EVENT: fetched event with guid"); } else { logger.debug("TRANS-TO_EVENT: did not find event with guid"); } } if (evinfo != null) { if (rid != null) { // We just retrieved it's master masterEI = evinfo; masterEI.setInstanceOnly(true); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; ical.addComponent(masterEI); } else if (methodType == ScheduleMethods.methodTypeCancel) { // This should never have an rid for cancel of entire event. evinfo.setInstanceOnly(evinfo.getEvent().getSuppressed()); } else { // Presumably sent an update for the entire event. No longer suppressed master evinfo.getEvent().setSuppressed(false); } } else if (rid != null) { /* Manufacture a master for the instance */ masterEI = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); final BwEvent e = masterEI.getEvent(); // XXX This seems bogus final DtStart mdtStart; final String bogusDate = "19980118"; final String bogusTime = "T230000"; // Base dtstart on the recurrence id. final boolean isDateType = ridObj.getDateType(); if (isDateType) { mdtStart = new DtStart(new Date(bogusDate)); } else if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + bogusTime + "Z"); } else if (ridObj.getTzid() == null) { mdtStart = new DtStart(bogusDate + bogusTime); } else { mdtStart = new DtStart(bogusDate + bogusTime, Timezones.getTz(ridObj.getTzid())); } IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), masterEI, mdtStart, null, null); e.setRecurring(true); // e.addRdate(ridObj); final var sum = (Summary)pl.getProperty(Property.SUMMARY); e.setSummary(sum.getValue()); e.setSuppressed(true); ical.addComponent(masterEI); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; masterEI.setInstanceOnly(rid != null); } } if (evinfo == null) { evinfo = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); } else if (evinfo.getEvent().getEntityType() != entityType) { return Response.notOk(resp, failed, "org.bedework.mismatched.entity.type: " + val); } final ChangeTable chg = evinfo.getChangeset( cb.getPrincipal().getPrincipalRef()); if (rid != null) { final String evrid = evinfo.getEvent().getRecurrenceId(); if ((evrid == null) || (!evrid.equals(rid))) { logger. warn("Mismatched rid ev=" + evrid + " expected " + rid); chg.changed(PropertyInfoIndex.RECURRENCE_ID, evrid, rid); // XXX spurious??? } if (masterEI.getEvent().getSuppressed()) { masterEI.getEvent().addRdate(ridObj); } } ev = evinfo.getEvent(); ev.setScheduleMethod(methodType); DtEnd dtEnd = null; if (entityType == IcalDefs.entityTypeTodo) { final Due due = pl.getProperty(Property.DUE); if (due != null ) { dtEnd = new DtEnd(due.getParameters(), due.getValue()); } } else { dtEnd = pl.getProperty(Property.DTEND); } final Duration duration = pl.getProperty(Property.DURATION); IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), evinfo, dtStart, dtEnd, duration); for (final Property prop: pl) { testXparams(prop, hasXparams); //debug("ical prop " + prop.getClass().getName()); String pval = prop.getValue(); if ((pval != null) && (pval.length() == 0)) { pval = null; } final PropertyInfoIndex pi; if (prop instanceof XProperty) { pi = PropertyInfoIndex.XPROP; } else { pi = PropertyInfoIndex.fromName(prop.getName()); } if (pi == null) { logger.debug("Unknown property with name " + prop.getName() + " class " + prop.getClass() + " and value " + pval); continue; } chg.present(pi); switch (pi) { case ACCEPT_RESPONSE: /* ------------------- Accept Response -------------------- */ String sval = prop.getValue(); if (chg.changed(pi, ev.getPollAcceptResponse(), sval)) { ev.setPollAcceptResponse(sval); } break; case ATTACH: /* ------------------- Attachment -------------------- */ chg.addValue(pi, IcalUtil.getAttachment((Attach)prop)); break; case ATTENDEE: /* ------------------- Attendee -------------------- */ if (methodType == ScheduleMethods.methodTypePublish) { if (cb.getStrictness() == IcalCallback.conformanceStrict) { return Response.notOk(resp, failed, CalFacadeException.attendeesInPublish); } //if (cb.getStrictness() == IcalCallback.conformanceWarn) { // warn("Had attendees for PUBLISH"); //} } final Attendee attPr = (Attendee)prop; if (evinfo.getNewEvent() || !mergeAttendees) { chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { final String pUri = cb.getCaladdr(attPr.getValue()); if (pUri.equals(attUri)) { /* Only update for our own attendee * We're doing a PUT and this must be the attendee updating their * partstat. We don't allow them to change other attendees * whatever the PUT content says. */ chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { // Use the value we currently have boolean found = false; for (final BwAttendee att: ev.getAttendees()) { if (pUri.equals(att.getAttendeeUri())) { chg.addValue(pi, att.clone()); found = true; break; } } if (!found) { // An added attendee final BwAttendee att = IcalUtil .getAttendee(cb, attPr); att.setPartstat(IcalDefs.partstatValNeedsAction); chg.addValue(pi, att); } } } break; case BUSYTYPE: final int ibt = BwEvent.fromBusyTypeString(pval); if (chg.changed(pi, ev.getBusyType(), ibt)) { ev.setBusyType(ibt); } break; case CATEGORIES: /* ------------------- Categories -------------------- */ final Categories cats = (Categories)prop; final TextList cl = cats.getCategories(); String lang = IcalUtil.getLang(cats); if (cl != null) { /* Got some categories */ for (final String wd: cl) { if (wd == null) { continue; } final BwString key = new BwString(lang, wd); final var fcResp = cb.findCategory(key); final BwCategory cat; if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isNotFound()) { cat = BwCategory.makeCategory(); cat.setWord(key); cb.addCategory(cat); } else { cat = fcResp.getEntity(); } chg.addValue(pi, cat); } } break; case CLASS: /* ------------------- Class -------------------- */ if (chg.changed(pi, ev.getClassification(), pval)) { ev.setClassification(pval); } break; case COMMENT: /* ------------------- Comment -------------------- */ chg.addValue(pi, new BwString(null, pval)); break; case COMPLETED: /* ------------------- Completed -------------------- */ if (chg.changed(pi, ev.getCompleted(), pval)) { ev.setCompleted(pval); } break; case CONCEPT: /* ------------------- Concept -------------------- */ final Concept c = (Concept)prop; final String cval = c.getValue(); if (cval != null) { /* Got a concept */ chg.addValue(PropertyInfoIndex.XPROP, BwXproperty.makeIcalProperty("CONCEPT", null, cval)); } break; case CONTACT: /* ------------------- Contact -------------------- */ final String altrep = getAltRepPar(prop); lang = IcalUtil.getLang(prop); final String uid = getUidPar(prop); final BwString nm = new BwString(lang, pval); BwContact contact = null; if (uid != null) { final var fcResp = cb.getContact(uid); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { final var fcResp = cb.findContact(nm); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { contact = BwContact.makeContact(); contact.setCn(nm); contact.setLink(altrep); cb.addContact(contact); } else { contact.setCn(nm); contact.setLink(altrep); } chg.addValue(pi, contact); break; case CREATED: /* ------------------- Created -------------------- */ if (chg.changed(pi, ev.getCreated(), pval)) { ev.setCreated(pval); } break; case DESCRIPTION: /* ------------------- Description -------------------- */ if (chg.changed(pi, ev.getDescription(), pval)) { ev.setDescription(pval); } break; case DTEND: /* ------------------- DtEnd -------------------- */ break; case DTSTAMP: /* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval); break; case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE: /* -------------------- Due ------------------------ */ break; case DURATION: /* ------------------- Duration -------------------- */ break; case EXDATE: /* ------------------- ExDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case EXRULE: /* ------------------- ExRule -------------------- */ chg.addValue(pi, pval); break; case FREEBUSY: /* ------------------- freebusy -------------------- */ final FreeBusy fbusy = (FreeBusy)prop; final PeriodList perpl = fbusy.getPeriods(); final Parameter par = IcalUtil.getParameter(fbusy, "FBTYPE"); final int fbtype; if (par == null) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY)) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY_TENTATIVE)) { fbtype = BwFreeBusyComponent.typeBusyTentative; } else if (par.equals(FbType.BUSY_UNAVAILABLE)) { fbtype = BwFreeBusyComponent.typeBusyUnavailable; } else if (par.equals(FbType.FREE)) { fbtype = BwFreeBusyComponent.typeFree; } else { if (logger.debug()) { logger.debug("Unsupported parameter " + par.getName()); } return Response.notOk(resp, failed, "Unsupported parameter " + par.getName()); } final BwFreeBusyComponent fbc = new BwFreeBusyComponent(); fbc.setType(fbtype); for (final Period per : perpl) { fbc.addPeriod(per); } ev.addFreeBusyPeriod(fbc); break; case GEO: /* ------------------- Geo -------------------- */ final Geo g = (Geo)prop; final BwGeo geo = new BwGeo(g.getLatitude(), g.getLongitude()); if (chg.changed(pi, ev.getGeo(), geo)) { ev.setGeo(geo); } break; case LAST_MODIFIED: /* ------------------- LastModified -------------------- */ if (chg.changed(pi, ev.getLastmod(), pval)) { ev.setLastmod(pval); } break; case LOCATION: /* ------------------- Location -------------------- */ BwLocation loc = null; //String uid = getUidPar(prop); /* At the moment Mozilla lightning is broken and this leads to all * sorts of problems. if (uid != null) { loc = cb.getLocation(uid); } */ lang = IcalUtil.getLang(prop); BwString addr = null; if (pval != null) { if (loc == null) { addr = new BwString(lang, pval); final var fcResp = cb.findLocation(addr); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { loc = fcResp.getEntity(); } } if (loc == null) { loc = BwLocation.makeLocation(); loc.setAddress(addr); cb.addLocation(loc); } } final BwLocation evloc = ev.getLocation(); if (chg.changed(pi, evloc, loc)) { // CHGTBL - this only shows that it's a different location object ev.setLocation(loc); } else if ((loc != null) && (evloc != null)) { // See if the value is changed final String evval = evloc.getAddress().getValue(); final String inval = loc.getAddress().getValue(); if (!evval.equals(inval)) { chg.changed(pi, evval, inval); evloc.getAddress().setValue(inval); } } break; case ORGANIZER: /* ------------------- Organizer -------------------- */ final BwOrganizer org = IcalUtil.getOrganizer(cb, (Organizer)prop); final BwOrganizer evorg = ev.getOrganizer(); final BwOrganizer evorgCopy; if (evorg == null) { evorgCopy = null; } else { evorgCopy = (BwOrganizer)evorg.clone(); } if (chg.changed(pi, evorgCopy, org)) { if (evorg == null) { ev.setOrganizer(org); } else { evorg.update(org); } } break; case PERCENT_COMPLETE: /* ------------------- PercentComplete -------------------- */ Integer ival = ((PercentComplete)prop).getPercentage(); if (chg.changed(pi, ev.getPercentComplete(), ival)) { ev.setPercentComplete(ival); } break; case POLL_MODE: /* ------------------- Poll mode -------------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollMode(), sval)) { ev.setPollMode(sval); } break; case POLL_PROPERTIES: /* ------------------- Poll properties ---------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollProperties(), sval)) { ev.setPollProperties(sval); } break; case POLL_WINNER: /* ------------------- Poll winner -------------------- */ ival = ((PollWinner)prop).getPollwinner(); if (chg.changed(pi, ev.getPollWinner(), ival)) { ev.setPollWinner(ival); } break; case PRIORITY: /* ------------------- Priority -------------------- */ ival = ((Priority)prop).getLevel(); if (chg.changed(pi, ev.getPriority(), ival)) { ev.setPriority(ival); } break; case RDATE: /* ------------------- RDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case RECURRENCE_ID: /* ------------------- RecurrenceID -------------------- */ // Done above break; case RELATED_TO: /* ------------------- RelatedTo -------------------- */ final RelatedTo irelto = (RelatedTo)prop; final BwRelatedTo relto = new BwRelatedTo(); final String parval = IcalUtil.getParameterVal(irelto, "RELTYPE"); if (parval != null) { relto.setRelType(parval); } relto.setValue(irelto.getValue()); if (chg.changed(pi, ev.getRelatedTo(), relto)) { ev.setRelatedTo(relto); } break; case REQUEST_STATUS: /* ------------------- RequestStatus -------------------- */ final BwRequestStatus rs = BwRequestStatus .fromRequestStatus((RequestStatus)prop); chg.addValue(pi, rs); break; case RESOURCES: /* ------------------- Resources -------------------- */ final TextList rl = ((Resources)prop).getResources(); if (rl != null) { /* Got some resources */ lang = IcalUtil.getLang(prop); for (final String s: rl) { final BwString rsrc = new BwString(lang, s); chg.addValue(pi, rsrc); } } break; case RRULE: /* ------------------- RRule -------------------- */ chg.addValue(pi, pval); break; case SEQUENCE: /* ------------------- Sequence -------------------- */ final int seq = ((Sequence)prop).getSequenceNo(); if (seq != ev.getSequence()) { chg.changed(pi, ev.getSequence(), seq); ev.setSequence(seq); } break; case STATUS: /* ------------------- Status -------------------- */ if (chg.changed(pi, ev.getStatus(), pval)) { ev.setStatus(pval); } break; case SUMMARY: /* ------------------- Summary -------------------- */ if (chg.changed(pi, ev.getSummary(), pval)) { ev.setSummary(pval); } break; case TRANSP: /* ------------------- Transp -------------------- */ if (chg.changed(pi, ev.getPeruserTransparency( cb.getPrincipal() .getPrincipalRef()), pval)) { final BwXproperty pu = ev.setPeruserTransparency( cb.getPrincipal().getPrincipalRef(), pval); if (pu != null) { chg.addValue(PropertyInfoIndex.XPROP, pu); } } break; case UID: /* ------------------- Uid -------------------- */ /* We did this above */ break; case URL: /* ------------------- Url -------------------- */ if (chg.changed(pi, ev.getLink(), pval)) { ev.setLink(pval); } break; case XPROP: /* ------------------------- x-property --------------------------- */ final String name = prop.getName(); if (name.equalsIgnoreCase(BwXproperty.bedeworkCost)) { if (chg.changed(PropertyInfoIndex.COST, ev.getCost(), pval)) { ev.setCost(pval); } break; } if (name.equalsIgnoreCase(BwXproperty.xBedeworkCategories)) { if (checkCategory(cb, chg, ev, null, pval)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkLocation)) { if (checkLocation(cb, chg, ev, prop)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkContact)) { if (checkContact(cb, chg, ev, null, pval)) { break; } } /* See if this is an x-category that can be converted to a real category */ final XProperty xp = (XProperty)prop; chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(name, xp.getParameters() .toString(), pval)); break; default: if (logger.debug()) { logger.debug("Unsupported property with index " + pi + "; class " + prop.getClass() + " and value " + pval); } } } /* =================== Process sub-components =============== */ final ComponentList<Component> subComps; if (val instanceof ComponentContainer) { subComps = ((ComponentContainer<Component>)val).getComponents(); } else { subComps = null; } final Set<Integer> pids; if (vpoll) { pids = new TreeSet<>(); final BwEvent vp = evinfo.getEvent(); if (!Util.isEmpty(vp.getPollItems())) { vp.clearPollItems(); } } else { pids = null; } if (!Util.isEmpty(subComps)) { for (final var subComp: subComps) { if (subComp instanceof Available) { if (!(val instanceof VAvailability)) { return Response.error(resp, "AVAILABLE only valid in VAVAILABLE"); } final var avlResp = processAvailable(cb, cal, ical, (VAvailability)val, (Available)subComp, evinfo); if (!avlResp.isOk()) { return Response.fromResponse(resp, avlResp); } continue; } if (subComp instanceof Participant) { if (vpoll) { final var vresp = processVoter(cb, (VPoll)val, (Participant)subComp, evinfo, chg, mergeAttendees); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Participant object"); continue; } if (subComp instanceof VResource) { logger.warn("Unimplemented VResource object"); continue; } if (subComp instanceof VLocation) { logger.warn("Unimplemented VLocation object"); continue; } if (subComp instanceof VAlarm) { final var aresp = VAlarmUtil.processAlarm(cb, val, (VAlarm)subComp, ev, currentPrincipal, chg); if (!aresp.isOk()) { return Response.fromResponse(resp, aresp); } continue; } if (vpoll && (event || task)) { final var vresp = processCandidate((VPoll)val, subComp, evinfo, pids, chg); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Component object: " + subComp); } } /* Fix up timestamps. */ if (ev.getCreated() == null) { if (ev.getLastmod() != null) { ev.setCreated(ev.getLastmod()); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); } else { ev.updateDtstamp(); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } } if (ev.getLastmod() == null) { // created cannot be null now ev.setLastmod(ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } processTimezones(ev, ical, chg); /* Remove any recipients and originator */ if (ev.getRecipients() != null) { ev.getRecipients().clear(); } ev.setOriginator(null); if (hasXparams.value) { /* Save a text copy of the entire event as an x-property */ final Component valCopy = val.copy(); /* Remove potentially large values */ final Description desp = valCopy.getProperty(Property.DESCRIPTION); if (desp != null) { desp.setValue(null); } final Attach attachp = valCopy.getProperty(Property.ATTACH); // Don't store the entire attachment - we just need the parameters. if (attachp != null) { final Value v = attachp.getParameter(Parameter.VALUE); if (v != null) { attachp.setValue(String.valueOf(attachp.getValue().hashCode())); } } chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(BwXproperty.bedeworkIcal, null, valCopy.toString())); } chg.processChanges(ev, true, false); ev.setRecurring(ev.isRecurringEntity()); if (logger.debug()) { logger.debug(chg.toString()); logger.debug(ev.toString()); } if (masterEI != null) { // Just return notfound as this event is on its override list return Response.notFound(resp); } resp.setEntity(evinfo); return resp; } catch (final Throwable t) { if (logger.debug()) { logger.error(t); } return Response.error(resp, t); } }
NONSATD
true
break; case LOCATION: /* ------------------- Location -------------------- */ BwLocation loc = null; //String uid = getUidPar(prop);
ev.setGeo(geo); } break; case LAST_MODIFIED: /* ------------------- LastModified -------------------- */ if (chg.changed(pi, ev.getLastmod(), pval)) { ev.setLastmod(pval); } break; case LOCATION: /* ------------------- Location -------------------- */ BwLocation loc = null; //String uid = getUidPar(prop); /* At the moment Mozilla lightning is broken and this leads to all * sorts of problems. if (uid != null) { loc = cb.getLocation(uid); } */ lang = IcalUtil.getLang(prop); BwString addr = null;
fbc.addPeriod(per); } ev.addFreeBusyPeriod(fbc); break; case GEO: /* ------------------- Geo -------------------- */ final Geo g = (Geo)prop; final BwGeo geo = new BwGeo(g.getLatitude(), g.getLongitude()); if (chg.changed(pi, ev.getGeo(), geo)) { ev.setGeo(geo); } break; case LAST_MODIFIED: /* ------------------- LastModified -------------------- */ if (chg.changed(pi, ev.getLastmod(), pval)) { ev.setLastmod(pval); } break; case LOCATION: /* ------------------- Location -------------------- */ BwLocation loc = null; //String uid = getUidPar(prop); /* At the moment Mozilla lightning is broken and this leads to all * sorts of problems. if (uid != null) { loc = cb.getLocation(uid); } */ lang = IcalUtil.getLang(prop); BwString addr = null; if (pval != null) { if (loc == null) { addr = new BwString(lang, pval); final var fcResp = cb.findLocation(addr); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { loc = fcResp.getEntity(); }
7,893
50
//String uid = getUidPar(prop); /* At the moment Mozilla lightning is broken and this leads to all * sorts of problems. if (uid != null) { loc = cb.getLocation(uid); } */
public static GetEntityResponse<EventInfo> toEvent( final IcalCallback cb, final BwCalendar cal, final Icalendar ical, final Component val, final boolean mergeAttendees) { final var resp = new GetEntityResponse<EventInfo>(); if (val == null) { return Response.notOk(resp, failed, "No component supplied"); } String currentPrincipal = null; final BwPrincipal principal = cb.getPrincipal(); if (principal != null) { currentPrincipal = principal.getPrincipalRef(); } final Holder<Boolean> hasXparams = new Holder<>(Boolean.FALSE); final int methodType = ical.getMethodType(); String attUri = null; if (mergeAttendees) { // We'll need this later. attUri = cb.getCaladdr(cb.getPrincipal().getPrincipalRef()); } final String colPath; if (cal == null) { colPath = null; } else { colPath = cal.getPath(); } try { final PropertyList<Property> pl = val.getProperties(); boolean vpoll = false; boolean event = false; boolean task = false; if (pl == null) { // Empty component return Response.notOk(resp, failed, "Empty component"); } final int entityType; if (val instanceof VEvent) { entityType = IcalDefs.entityTypeEvent; event = true; } else if (val instanceof VToDo) { entityType = IcalDefs.entityTypeTodo; task = true; } else if (val instanceof VJournal) { entityType = IcalDefs.entityTypeJournal; } else if (val instanceof VFreeBusy) { entityType = IcalDefs.entityTypeFreeAndBusy; } else if (val instanceof VAvailability) { entityType = IcalDefs.entityTypeVavailability; } else if (val instanceof Available) { entityType = IcalDefs.entityTypeAvailable; } else if (val instanceof VPoll) { entityType = IcalDefs.entityTypeVpoll; vpoll = true; } else { return Response.error(resp, "org.bedework.invalid.component.type: " + val.getName()); } // Get the guid from the component String guid = null; final Uid uidp = pl.getProperty(Property.UID); if (uidp != null) { testXparams(uidp, hasXparams); guid = uidp.getValue(); } if (guid == null) { /* XXX A guid is required - but are there devices out there without a * guid - and if so how do we handle it? */ return Response.notOk(resp, failed, CalFacadeException.noGuid); } /* See if we have a recurrence id */ BwDateTime ridObj = null; String rid = null; TimeZone ridTz = null; final RecurrenceId ridp = pl.getProperty(Property.RECURRENCE_ID); if (ridp != null) { testXparams(ridp, hasXparams); ridObj = BwDateTime.makeBwDateTime(ridp); if (ridObj.getRange() != null) { /* XXX What do I do with it? */ logger.warn("TRANS-TO_EVENT: Got a recurrence id range"); } rid = ridObj.getDate(); } EventInfo masterEI = null; EventInfo evinfo = null; final BwEvent ev; /* If we have a recurrence id see if we already have the master (we should * get a master + all its overrides). * * If so find the override and use the annnotation or if no override, * make one. * * If no override retrieve the event, add it to our table and then locate the * annotation. * * If there is no annotation, create one. * * It's possible we have been sent 'detached' instances of a recurring * event. This may happen if we are invited to one or more instances of a * meeting. In this case we try to retrieve the master and if it doesn't * exist we manufacture one. We consider such an instance an update to * that instance only and leave the others alone. */ /* We need this in a couple of places */ final DtStart dtStart = pl.getProperty(Property.DTSTART); /* if (rid != null) { // See if we have a new master event. If so create a proxy to that event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI == null) { masterEI = makeNewEvent(cb, chg, entityType, guid, cal); BwEvent e = masterEI.getEvent(); // XXX This seems bogus DtStart mdtStart; String bogusDate = "19980118T230000"; if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + "Z"); } else if (dtStart.getTimeZone() == null) { mdtStart = new DtStart(bogusDate); } else { mdtStart = new DtStart(bogusDate + "Z", dtStart.getTimeZone()); } setDates(e, mdtStart, null, null, chg); e.setRecurring(true); e.addRdate(ridObj); e.setSuppressed(true); ical.addComponent(masterEI); } if (masterEI != null) { evinfo = masterEI.findOverride(rid); } } */ /* If this is a recurrence instance see if we can find the master We only need this because the master may follow the overrides. */ if (rid != null) { // See if we have a new master event. If so create a proxy to this event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI != null) { evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; } } if ((evinfo == null) && (cal != null) && (cal.getCalType() != BwCalendar.calTypeInbox) && (cal.getCalType() != BwCalendar.calTypePendingInbox) && (cal.getCalType() != BwCalendar.calTypeOutbox)) { if (logger.debug()) { logger.debug("TRANS-TO_EVENT: try to fetch event with guid=" + guid); } final GetEntitiesResponse<EventInfo> eisResp = cb.getEvent(colPath, guid); if (eisResp.isError()) { return Response.fromResponse(resp, eisResp); } final var eis = eisResp.getEntities(); if (!Util.isEmpty(eis)) { if (eis.size() > 1) { // DORECUR - wrong again return Response.notOk(resp, failed, "More than one event returned for guid."); } evinfo = eis.iterator().next(); } if (logger.debug()) { if (evinfo != null) { logger.debug("TRANS-TO_EVENT: fetched event with guid"); } else { logger.debug("TRANS-TO_EVENT: did not find event with guid"); } } if (evinfo != null) { if (rid != null) { // We just retrieved it's master masterEI = evinfo; masterEI.setInstanceOnly(true); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; ical.addComponent(masterEI); } else if (methodType == ScheduleMethods.methodTypeCancel) { // This should never have an rid for cancel of entire event. evinfo.setInstanceOnly(evinfo.getEvent().getSuppressed()); } else { // Presumably sent an update for the entire event. No longer suppressed master evinfo.getEvent().setSuppressed(false); } } else if (rid != null) { /* Manufacture a master for the instance */ masterEI = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); final BwEvent e = masterEI.getEvent(); // XXX This seems bogus final DtStart mdtStart; final String bogusDate = "19980118"; final String bogusTime = "T230000"; // Base dtstart on the recurrence id. final boolean isDateType = ridObj.getDateType(); if (isDateType) { mdtStart = new DtStart(new Date(bogusDate)); } else if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + bogusTime + "Z"); } else if (ridObj.getTzid() == null) { mdtStart = new DtStart(bogusDate + bogusTime); } else { mdtStart = new DtStart(bogusDate + bogusTime, Timezones.getTz(ridObj.getTzid())); } IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), masterEI, mdtStart, null, null); e.setRecurring(true); // e.addRdate(ridObj); final var sum = (Summary)pl.getProperty(Property.SUMMARY); e.setSummary(sum.getValue()); e.setSuppressed(true); ical.addComponent(masterEI); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; masterEI.setInstanceOnly(rid != null); } } if (evinfo == null) { evinfo = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); } else if (evinfo.getEvent().getEntityType() != entityType) { return Response.notOk(resp, failed, "org.bedework.mismatched.entity.type: " + val); } final ChangeTable chg = evinfo.getChangeset( cb.getPrincipal().getPrincipalRef()); if (rid != null) { final String evrid = evinfo.getEvent().getRecurrenceId(); if ((evrid == null) || (!evrid.equals(rid))) { logger. warn("Mismatched rid ev=" + evrid + " expected " + rid); chg.changed(PropertyInfoIndex.RECURRENCE_ID, evrid, rid); // XXX spurious??? } if (masterEI.getEvent().getSuppressed()) { masterEI.getEvent().addRdate(ridObj); } } ev = evinfo.getEvent(); ev.setScheduleMethod(methodType); DtEnd dtEnd = null; if (entityType == IcalDefs.entityTypeTodo) { final Due due = pl.getProperty(Property.DUE); if (due != null ) { dtEnd = new DtEnd(due.getParameters(), due.getValue()); } } else { dtEnd = pl.getProperty(Property.DTEND); } final Duration duration = pl.getProperty(Property.DURATION); IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), evinfo, dtStart, dtEnd, duration); for (final Property prop: pl) { testXparams(prop, hasXparams); //debug("ical prop " + prop.getClass().getName()); String pval = prop.getValue(); if ((pval != null) && (pval.length() == 0)) { pval = null; } final PropertyInfoIndex pi; if (prop instanceof XProperty) { pi = PropertyInfoIndex.XPROP; } else { pi = PropertyInfoIndex.fromName(prop.getName()); } if (pi == null) { logger.debug("Unknown property with name " + prop.getName() + " class " + prop.getClass() + " and value " + pval); continue; } chg.present(pi); switch (pi) { case ACCEPT_RESPONSE: /* ------------------- Accept Response -------------------- */ String sval = prop.getValue(); if (chg.changed(pi, ev.getPollAcceptResponse(), sval)) { ev.setPollAcceptResponse(sval); } break; case ATTACH: /* ------------------- Attachment -------------------- */ chg.addValue(pi, IcalUtil.getAttachment((Attach)prop)); break; case ATTENDEE: /* ------------------- Attendee -------------------- */ if (methodType == ScheduleMethods.methodTypePublish) { if (cb.getStrictness() == IcalCallback.conformanceStrict) { return Response.notOk(resp, failed, CalFacadeException.attendeesInPublish); } //if (cb.getStrictness() == IcalCallback.conformanceWarn) { // warn("Had attendees for PUBLISH"); //} } final Attendee attPr = (Attendee)prop; if (evinfo.getNewEvent() || !mergeAttendees) { chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { final String pUri = cb.getCaladdr(attPr.getValue()); if (pUri.equals(attUri)) { /* Only update for our own attendee * We're doing a PUT and this must be the attendee updating their * partstat. We don't allow them to change other attendees * whatever the PUT content says. */ chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { // Use the value we currently have boolean found = false; for (final BwAttendee att: ev.getAttendees()) { if (pUri.equals(att.getAttendeeUri())) { chg.addValue(pi, att.clone()); found = true; break; } } if (!found) { // An added attendee final BwAttendee att = IcalUtil .getAttendee(cb, attPr); att.setPartstat(IcalDefs.partstatValNeedsAction); chg.addValue(pi, att); } } } break; case BUSYTYPE: final int ibt = BwEvent.fromBusyTypeString(pval); if (chg.changed(pi, ev.getBusyType(), ibt)) { ev.setBusyType(ibt); } break; case CATEGORIES: /* ------------------- Categories -------------------- */ final Categories cats = (Categories)prop; final TextList cl = cats.getCategories(); String lang = IcalUtil.getLang(cats); if (cl != null) { /* Got some categories */ for (final String wd: cl) { if (wd == null) { continue; } final BwString key = new BwString(lang, wd); final var fcResp = cb.findCategory(key); final BwCategory cat; if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isNotFound()) { cat = BwCategory.makeCategory(); cat.setWord(key); cb.addCategory(cat); } else { cat = fcResp.getEntity(); } chg.addValue(pi, cat); } } break; case CLASS: /* ------------------- Class -------------------- */ if (chg.changed(pi, ev.getClassification(), pval)) { ev.setClassification(pval); } break; case COMMENT: /* ------------------- Comment -------------------- */ chg.addValue(pi, new BwString(null, pval)); break; case COMPLETED: /* ------------------- Completed -------------------- */ if (chg.changed(pi, ev.getCompleted(), pval)) { ev.setCompleted(pval); } break; case CONCEPT: /* ------------------- Concept -------------------- */ final Concept c = (Concept)prop; final String cval = c.getValue(); if (cval != null) { /* Got a concept */ chg.addValue(PropertyInfoIndex.XPROP, BwXproperty.makeIcalProperty("CONCEPT", null, cval)); } break; case CONTACT: /* ------------------- Contact -------------------- */ final String altrep = getAltRepPar(prop); lang = IcalUtil.getLang(prop); final String uid = getUidPar(prop); final BwString nm = new BwString(lang, pval); BwContact contact = null; if (uid != null) { final var fcResp = cb.getContact(uid); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { final var fcResp = cb.findContact(nm); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { contact = BwContact.makeContact(); contact.setCn(nm); contact.setLink(altrep); cb.addContact(contact); } else { contact.setCn(nm); contact.setLink(altrep); } chg.addValue(pi, contact); break; case CREATED: /* ------------------- Created -------------------- */ if (chg.changed(pi, ev.getCreated(), pval)) { ev.setCreated(pval); } break; case DESCRIPTION: /* ------------------- Description -------------------- */ if (chg.changed(pi, ev.getDescription(), pval)) { ev.setDescription(pval); } break; case DTEND: /* ------------------- DtEnd -------------------- */ break; case DTSTAMP: /* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval); break; case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE: /* -------------------- Due ------------------------ */ break; case DURATION: /* ------------------- Duration -------------------- */ break; case EXDATE: /* ------------------- ExDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case EXRULE: /* ------------------- ExRule -------------------- */ chg.addValue(pi, pval); break; case FREEBUSY: /* ------------------- freebusy -------------------- */ final FreeBusy fbusy = (FreeBusy)prop; final PeriodList perpl = fbusy.getPeriods(); final Parameter par = IcalUtil.getParameter(fbusy, "FBTYPE"); final int fbtype; if (par == null) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY)) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY_TENTATIVE)) { fbtype = BwFreeBusyComponent.typeBusyTentative; } else if (par.equals(FbType.BUSY_UNAVAILABLE)) { fbtype = BwFreeBusyComponent.typeBusyUnavailable; } else if (par.equals(FbType.FREE)) { fbtype = BwFreeBusyComponent.typeFree; } else { if (logger.debug()) { logger.debug("Unsupported parameter " + par.getName()); } return Response.notOk(resp, failed, "Unsupported parameter " + par.getName()); } final BwFreeBusyComponent fbc = new BwFreeBusyComponent(); fbc.setType(fbtype); for (final Period per : perpl) { fbc.addPeriod(per); } ev.addFreeBusyPeriod(fbc); break; case GEO: /* ------------------- Geo -------------------- */ final Geo g = (Geo)prop; final BwGeo geo = new BwGeo(g.getLatitude(), g.getLongitude()); if (chg.changed(pi, ev.getGeo(), geo)) { ev.setGeo(geo); } break; case LAST_MODIFIED: /* ------------------- LastModified -------------------- */ if (chg.changed(pi, ev.getLastmod(), pval)) { ev.setLastmod(pval); } break; case LOCATION: /* ------------------- Location -------------------- */ BwLocation loc = null; //String uid = getUidPar(prop); /* At the moment Mozilla lightning is broken and this leads to all * sorts of problems. if (uid != null) { loc = cb.getLocation(uid); } */ lang = IcalUtil.getLang(prop); BwString addr = null; if (pval != null) { if (loc == null) { addr = new BwString(lang, pval); final var fcResp = cb.findLocation(addr); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { loc = fcResp.getEntity(); } } if (loc == null) { loc = BwLocation.makeLocation(); loc.setAddress(addr); cb.addLocation(loc); } } final BwLocation evloc = ev.getLocation(); if (chg.changed(pi, evloc, loc)) { // CHGTBL - this only shows that it's a different location object ev.setLocation(loc); } else if ((loc != null) && (evloc != null)) { // See if the value is changed final String evval = evloc.getAddress().getValue(); final String inval = loc.getAddress().getValue(); if (!evval.equals(inval)) { chg.changed(pi, evval, inval); evloc.getAddress().setValue(inval); } } break; case ORGANIZER: /* ------------------- Organizer -------------------- */ final BwOrganizer org = IcalUtil.getOrganizer(cb, (Organizer)prop); final BwOrganizer evorg = ev.getOrganizer(); final BwOrganizer evorgCopy; if (evorg == null) { evorgCopy = null; } else { evorgCopy = (BwOrganizer)evorg.clone(); } if (chg.changed(pi, evorgCopy, org)) { if (evorg == null) { ev.setOrganizer(org); } else { evorg.update(org); } } break; case PERCENT_COMPLETE: /* ------------------- PercentComplete -------------------- */ Integer ival = ((PercentComplete)prop).getPercentage(); if (chg.changed(pi, ev.getPercentComplete(), ival)) { ev.setPercentComplete(ival); } break; case POLL_MODE: /* ------------------- Poll mode -------------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollMode(), sval)) { ev.setPollMode(sval); } break; case POLL_PROPERTIES: /* ------------------- Poll properties ---------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollProperties(), sval)) { ev.setPollProperties(sval); } break; case POLL_WINNER: /* ------------------- Poll winner -------------------- */ ival = ((PollWinner)prop).getPollwinner(); if (chg.changed(pi, ev.getPollWinner(), ival)) { ev.setPollWinner(ival); } break; case PRIORITY: /* ------------------- Priority -------------------- */ ival = ((Priority)prop).getLevel(); if (chg.changed(pi, ev.getPriority(), ival)) { ev.setPriority(ival); } break; case RDATE: /* ------------------- RDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case RECURRENCE_ID: /* ------------------- RecurrenceID -------------------- */ // Done above break; case RELATED_TO: /* ------------------- RelatedTo -------------------- */ final RelatedTo irelto = (RelatedTo)prop; final BwRelatedTo relto = new BwRelatedTo(); final String parval = IcalUtil.getParameterVal(irelto, "RELTYPE"); if (parval != null) { relto.setRelType(parval); } relto.setValue(irelto.getValue()); if (chg.changed(pi, ev.getRelatedTo(), relto)) { ev.setRelatedTo(relto); } break; case REQUEST_STATUS: /* ------------------- RequestStatus -------------------- */ final BwRequestStatus rs = BwRequestStatus .fromRequestStatus((RequestStatus)prop); chg.addValue(pi, rs); break; case RESOURCES: /* ------------------- Resources -------------------- */ final TextList rl = ((Resources)prop).getResources(); if (rl != null) { /* Got some resources */ lang = IcalUtil.getLang(prop); for (final String s: rl) { final BwString rsrc = new BwString(lang, s); chg.addValue(pi, rsrc); } } break; case RRULE: /* ------------------- RRule -------------------- */ chg.addValue(pi, pval); break; case SEQUENCE: /* ------------------- Sequence -------------------- */ final int seq = ((Sequence)prop).getSequenceNo(); if (seq != ev.getSequence()) { chg.changed(pi, ev.getSequence(), seq); ev.setSequence(seq); } break; case STATUS: /* ------------------- Status -------------------- */ if (chg.changed(pi, ev.getStatus(), pval)) { ev.setStatus(pval); } break; case SUMMARY: /* ------------------- Summary -------------------- */ if (chg.changed(pi, ev.getSummary(), pval)) { ev.setSummary(pval); } break; case TRANSP: /* ------------------- Transp -------------------- */ if (chg.changed(pi, ev.getPeruserTransparency( cb.getPrincipal() .getPrincipalRef()), pval)) { final BwXproperty pu = ev.setPeruserTransparency( cb.getPrincipal().getPrincipalRef(), pval); if (pu != null) { chg.addValue(PropertyInfoIndex.XPROP, pu); } } break; case UID: /* ------------------- Uid -------------------- */ /* We did this above */ break; case URL: /* ------------------- Url -------------------- */ if (chg.changed(pi, ev.getLink(), pval)) { ev.setLink(pval); } break; case XPROP: /* ------------------------- x-property --------------------------- */ final String name = prop.getName(); if (name.equalsIgnoreCase(BwXproperty.bedeworkCost)) { if (chg.changed(PropertyInfoIndex.COST, ev.getCost(), pval)) { ev.setCost(pval); } break; } if (name.equalsIgnoreCase(BwXproperty.xBedeworkCategories)) { if (checkCategory(cb, chg, ev, null, pval)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkLocation)) { if (checkLocation(cb, chg, ev, prop)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkContact)) { if (checkContact(cb, chg, ev, null, pval)) { break; } } /* See if this is an x-category that can be converted to a real category */ final XProperty xp = (XProperty)prop; chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(name, xp.getParameters() .toString(), pval)); break; default: if (logger.debug()) { logger.debug("Unsupported property with index " + pi + "; class " + prop.getClass() + " and value " + pval); } } } /* =================== Process sub-components =============== */ final ComponentList<Component> subComps; if (val instanceof ComponentContainer) { subComps = ((ComponentContainer<Component>)val).getComponents(); } else { subComps = null; } final Set<Integer> pids; if (vpoll) { pids = new TreeSet<>(); final BwEvent vp = evinfo.getEvent(); if (!Util.isEmpty(vp.getPollItems())) { vp.clearPollItems(); } } else { pids = null; } if (!Util.isEmpty(subComps)) { for (final var subComp: subComps) { if (subComp instanceof Available) { if (!(val instanceof VAvailability)) { return Response.error(resp, "AVAILABLE only valid in VAVAILABLE"); } final var avlResp = processAvailable(cb, cal, ical, (VAvailability)val, (Available)subComp, evinfo); if (!avlResp.isOk()) { return Response.fromResponse(resp, avlResp); } continue; } if (subComp instanceof Participant) { if (vpoll) { final var vresp = processVoter(cb, (VPoll)val, (Participant)subComp, evinfo, chg, mergeAttendees); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Participant object"); continue; } if (subComp instanceof VResource) { logger.warn("Unimplemented VResource object"); continue; } if (subComp instanceof VLocation) { logger.warn("Unimplemented VLocation object"); continue; } if (subComp instanceof VAlarm) { final var aresp = VAlarmUtil.processAlarm(cb, val, (VAlarm)subComp, ev, currentPrincipal, chg); if (!aresp.isOk()) { return Response.fromResponse(resp, aresp); } continue; } if (vpoll && (event || task)) { final var vresp = processCandidate((VPoll)val, subComp, evinfo, pids, chg); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Component object: " + subComp); } } /* Fix up timestamps. */ if (ev.getCreated() == null) { if (ev.getLastmod() != null) { ev.setCreated(ev.getLastmod()); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); } else { ev.updateDtstamp(); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } } if (ev.getLastmod() == null) { // created cannot be null now ev.setLastmod(ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } processTimezones(ev, ical, chg); /* Remove any recipients and originator */ if (ev.getRecipients() != null) { ev.getRecipients().clear(); } ev.setOriginator(null); if (hasXparams.value) { /* Save a text copy of the entire event as an x-property */ final Component valCopy = val.copy(); /* Remove potentially large values */ final Description desp = valCopy.getProperty(Property.DESCRIPTION); if (desp != null) { desp.setValue(null); } final Attach attachp = valCopy.getProperty(Property.ATTACH); // Don't store the entire attachment - we just need the parameters. if (attachp != null) { final Value v = attachp.getParameter(Parameter.VALUE); if (v != null) { attachp.setValue(String.valueOf(attachp.getValue().hashCode())); } } chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(BwXproperty.bedeworkIcal, null, valCopy.toString())); } chg.processChanges(ev, true, false); ev.setRecurring(ev.isRecurringEntity()); if (logger.debug()) { logger.debug(chg.toString()); logger.debug(ev.toString()); } if (masterEI != null) { // Just return notfound as this event is on its override list return Response.notFound(resp); } resp.setEntity(evinfo); return resp; } catch (final Throwable t) { if (logger.debug()) { logger.error(t); } return Response.error(resp, t); } }
DEFECT
true
/* ------------------- Location -------------------- */ BwLocation loc = null; //String uid = getUidPar(prop); /* At the moment Mozilla lightning is broken and this leads to all * sorts of problems. if (uid != null) { loc = cb.getLocation(uid); } */ lang = IcalUtil.getLang(prop); BwString addr = null;
break; case LAST_MODIFIED: /* ------------------- LastModified -------------------- */ if (chg.changed(pi, ev.getLastmod(), pval)) { ev.setLastmod(pval); } break; case LOCATION: /* ------------------- Location -------------------- */ BwLocation loc = null; //String uid = getUidPar(prop); /* At the moment Mozilla lightning is broken and this leads to all * sorts of problems. if (uid != null) { loc = cb.getLocation(uid); } */ lang = IcalUtil.getLang(prop); BwString addr = null; if (pval != null) { if (loc == null) { addr = new BwString(lang, pval); final var fcResp = cb.findLocation(addr); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) {
ev.addFreeBusyPeriod(fbc); break; case GEO: /* ------------------- Geo -------------------- */ final Geo g = (Geo)prop; final BwGeo geo = new BwGeo(g.getLatitude(), g.getLongitude()); if (chg.changed(pi, ev.getGeo(), geo)) { ev.setGeo(geo); } break; case LAST_MODIFIED: /* ------------------- LastModified -------------------- */ if (chg.changed(pi, ev.getLastmod(), pval)) { ev.setLastmod(pval); } break; case LOCATION: /* ------------------- Location -------------------- */ BwLocation loc = null; //String uid = getUidPar(prop); /* At the moment Mozilla lightning is broken and this leads to all * sorts of problems. if (uid != null) { loc = cb.getLocation(uid); } */ lang = IcalUtil.getLang(prop); BwString addr = null; if (pval != null) { if (loc == null) { addr = new BwString(lang, pval); final var fcResp = cb.findLocation(addr); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { loc = fcResp.getEntity(); } } if (loc == null) { loc = BwLocation.makeLocation(); loc.setAddress(addr); cb.addLocation(loc); } } final BwLocation evloc = ev.getLocation();
7,893
51
// CHGTBL - this only shows that it's a different location object
public static GetEntityResponse<EventInfo> toEvent( final IcalCallback cb, final BwCalendar cal, final Icalendar ical, final Component val, final boolean mergeAttendees) { final var resp = new GetEntityResponse<EventInfo>(); if (val == null) { return Response.notOk(resp, failed, "No component supplied"); } String currentPrincipal = null; final BwPrincipal principal = cb.getPrincipal(); if (principal != null) { currentPrincipal = principal.getPrincipalRef(); } final Holder<Boolean> hasXparams = new Holder<>(Boolean.FALSE); final int methodType = ical.getMethodType(); String attUri = null; if (mergeAttendees) { // We'll need this later. attUri = cb.getCaladdr(cb.getPrincipal().getPrincipalRef()); } final String colPath; if (cal == null) { colPath = null; } else { colPath = cal.getPath(); } try { final PropertyList<Property> pl = val.getProperties(); boolean vpoll = false; boolean event = false; boolean task = false; if (pl == null) { // Empty component return Response.notOk(resp, failed, "Empty component"); } final int entityType; if (val instanceof VEvent) { entityType = IcalDefs.entityTypeEvent; event = true; } else if (val instanceof VToDo) { entityType = IcalDefs.entityTypeTodo; task = true; } else if (val instanceof VJournal) { entityType = IcalDefs.entityTypeJournal; } else if (val instanceof VFreeBusy) { entityType = IcalDefs.entityTypeFreeAndBusy; } else if (val instanceof VAvailability) { entityType = IcalDefs.entityTypeVavailability; } else if (val instanceof Available) { entityType = IcalDefs.entityTypeAvailable; } else if (val instanceof VPoll) { entityType = IcalDefs.entityTypeVpoll; vpoll = true; } else { return Response.error(resp, "org.bedework.invalid.component.type: " + val.getName()); } // Get the guid from the component String guid = null; final Uid uidp = pl.getProperty(Property.UID); if (uidp != null) { testXparams(uidp, hasXparams); guid = uidp.getValue(); } if (guid == null) { /* XXX A guid is required - but are there devices out there without a * guid - and if so how do we handle it? */ return Response.notOk(resp, failed, CalFacadeException.noGuid); } /* See if we have a recurrence id */ BwDateTime ridObj = null; String rid = null; TimeZone ridTz = null; final RecurrenceId ridp = pl.getProperty(Property.RECURRENCE_ID); if (ridp != null) { testXparams(ridp, hasXparams); ridObj = BwDateTime.makeBwDateTime(ridp); if (ridObj.getRange() != null) { /* XXX What do I do with it? */ logger.warn("TRANS-TO_EVENT: Got a recurrence id range"); } rid = ridObj.getDate(); } EventInfo masterEI = null; EventInfo evinfo = null; final BwEvent ev; /* If we have a recurrence id see if we already have the master (we should * get a master + all its overrides). * * If so find the override and use the annnotation or if no override, * make one. * * If no override retrieve the event, add it to our table and then locate the * annotation. * * If there is no annotation, create one. * * It's possible we have been sent 'detached' instances of a recurring * event. This may happen if we are invited to one or more instances of a * meeting. In this case we try to retrieve the master and if it doesn't * exist we manufacture one. We consider such an instance an update to * that instance only and leave the others alone. */ /* We need this in a couple of places */ final DtStart dtStart = pl.getProperty(Property.DTSTART); /* if (rid != null) { // See if we have a new master event. If so create a proxy to that event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI == null) { masterEI = makeNewEvent(cb, chg, entityType, guid, cal); BwEvent e = masterEI.getEvent(); // XXX This seems bogus DtStart mdtStart; String bogusDate = "19980118T230000"; if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + "Z"); } else if (dtStart.getTimeZone() == null) { mdtStart = new DtStart(bogusDate); } else { mdtStart = new DtStart(bogusDate + "Z", dtStart.getTimeZone()); } setDates(e, mdtStart, null, null, chg); e.setRecurring(true); e.addRdate(ridObj); e.setSuppressed(true); ical.addComponent(masterEI); } if (masterEI != null) { evinfo = masterEI.findOverride(rid); } } */ /* If this is a recurrence instance see if we can find the master We only need this because the master may follow the overrides. */ if (rid != null) { // See if we have a new master event. If so create a proxy to this event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI != null) { evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; } } if ((evinfo == null) && (cal != null) && (cal.getCalType() != BwCalendar.calTypeInbox) && (cal.getCalType() != BwCalendar.calTypePendingInbox) && (cal.getCalType() != BwCalendar.calTypeOutbox)) { if (logger.debug()) { logger.debug("TRANS-TO_EVENT: try to fetch event with guid=" + guid); } final GetEntitiesResponse<EventInfo> eisResp = cb.getEvent(colPath, guid); if (eisResp.isError()) { return Response.fromResponse(resp, eisResp); } final var eis = eisResp.getEntities(); if (!Util.isEmpty(eis)) { if (eis.size() > 1) { // DORECUR - wrong again return Response.notOk(resp, failed, "More than one event returned for guid."); } evinfo = eis.iterator().next(); } if (logger.debug()) { if (evinfo != null) { logger.debug("TRANS-TO_EVENT: fetched event with guid"); } else { logger.debug("TRANS-TO_EVENT: did not find event with guid"); } } if (evinfo != null) { if (rid != null) { // We just retrieved it's master masterEI = evinfo; masterEI.setInstanceOnly(true); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; ical.addComponent(masterEI); } else if (methodType == ScheduleMethods.methodTypeCancel) { // This should never have an rid for cancel of entire event. evinfo.setInstanceOnly(evinfo.getEvent().getSuppressed()); } else { // Presumably sent an update for the entire event. No longer suppressed master evinfo.getEvent().setSuppressed(false); } } else if (rid != null) { /* Manufacture a master for the instance */ masterEI = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); final BwEvent e = masterEI.getEvent(); // XXX This seems bogus final DtStart mdtStart; final String bogusDate = "19980118"; final String bogusTime = "T230000"; // Base dtstart on the recurrence id. final boolean isDateType = ridObj.getDateType(); if (isDateType) { mdtStart = new DtStart(new Date(bogusDate)); } else if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + bogusTime + "Z"); } else if (ridObj.getTzid() == null) { mdtStart = new DtStart(bogusDate + bogusTime); } else { mdtStart = new DtStart(bogusDate + bogusTime, Timezones.getTz(ridObj.getTzid())); } IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), masterEI, mdtStart, null, null); e.setRecurring(true); // e.addRdate(ridObj); final var sum = (Summary)pl.getProperty(Property.SUMMARY); e.setSummary(sum.getValue()); e.setSuppressed(true); ical.addComponent(masterEI); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; masterEI.setInstanceOnly(rid != null); } } if (evinfo == null) { evinfo = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); } else if (evinfo.getEvent().getEntityType() != entityType) { return Response.notOk(resp, failed, "org.bedework.mismatched.entity.type: " + val); } final ChangeTable chg = evinfo.getChangeset( cb.getPrincipal().getPrincipalRef()); if (rid != null) { final String evrid = evinfo.getEvent().getRecurrenceId(); if ((evrid == null) || (!evrid.equals(rid))) { logger. warn("Mismatched rid ev=" + evrid + " expected " + rid); chg.changed(PropertyInfoIndex.RECURRENCE_ID, evrid, rid); // XXX spurious??? } if (masterEI.getEvent().getSuppressed()) { masterEI.getEvent().addRdate(ridObj); } } ev = evinfo.getEvent(); ev.setScheduleMethod(methodType); DtEnd dtEnd = null; if (entityType == IcalDefs.entityTypeTodo) { final Due due = pl.getProperty(Property.DUE); if (due != null ) { dtEnd = new DtEnd(due.getParameters(), due.getValue()); } } else { dtEnd = pl.getProperty(Property.DTEND); } final Duration duration = pl.getProperty(Property.DURATION); IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), evinfo, dtStart, dtEnd, duration); for (final Property prop: pl) { testXparams(prop, hasXparams); //debug("ical prop " + prop.getClass().getName()); String pval = prop.getValue(); if ((pval != null) && (pval.length() == 0)) { pval = null; } final PropertyInfoIndex pi; if (prop instanceof XProperty) { pi = PropertyInfoIndex.XPROP; } else { pi = PropertyInfoIndex.fromName(prop.getName()); } if (pi == null) { logger.debug("Unknown property with name " + prop.getName() + " class " + prop.getClass() + " and value " + pval); continue; } chg.present(pi); switch (pi) { case ACCEPT_RESPONSE: /* ------------------- Accept Response -------------------- */ String sval = prop.getValue(); if (chg.changed(pi, ev.getPollAcceptResponse(), sval)) { ev.setPollAcceptResponse(sval); } break; case ATTACH: /* ------------------- Attachment -------------------- */ chg.addValue(pi, IcalUtil.getAttachment((Attach)prop)); break; case ATTENDEE: /* ------------------- Attendee -------------------- */ if (methodType == ScheduleMethods.methodTypePublish) { if (cb.getStrictness() == IcalCallback.conformanceStrict) { return Response.notOk(resp, failed, CalFacadeException.attendeesInPublish); } //if (cb.getStrictness() == IcalCallback.conformanceWarn) { // warn("Had attendees for PUBLISH"); //} } final Attendee attPr = (Attendee)prop; if (evinfo.getNewEvent() || !mergeAttendees) { chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { final String pUri = cb.getCaladdr(attPr.getValue()); if (pUri.equals(attUri)) { /* Only update for our own attendee * We're doing a PUT and this must be the attendee updating their * partstat. We don't allow them to change other attendees * whatever the PUT content says. */ chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { // Use the value we currently have boolean found = false; for (final BwAttendee att: ev.getAttendees()) { if (pUri.equals(att.getAttendeeUri())) { chg.addValue(pi, att.clone()); found = true; break; } } if (!found) { // An added attendee final BwAttendee att = IcalUtil .getAttendee(cb, attPr); att.setPartstat(IcalDefs.partstatValNeedsAction); chg.addValue(pi, att); } } } break; case BUSYTYPE: final int ibt = BwEvent.fromBusyTypeString(pval); if (chg.changed(pi, ev.getBusyType(), ibt)) { ev.setBusyType(ibt); } break; case CATEGORIES: /* ------------------- Categories -------------------- */ final Categories cats = (Categories)prop; final TextList cl = cats.getCategories(); String lang = IcalUtil.getLang(cats); if (cl != null) { /* Got some categories */ for (final String wd: cl) { if (wd == null) { continue; } final BwString key = new BwString(lang, wd); final var fcResp = cb.findCategory(key); final BwCategory cat; if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isNotFound()) { cat = BwCategory.makeCategory(); cat.setWord(key); cb.addCategory(cat); } else { cat = fcResp.getEntity(); } chg.addValue(pi, cat); } } break; case CLASS: /* ------------------- Class -------------------- */ if (chg.changed(pi, ev.getClassification(), pval)) { ev.setClassification(pval); } break; case COMMENT: /* ------------------- Comment -------------------- */ chg.addValue(pi, new BwString(null, pval)); break; case COMPLETED: /* ------------------- Completed -------------------- */ if (chg.changed(pi, ev.getCompleted(), pval)) { ev.setCompleted(pval); } break; case CONCEPT: /* ------------------- Concept -------------------- */ final Concept c = (Concept)prop; final String cval = c.getValue(); if (cval != null) { /* Got a concept */ chg.addValue(PropertyInfoIndex.XPROP, BwXproperty.makeIcalProperty("CONCEPT", null, cval)); } break; case CONTACT: /* ------------------- Contact -------------------- */ final String altrep = getAltRepPar(prop); lang = IcalUtil.getLang(prop); final String uid = getUidPar(prop); final BwString nm = new BwString(lang, pval); BwContact contact = null; if (uid != null) { final var fcResp = cb.getContact(uid); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { final var fcResp = cb.findContact(nm); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { contact = BwContact.makeContact(); contact.setCn(nm); contact.setLink(altrep); cb.addContact(contact); } else { contact.setCn(nm); contact.setLink(altrep); } chg.addValue(pi, contact); break; case CREATED: /* ------------------- Created -------------------- */ if (chg.changed(pi, ev.getCreated(), pval)) { ev.setCreated(pval); } break; case DESCRIPTION: /* ------------------- Description -------------------- */ if (chg.changed(pi, ev.getDescription(), pval)) { ev.setDescription(pval); } break; case DTEND: /* ------------------- DtEnd -------------------- */ break; case DTSTAMP: /* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval); break; case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE: /* -------------------- Due ------------------------ */ break; case DURATION: /* ------------------- Duration -------------------- */ break; case EXDATE: /* ------------------- ExDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case EXRULE: /* ------------------- ExRule -------------------- */ chg.addValue(pi, pval); break; case FREEBUSY: /* ------------------- freebusy -------------------- */ final FreeBusy fbusy = (FreeBusy)prop; final PeriodList perpl = fbusy.getPeriods(); final Parameter par = IcalUtil.getParameter(fbusy, "FBTYPE"); final int fbtype; if (par == null) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY)) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY_TENTATIVE)) { fbtype = BwFreeBusyComponent.typeBusyTentative; } else if (par.equals(FbType.BUSY_UNAVAILABLE)) { fbtype = BwFreeBusyComponent.typeBusyUnavailable; } else if (par.equals(FbType.FREE)) { fbtype = BwFreeBusyComponent.typeFree; } else { if (logger.debug()) { logger.debug("Unsupported parameter " + par.getName()); } return Response.notOk(resp, failed, "Unsupported parameter " + par.getName()); } final BwFreeBusyComponent fbc = new BwFreeBusyComponent(); fbc.setType(fbtype); for (final Period per : perpl) { fbc.addPeriod(per); } ev.addFreeBusyPeriod(fbc); break; case GEO: /* ------------------- Geo -------------------- */ final Geo g = (Geo)prop; final BwGeo geo = new BwGeo(g.getLatitude(), g.getLongitude()); if (chg.changed(pi, ev.getGeo(), geo)) { ev.setGeo(geo); } break; case LAST_MODIFIED: /* ------------------- LastModified -------------------- */ if (chg.changed(pi, ev.getLastmod(), pval)) { ev.setLastmod(pval); } break; case LOCATION: /* ------------------- Location -------------------- */ BwLocation loc = null; //String uid = getUidPar(prop); /* At the moment Mozilla lightning is broken and this leads to all * sorts of problems. if (uid != null) { loc = cb.getLocation(uid); } */ lang = IcalUtil.getLang(prop); BwString addr = null; if (pval != null) { if (loc == null) { addr = new BwString(lang, pval); final var fcResp = cb.findLocation(addr); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { loc = fcResp.getEntity(); } } if (loc == null) { loc = BwLocation.makeLocation(); loc.setAddress(addr); cb.addLocation(loc); } } final BwLocation evloc = ev.getLocation(); if (chg.changed(pi, evloc, loc)) { // CHGTBL - this only shows that it's a different location object ev.setLocation(loc); } else if ((loc != null) && (evloc != null)) { // See if the value is changed final String evval = evloc.getAddress().getValue(); final String inval = loc.getAddress().getValue(); if (!evval.equals(inval)) { chg.changed(pi, evval, inval); evloc.getAddress().setValue(inval); } } break; case ORGANIZER: /* ------------------- Organizer -------------------- */ final BwOrganizer org = IcalUtil.getOrganizer(cb, (Organizer)prop); final BwOrganizer evorg = ev.getOrganizer(); final BwOrganizer evorgCopy; if (evorg == null) { evorgCopy = null; } else { evorgCopy = (BwOrganizer)evorg.clone(); } if (chg.changed(pi, evorgCopy, org)) { if (evorg == null) { ev.setOrganizer(org); } else { evorg.update(org); } } break; case PERCENT_COMPLETE: /* ------------------- PercentComplete -------------------- */ Integer ival = ((PercentComplete)prop).getPercentage(); if (chg.changed(pi, ev.getPercentComplete(), ival)) { ev.setPercentComplete(ival); } break; case POLL_MODE: /* ------------------- Poll mode -------------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollMode(), sval)) { ev.setPollMode(sval); } break; case POLL_PROPERTIES: /* ------------------- Poll properties ---------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollProperties(), sval)) { ev.setPollProperties(sval); } break; case POLL_WINNER: /* ------------------- Poll winner -------------------- */ ival = ((PollWinner)prop).getPollwinner(); if (chg.changed(pi, ev.getPollWinner(), ival)) { ev.setPollWinner(ival); } break; case PRIORITY: /* ------------------- Priority -------------------- */ ival = ((Priority)prop).getLevel(); if (chg.changed(pi, ev.getPriority(), ival)) { ev.setPriority(ival); } break; case RDATE: /* ------------------- RDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case RECURRENCE_ID: /* ------------------- RecurrenceID -------------------- */ // Done above break; case RELATED_TO: /* ------------------- RelatedTo -------------------- */ final RelatedTo irelto = (RelatedTo)prop; final BwRelatedTo relto = new BwRelatedTo(); final String parval = IcalUtil.getParameterVal(irelto, "RELTYPE"); if (parval != null) { relto.setRelType(parval); } relto.setValue(irelto.getValue()); if (chg.changed(pi, ev.getRelatedTo(), relto)) { ev.setRelatedTo(relto); } break; case REQUEST_STATUS: /* ------------------- RequestStatus -------------------- */ final BwRequestStatus rs = BwRequestStatus .fromRequestStatus((RequestStatus)prop); chg.addValue(pi, rs); break; case RESOURCES: /* ------------------- Resources -------------------- */ final TextList rl = ((Resources)prop).getResources(); if (rl != null) { /* Got some resources */ lang = IcalUtil.getLang(prop); for (final String s: rl) { final BwString rsrc = new BwString(lang, s); chg.addValue(pi, rsrc); } } break; case RRULE: /* ------------------- RRule -------------------- */ chg.addValue(pi, pval); break; case SEQUENCE: /* ------------------- Sequence -------------------- */ final int seq = ((Sequence)prop).getSequenceNo(); if (seq != ev.getSequence()) { chg.changed(pi, ev.getSequence(), seq); ev.setSequence(seq); } break; case STATUS: /* ------------------- Status -------------------- */ if (chg.changed(pi, ev.getStatus(), pval)) { ev.setStatus(pval); } break; case SUMMARY: /* ------------------- Summary -------------------- */ if (chg.changed(pi, ev.getSummary(), pval)) { ev.setSummary(pval); } break; case TRANSP: /* ------------------- Transp -------------------- */ if (chg.changed(pi, ev.getPeruserTransparency( cb.getPrincipal() .getPrincipalRef()), pval)) { final BwXproperty pu = ev.setPeruserTransparency( cb.getPrincipal().getPrincipalRef(), pval); if (pu != null) { chg.addValue(PropertyInfoIndex.XPROP, pu); } } break; case UID: /* ------------------- Uid -------------------- */ /* We did this above */ break; case URL: /* ------------------- Url -------------------- */ if (chg.changed(pi, ev.getLink(), pval)) { ev.setLink(pval); } break; case XPROP: /* ------------------------- x-property --------------------------- */ final String name = prop.getName(); if (name.equalsIgnoreCase(BwXproperty.bedeworkCost)) { if (chg.changed(PropertyInfoIndex.COST, ev.getCost(), pval)) { ev.setCost(pval); } break; } if (name.equalsIgnoreCase(BwXproperty.xBedeworkCategories)) { if (checkCategory(cb, chg, ev, null, pval)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkLocation)) { if (checkLocation(cb, chg, ev, prop)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkContact)) { if (checkContact(cb, chg, ev, null, pval)) { break; } } /* See if this is an x-category that can be converted to a real category */ final XProperty xp = (XProperty)prop; chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(name, xp.getParameters() .toString(), pval)); break; default: if (logger.debug()) { logger.debug("Unsupported property with index " + pi + "; class " + prop.getClass() + " and value " + pval); } } } /* =================== Process sub-components =============== */ final ComponentList<Component> subComps; if (val instanceof ComponentContainer) { subComps = ((ComponentContainer<Component>)val).getComponents(); } else { subComps = null; } final Set<Integer> pids; if (vpoll) { pids = new TreeSet<>(); final BwEvent vp = evinfo.getEvent(); if (!Util.isEmpty(vp.getPollItems())) { vp.clearPollItems(); } } else { pids = null; } if (!Util.isEmpty(subComps)) { for (final var subComp: subComps) { if (subComp instanceof Available) { if (!(val instanceof VAvailability)) { return Response.error(resp, "AVAILABLE only valid in VAVAILABLE"); } final var avlResp = processAvailable(cb, cal, ical, (VAvailability)val, (Available)subComp, evinfo); if (!avlResp.isOk()) { return Response.fromResponse(resp, avlResp); } continue; } if (subComp instanceof Participant) { if (vpoll) { final var vresp = processVoter(cb, (VPoll)val, (Participant)subComp, evinfo, chg, mergeAttendees); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Participant object"); continue; } if (subComp instanceof VResource) { logger.warn("Unimplemented VResource object"); continue; } if (subComp instanceof VLocation) { logger.warn("Unimplemented VLocation object"); continue; } if (subComp instanceof VAlarm) { final var aresp = VAlarmUtil.processAlarm(cb, val, (VAlarm)subComp, ev, currentPrincipal, chg); if (!aresp.isOk()) { return Response.fromResponse(resp, aresp); } continue; } if (vpoll && (event || task)) { final var vresp = processCandidate((VPoll)val, subComp, evinfo, pids, chg); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Component object: " + subComp); } } /* Fix up timestamps. */ if (ev.getCreated() == null) { if (ev.getLastmod() != null) { ev.setCreated(ev.getLastmod()); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); } else { ev.updateDtstamp(); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } } if (ev.getLastmod() == null) { // created cannot be null now ev.setLastmod(ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } processTimezones(ev, ical, chg); /* Remove any recipients and originator */ if (ev.getRecipients() != null) { ev.getRecipients().clear(); } ev.setOriginator(null); if (hasXparams.value) { /* Save a text copy of the entire event as an x-property */ final Component valCopy = val.copy(); /* Remove potentially large values */ final Description desp = valCopy.getProperty(Property.DESCRIPTION); if (desp != null) { desp.setValue(null); } final Attach attachp = valCopy.getProperty(Property.ATTACH); // Don't store the entire attachment - we just need the parameters. if (attachp != null) { final Value v = attachp.getParameter(Parameter.VALUE); if (v != null) { attachp.setValue(String.valueOf(attachp.getValue().hashCode())); } } chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(BwXproperty.bedeworkIcal, null, valCopy.toString())); } chg.processChanges(ev, true, false); ev.setRecurring(ev.isRecurringEntity()); if (logger.debug()) { logger.debug(chg.toString()); logger.debug(ev.toString()); } if (masterEI != null) { // Just return notfound as this event is on its override list return Response.notFound(resp); } resp.setEntity(evinfo); return resp; } catch (final Throwable t) { if (logger.debug()) { logger.error(t); } return Response.error(resp, t); } }
NONSATD
true
final BwLocation evloc = ev.getLocation(); if (chg.changed(pi, evloc, loc)) { // CHGTBL - this only shows that it's a different location object ev.setLocation(loc); } else if ((loc != null) && (evloc != null)) {
} } if (loc == null) { loc = BwLocation.makeLocation(); loc.setAddress(addr); cb.addLocation(loc); } } final BwLocation evloc = ev.getLocation(); if (chg.changed(pi, evloc, loc)) { // CHGTBL - this only shows that it's a different location object ev.setLocation(loc); } else if ((loc != null) && (evloc != null)) { // See if the value is changed final String evval = evloc.getAddress().getValue(); final String inval = loc.getAddress().getValue(); if (!evval.equals(inval)) { chg.changed(pi, evval, inval); evloc.getAddress().setValue(inval); } }
BwString addr = null; if (pval != null) { if (loc == null) { addr = new BwString(lang, pval); final var fcResp = cb.findLocation(addr); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { loc = fcResp.getEntity(); } } if (loc == null) { loc = BwLocation.makeLocation(); loc.setAddress(addr); cb.addLocation(loc); } } final BwLocation evloc = ev.getLocation(); if (chg.changed(pi, evloc, loc)) { // CHGTBL - this only shows that it's a different location object ev.setLocation(loc); } else if ((loc != null) && (evloc != null)) { // See if the value is changed final String evval = evloc.getAddress().getValue(); final String inval = loc.getAddress().getValue(); if (!evval.equals(inval)) { chg.changed(pi, evval, inval); evloc.getAddress().setValue(inval); } } break; case ORGANIZER: /* ------------------- Organizer -------------------- */ final BwOrganizer org = IcalUtil.getOrganizer(cb, (Organizer)prop); final BwOrganizer evorg = ev.getOrganizer(); final BwOrganizer evorgCopy; if (evorg == null) { evorgCopy = null; } else { evorgCopy = (BwOrganizer)evorg.clone();
7,893
52
// See if the value is changed
public static GetEntityResponse<EventInfo> toEvent( final IcalCallback cb, final BwCalendar cal, final Icalendar ical, final Component val, final boolean mergeAttendees) { final var resp = new GetEntityResponse<EventInfo>(); if (val == null) { return Response.notOk(resp, failed, "No component supplied"); } String currentPrincipal = null; final BwPrincipal principal = cb.getPrincipal(); if (principal != null) { currentPrincipal = principal.getPrincipalRef(); } final Holder<Boolean> hasXparams = new Holder<>(Boolean.FALSE); final int methodType = ical.getMethodType(); String attUri = null; if (mergeAttendees) { // We'll need this later. attUri = cb.getCaladdr(cb.getPrincipal().getPrincipalRef()); } final String colPath; if (cal == null) { colPath = null; } else { colPath = cal.getPath(); } try { final PropertyList<Property> pl = val.getProperties(); boolean vpoll = false; boolean event = false; boolean task = false; if (pl == null) { // Empty component return Response.notOk(resp, failed, "Empty component"); } final int entityType; if (val instanceof VEvent) { entityType = IcalDefs.entityTypeEvent; event = true; } else if (val instanceof VToDo) { entityType = IcalDefs.entityTypeTodo; task = true; } else if (val instanceof VJournal) { entityType = IcalDefs.entityTypeJournal; } else if (val instanceof VFreeBusy) { entityType = IcalDefs.entityTypeFreeAndBusy; } else if (val instanceof VAvailability) { entityType = IcalDefs.entityTypeVavailability; } else if (val instanceof Available) { entityType = IcalDefs.entityTypeAvailable; } else if (val instanceof VPoll) { entityType = IcalDefs.entityTypeVpoll; vpoll = true; } else { return Response.error(resp, "org.bedework.invalid.component.type: " + val.getName()); } // Get the guid from the component String guid = null; final Uid uidp = pl.getProperty(Property.UID); if (uidp != null) { testXparams(uidp, hasXparams); guid = uidp.getValue(); } if (guid == null) { /* XXX A guid is required - but are there devices out there without a * guid - and if so how do we handle it? */ return Response.notOk(resp, failed, CalFacadeException.noGuid); } /* See if we have a recurrence id */ BwDateTime ridObj = null; String rid = null; TimeZone ridTz = null; final RecurrenceId ridp = pl.getProperty(Property.RECURRENCE_ID); if (ridp != null) { testXparams(ridp, hasXparams); ridObj = BwDateTime.makeBwDateTime(ridp); if (ridObj.getRange() != null) { /* XXX What do I do with it? */ logger.warn("TRANS-TO_EVENT: Got a recurrence id range"); } rid = ridObj.getDate(); } EventInfo masterEI = null; EventInfo evinfo = null; final BwEvent ev; /* If we have a recurrence id see if we already have the master (we should * get a master + all its overrides). * * If so find the override and use the annnotation or if no override, * make one. * * If no override retrieve the event, add it to our table and then locate the * annotation. * * If there is no annotation, create one. * * It's possible we have been sent 'detached' instances of a recurring * event. This may happen if we are invited to one or more instances of a * meeting. In this case we try to retrieve the master and if it doesn't * exist we manufacture one. We consider such an instance an update to * that instance only and leave the others alone. */ /* We need this in a couple of places */ final DtStart dtStart = pl.getProperty(Property.DTSTART); /* if (rid != null) { // See if we have a new master event. If so create a proxy to that event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI == null) { masterEI = makeNewEvent(cb, chg, entityType, guid, cal); BwEvent e = masterEI.getEvent(); // XXX This seems bogus DtStart mdtStart; String bogusDate = "19980118T230000"; if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + "Z"); } else if (dtStart.getTimeZone() == null) { mdtStart = new DtStart(bogusDate); } else { mdtStart = new DtStart(bogusDate + "Z", dtStart.getTimeZone()); } setDates(e, mdtStart, null, null, chg); e.setRecurring(true); e.addRdate(ridObj); e.setSuppressed(true); ical.addComponent(masterEI); } if (masterEI != null) { evinfo = masterEI.findOverride(rid); } } */ /* If this is a recurrence instance see if we can find the master We only need this because the master may follow the overrides. */ if (rid != null) { // See if we have a new master event. If so create a proxy to this event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI != null) { evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; } } if ((evinfo == null) && (cal != null) && (cal.getCalType() != BwCalendar.calTypeInbox) && (cal.getCalType() != BwCalendar.calTypePendingInbox) && (cal.getCalType() != BwCalendar.calTypeOutbox)) { if (logger.debug()) { logger.debug("TRANS-TO_EVENT: try to fetch event with guid=" + guid); } final GetEntitiesResponse<EventInfo> eisResp = cb.getEvent(colPath, guid); if (eisResp.isError()) { return Response.fromResponse(resp, eisResp); } final var eis = eisResp.getEntities(); if (!Util.isEmpty(eis)) { if (eis.size() > 1) { // DORECUR - wrong again return Response.notOk(resp, failed, "More than one event returned for guid."); } evinfo = eis.iterator().next(); } if (logger.debug()) { if (evinfo != null) { logger.debug("TRANS-TO_EVENT: fetched event with guid"); } else { logger.debug("TRANS-TO_EVENT: did not find event with guid"); } } if (evinfo != null) { if (rid != null) { // We just retrieved it's master masterEI = evinfo; masterEI.setInstanceOnly(true); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; ical.addComponent(masterEI); } else if (methodType == ScheduleMethods.methodTypeCancel) { // This should never have an rid for cancel of entire event. evinfo.setInstanceOnly(evinfo.getEvent().getSuppressed()); } else { // Presumably sent an update for the entire event. No longer suppressed master evinfo.getEvent().setSuppressed(false); } } else if (rid != null) { /* Manufacture a master for the instance */ masterEI = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); final BwEvent e = masterEI.getEvent(); // XXX This seems bogus final DtStart mdtStart; final String bogusDate = "19980118"; final String bogusTime = "T230000"; // Base dtstart on the recurrence id. final boolean isDateType = ridObj.getDateType(); if (isDateType) { mdtStart = new DtStart(new Date(bogusDate)); } else if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + bogusTime + "Z"); } else if (ridObj.getTzid() == null) { mdtStart = new DtStart(bogusDate + bogusTime); } else { mdtStart = new DtStart(bogusDate + bogusTime, Timezones.getTz(ridObj.getTzid())); } IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), masterEI, mdtStart, null, null); e.setRecurring(true); // e.addRdate(ridObj); final var sum = (Summary)pl.getProperty(Property.SUMMARY); e.setSummary(sum.getValue()); e.setSuppressed(true); ical.addComponent(masterEI); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; masterEI.setInstanceOnly(rid != null); } } if (evinfo == null) { evinfo = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); } else if (evinfo.getEvent().getEntityType() != entityType) { return Response.notOk(resp, failed, "org.bedework.mismatched.entity.type: " + val); } final ChangeTable chg = evinfo.getChangeset( cb.getPrincipal().getPrincipalRef()); if (rid != null) { final String evrid = evinfo.getEvent().getRecurrenceId(); if ((evrid == null) || (!evrid.equals(rid))) { logger. warn("Mismatched rid ev=" + evrid + " expected " + rid); chg.changed(PropertyInfoIndex.RECURRENCE_ID, evrid, rid); // XXX spurious??? } if (masterEI.getEvent().getSuppressed()) { masterEI.getEvent().addRdate(ridObj); } } ev = evinfo.getEvent(); ev.setScheduleMethod(methodType); DtEnd dtEnd = null; if (entityType == IcalDefs.entityTypeTodo) { final Due due = pl.getProperty(Property.DUE); if (due != null ) { dtEnd = new DtEnd(due.getParameters(), due.getValue()); } } else { dtEnd = pl.getProperty(Property.DTEND); } final Duration duration = pl.getProperty(Property.DURATION); IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), evinfo, dtStart, dtEnd, duration); for (final Property prop: pl) { testXparams(prop, hasXparams); //debug("ical prop " + prop.getClass().getName()); String pval = prop.getValue(); if ((pval != null) && (pval.length() == 0)) { pval = null; } final PropertyInfoIndex pi; if (prop instanceof XProperty) { pi = PropertyInfoIndex.XPROP; } else { pi = PropertyInfoIndex.fromName(prop.getName()); } if (pi == null) { logger.debug("Unknown property with name " + prop.getName() + " class " + prop.getClass() + " and value " + pval); continue; } chg.present(pi); switch (pi) { case ACCEPT_RESPONSE: /* ------------------- Accept Response -------------------- */ String sval = prop.getValue(); if (chg.changed(pi, ev.getPollAcceptResponse(), sval)) { ev.setPollAcceptResponse(sval); } break; case ATTACH: /* ------------------- Attachment -------------------- */ chg.addValue(pi, IcalUtil.getAttachment((Attach)prop)); break; case ATTENDEE: /* ------------------- Attendee -------------------- */ if (methodType == ScheduleMethods.methodTypePublish) { if (cb.getStrictness() == IcalCallback.conformanceStrict) { return Response.notOk(resp, failed, CalFacadeException.attendeesInPublish); } //if (cb.getStrictness() == IcalCallback.conformanceWarn) { // warn("Had attendees for PUBLISH"); //} } final Attendee attPr = (Attendee)prop; if (evinfo.getNewEvent() || !mergeAttendees) { chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { final String pUri = cb.getCaladdr(attPr.getValue()); if (pUri.equals(attUri)) { /* Only update for our own attendee * We're doing a PUT and this must be the attendee updating their * partstat. We don't allow them to change other attendees * whatever the PUT content says. */ chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { // Use the value we currently have boolean found = false; for (final BwAttendee att: ev.getAttendees()) { if (pUri.equals(att.getAttendeeUri())) { chg.addValue(pi, att.clone()); found = true; break; } } if (!found) { // An added attendee final BwAttendee att = IcalUtil .getAttendee(cb, attPr); att.setPartstat(IcalDefs.partstatValNeedsAction); chg.addValue(pi, att); } } } break; case BUSYTYPE: final int ibt = BwEvent.fromBusyTypeString(pval); if (chg.changed(pi, ev.getBusyType(), ibt)) { ev.setBusyType(ibt); } break; case CATEGORIES: /* ------------------- Categories -------------------- */ final Categories cats = (Categories)prop; final TextList cl = cats.getCategories(); String lang = IcalUtil.getLang(cats); if (cl != null) { /* Got some categories */ for (final String wd: cl) { if (wd == null) { continue; } final BwString key = new BwString(lang, wd); final var fcResp = cb.findCategory(key); final BwCategory cat; if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isNotFound()) { cat = BwCategory.makeCategory(); cat.setWord(key); cb.addCategory(cat); } else { cat = fcResp.getEntity(); } chg.addValue(pi, cat); } } break; case CLASS: /* ------------------- Class -------------------- */ if (chg.changed(pi, ev.getClassification(), pval)) { ev.setClassification(pval); } break; case COMMENT: /* ------------------- Comment -------------------- */ chg.addValue(pi, new BwString(null, pval)); break; case COMPLETED: /* ------------------- Completed -------------------- */ if (chg.changed(pi, ev.getCompleted(), pval)) { ev.setCompleted(pval); } break; case CONCEPT: /* ------------------- Concept -------------------- */ final Concept c = (Concept)prop; final String cval = c.getValue(); if (cval != null) { /* Got a concept */ chg.addValue(PropertyInfoIndex.XPROP, BwXproperty.makeIcalProperty("CONCEPT", null, cval)); } break; case CONTACT: /* ------------------- Contact -------------------- */ final String altrep = getAltRepPar(prop); lang = IcalUtil.getLang(prop); final String uid = getUidPar(prop); final BwString nm = new BwString(lang, pval); BwContact contact = null; if (uid != null) { final var fcResp = cb.getContact(uid); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { final var fcResp = cb.findContact(nm); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { contact = BwContact.makeContact(); contact.setCn(nm); contact.setLink(altrep); cb.addContact(contact); } else { contact.setCn(nm); contact.setLink(altrep); } chg.addValue(pi, contact); break; case CREATED: /* ------------------- Created -------------------- */ if (chg.changed(pi, ev.getCreated(), pval)) { ev.setCreated(pval); } break; case DESCRIPTION: /* ------------------- Description -------------------- */ if (chg.changed(pi, ev.getDescription(), pval)) { ev.setDescription(pval); } break; case DTEND: /* ------------------- DtEnd -------------------- */ break; case DTSTAMP: /* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval); break; case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE: /* -------------------- Due ------------------------ */ break; case DURATION: /* ------------------- Duration -------------------- */ break; case EXDATE: /* ------------------- ExDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case EXRULE: /* ------------------- ExRule -------------------- */ chg.addValue(pi, pval); break; case FREEBUSY: /* ------------------- freebusy -------------------- */ final FreeBusy fbusy = (FreeBusy)prop; final PeriodList perpl = fbusy.getPeriods(); final Parameter par = IcalUtil.getParameter(fbusy, "FBTYPE"); final int fbtype; if (par == null) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY)) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY_TENTATIVE)) { fbtype = BwFreeBusyComponent.typeBusyTentative; } else if (par.equals(FbType.BUSY_UNAVAILABLE)) { fbtype = BwFreeBusyComponent.typeBusyUnavailable; } else if (par.equals(FbType.FREE)) { fbtype = BwFreeBusyComponent.typeFree; } else { if (logger.debug()) { logger.debug("Unsupported parameter " + par.getName()); } return Response.notOk(resp, failed, "Unsupported parameter " + par.getName()); } final BwFreeBusyComponent fbc = new BwFreeBusyComponent(); fbc.setType(fbtype); for (final Period per : perpl) { fbc.addPeriod(per); } ev.addFreeBusyPeriod(fbc); break; case GEO: /* ------------------- Geo -------------------- */ final Geo g = (Geo)prop; final BwGeo geo = new BwGeo(g.getLatitude(), g.getLongitude()); if (chg.changed(pi, ev.getGeo(), geo)) { ev.setGeo(geo); } break; case LAST_MODIFIED: /* ------------------- LastModified -------------------- */ if (chg.changed(pi, ev.getLastmod(), pval)) { ev.setLastmod(pval); } break; case LOCATION: /* ------------------- Location -------------------- */ BwLocation loc = null; //String uid = getUidPar(prop); /* At the moment Mozilla lightning is broken and this leads to all * sorts of problems. if (uid != null) { loc = cb.getLocation(uid); } */ lang = IcalUtil.getLang(prop); BwString addr = null; if (pval != null) { if (loc == null) { addr = new BwString(lang, pval); final var fcResp = cb.findLocation(addr); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { loc = fcResp.getEntity(); } } if (loc == null) { loc = BwLocation.makeLocation(); loc.setAddress(addr); cb.addLocation(loc); } } final BwLocation evloc = ev.getLocation(); if (chg.changed(pi, evloc, loc)) { // CHGTBL - this only shows that it's a different location object ev.setLocation(loc); } else if ((loc != null) && (evloc != null)) { // See if the value is changed final String evval = evloc.getAddress().getValue(); final String inval = loc.getAddress().getValue(); if (!evval.equals(inval)) { chg.changed(pi, evval, inval); evloc.getAddress().setValue(inval); } } break; case ORGANIZER: /* ------------------- Organizer -------------------- */ final BwOrganizer org = IcalUtil.getOrganizer(cb, (Organizer)prop); final BwOrganizer evorg = ev.getOrganizer(); final BwOrganizer evorgCopy; if (evorg == null) { evorgCopy = null; } else { evorgCopy = (BwOrganizer)evorg.clone(); } if (chg.changed(pi, evorgCopy, org)) { if (evorg == null) { ev.setOrganizer(org); } else { evorg.update(org); } } break; case PERCENT_COMPLETE: /* ------------------- PercentComplete -------------------- */ Integer ival = ((PercentComplete)prop).getPercentage(); if (chg.changed(pi, ev.getPercentComplete(), ival)) { ev.setPercentComplete(ival); } break; case POLL_MODE: /* ------------------- Poll mode -------------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollMode(), sval)) { ev.setPollMode(sval); } break; case POLL_PROPERTIES: /* ------------------- Poll properties ---------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollProperties(), sval)) { ev.setPollProperties(sval); } break; case POLL_WINNER: /* ------------------- Poll winner -------------------- */ ival = ((PollWinner)prop).getPollwinner(); if (chg.changed(pi, ev.getPollWinner(), ival)) { ev.setPollWinner(ival); } break; case PRIORITY: /* ------------------- Priority -------------------- */ ival = ((Priority)prop).getLevel(); if (chg.changed(pi, ev.getPriority(), ival)) { ev.setPriority(ival); } break; case RDATE: /* ------------------- RDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case RECURRENCE_ID: /* ------------------- RecurrenceID -------------------- */ // Done above break; case RELATED_TO: /* ------------------- RelatedTo -------------------- */ final RelatedTo irelto = (RelatedTo)prop; final BwRelatedTo relto = new BwRelatedTo(); final String parval = IcalUtil.getParameterVal(irelto, "RELTYPE"); if (parval != null) { relto.setRelType(parval); } relto.setValue(irelto.getValue()); if (chg.changed(pi, ev.getRelatedTo(), relto)) { ev.setRelatedTo(relto); } break; case REQUEST_STATUS: /* ------------------- RequestStatus -------------------- */ final BwRequestStatus rs = BwRequestStatus .fromRequestStatus((RequestStatus)prop); chg.addValue(pi, rs); break; case RESOURCES: /* ------------------- Resources -------------------- */ final TextList rl = ((Resources)prop).getResources(); if (rl != null) { /* Got some resources */ lang = IcalUtil.getLang(prop); for (final String s: rl) { final BwString rsrc = new BwString(lang, s); chg.addValue(pi, rsrc); } } break; case RRULE: /* ------------------- RRule -------------------- */ chg.addValue(pi, pval); break; case SEQUENCE: /* ------------------- Sequence -------------------- */ final int seq = ((Sequence)prop).getSequenceNo(); if (seq != ev.getSequence()) { chg.changed(pi, ev.getSequence(), seq); ev.setSequence(seq); } break; case STATUS: /* ------------------- Status -------------------- */ if (chg.changed(pi, ev.getStatus(), pval)) { ev.setStatus(pval); } break; case SUMMARY: /* ------------------- Summary -------------------- */ if (chg.changed(pi, ev.getSummary(), pval)) { ev.setSummary(pval); } break; case TRANSP: /* ------------------- Transp -------------------- */ if (chg.changed(pi, ev.getPeruserTransparency( cb.getPrincipal() .getPrincipalRef()), pval)) { final BwXproperty pu = ev.setPeruserTransparency( cb.getPrincipal().getPrincipalRef(), pval); if (pu != null) { chg.addValue(PropertyInfoIndex.XPROP, pu); } } break; case UID: /* ------------------- Uid -------------------- */ /* We did this above */ break; case URL: /* ------------------- Url -------------------- */ if (chg.changed(pi, ev.getLink(), pval)) { ev.setLink(pval); } break; case XPROP: /* ------------------------- x-property --------------------------- */ final String name = prop.getName(); if (name.equalsIgnoreCase(BwXproperty.bedeworkCost)) { if (chg.changed(PropertyInfoIndex.COST, ev.getCost(), pval)) { ev.setCost(pval); } break; } if (name.equalsIgnoreCase(BwXproperty.xBedeworkCategories)) { if (checkCategory(cb, chg, ev, null, pval)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkLocation)) { if (checkLocation(cb, chg, ev, prop)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkContact)) { if (checkContact(cb, chg, ev, null, pval)) { break; } } /* See if this is an x-category that can be converted to a real category */ final XProperty xp = (XProperty)prop; chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(name, xp.getParameters() .toString(), pval)); break; default: if (logger.debug()) { logger.debug("Unsupported property with index " + pi + "; class " + prop.getClass() + " and value " + pval); } } } /* =================== Process sub-components =============== */ final ComponentList<Component> subComps; if (val instanceof ComponentContainer) { subComps = ((ComponentContainer<Component>)val).getComponents(); } else { subComps = null; } final Set<Integer> pids; if (vpoll) { pids = new TreeSet<>(); final BwEvent vp = evinfo.getEvent(); if (!Util.isEmpty(vp.getPollItems())) { vp.clearPollItems(); } } else { pids = null; } if (!Util.isEmpty(subComps)) { for (final var subComp: subComps) { if (subComp instanceof Available) { if (!(val instanceof VAvailability)) { return Response.error(resp, "AVAILABLE only valid in VAVAILABLE"); } final var avlResp = processAvailable(cb, cal, ical, (VAvailability)val, (Available)subComp, evinfo); if (!avlResp.isOk()) { return Response.fromResponse(resp, avlResp); } continue; } if (subComp instanceof Participant) { if (vpoll) { final var vresp = processVoter(cb, (VPoll)val, (Participant)subComp, evinfo, chg, mergeAttendees); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Participant object"); continue; } if (subComp instanceof VResource) { logger.warn("Unimplemented VResource object"); continue; } if (subComp instanceof VLocation) { logger.warn("Unimplemented VLocation object"); continue; } if (subComp instanceof VAlarm) { final var aresp = VAlarmUtil.processAlarm(cb, val, (VAlarm)subComp, ev, currentPrincipal, chg); if (!aresp.isOk()) { return Response.fromResponse(resp, aresp); } continue; } if (vpoll && (event || task)) { final var vresp = processCandidate((VPoll)val, subComp, evinfo, pids, chg); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Component object: " + subComp); } } /* Fix up timestamps. */ if (ev.getCreated() == null) { if (ev.getLastmod() != null) { ev.setCreated(ev.getLastmod()); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); } else { ev.updateDtstamp(); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } } if (ev.getLastmod() == null) { // created cannot be null now ev.setLastmod(ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } processTimezones(ev, ical, chg); /* Remove any recipients and originator */ if (ev.getRecipients() != null) { ev.getRecipients().clear(); } ev.setOriginator(null); if (hasXparams.value) { /* Save a text copy of the entire event as an x-property */ final Component valCopy = val.copy(); /* Remove potentially large values */ final Description desp = valCopy.getProperty(Property.DESCRIPTION); if (desp != null) { desp.setValue(null); } final Attach attachp = valCopy.getProperty(Property.ATTACH); // Don't store the entire attachment - we just need the parameters. if (attachp != null) { final Value v = attachp.getParameter(Parameter.VALUE); if (v != null) { attachp.setValue(String.valueOf(attachp.getValue().hashCode())); } } chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(BwXproperty.bedeworkIcal, null, valCopy.toString())); } chg.processChanges(ev, true, false); ev.setRecurring(ev.isRecurringEntity()); if (logger.debug()) { logger.debug(chg.toString()); logger.debug(ev.toString()); } if (masterEI != null) { // Just return notfound as this event is on its override list return Response.notFound(resp); } resp.setEntity(evinfo); return resp; } catch (final Throwable t) { if (logger.debug()) { logger.error(t); } return Response.error(resp, t); } }
NONSATD
true
ev.setLocation(loc); } else if ((loc != null) && (evloc != null)) { // See if the value is changed final String evval = evloc.getAddress().getValue(); final String inval = loc.getAddress().getValue();
loc = BwLocation.makeLocation(); loc.setAddress(addr); cb.addLocation(loc); } } final BwLocation evloc = ev.getLocation(); if (chg.changed(pi, evloc, loc)) { // CHGTBL - this only shows that it's a different location object ev.setLocation(loc); } else if ((loc != null) && (evloc != null)) { // See if the value is changed final String evval = evloc.getAddress().getValue(); final String inval = loc.getAddress().getValue(); if (!evval.equals(inval)) { chg.changed(pi, evval, inval); evloc.getAddress().setValue(inval); } } break; case ORGANIZER: /* ------------------- Organizer -------------------- */
addr = new BwString(lang, pval); final var fcResp = cb.findLocation(addr); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { loc = fcResp.getEntity(); } } if (loc == null) { loc = BwLocation.makeLocation(); loc.setAddress(addr); cb.addLocation(loc); } } final BwLocation evloc = ev.getLocation(); if (chg.changed(pi, evloc, loc)) { // CHGTBL - this only shows that it's a different location object ev.setLocation(loc); } else if ((loc != null) && (evloc != null)) { // See if the value is changed final String evval = evloc.getAddress().getValue(); final String inval = loc.getAddress().getValue(); if (!evval.equals(inval)) { chg.changed(pi, evval, inval); evloc.getAddress().setValue(inval); } } break; case ORGANIZER: /* ------------------- Organizer -------------------- */ final BwOrganizer org = IcalUtil.getOrganizer(cb, (Organizer)prop); final BwOrganizer evorg = ev.getOrganizer(); final BwOrganizer evorgCopy; if (evorg == null) { evorgCopy = null; } else { evorgCopy = (BwOrganizer)evorg.clone(); } if (chg.changed(pi, evorgCopy, org)) { if (evorg == null) {
7,893
53
/* ------------------- Organizer -------------------- */
public static GetEntityResponse<EventInfo> toEvent( final IcalCallback cb, final BwCalendar cal, final Icalendar ical, final Component val, final boolean mergeAttendees) { final var resp = new GetEntityResponse<EventInfo>(); if (val == null) { return Response.notOk(resp, failed, "No component supplied"); } String currentPrincipal = null; final BwPrincipal principal = cb.getPrincipal(); if (principal != null) { currentPrincipal = principal.getPrincipalRef(); } final Holder<Boolean> hasXparams = new Holder<>(Boolean.FALSE); final int methodType = ical.getMethodType(); String attUri = null; if (mergeAttendees) { // We'll need this later. attUri = cb.getCaladdr(cb.getPrincipal().getPrincipalRef()); } final String colPath; if (cal == null) { colPath = null; } else { colPath = cal.getPath(); } try { final PropertyList<Property> pl = val.getProperties(); boolean vpoll = false; boolean event = false; boolean task = false; if (pl == null) { // Empty component return Response.notOk(resp, failed, "Empty component"); } final int entityType; if (val instanceof VEvent) { entityType = IcalDefs.entityTypeEvent; event = true; } else if (val instanceof VToDo) { entityType = IcalDefs.entityTypeTodo; task = true; } else if (val instanceof VJournal) { entityType = IcalDefs.entityTypeJournal; } else if (val instanceof VFreeBusy) { entityType = IcalDefs.entityTypeFreeAndBusy; } else if (val instanceof VAvailability) { entityType = IcalDefs.entityTypeVavailability; } else if (val instanceof Available) { entityType = IcalDefs.entityTypeAvailable; } else if (val instanceof VPoll) { entityType = IcalDefs.entityTypeVpoll; vpoll = true; } else { return Response.error(resp, "org.bedework.invalid.component.type: " + val.getName()); } // Get the guid from the component String guid = null; final Uid uidp = pl.getProperty(Property.UID); if (uidp != null) { testXparams(uidp, hasXparams); guid = uidp.getValue(); } if (guid == null) { /* XXX A guid is required - but are there devices out there without a * guid - and if so how do we handle it? */ return Response.notOk(resp, failed, CalFacadeException.noGuid); } /* See if we have a recurrence id */ BwDateTime ridObj = null; String rid = null; TimeZone ridTz = null; final RecurrenceId ridp = pl.getProperty(Property.RECURRENCE_ID); if (ridp != null) { testXparams(ridp, hasXparams); ridObj = BwDateTime.makeBwDateTime(ridp); if (ridObj.getRange() != null) { /* XXX What do I do with it? */ logger.warn("TRANS-TO_EVENT: Got a recurrence id range"); } rid = ridObj.getDate(); } EventInfo masterEI = null; EventInfo evinfo = null; final BwEvent ev; /* If we have a recurrence id see if we already have the master (we should * get a master + all its overrides). * * If so find the override and use the annnotation or if no override, * make one. * * If no override retrieve the event, add it to our table and then locate the * annotation. * * If there is no annotation, create one. * * It's possible we have been sent 'detached' instances of a recurring * event. This may happen if we are invited to one or more instances of a * meeting. In this case we try to retrieve the master and if it doesn't * exist we manufacture one. We consider such an instance an update to * that instance only and leave the others alone. */ /* We need this in a couple of places */ final DtStart dtStart = pl.getProperty(Property.DTSTART); /* if (rid != null) { // See if we have a new master event. If so create a proxy to that event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI == null) { masterEI = makeNewEvent(cb, chg, entityType, guid, cal); BwEvent e = masterEI.getEvent(); // XXX This seems bogus DtStart mdtStart; String bogusDate = "19980118T230000"; if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + "Z"); } else if (dtStart.getTimeZone() == null) { mdtStart = new DtStart(bogusDate); } else { mdtStart = new DtStart(bogusDate + "Z", dtStart.getTimeZone()); } setDates(e, mdtStart, null, null, chg); e.setRecurring(true); e.addRdate(ridObj); e.setSuppressed(true); ical.addComponent(masterEI); } if (masterEI != null) { evinfo = masterEI.findOverride(rid); } } */ /* If this is a recurrence instance see if we can find the master We only need this because the master may follow the overrides. */ if (rid != null) { // See if we have a new master event. If so create a proxy to this event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI != null) { evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; } } if ((evinfo == null) && (cal != null) && (cal.getCalType() != BwCalendar.calTypeInbox) && (cal.getCalType() != BwCalendar.calTypePendingInbox) && (cal.getCalType() != BwCalendar.calTypeOutbox)) { if (logger.debug()) { logger.debug("TRANS-TO_EVENT: try to fetch event with guid=" + guid); } final GetEntitiesResponse<EventInfo> eisResp = cb.getEvent(colPath, guid); if (eisResp.isError()) { return Response.fromResponse(resp, eisResp); } final var eis = eisResp.getEntities(); if (!Util.isEmpty(eis)) { if (eis.size() > 1) { // DORECUR - wrong again return Response.notOk(resp, failed, "More than one event returned for guid."); } evinfo = eis.iterator().next(); } if (logger.debug()) { if (evinfo != null) { logger.debug("TRANS-TO_EVENT: fetched event with guid"); } else { logger.debug("TRANS-TO_EVENT: did not find event with guid"); } } if (evinfo != null) { if (rid != null) { // We just retrieved it's master masterEI = evinfo; masterEI.setInstanceOnly(true); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; ical.addComponent(masterEI); } else if (methodType == ScheduleMethods.methodTypeCancel) { // This should never have an rid for cancel of entire event. evinfo.setInstanceOnly(evinfo.getEvent().getSuppressed()); } else { // Presumably sent an update for the entire event. No longer suppressed master evinfo.getEvent().setSuppressed(false); } } else if (rid != null) { /* Manufacture a master for the instance */ masterEI = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); final BwEvent e = masterEI.getEvent(); // XXX This seems bogus final DtStart mdtStart; final String bogusDate = "19980118"; final String bogusTime = "T230000"; // Base dtstart on the recurrence id. final boolean isDateType = ridObj.getDateType(); if (isDateType) { mdtStart = new DtStart(new Date(bogusDate)); } else if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + bogusTime + "Z"); } else if (ridObj.getTzid() == null) { mdtStart = new DtStart(bogusDate + bogusTime); } else { mdtStart = new DtStart(bogusDate + bogusTime, Timezones.getTz(ridObj.getTzid())); } IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), masterEI, mdtStart, null, null); e.setRecurring(true); // e.addRdate(ridObj); final var sum = (Summary)pl.getProperty(Property.SUMMARY); e.setSummary(sum.getValue()); e.setSuppressed(true); ical.addComponent(masterEI); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; masterEI.setInstanceOnly(rid != null); } } if (evinfo == null) { evinfo = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); } else if (evinfo.getEvent().getEntityType() != entityType) { return Response.notOk(resp, failed, "org.bedework.mismatched.entity.type: " + val); } final ChangeTable chg = evinfo.getChangeset( cb.getPrincipal().getPrincipalRef()); if (rid != null) { final String evrid = evinfo.getEvent().getRecurrenceId(); if ((evrid == null) || (!evrid.equals(rid))) { logger. warn("Mismatched rid ev=" + evrid + " expected " + rid); chg.changed(PropertyInfoIndex.RECURRENCE_ID, evrid, rid); // XXX spurious??? } if (masterEI.getEvent().getSuppressed()) { masterEI.getEvent().addRdate(ridObj); } } ev = evinfo.getEvent(); ev.setScheduleMethod(methodType); DtEnd dtEnd = null; if (entityType == IcalDefs.entityTypeTodo) { final Due due = pl.getProperty(Property.DUE); if (due != null ) { dtEnd = new DtEnd(due.getParameters(), due.getValue()); } } else { dtEnd = pl.getProperty(Property.DTEND); } final Duration duration = pl.getProperty(Property.DURATION); IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), evinfo, dtStart, dtEnd, duration); for (final Property prop: pl) { testXparams(prop, hasXparams); //debug("ical prop " + prop.getClass().getName()); String pval = prop.getValue(); if ((pval != null) && (pval.length() == 0)) { pval = null; } final PropertyInfoIndex pi; if (prop instanceof XProperty) { pi = PropertyInfoIndex.XPROP; } else { pi = PropertyInfoIndex.fromName(prop.getName()); } if (pi == null) { logger.debug("Unknown property with name " + prop.getName() + " class " + prop.getClass() + " and value " + pval); continue; } chg.present(pi); switch (pi) { case ACCEPT_RESPONSE: /* ------------------- Accept Response -------------------- */ String sval = prop.getValue(); if (chg.changed(pi, ev.getPollAcceptResponse(), sval)) { ev.setPollAcceptResponse(sval); } break; case ATTACH: /* ------------------- Attachment -------------------- */ chg.addValue(pi, IcalUtil.getAttachment((Attach)prop)); break; case ATTENDEE: /* ------------------- Attendee -------------------- */ if (methodType == ScheduleMethods.methodTypePublish) { if (cb.getStrictness() == IcalCallback.conformanceStrict) { return Response.notOk(resp, failed, CalFacadeException.attendeesInPublish); } //if (cb.getStrictness() == IcalCallback.conformanceWarn) { // warn("Had attendees for PUBLISH"); //} } final Attendee attPr = (Attendee)prop; if (evinfo.getNewEvent() || !mergeAttendees) { chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { final String pUri = cb.getCaladdr(attPr.getValue()); if (pUri.equals(attUri)) { /* Only update for our own attendee * We're doing a PUT and this must be the attendee updating their * partstat. We don't allow them to change other attendees * whatever the PUT content says. */ chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { // Use the value we currently have boolean found = false; for (final BwAttendee att: ev.getAttendees()) { if (pUri.equals(att.getAttendeeUri())) { chg.addValue(pi, att.clone()); found = true; break; } } if (!found) { // An added attendee final BwAttendee att = IcalUtil .getAttendee(cb, attPr); att.setPartstat(IcalDefs.partstatValNeedsAction); chg.addValue(pi, att); } } } break; case BUSYTYPE: final int ibt = BwEvent.fromBusyTypeString(pval); if (chg.changed(pi, ev.getBusyType(), ibt)) { ev.setBusyType(ibt); } break; case CATEGORIES: /* ------------------- Categories -------------------- */ final Categories cats = (Categories)prop; final TextList cl = cats.getCategories(); String lang = IcalUtil.getLang(cats); if (cl != null) { /* Got some categories */ for (final String wd: cl) { if (wd == null) { continue; } final BwString key = new BwString(lang, wd); final var fcResp = cb.findCategory(key); final BwCategory cat; if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isNotFound()) { cat = BwCategory.makeCategory(); cat.setWord(key); cb.addCategory(cat); } else { cat = fcResp.getEntity(); } chg.addValue(pi, cat); } } break; case CLASS: /* ------------------- Class -------------------- */ if (chg.changed(pi, ev.getClassification(), pval)) { ev.setClassification(pval); } break; case COMMENT: /* ------------------- Comment -------------------- */ chg.addValue(pi, new BwString(null, pval)); break; case COMPLETED: /* ------------------- Completed -------------------- */ if (chg.changed(pi, ev.getCompleted(), pval)) { ev.setCompleted(pval); } break; case CONCEPT: /* ------------------- Concept -------------------- */ final Concept c = (Concept)prop; final String cval = c.getValue(); if (cval != null) { /* Got a concept */ chg.addValue(PropertyInfoIndex.XPROP, BwXproperty.makeIcalProperty("CONCEPT", null, cval)); } break; case CONTACT: /* ------------------- Contact -------------------- */ final String altrep = getAltRepPar(prop); lang = IcalUtil.getLang(prop); final String uid = getUidPar(prop); final BwString nm = new BwString(lang, pval); BwContact contact = null; if (uid != null) { final var fcResp = cb.getContact(uid); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { final var fcResp = cb.findContact(nm); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { contact = BwContact.makeContact(); contact.setCn(nm); contact.setLink(altrep); cb.addContact(contact); } else { contact.setCn(nm); contact.setLink(altrep); } chg.addValue(pi, contact); break; case CREATED: /* ------------------- Created -------------------- */ if (chg.changed(pi, ev.getCreated(), pval)) { ev.setCreated(pval); } break; case DESCRIPTION: /* ------------------- Description -------------------- */ if (chg.changed(pi, ev.getDescription(), pval)) { ev.setDescription(pval); } break; case DTEND: /* ------------------- DtEnd -------------------- */ break; case DTSTAMP: /* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval); break; case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE: /* -------------------- Due ------------------------ */ break; case DURATION: /* ------------------- Duration -------------------- */ break; case EXDATE: /* ------------------- ExDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case EXRULE: /* ------------------- ExRule -------------------- */ chg.addValue(pi, pval); break; case FREEBUSY: /* ------------------- freebusy -------------------- */ final FreeBusy fbusy = (FreeBusy)prop; final PeriodList perpl = fbusy.getPeriods(); final Parameter par = IcalUtil.getParameter(fbusy, "FBTYPE"); final int fbtype; if (par == null) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY)) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY_TENTATIVE)) { fbtype = BwFreeBusyComponent.typeBusyTentative; } else if (par.equals(FbType.BUSY_UNAVAILABLE)) { fbtype = BwFreeBusyComponent.typeBusyUnavailable; } else if (par.equals(FbType.FREE)) { fbtype = BwFreeBusyComponent.typeFree; } else { if (logger.debug()) { logger.debug("Unsupported parameter " + par.getName()); } return Response.notOk(resp, failed, "Unsupported parameter " + par.getName()); } final BwFreeBusyComponent fbc = new BwFreeBusyComponent(); fbc.setType(fbtype); for (final Period per : perpl) { fbc.addPeriod(per); } ev.addFreeBusyPeriod(fbc); break; case GEO: /* ------------------- Geo -------------------- */ final Geo g = (Geo)prop; final BwGeo geo = new BwGeo(g.getLatitude(), g.getLongitude()); if (chg.changed(pi, ev.getGeo(), geo)) { ev.setGeo(geo); } break; case LAST_MODIFIED: /* ------------------- LastModified -------------------- */ if (chg.changed(pi, ev.getLastmod(), pval)) { ev.setLastmod(pval); } break; case LOCATION: /* ------------------- Location -------------------- */ BwLocation loc = null; //String uid = getUidPar(prop); /* At the moment Mozilla lightning is broken and this leads to all * sorts of problems. if (uid != null) { loc = cb.getLocation(uid); } */ lang = IcalUtil.getLang(prop); BwString addr = null; if (pval != null) { if (loc == null) { addr = new BwString(lang, pval); final var fcResp = cb.findLocation(addr); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { loc = fcResp.getEntity(); } } if (loc == null) { loc = BwLocation.makeLocation(); loc.setAddress(addr); cb.addLocation(loc); } } final BwLocation evloc = ev.getLocation(); if (chg.changed(pi, evloc, loc)) { // CHGTBL - this only shows that it's a different location object ev.setLocation(loc); } else if ((loc != null) && (evloc != null)) { // See if the value is changed final String evval = evloc.getAddress().getValue(); final String inval = loc.getAddress().getValue(); if (!evval.equals(inval)) { chg.changed(pi, evval, inval); evloc.getAddress().setValue(inval); } } break; case ORGANIZER: /* ------------------- Organizer -------------------- */ final BwOrganizer org = IcalUtil.getOrganizer(cb, (Organizer)prop); final BwOrganizer evorg = ev.getOrganizer(); final BwOrganizer evorgCopy; if (evorg == null) { evorgCopy = null; } else { evorgCopy = (BwOrganizer)evorg.clone(); } if (chg.changed(pi, evorgCopy, org)) { if (evorg == null) { ev.setOrganizer(org); } else { evorg.update(org); } } break; case PERCENT_COMPLETE: /* ------------------- PercentComplete -------------------- */ Integer ival = ((PercentComplete)prop).getPercentage(); if (chg.changed(pi, ev.getPercentComplete(), ival)) { ev.setPercentComplete(ival); } break; case POLL_MODE: /* ------------------- Poll mode -------------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollMode(), sval)) { ev.setPollMode(sval); } break; case POLL_PROPERTIES: /* ------------------- Poll properties ---------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollProperties(), sval)) { ev.setPollProperties(sval); } break; case POLL_WINNER: /* ------------------- Poll winner -------------------- */ ival = ((PollWinner)prop).getPollwinner(); if (chg.changed(pi, ev.getPollWinner(), ival)) { ev.setPollWinner(ival); } break; case PRIORITY: /* ------------------- Priority -------------------- */ ival = ((Priority)prop).getLevel(); if (chg.changed(pi, ev.getPriority(), ival)) { ev.setPriority(ival); } break; case RDATE: /* ------------------- RDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case RECURRENCE_ID: /* ------------------- RecurrenceID -------------------- */ // Done above break; case RELATED_TO: /* ------------------- RelatedTo -------------------- */ final RelatedTo irelto = (RelatedTo)prop; final BwRelatedTo relto = new BwRelatedTo(); final String parval = IcalUtil.getParameterVal(irelto, "RELTYPE"); if (parval != null) { relto.setRelType(parval); } relto.setValue(irelto.getValue()); if (chg.changed(pi, ev.getRelatedTo(), relto)) { ev.setRelatedTo(relto); } break; case REQUEST_STATUS: /* ------------------- RequestStatus -------------------- */ final BwRequestStatus rs = BwRequestStatus .fromRequestStatus((RequestStatus)prop); chg.addValue(pi, rs); break; case RESOURCES: /* ------------------- Resources -------------------- */ final TextList rl = ((Resources)prop).getResources(); if (rl != null) { /* Got some resources */ lang = IcalUtil.getLang(prop); for (final String s: rl) { final BwString rsrc = new BwString(lang, s); chg.addValue(pi, rsrc); } } break; case RRULE: /* ------------------- RRule -------------------- */ chg.addValue(pi, pval); break; case SEQUENCE: /* ------------------- Sequence -------------------- */ final int seq = ((Sequence)prop).getSequenceNo(); if (seq != ev.getSequence()) { chg.changed(pi, ev.getSequence(), seq); ev.setSequence(seq); } break; case STATUS: /* ------------------- Status -------------------- */ if (chg.changed(pi, ev.getStatus(), pval)) { ev.setStatus(pval); } break; case SUMMARY: /* ------------------- Summary -------------------- */ if (chg.changed(pi, ev.getSummary(), pval)) { ev.setSummary(pval); } break; case TRANSP: /* ------------------- Transp -------------------- */ if (chg.changed(pi, ev.getPeruserTransparency( cb.getPrincipal() .getPrincipalRef()), pval)) { final BwXproperty pu = ev.setPeruserTransparency( cb.getPrincipal().getPrincipalRef(), pval); if (pu != null) { chg.addValue(PropertyInfoIndex.XPROP, pu); } } break; case UID: /* ------------------- Uid -------------------- */ /* We did this above */ break; case URL: /* ------------------- Url -------------------- */ if (chg.changed(pi, ev.getLink(), pval)) { ev.setLink(pval); } break; case XPROP: /* ------------------------- x-property --------------------------- */ final String name = prop.getName(); if (name.equalsIgnoreCase(BwXproperty.bedeworkCost)) { if (chg.changed(PropertyInfoIndex.COST, ev.getCost(), pval)) { ev.setCost(pval); } break; } if (name.equalsIgnoreCase(BwXproperty.xBedeworkCategories)) { if (checkCategory(cb, chg, ev, null, pval)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkLocation)) { if (checkLocation(cb, chg, ev, prop)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkContact)) { if (checkContact(cb, chg, ev, null, pval)) { break; } } /* See if this is an x-category that can be converted to a real category */ final XProperty xp = (XProperty)prop; chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(name, xp.getParameters() .toString(), pval)); break; default: if (logger.debug()) { logger.debug("Unsupported property with index " + pi + "; class " + prop.getClass() + " and value " + pval); } } } /* =================== Process sub-components =============== */ final ComponentList<Component> subComps; if (val instanceof ComponentContainer) { subComps = ((ComponentContainer<Component>)val).getComponents(); } else { subComps = null; } final Set<Integer> pids; if (vpoll) { pids = new TreeSet<>(); final BwEvent vp = evinfo.getEvent(); if (!Util.isEmpty(vp.getPollItems())) { vp.clearPollItems(); } } else { pids = null; } if (!Util.isEmpty(subComps)) { for (final var subComp: subComps) { if (subComp instanceof Available) { if (!(val instanceof VAvailability)) { return Response.error(resp, "AVAILABLE only valid in VAVAILABLE"); } final var avlResp = processAvailable(cb, cal, ical, (VAvailability)val, (Available)subComp, evinfo); if (!avlResp.isOk()) { return Response.fromResponse(resp, avlResp); } continue; } if (subComp instanceof Participant) { if (vpoll) { final var vresp = processVoter(cb, (VPoll)val, (Participant)subComp, evinfo, chg, mergeAttendees); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Participant object"); continue; } if (subComp instanceof VResource) { logger.warn("Unimplemented VResource object"); continue; } if (subComp instanceof VLocation) { logger.warn("Unimplemented VLocation object"); continue; } if (subComp instanceof VAlarm) { final var aresp = VAlarmUtil.processAlarm(cb, val, (VAlarm)subComp, ev, currentPrincipal, chg); if (!aresp.isOk()) { return Response.fromResponse(resp, aresp); } continue; } if (vpoll && (event || task)) { final var vresp = processCandidate((VPoll)val, subComp, evinfo, pids, chg); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Component object: " + subComp); } } /* Fix up timestamps. */ if (ev.getCreated() == null) { if (ev.getLastmod() != null) { ev.setCreated(ev.getLastmod()); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); } else { ev.updateDtstamp(); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } } if (ev.getLastmod() == null) { // created cannot be null now ev.setLastmod(ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } processTimezones(ev, ical, chg); /* Remove any recipients and originator */ if (ev.getRecipients() != null) { ev.getRecipients().clear(); } ev.setOriginator(null); if (hasXparams.value) { /* Save a text copy of the entire event as an x-property */ final Component valCopy = val.copy(); /* Remove potentially large values */ final Description desp = valCopy.getProperty(Property.DESCRIPTION); if (desp != null) { desp.setValue(null); } final Attach attachp = valCopy.getProperty(Property.ATTACH); // Don't store the entire attachment - we just need the parameters. if (attachp != null) { final Value v = attachp.getParameter(Parameter.VALUE); if (v != null) { attachp.setValue(String.valueOf(attachp.getValue().hashCode())); } } chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(BwXproperty.bedeworkIcal, null, valCopy.toString())); } chg.processChanges(ev, true, false); ev.setRecurring(ev.isRecurringEntity()); if (logger.debug()) { logger.debug(chg.toString()); logger.debug(ev.toString()); } if (masterEI != null) { // Just return notfound as this event is on its override list return Response.notFound(resp); } resp.setEntity(evinfo); return resp; } catch (final Throwable t) { if (logger.debug()) { logger.error(t); } return Response.error(resp, t); } }
NONSATD
true
break; case ORGANIZER: /* ------------------- Organizer -------------------- */ final BwOrganizer org = IcalUtil.getOrganizer(cb, (Organizer)prop); final BwOrganizer evorg = ev.getOrganizer();
// See if the value is changed final String evval = evloc.getAddress().getValue(); final String inval = loc.getAddress().getValue(); if (!evval.equals(inval)) { chg.changed(pi, evval, inval); evloc.getAddress().setValue(inval); } } break; case ORGANIZER: /* ------------------- Organizer -------------------- */ final BwOrganizer org = IcalUtil.getOrganizer(cb, (Organizer)prop); final BwOrganizer evorg = ev.getOrganizer(); final BwOrganizer evorgCopy; if (evorg == null) { evorgCopy = null; } else { evorgCopy = (BwOrganizer)evorg.clone(); } if (chg.changed(pi, evorgCopy, org)) { if (evorg == null) {
loc = BwLocation.makeLocation(); loc.setAddress(addr); cb.addLocation(loc); } } final BwLocation evloc = ev.getLocation(); if (chg.changed(pi, evloc, loc)) { // CHGTBL - this only shows that it's a different location object ev.setLocation(loc); } else if ((loc != null) && (evloc != null)) { // See if the value is changed final String evval = evloc.getAddress().getValue(); final String inval = loc.getAddress().getValue(); if (!evval.equals(inval)) { chg.changed(pi, evval, inval); evloc.getAddress().setValue(inval); } } break; case ORGANIZER: /* ------------------- Organizer -------------------- */ final BwOrganizer org = IcalUtil.getOrganizer(cb, (Organizer)prop); final BwOrganizer evorg = ev.getOrganizer(); final BwOrganizer evorgCopy; if (evorg == null) { evorgCopy = null; } else { evorgCopy = (BwOrganizer)evorg.clone(); } if (chg.changed(pi, evorgCopy, org)) { if (evorg == null) { ev.setOrganizer(org); } else { evorg.update(org); } } break; case PERCENT_COMPLETE: /* ------------------- PercentComplete -------------------- */ Integer ival = ((PercentComplete)prop).getPercentage(); if (chg.changed(pi, ev.getPercentComplete(), ival)) {
7,893
54
/* ------------------- PercentComplete -------------------- */
public static GetEntityResponse<EventInfo> toEvent( final IcalCallback cb, final BwCalendar cal, final Icalendar ical, final Component val, final boolean mergeAttendees) { final var resp = new GetEntityResponse<EventInfo>(); if (val == null) { return Response.notOk(resp, failed, "No component supplied"); } String currentPrincipal = null; final BwPrincipal principal = cb.getPrincipal(); if (principal != null) { currentPrincipal = principal.getPrincipalRef(); } final Holder<Boolean> hasXparams = new Holder<>(Boolean.FALSE); final int methodType = ical.getMethodType(); String attUri = null; if (mergeAttendees) { // We'll need this later. attUri = cb.getCaladdr(cb.getPrincipal().getPrincipalRef()); } final String colPath; if (cal == null) { colPath = null; } else { colPath = cal.getPath(); } try { final PropertyList<Property> pl = val.getProperties(); boolean vpoll = false; boolean event = false; boolean task = false; if (pl == null) { // Empty component return Response.notOk(resp, failed, "Empty component"); } final int entityType; if (val instanceof VEvent) { entityType = IcalDefs.entityTypeEvent; event = true; } else if (val instanceof VToDo) { entityType = IcalDefs.entityTypeTodo; task = true; } else if (val instanceof VJournal) { entityType = IcalDefs.entityTypeJournal; } else if (val instanceof VFreeBusy) { entityType = IcalDefs.entityTypeFreeAndBusy; } else if (val instanceof VAvailability) { entityType = IcalDefs.entityTypeVavailability; } else if (val instanceof Available) { entityType = IcalDefs.entityTypeAvailable; } else if (val instanceof VPoll) { entityType = IcalDefs.entityTypeVpoll; vpoll = true; } else { return Response.error(resp, "org.bedework.invalid.component.type: " + val.getName()); } // Get the guid from the component String guid = null; final Uid uidp = pl.getProperty(Property.UID); if (uidp != null) { testXparams(uidp, hasXparams); guid = uidp.getValue(); } if (guid == null) { /* XXX A guid is required - but are there devices out there without a * guid - and if so how do we handle it? */ return Response.notOk(resp, failed, CalFacadeException.noGuid); } /* See if we have a recurrence id */ BwDateTime ridObj = null; String rid = null; TimeZone ridTz = null; final RecurrenceId ridp = pl.getProperty(Property.RECURRENCE_ID); if (ridp != null) { testXparams(ridp, hasXparams); ridObj = BwDateTime.makeBwDateTime(ridp); if (ridObj.getRange() != null) { /* XXX What do I do with it? */ logger.warn("TRANS-TO_EVENT: Got a recurrence id range"); } rid = ridObj.getDate(); } EventInfo masterEI = null; EventInfo evinfo = null; final BwEvent ev; /* If we have a recurrence id see if we already have the master (we should * get a master + all its overrides). * * If so find the override and use the annnotation or if no override, * make one. * * If no override retrieve the event, add it to our table and then locate the * annotation. * * If there is no annotation, create one. * * It's possible we have been sent 'detached' instances of a recurring * event. This may happen if we are invited to one or more instances of a * meeting. In this case we try to retrieve the master and if it doesn't * exist we manufacture one. We consider such an instance an update to * that instance only and leave the others alone. */ /* We need this in a couple of places */ final DtStart dtStart = pl.getProperty(Property.DTSTART); /* if (rid != null) { // See if we have a new master event. If so create a proxy to that event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI == null) { masterEI = makeNewEvent(cb, chg, entityType, guid, cal); BwEvent e = masterEI.getEvent(); // XXX This seems bogus DtStart mdtStart; String bogusDate = "19980118T230000"; if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + "Z"); } else if (dtStart.getTimeZone() == null) { mdtStart = new DtStart(bogusDate); } else { mdtStart = new DtStart(bogusDate + "Z", dtStart.getTimeZone()); } setDates(e, mdtStart, null, null, chg); e.setRecurring(true); e.addRdate(ridObj); e.setSuppressed(true); ical.addComponent(masterEI); } if (masterEI != null) { evinfo = masterEI.findOverride(rid); } } */ /* If this is a recurrence instance see if we can find the master We only need this because the master may follow the overrides. */ if (rid != null) { // See if we have a new master event. If so create a proxy to this event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI != null) { evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; } } if ((evinfo == null) && (cal != null) && (cal.getCalType() != BwCalendar.calTypeInbox) && (cal.getCalType() != BwCalendar.calTypePendingInbox) && (cal.getCalType() != BwCalendar.calTypeOutbox)) { if (logger.debug()) { logger.debug("TRANS-TO_EVENT: try to fetch event with guid=" + guid); } final GetEntitiesResponse<EventInfo> eisResp = cb.getEvent(colPath, guid); if (eisResp.isError()) { return Response.fromResponse(resp, eisResp); } final var eis = eisResp.getEntities(); if (!Util.isEmpty(eis)) { if (eis.size() > 1) { // DORECUR - wrong again return Response.notOk(resp, failed, "More than one event returned for guid."); } evinfo = eis.iterator().next(); } if (logger.debug()) { if (evinfo != null) { logger.debug("TRANS-TO_EVENT: fetched event with guid"); } else { logger.debug("TRANS-TO_EVENT: did not find event with guid"); } } if (evinfo != null) { if (rid != null) { // We just retrieved it's master masterEI = evinfo; masterEI.setInstanceOnly(true); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; ical.addComponent(masterEI); } else if (methodType == ScheduleMethods.methodTypeCancel) { // This should never have an rid for cancel of entire event. evinfo.setInstanceOnly(evinfo.getEvent().getSuppressed()); } else { // Presumably sent an update for the entire event. No longer suppressed master evinfo.getEvent().setSuppressed(false); } } else if (rid != null) { /* Manufacture a master for the instance */ masterEI = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); final BwEvent e = masterEI.getEvent(); // XXX This seems bogus final DtStart mdtStart; final String bogusDate = "19980118"; final String bogusTime = "T230000"; // Base dtstart on the recurrence id. final boolean isDateType = ridObj.getDateType(); if (isDateType) { mdtStart = new DtStart(new Date(bogusDate)); } else if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + bogusTime + "Z"); } else if (ridObj.getTzid() == null) { mdtStart = new DtStart(bogusDate + bogusTime); } else { mdtStart = new DtStart(bogusDate + bogusTime, Timezones.getTz(ridObj.getTzid())); } IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), masterEI, mdtStart, null, null); e.setRecurring(true); // e.addRdate(ridObj); final var sum = (Summary)pl.getProperty(Property.SUMMARY); e.setSummary(sum.getValue()); e.setSuppressed(true); ical.addComponent(masterEI); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; masterEI.setInstanceOnly(rid != null); } } if (evinfo == null) { evinfo = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); } else if (evinfo.getEvent().getEntityType() != entityType) { return Response.notOk(resp, failed, "org.bedework.mismatched.entity.type: " + val); } final ChangeTable chg = evinfo.getChangeset( cb.getPrincipal().getPrincipalRef()); if (rid != null) { final String evrid = evinfo.getEvent().getRecurrenceId(); if ((evrid == null) || (!evrid.equals(rid))) { logger. warn("Mismatched rid ev=" + evrid + " expected " + rid); chg.changed(PropertyInfoIndex.RECURRENCE_ID, evrid, rid); // XXX spurious??? } if (masterEI.getEvent().getSuppressed()) { masterEI.getEvent().addRdate(ridObj); } } ev = evinfo.getEvent(); ev.setScheduleMethod(methodType); DtEnd dtEnd = null; if (entityType == IcalDefs.entityTypeTodo) { final Due due = pl.getProperty(Property.DUE); if (due != null ) { dtEnd = new DtEnd(due.getParameters(), due.getValue()); } } else { dtEnd = pl.getProperty(Property.DTEND); } final Duration duration = pl.getProperty(Property.DURATION); IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), evinfo, dtStart, dtEnd, duration); for (final Property prop: pl) { testXparams(prop, hasXparams); //debug("ical prop " + prop.getClass().getName()); String pval = prop.getValue(); if ((pval != null) && (pval.length() == 0)) { pval = null; } final PropertyInfoIndex pi; if (prop instanceof XProperty) { pi = PropertyInfoIndex.XPROP; } else { pi = PropertyInfoIndex.fromName(prop.getName()); } if (pi == null) { logger.debug("Unknown property with name " + prop.getName() + " class " + prop.getClass() + " and value " + pval); continue; } chg.present(pi); switch (pi) { case ACCEPT_RESPONSE: /* ------------------- Accept Response -------------------- */ String sval = prop.getValue(); if (chg.changed(pi, ev.getPollAcceptResponse(), sval)) { ev.setPollAcceptResponse(sval); } break; case ATTACH: /* ------------------- Attachment -------------------- */ chg.addValue(pi, IcalUtil.getAttachment((Attach)prop)); break; case ATTENDEE: /* ------------------- Attendee -------------------- */ if (methodType == ScheduleMethods.methodTypePublish) { if (cb.getStrictness() == IcalCallback.conformanceStrict) { return Response.notOk(resp, failed, CalFacadeException.attendeesInPublish); } //if (cb.getStrictness() == IcalCallback.conformanceWarn) { // warn("Had attendees for PUBLISH"); //} } final Attendee attPr = (Attendee)prop; if (evinfo.getNewEvent() || !mergeAttendees) { chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { final String pUri = cb.getCaladdr(attPr.getValue()); if (pUri.equals(attUri)) { /* Only update for our own attendee * We're doing a PUT and this must be the attendee updating their * partstat. We don't allow them to change other attendees * whatever the PUT content says. */ chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { // Use the value we currently have boolean found = false; for (final BwAttendee att: ev.getAttendees()) { if (pUri.equals(att.getAttendeeUri())) { chg.addValue(pi, att.clone()); found = true; break; } } if (!found) { // An added attendee final BwAttendee att = IcalUtil .getAttendee(cb, attPr); att.setPartstat(IcalDefs.partstatValNeedsAction); chg.addValue(pi, att); } } } break; case BUSYTYPE: final int ibt = BwEvent.fromBusyTypeString(pval); if (chg.changed(pi, ev.getBusyType(), ibt)) { ev.setBusyType(ibt); } break; case CATEGORIES: /* ------------------- Categories -------------------- */ final Categories cats = (Categories)prop; final TextList cl = cats.getCategories(); String lang = IcalUtil.getLang(cats); if (cl != null) { /* Got some categories */ for (final String wd: cl) { if (wd == null) { continue; } final BwString key = new BwString(lang, wd); final var fcResp = cb.findCategory(key); final BwCategory cat; if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isNotFound()) { cat = BwCategory.makeCategory(); cat.setWord(key); cb.addCategory(cat); } else { cat = fcResp.getEntity(); } chg.addValue(pi, cat); } } break; case CLASS: /* ------------------- Class -------------------- */ if (chg.changed(pi, ev.getClassification(), pval)) { ev.setClassification(pval); } break; case COMMENT: /* ------------------- Comment -------------------- */ chg.addValue(pi, new BwString(null, pval)); break; case COMPLETED: /* ------------------- Completed -------------------- */ if (chg.changed(pi, ev.getCompleted(), pval)) { ev.setCompleted(pval); } break; case CONCEPT: /* ------------------- Concept -------------------- */ final Concept c = (Concept)prop; final String cval = c.getValue(); if (cval != null) { /* Got a concept */ chg.addValue(PropertyInfoIndex.XPROP, BwXproperty.makeIcalProperty("CONCEPT", null, cval)); } break; case CONTACT: /* ------------------- Contact -------------------- */ final String altrep = getAltRepPar(prop); lang = IcalUtil.getLang(prop); final String uid = getUidPar(prop); final BwString nm = new BwString(lang, pval); BwContact contact = null; if (uid != null) { final var fcResp = cb.getContact(uid); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { final var fcResp = cb.findContact(nm); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { contact = BwContact.makeContact(); contact.setCn(nm); contact.setLink(altrep); cb.addContact(contact); } else { contact.setCn(nm); contact.setLink(altrep); } chg.addValue(pi, contact); break; case CREATED: /* ------------------- Created -------------------- */ if (chg.changed(pi, ev.getCreated(), pval)) { ev.setCreated(pval); } break; case DESCRIPTION: /* ------------------- Description -------------------- */ if (chg.changed(pi, ev.getDescription(), pval)) { ev.setDescription(pval); } break; case DTEND: /* ------------------- DtEnd -------------------- */ break; case DTSTAMP: /* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval); break; case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE: /* -------------------- Due ------------------------ */ break; case DURATION: /* ------------------- Duration -------------------- */ break; case EXDATE: /* ------------------- ExDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case EXRULE: /* ------------------- ExRule -------------------- */ chg.addValue(pi, pval); break; case FREEBUSY: /* ------------------- freebusy -------------------- */ final FreeBusy fbusy = (FreeBusy)prop; final PeriodList perpl = fbusy.getPeriods(); final Parameter par = IcalUtil.getParameter(fbusy, "FBTYPE"); final int fbtype; if (par == null) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY)) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY_TENTATIVE)) { fbtype = BwFreeBusyComponent.typeBusyTentative; } else if (par.equals(FbType.BUSY_UNAVAILABLE)) { fbtype = BwFreeBusyComponent.typeBusyUnavailable; } else if (par.equals(FbType.FREE)) { fbtype = BwFreeBusyComponent.typeFree; } else { if (logger.debug()) { logger.debug("Unsupported parameter " + par.getName()); } return Response.notOk(resp, failed, "Unsupported parameter " + par.getName()); } final BwFreeBusyComponent fbc = new BwFreeBusyComponent(); fbc.setType(fbtype); for (final Period per : perpl) { fbc.addPeriod(per); } ev.addFreeBusyPeriod(fbc); break; case GEO: /* ------------------- Geo -------------------- */ final Geo g = (Geo)prop; final BwGeo geo = new BwGeo(g.getLatitude(), g.getLongitude()); if (chg.changed(pi, ev.getGeo(), geo)) { ev.setGeo(geo); } break; case LAST_MODIFIED: /* ------------------- LastModified -------------------- */ if (chg.changed(pi, ev.getLastmod(), pval)) { ev.setLastmod(pval); } break; case LOCATION: /* ------------------- Location -------------------- */ BwLocation loc = null; //String uid = getUidPar(prop); /* At the moment Mozilla lightning is broken and this leads to all * sorts of problems. if (uid != null) { loc = cb.getLocation(uid); } */ lang = IcalUtil.getLang(prop); BwString addr = null; if (pval != null) { if (loc == null) { addr = new BwString(lang, pval); final var fcResp = cb.findLocation(addr); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { loc = fcResp.getEntity(); } } if (loc == null) { loc = BwLocation.makeLocation(); loc.setAddress(addr); cb.addLocation(loc); } } final BwLocation evloc = ev.getLocation(); if (chg.changed(pi, evloc, loc)) { // CHGTBL - this only shows that it's a different location object ev.setLocation(loc); } else if ((loc != null) && (evloc != null)) { // See if the value is changed final String evval = evloc.getAddress().getValue(); final String inval = loc.getAddress().getValue(); if (!evval.equals(inval)) { chg.changed(pi, evval, inval); evloc.getAddress().setValue(inval); } } break; case ORGANIZER: /* ------------------- Organizer -------------------- */ final BwOrganizer org = IcalUtil.getOrganizer(cb, (Organizer)prop); final BwOrganizer evorg = ev.getOrganizer(); final BwOrganizer evorgCopy; if (evorg == null) { evorgCopy = null; } else { evorgCopy = (BwOrganizer)evorg.clone(); } if (chg.changed(pi, evorgCopy, org)) { if (evorg == null) { ev.setOrganizer(org); } else { evorg.update(org); } } break; case PERCENT_COMPLETE: /* ------------------- PercentComplete -------------------- */ Integer ival = ((PercentComplete)prop).getPercentage(); if (chg.changed(pi, ev.getPercentComplete(), ival)) { ev.setPercentComplete(ival); } break; case POLL_MODE: /* ------------------- Poll mode -------------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollMode(), sval)) { ev.setPollMode(sval); } break; case POLL_PROPERTIES: /* ------------------- Poll properties ---------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollProperties(), sval)) { ev.setPollProperties(sval); } break; case POLL_WINNER: /* ------------------- Poll winner -------------------- */ ival = ((PollWinner)prop).getPollwinner(); if (chg.changed(pi, ev.getPollWinner(), ival)) { ev.setPollWinner(ival); } break; case PRIORITY: /* ------------------- Priority -------------------- */ ival = ((Priority)prop).getLevel(); if (chg.changed(pi, ev.getPriority(), ival)) { ev.setPriority(ival); } break; case RDATE: /* ------------------- RDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case RECURRENCE_ID: /* ------------------- RecurrenceID -------------------- */ // Done above break; case RELATED_TO: /* ------------------- RelatedTo -------------------- */ final RelatedTo irelto = (RelatedTo)prop; final BwRelatedTo relto = new BwRelatedTo(); final String parval = IcalUtil.getParameterVal(irelto, "RELTYPE"); if (parval != null) { relto.setRelType(parval); } relto.setValue(irelto.getValue()); if (chg.changed(pi, ev.getRelatedTo(), relto)) { ev.setRelatedTo(relto); } break; case REQUEST_STATUS: /* ------------------- RequestStatus -------------------- */ final BwRequestStatus rs = BwRequestStatus .fromRequestStatus((RequestStatus)prop); chg.addValue(pi, rs); break; case RESOURCES: /* ------------------- Resources -------------------- */ final TextList rl = ((Resources)prop).getResources(); if (rl != null) { /* Got some resources */ lang = IcalUtil.getLang(prop); for (final String s: rl) { final BwString rsrc = new BwString(lang, s); chg.addValue(pi, rsrc); } } break; case RRULE: /* ------------------- RRule -------------------- */ chg.addValue(pi, pval); break; case SEQUENCE: /* ------------------- Sequence -------------------- */ final int seq = ((Sequence)prop).getSequenceNo(); if (seq != ev.getSequence()) { chg.changed(pi, ev.getSequence(), seq); ev.setSequence(seq); } break; case STATUS: /* ------------------- Status -------------------- */ if (chg.changed(pi, ev.getStatus(), pval)) { ev.setStatus(pval); } break; case SUMMARY: /* ------------------- Summary -------------------- */ if (chg.changed(pi, ev.getSummary(), pval)) { ev.setSummary(pval); } break; case TRANSP: /* ------------------- Transp -------------------- */ if (chg.changed(pi, ev.getPeruserTransparency( cb.getPrincipal() .getPrincipalRef()), pval)) { final BwXproperty pu = ev.setPeruserTransparency( cb.getPrincipal().getPrincipalRef(), pval); if (pu != null) { chg.addValue(PropertyInfoIndex.XPROP, pu); } } break; case UID: /* ------------------- Uid -------------------- */ /* We did this above */ break; case URL: /* ------------------- Url -------------------- */ if (chg.changed(pi, ev.getLink(), pval)) { ev.setLink(pval); } break; case XPROP: /* ------------------------- x-property --------------------------- */ final String name = prop.getName(); if (name.equalsIgnoreCase(BwXproperty.bedeworkCost)) { if (chg.changed(PropertyInfoIndex.COST, ev.getCost(), pval)) { ev.setCost(pval); } break; } if (name.equalsIgnoreCase(BwXproperty.xBedeworkCategories)) { if (checkCategory(cb, chg, ev, null, pval)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkLocation)) { if (checkLocation(cb, chg, ev, prop)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkContact)) { if (checkContact(cb, chg, ev, null, pval)) { break; } } /* See if this is an x-category that can be converted to a real category */ final XProperty xp = (XProperty)prop; chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(name, xp.getParameters() .toString(), pval)); break; default: if (logger.debug()) { logger.debug("Unsupported property with index " + pi + "; class " + prop.getClass() + " and value " + pval); } } } /* =================== Process sub-components =============== */ final ComponentList<Component> subComps; if (val instanceof ComponentContainer) { subComps = ((ComponentContainer<Component>)val).getComponents(); } else { subComps = null; } final Set<Integer> pids; if (vpoll) { pids = new TreeSet<>(); final BwEvent vp = evinfo.getEvent(); if (!Util.isEmpty(vp.getPollItems())) { vp.clearPollItems(); } } else { pids = null; } if (!Util.isEmpty(subComps)) { for (final var subComp: subComps) { if (subComp instanceof Available) { if (!(val instanceof VAvailability)) { return Response.error(resp, "AVAILABLE only valid in VAVAILABLE"); } final var avlResp = processAvailable(cb, cal, ical, (VAvailability)val, (Available)subComp, evinfo); if (!avlResp.isOk()) { return Response.fromResponse(resp, avlResp); } continue; } if (subComp instanceof Participant) { if (vpoll) { final var vresp = processVoter(cb, (VPoll)val, (Participant)subComp, evinfo, chg, mergeAttendees); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Participant object"); continue; } if (subComp instanceof VResource) { logger.warn("Unimplemented VResource object"); continue; } if (subComp instanceof VLocation) { logger.warn("Unimplemented VLocation object"); continue; } if (subComp instanceof VAlarm) { final var aresp = VAlarmUtil.processAlarm(cb, val, (VAlarm)subComp, ev, currentPrincipal, chg); if (!aresp.isOk()) { return Response.fromResponse(resp, aresp); } continue; } if (vpoll && (event || task)) { final var vresp = processCandidate((VPoll)val, subComp, evinfo, pids, chg); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Component object: " + subComp); } } /* Fix up timestamps. */ if (ev.getCreated() == null) { if (ev.getLastmod() != null) { ev.setCreated(ev.getLastmod()); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); } else { ev.updateDtstamp(); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } } if (ev.getLastmod() == null) { // created cannot be null now ev.setLastmod(ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } processTimezones(ev, ical, chg); /* Remove any recipients and originator */ if (ev.getRecipients() != null) { ev.getRecipients().clear(); } ev.setOriginator(null); if (hasXparams.value) { /* Save a text copy of the entire event as an x-property */ final Component valCopy = val.copy(); /* Remove potentially large values */ final Description desp = valCopy.getProperty(Property.DESCRIPTION); if (desp != null) { desp.setValue(null); } final Attach attachp = valCopy.getProperty(Property.ATTACH); // Don't store the entire attachment - we just need the parameters. if (attachp != null) { final Value v = attachp.getParameter(Parameter.VALUE); if (v != null) { attachp.setValue(String.valueOf(attachp.getValue().hashCode())); } } chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(BwXproperty.bedeworkIcal, null, valCopy.toString())); } chg.processChanges(ev, true, false); ev.setRecurring(ev.isRecurringEntity()); if (logger.debug()) { logger.debug(chg.toString()); logger.debug(ev.toString()); } if (masterEI != null) { // Just return notfound as this event is on its override list return Response.notFound(resp); } resp.setEntity(evinfo); return resp; } catch (final Throwable t) { if (logger.debug()) { logger.error(t); } return Response.error(resp, t); } }
NONSATD
true
break; case PERCENT_COMPLETE: /* ------------------- PercentComplete -------------------- */ Integer ival = ((PercentComplete)prop).getPercentage(); if (chg.changed(pi, ev.getPercentComplete(), ival)) {
} if (chg.changed(pi, evorgCopy, org)) { if (evorg == null) { ev.setOrganizer(org); } else { evorg.update(org); } } break; case PERCENT_COMPLETE: /* ------------------- PercentComplete -------------------- */ Integer ival = ((PercentComplete)prop).getPercentage(); if (chg.changed(pi, ev.getPercentComplete(), ival)) { ev.setPercentComplete(ival); } break; case POLL_MODE: /* ------------------- Poll mode -------------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollMode(), sval)) { ev.setPollMode(sval);
break; case ORGANIZER: /* ------------------- Organizer -------------------- */ final BwOrganizer org = IcalUtil.getOrganizer(cb, (Organizer)prop); final BwOrganizer evorg = ev.getOrganizer(); final BwOrganizer evorgCopy; if (evorg == null) { evorgCopy = null; } else { evorgCopy = (BwOrganizer)evorg.clone(); } if (chg.changed(pi, evorgCopy, org)) { if (evorg == null) { ev.setOrganizer(org); } else { evorg.update(org); } } break; case PERCENT_COMPLETE: /* ------------------- PercentComplete -------------------- */ Integer ival = ((PercentComplete)prop).getPercentage(); if (chg.changed(pi, ev.getPercentComplete(), ival)) { ev.setPercentComplete(ival); } break; case POLL_MODE: /* ------------------- Poll mode -------------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollMode(), sval)) { ev.setPollMode(sval); } break; case POLL_PROPERTIES: /* ------------------- Poll properties ---------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollProperties(), sval)) { ev.setPollProperties(sval); } break; case POLL_WINNER:
7,893
55
/* ------------------- Poll mode -------------------- */
public static GetEntityResponse<EventInfo> toEvent( final IcalCallback cb, final BwCalendar cal, final Icalendar ical, final Component val, final boolean mergeAttendees) { final var resp = new GetEntityResponse<EventInfo>(); if (val == null) { return Response.notOk(resp, failed, "No component supplied"); } String currentPrincipal = null; final BwPrincipal principal = cb.getPrincipal(); if (principal != null) { currentPrincipal = principal.getPrincipalRef(); } final Holder<Boolean> hasXparams = new Holder<>(Boolean.FALSE); final int methodType = ical.getMethodType(); String attUri = null; if (mergeAttendees) { // We'll need this later. attUri = cb.getCaladdr(cb.getPrincipal().getPrincipalRef()); } final String colPath; if (cal == null) { colPath = null; } else { colPath = cal.getPath(); } try { final PropertyList<Property> pl = val.getProperties(); boolean vpoll = false; boolean event = false; boolean task = false; if (pl == null) { // Empty component return Response.notOk(resp, failed, "Empty component"); } final int entityType; if (val instanceof VEvent) { entityType = IcalDefs.entityTypeEvent; event = true; } else if (val instanceof VToDo) { entityType = IcalDefs.entityTypeTodo; task = true; } else if (val instanceof VJournal) { entityType = IcalDefs.entityTypeJournal; } else if (val instanceof VFreeBusy) { entityType = IcalDefs.entityTypeFreeAndBusy; } else if (val instanceof VAvailability) { entityType = IcalDefs.entityTypeVavailability; } else if (val instanceof Available) { entityType = IcalDefs.entityTypeAvailable; } else if (val instanceof VPoll) { entityType = IcalDefs.entityTypeVpoll; vpoll = true; } else { return Response.error(resp, "org.bedework.invalid.component.type: " + val.getName()); } // Get the guid from the component String guid = null; final Uid uidp = pl.getProperty(Property.UID); if (uidp != null) { testXparams(uidp, hasXparams); guid = uidp.getValue(); } if (guid == null) { /* XXX A guid is required - but are there devices out there without a * guid - and if so how do we handle it? */ return Response.notOk(resp, failed, CalFacadeException.noGuid); } /* See if we have a recurrence id */ BwDateTime ridObj = null; String rid = null; TimeZone ridTz = null; final RecurrenceId ridp = pl.getProperty(Property.RECURRENCE_ID); if (ridp != null) { testXparams(ridp, hasXparams); ridObj = BwDateTime.makeBwDateTime(ridp); if (ridObj.getRange() != null) { /* XXX What do I do with it? */ logger.warn("TRANS-TO_EVENT: Got a recurrence id range"); } rid = ridObj.getDate(); } EventInfo masterEI = null; EventInfo evinfo = null; final BwEvent ev; /* If we have a recurrence id see if we already have the master (we should * get a master + all its overrides). * * If so find the override and use the annnotation or if no override, * make one. * * If no override retrieve the event, add it to our table and then locate the * annotation. * * If there is no annotation, create one. * * It's possible we have been sent 'detached' instances of a recurring * event. This may happen if we are invited to one or more instances of a * meeting. In this case we try to retrieve the master and if it doesn't * exist we manufacture one. We consider such an instance an update to * that instance only and leave the others alone. */ /* We need this in a couple of places */ final DtStart dtStart = pl.getProperty(Property.DTSTART); /* if (rid != null) { // See if we have a new master event. If so create a proxy to that event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI == null) { masterEI = makeNewEvent(cb, chg, entityType, guid, cal); BwEvent e = masterEI.getEvent(); // XXX This seems bogus DtStart mdtStart; String bogusDate = "19980118T230000"; if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + "Z"); } else if (dtStart.getTimeZone() == null) { mdtStart = new DtStart(bogusDate); } else { mdtStart = new DtStart(bogusDate + "Z", dtStart.getTimeZone()); } setDates(e, mdtStart, null, null, chg); e.setRecurring(true); e.addRdate(ridObj); e.setSuppressed(true); ical.addComponent(masterEI); } if (masterEI != null) { evinfo = masterEI.findOverride(rid); } } */ /* If this is a recurrence instance see if we can find the master We only need this because the master may follow the overrides. */ if (rid != null) { // See if we have a new master event. If so create a proxy to this event. masterEI = findMaster(guid, ical.getComponents()); if (masterEI != null) { evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; } } if ((evinfo == null) && (cal != null) && (cal.getCalType() != BwCalendar.calTypeInbox) && (cal.getCalType() != BwCalendar.calTypePendingInbox) && (cal.getCalType() != BwCalendar.calTypeOutbox)) { if (logger.debug()) { logger.debug("TRANS-TO_EVENT: try to fetch event with guid=" + guid); } final GetEntitiesResponse<EventInfo> eisResp = cb.getEvent(colPath, guid); if (eisResp.isError()) { return Response.fromResponse(resp, eisResp); } final var eis = eisResp.getEntities(); if (!Util.isEmpty(eis)) { if (eis.size() > 1) { // DORECUR - wrong again return Response.notOk(resp, failed, "More than one event returned for guid."); } evinfo = eis.iterator().next(); } if (logger.debug()) { if (evinfo != null) { logger.debug("TRANS-TO_EVENT: fetched event with guid"); } else { logger.debug("TRANS-TO_EVENT: did not find event with guid"); } } if (evinfo != null) { if (rid != null) { // We just retrieved it's master masterEI = evinfo; masterEI.setInstanceOnly(true); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; ical.addComponent(masterEI); } else if (methodType == ScheduleMethods.methodTypeCancel) { // This should never have an rid for cancel of entire event. evinfo.setInstanceOnly(evinfo.getEvent().getSuppressed()); } else { // Presumably sent an update for the entire event. No longer suppressed master evinfo.getEvent().setSuppressed(false); } } else if (rid != null) { /* Manufacture a master for the instance */ masterEI = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); final BwEvent e = masterEI.getEvent(); // XXX This seems bogus final DtStart mdtStart; final String bogusDate = "19980118"; final String bogusTime = "T230000"; // Base dtstart on the recurrence id. final boolean isDateType = ridObj.getDateType(); if (isDateType) { mdtStart = new DtStart(new Date(bogusDate)); } else if (dtStart.isUtc()) { mdtStart = new DtStart(bogusDate + bogusTime + "Z"); } else if (ridObj.getTzid() == null) { mdtStart = new DtStart(bogusDate + bogusTime); } else { mdtStart = new DtStart(bogusDate + bogusTime, Timezones.getTz(ridObj.getTzid())); } IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), masterEI, mdtStart, null, null); e.setRecurring(true); // e.addRdate(ridObj); final var sum = (Summary)pl.getProperty(Property.SUMMARY); e.setSummary(sum.getValue()); e.setSuppressed(true); ical.addComponent(masterEI); evinfo = masterEI.findOverride(rid); evinfo.recurrenceSeen = true; masterEI.setInstanceOnly(rid != null); } } if (evinfo == null) { evinfo = CnvUtil.makeNewEvent(cb, entityType, guid, colPath); } else if (evinfo.getEvent().getEntityType() != entityType) { return Response.notOk(resp, failed, "org.bedework.mismatched.entity.type: " + val); } final ChangeTable chg = evinfo.getChangeset( cb.getPrincipal().getPrincipalRef()); if (rid != null) { final String evrid = evinfo.getEvent().getRecurrenceId(); if ((evrid == null) || (!evrid.equals(rid))) { logger. warn("Mismatched rid ev=" + evrid + " expected " + rid); chg.changed(PropertyInfoIndex.RECURRENCE_ID, evrid, rid); // XXX spurious??? } if (masterEI.getEvent().getSuppressed()) { masterEI.getEvent().addRdate(ridObj); } } ev = evinfo.getEvent(); ev.setScheduleMethod(methodType); DtEnd dtEnd = null; if (entityType == IcalDefs.entityTypeTodo) { final Due due = pl.getProperty(Property.DUE); if (due != null ) { dtEnd = new DtEnd(due.getParameters(), due.getValue()); } } else { dtEnd = pl.getProperty(Property.DTEND); } final Duration duration = pl.getProperty(Property.DURATION); IcalUtil.setDates(cb.getPrincipal().getPrincipalRef(), evinfo, dtStart, dtEnd, duration); for (final Property prop: pl) { testXparams(prop, hasXparams); //debug("ical prop " + prop.getClass().getName()); String pval = prop.getValue(); if ((pval != null) && (pval.length() == 0)) { pval = null; } final PropertyInfoIndex pi; if (prop instanceof XProperty) { pi = PropertyInfoIndex.XPROP; } else { pi = PropertyInfoIndex.fromName(prop.getName()); } if (pi == null) { logger.debug("Unknown property with name " + prop.getName() + " class " + prop.getClass() + " and value " + pval); continue; } chg.present(pi); switch (pi) { case ACCEPT_RESPONSE: /* ------------------- Accept Response -------------------- */ String sval = prop.getValue(); if (chg.changed(pi, ev.getPollAcceptResponse(), sval)) { ev.setPollAcceptResponse(sval); } break; case ATTACH: /* ------------------- Attachment -------------------- */ chg.addValue(pi, IcalUtil.getAttachment((Attach)prop)); break; case ATTENDEE: /* ------------------- Attendee -------------------- */ if (methodType == ScheduleMethods.methodTypePublish) { if (cb.getStrictness() == IcalCallback.conformanceStrict) { return Response.notOk(resp, failed, CalFacadeException.attendeesInPublish); } //if (cb.getStrictness() == IcalCallback.conformanceWarn) { // warn("Had attendees for PUBLISH"); //} } final Attendee attPr = (Attendee)prop; if (evinfo.getNewEvent() || !mergeAttendees) { chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { final String pUri = cb.getCaladdr(attPr.getValue()); if (pUri.equals(attUri)) { /* Only update for our own attendee * We're doing a PUT and this must be the attendee updating their * partstat. We don't allow them to change other attendees * whatever the PUT content says. */ chg.addValue(pi, IcalUtil.getAttendee(cb, attPr)); } else { // Use the value we currently have boolean found = false; for (final BwAttendee att: ev.getAttendees()) { if (pUri.equals(att.getAttendeeUri())) { chg.addValue(pi, att.clone()); found = true; break; } } if (!found) { // An added attendee final BwAttendee att = IcalUtil .getAttendee(cb, attPr); att.setPartstat(IcalDefs.partstatValNeedsAction); chg.addValue(pi, att); } } } break; case BUSYTYPE: final int ibt = BwEvent.fromBusyTypeString(pval); if (chg.changed(pi, ev.getBusyType(), ibt)) { ev.setBusyType(ibt); } break; case CATEGORIES: /* ------------------- Categories -------------------- */ final Categories cats = (Categories)prop; final TextList cl = cats.getCategories(); String lang = IcalUtil.getLang(cats); if (cl != null) { /* Got some categories */ for (final String wd: cl) { if (wd == null) { continue; } final BwString key = new BwString(lang, wd); final var fcResp = cb.findCategory(key); final BwCategory cat; if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isNotFound()) { cat = BwCategory.makeCategory(); cat.setWord(key); cb.addCategory(cat); } else { cat = fcResp.getEntity(); } chg.addValue(pi, cat); } } break; case CLASS: /* ------------------- Class -------------------- */ if (chg.changed(pi, ev.getClassification(), pval)) { ev.setClassification(pval); } break; case COMMENT: /* ------------------- Comment -------------------- */ chg.addValue(pi, new BwString(null, pval)); break; case COMPLETED: /* ------------------- Completed -------------------- */ if (chg.changed(pi, ev.getCompleted(), pval)) { ev.setCompleted(pval); } break; case CONCEPT: /* ------------------- Concept -------------------- */ final Concept c = (Concept)prop; final String cval = c.getValue(); if (cval != null) { /* Got a concept */ chg.addValue(PropertyInfoIndex.XPROP, BwXproperty.makeIcalProperty("CONCEPT", null, cval)); } break; case CONTACT: /* ------------------- Contact -------------------- */ final String altrep = getAltRepPar(prop); lang = IcalUtil.getLang(prop); final String uid = getUidPar(prop); final BwString nm = new BwString(lang, pval); BwContact contact = null; if (uid != null) { final var fcResp = cb.getContact(uid); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { final var fcResp = cb.findContact(nm); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { contact = fcResp.getEntity(); } } if (contact == null) { contact = BwContact.makeContact(); contact.setCn(nm); contact.setLink(altrep); cb.addContact(contact); } else { contact.setCn(nm); contact.setLink(altrep); } chg.addValue(pi, contact); break; case CREATED: /* ------------------- Created -------------------- */ if (chg.changed(pi, ev.getCreated(), pval)) { ev.setCreated(pval); } break; case DESCRIPTION: /* ------------------- Description -------------------- */ if (chg.changed(pi, ev.getDescription(), pval)) { ev.setDescription(pval); } break; case DTEND: /* ------------------- DtEnd -------------------- */ break; case DTSTAMP: /* ------------------- DtStamp -------------------- */ ev.setDtstamp(pval); break; case DTSTART: /* ------------------- DtStart -------------------- */ break; case DUE: /* -------------------- Due ------------------------ */ break; case DURATION: /* ------------------- Duration -------------------- */ break; case EXDATE: /* ------------------- ExDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case EXRULE: /* ------------------- ExRule -------------------- */ chg.addValue(pi, pval); break; case FREEBUSY: /* ------------------- freebusy -------------------- */ final FreeBusy fbusy = (FreeBusy)prop; final PeriodList perpl = fbusy.getPeriods(); final Parameter par = IcalUtil.getParameter(fbusy, "FBTYPE"); final int fbtype; if (par == null) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY)) { fbtype = BwFreeBusyComponent.typeBusy; } else if (par.equals(FbType.BUSY_TENTATIVE)) { fbtype = BwFreeBusyComponent.typeBusyTentative; } else if (par.equals(FbType.BUSY_UNAVAILABLE)) { fbtype = BwFreeBusyComponent.typeBusyUnavailable; } else if (par.equals(FbType.FREE)) { fbtype = BwFreeBusyComponent.typeFree; } else { if (logger.debug()) { logger.debug("Unsupported parameter " + par.getName()); } return Response.notOk(resp, failed, "Unsupported parameter " + par.getName()); } final BwFreeBusyComponent fbc = new BwFreeBusyComponent(); fbc.setType(fbtype); for (final Period per : perpl) { fbc.addPeriod(per); } ev.addFreeBusyPeriod(fbc); break; case GEO: /* ------------------- Geo -------------------- */ final Geo g = (Geo)prop; final BwGeo geo = new BwGeo(g.getLatitude(), g.getLongitude()); if (chg.changed(pi, ev.getGeo(), geo)) { ev.setGeo(geo); } break; case LAST_MODIFIED: /* ------------------- LastModified -------------------- */ if (chg.changed(pi, ev.getLastmod(), pval)) { ev.setLastmod(pval); } break; case LOCATION: /* ------------------- Location -------------------- */ BwLocation loc = null; //String uid = getUidPar(prop); /* At the moment Mozilla lightning is broken and this leads to all * sorts of problems. if (uid != null) { loc = cb.getLocation(uid); } */ lang = IcalUtil.getLang(prop); BwString addr = null; if (pval != null) { if (loc == null) { addr = new BwString(lang, pval); final var fcResp = cb.findLocation(addr); if (fcResp.isError()) { return Response.fromResponse(resp, fcResp); } if (fcResp.isOk()) { loc = fcResp.getEntity(); } } if (loc == null) { loc = BwLocation.makeLocation(); loc.setAddress(addr); cb.addLocation(loc); } } final BwLocation evloc = ev.getLocation(); if (chg.changed(pi, evloc, loc)) { // CHGTBL - this only shows that it's a different location object ev.setLocation(loc); } else if ((loc != null) && (evloc != null)) { // See if the value is changed final String evval = evloc.getAddress().getValue(); final String inval = loc.getAddress().getValue(); if (!evval.equals(inval)) { chg.changed(pi, evval, inval); evloc.getAddress().setValue(inval); } } break; case ORGANIZER: /* ------------------- Organizer -------------------- */ final BwOrganizer org = IcalUtil.getOrganizer(cb, (Organizer)prop); final BwOrganizer evorg = ev.getOrganizer(); final BwOrganizer evorgCopy; if (evorg == null) { evorgCopy = null; } else { evorgCopy = (BwOrganizer)evorg.clone(); } if (chg.changed(pi, evorgCopy, org)) { if (evorg == null) { ev.setOrganizer(org); } else { evorg.update(org); } } break; case PERCENT_COMPLETE: /* ------------------- PercentComplete -------------------- */ Integer ival = ((PercentComplete)prop).getPercentage(); if (chg.changed(pi, ev.getPercentComplete(), ival)) { ev.setPercentComplete(ival); } break; case POLL_MODE: /* ------------------- Poll mode -------------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollMode(), sval)) { ev.setPollMode(sval); } break; case POLL_PROPERTIES: /* ------------------- Poll properties ---------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollProperties(), sval)) { ev.setPollProperties(sval); } break; case POLL_WINNER: /* ------------------- Poll winner -------------------- */ ival = ((PollWinner)prop).getPollwinner(); if (chg.changed(pi, ev.getPollWinner(), ival)) { ev.setPollWinner(ival); } break; case PRIORITY: /* ------------------- Priority -------------------- */ ival = ((Priority)prop).getLevel(); if (chg.changed(pi, ev.getPriority(), ival)) { ev.setPriority(ival); } break; case RDATE: /* ------------------- RDate -------------------- */ chg.addValues(pi, IcalUtil.makeDateTimes((DateListProperty)prop)); break; case RECURRENCE_ID: /* ------------------- RecurrenceID -------------------- */ // Done above break; case RELATED_TO: /* ------------------- RelatedTo -------------------- */ final RelatedTo irelto = (RelatedTo)prop; final BwRelatedTo relto = new BwRelatedTo(); final String parval = IcalUtil.getParameterVal(irelto, "RELTYPE"); if (parval != null) { relto.setRelType(parval); } relto.setValue(irelto.getValue()); if (chg.changed(pi, ev.getRelatedTo(), relto)) { ev.setRelatedTo(relto); } break; case REQUEST_STATUS: /* ------------------- RequestStatus -------------------- */ final BwRequestStatus rs = BwRequestStatus .fromRequestStatus((RequestStatus)prop); chg.addValue(pi, rs); break; case RESOURCES: /* ------------------- Resources -------------------- */ final TextList rl = ((Resources)prop).getResources(); if (rl != null) { /* Got some resources */ lang = IcalUtil.getLang(prop); for (final String s: rl) { final BwString rsrc = new BwString(lang, s); chg.addValue(pi, rsrc); } } break; case RRULE: /* ------------------- RRule -------------------- */ chg.addValue(pi, pval); break; case SEQUENCE: /* ------------------- Sequence -------------------- */ final int seq = ((Sequence)prop).getSequenceNo(); if (seq != ev.getSequence()) { chg.changed(pi, ev.getSequence(), seq); ev.setSequence(seq); } break; case STATUS: /* ------------------- Status -------------------- */ if (chg.changed(pi, ev.getStatus(), pval)) { ev.setStatus(pval); } break; case SUMMARY: /* ------------------- Summary -------------------- */ if (chg.changed(pi, ev.getSummary(), pval)) { ev.setSummary(pval); } break; case TRANSP: /* ------------------- Transp -------------------- */ if (chg.changed(pi, ev.getPeruserTransparency( cb.getPrincipal() .getPrincipalRef()), pval)) { final BwXproperty pu = ev.setPeruserTransparency( cb.getPrincipal().getPrincipalRef(), pval); if (pu != null) { chg.addValue(PropertyInfoIndex.XPROP, pu); } } break; case UID: /* ------------------- Uid -------------------- */ /* We did this above */ break; case URL: /* ------------------- Url -------------------- */ if (chg.changed(pi, ev.getLink(), pval)) { ev.setLink(pval); } break; case XPROP: /* ------------------------- x-property --------------------------- */ final String name = prop.getName(); if (name.equalsIgnoreCase(BwXproperty.bedeworkCost)) { if (chg.changed(PropertyInfoIndex.COST, ev.getCost(), pval)) { ev.setCost(pval); } break; } if (name.equalsIgnoreCase(BwXproperty.xBedeworkCategories)) { if (checkCategory(cb, chg, ev, null, pval)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkLocation)) { if (checkLocation(cb, chg, ev, prop)) { break; } } if (name.equalsIgnoreCase(BwXproperty.xBedeworkContact)) { if (checkContact(cb, chg, ev, null, pval)) { break; } } /* See if this is an x-category that can be converted to a real category */ final XProperty xp = (XProperty)prop; chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(name, xp.getParameters() .toString(), pval)); break; default: if (logger.debug()) { logger.debug("Unsupported property with index " + pi + "; class " + prop.getClass() + " and value " + pval); } } } /* =================== Process sub-components =============== */ final ComponentList<Component> subComps; if (val instanceof ComponentContainer) { subComps = ((ComponentContainer<Component>)val).getComponents(); } else { subComps = null; } final Set<Integer> pids; if (vpoll) { pids = new TreeSet<>(); final BwEvent vp = evinfo.getEvent(); if (!Util.isEmpty(vp.getPollItems())) { vp.clearPollItems(); } } else { pids = null; } if (!Util.isEmpty(subComps)) { for (final var subComp: subComps) { if (subComp instanceof Available) { if (!(val instanceof VAvailability)) { return Response.error(resp, "AVAILABLE only valid in VAVAILABLE"); } final var avlResp = processAvailable(cb, cal, ical, (VAvailability)val, (Available)subComp, evinfo); if (!avlResp.isOk()) { return Response.fromResponse(resp, avlResp); } continue; } if (subComp instanceof Participant) { if (vpoll) { final var vresp = processVoter(cb, (VPoll)val, (Participant)subComp, evinfo, chg, mergeAttendees); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Participant object"); continue; } if (subComp instanceof VResource) { logger.warn("Unimplemented VResource object"); continue; } if (subComp instanceof VLocation) { logger.warn("Unimplemented VLocation object"); continue; } if (subComp instanceof VAlarm) { final var aresp = VAlarmUtil.processAlarm(cb, val, (VAlarm)subComp, ev, currentPrincipal, chg); if (!aresp.isOk()) { return Response.fromResponse(resp, aresp); } continue; } if (vpoll && (event || task)) { final var vresp = processCandidate((VPoll)val, subComp, evinfo, pids, chg); if (!vresp.isOk()) { return Response.fromResponse(resp, vresp); } continue; } logger.warn("Unimplemented Component object: " + subComp); } } /* Fix up timestamps. */ if (ev.getCreated() == null) { if (ev.getLastmod() != null) { ev.setCreated(ev.getLastmod()); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); } else { ev.updateDtstamp(); chg.changed(PropertyInfoIndex.CREATED, null, ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } } if (ev.getLastmod() == null) { // created cannot be null now ev.setLastmod(ev.getCreated()); chg.changed(PropertyInfoIndex.LAST_MODIFIED, null, ev.getLastmod()); } processTimezones(ev, ical, chg); /* Remove any recipients and originator */ if (ev.getRecipients() != null) { ev.getRecipients().clear(); } ev.setOriginator(null); if (hasXparams.value) { /* Save a text copy of the entire event as an x-property */ final Component valCopy = val.copy(); /* Remove potentially large values */ final Description desp = valCopy.getProperty(Property.DESCRIPTION); if (desp != null) { desp.setValue(null); } final Attach attachp = valCopy.getProperty(Property.ATTACH); // Don't store the entire attachment - we just need the parameters. if (attachp != null) { final Value v = attachp.getParameter(Parameter.VALUE); if (v != null) { attachp.setValue(String.valueOf(attachp.getValue().hashCode())); } } chg.addValue(PropertyInfoIndex.XPROP, new BwXproperty(BwXproperty.bedeworkIcal, null, valCopy.toString())); } chg.processChanges(ev, true, false); ev.setRecurring(ev.isRecurringEntity()); if (logger.debug()) { logger.debug(chg.toString()); logger.debug(ev.toString()); } if (masterEI != null) { // Just return notfound as this event is on its override list return Response.notFound(resp); } resp.setEntity(evinfo); return resp; } catch (final Throwable t) { if (logger.debug()) { logger.error(t); } return Response.error(resp, t); } }
NONSATD
true
break; case POLL_MODE: /* ------------------- Poll mode -------------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollMode(), sval)) {
} break; case PERCENT_COMPLETE: /* ------------------- PercentComplete -------------------- */ Integer ival = ((PercentComplete)prop).getPercentage(); if (chg.changed(pi, ev.getPercentComplete(), ival)) { ev.setPercentComplete(ival); } break; case POLL_MODE: /* ------------------- Poll mode -------------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollMode(), sval)) { ev.setPollMode(sval); } break; case POLL_PROPERTIES: /* ------------------- Poll properties ---------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollProperties(), sval)) { ev.setPollProperties(sval);
evorgCopy = null; } else { evorgCopy = (BwOrganizer)evorg.clone(); } if (chg.changed(pi, evorgCopy, org)) { if (evorg == null) { ev.setOrganizer(org); } else { evorg.update(org); } } break; case PERCENT_COMPLETE: /* ------------------- PercentComplete -------------------- */ Integer ival = ((PercentComplete)prop).getPercentage(); if (chg.changed(pi, ev.getPercentComplete(), ival)) { ev.setPercentComplete(ival); } break; case POLL_MODE: /* ------------------- Poll mode -------------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollMode(), sval)) { ev.setPollMode(sval); } break; case POLL_PROPERTIES: /* ------------------- Poll properties ---------------- */ sval = prop.getValue(); if (chg.changed(pi, ev.getPollProperties(), sval)) { ev.setPollProperties(sval); } break; case POLL_WINNER: /* ------------------- Poll winner -------------------- */ ival = ((PollWinner)prop).getPollwinner(); if (chg.changed(pi, ev.getPollWinner(), ival)) { ev.setPollWinner(ival); } break; case PRIORITY: