Skip to content

Commit

Permalink
Removed anonymous classes
Browse files Browse the repository at this point in the history
  • Loading branch information
car031 committed May 23, 2023
1 parent a4d379a commit b29cc4e
Show file tree
Hide file tree
Showing 155 changed files with 3,218 additions and 5,535 deletions.
105 changes: 105 additions & 0 deletions logicaldoc-cmis/src/test/java/com/logicaldoc/cmis/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package com.logicaldoc.cmis;

import org.apache.chemistry.opencmis.client.api.*;
import org.apache.chemistry.opencmis.client.runtime.OperationContextImpl;
import org.apache.chemistry.opencmis.client.runtime.SessionFactoryImpl;
import org.apache.chemistry.opencmis.client.runtime.repository.ObjectFactoryImpl;
import org.apache.chemistry.opencmis.commons.PropertyIds;
import org.apache.chemistry.opencmis.commons.SessionParameter;
import org.apache.chemistry.opencmis.commons.data.ContentStream;
import org.apache.chemistry.opencmis.commons.enums.BindingType;
import org.apache.chemistry.opencmis.commons.enums.VersioningState;
import org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;

import com.logicaldoc.core.document.Document;

public class Main {
public static final String TEMPLATE_ID = "ldoc:template";

public static final String METADATA_PREFIX = "ldoc:ext_";
public static final String OC_DOCUMENT_TEMPLATE_ID = "CampusDocument";
public static final String OC_DOCUMENT_PREFIX_PREFIX = METADATA_PREFIX + OC_DOCUMENT_TEMPLATE_ID + "-";
public static final String OC_DOCUMENT_TITLE = OC_DOCUMENT_PREFIX_PREFIX + "title";


private final static Logger LOG = Logger.getLogger(Main.class.getName());

public static void main(String[] args) {
String ldocCmisUrl = "http://localhost:8080/service/cmis";
String username = "admin";
String password = "admin";

SessionFactory sessionFactory = SessionFactoryImpl.newInstance();
Map<String, String> parameters = new HashMap<>();
parameters.put(SessionParameter.USER, username);
parameters.put(SessionParameter.PASSWORD, password);
parameters.put(SessionParameter.CONNECT_TIMEOUT, "5000");
parameters.put(SessionParameter.READ_TIMEOUT, "30000");
parameters.put(SessionParameter.ATOMPUB_URL, ldocCmisUrl);
parameters.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());

try {
List<Repository> repositories = sessionFactory.getRepositories(parameters);
for (Repository repository : repositories) {
LOG.info("Found repositories include " + repository.getName() + " with id " + repository.getId());
}
parameters.put(SessionParameter.REPOSITORY_ID, repositories.get(0).getId());
LOG.info("Managed Cmis Connection Factory created at " + LocalDateTime.now());
Session session = sessionFactory.createSession(parameters);

// CmisObject found = session.getObject("63208755");

org.apache.chemistry.opencmis.client.api.Document document = createDocument(session, "103");
LOG.info("Created file name="+document.getName());
// renameDocument(session, document.getId(), "myNewDemo.txt");
} catch (CmisBaseException | IllegalArgumentException e) {
LOG.info("Error while initializing a session: " + e.getMessage());
throw e;
}
}

// static void renameDocument(Session session, String id, String newName) {
// CmisObject object = session.getObject(id);
// if (object instanceof Document) {
// Document doc =(Document) object;
// LOG.info("Rename: " + doc.getId() + " | " + doc.getName() + " => " + newName);
// doc.rename(newName);
// LOG.info("Renamed to " + doc.getName());
// }
// }

static org.apache.chemistry.opencmis.client.api.Document createDocument(Session session, String id) {
CmisObject object = session.getObject(id);
if (object instanceof Folder) {
Folder folder=(Folder) object;
String name = "mydemo.txt";
String myDemoText = "Hello world";

Map<String, Object> props = new HashMap<>();
props.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document");
props.put(PropertyIds.NAME, name);
// props.put(TEMPLATE_ID, OC_DOCUMENT_TEMPLATE_ID);
// props.put(OC_DOCUMENT_TITLE, name);

byte[] bytes = myDemoText.getBytes(StandardCharsets.UTF_8);
InputStream stream = new ByteArrayInputStream(bytes);

ContentStream contentStream = new ObjectFactoryImpl().createContentStream(name, bytes.length, "text/plain",
stream);
org.apache.chemistry.opencmis.client.api.Document document = folder.createDocument(props, contentStream, VersioningState.NONE);
LOG.info("Created file " + name + " in folder " + folder.getPath());
return document;
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public Object newInstance(String className)

try {
return Class.forName(className).getDeclaredConstructor().newInstance();
} catch (Throwable t) {
} catch (Exception t) {
// The classname as is was not found, so try to prefix with our root
// package
return Class.forName("com.logicaldoc." + className).getDeclaredConstructor().newInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@
import com.smartgwt.client.widgets.form.fields.ButtonItem;
import com.smartgwt.client.widgets.form.fields.SelectItem;
import com.smartgwt.client.widgets.form.fields.StaticTextItem;
import com.smartgwt.client.widgets.grid.CellFormatter;
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.grid.ListGridField;
import com.smartgwt.client.widgets.grid.ListGridRecord;
import com.smartgwt.client.widgets.layout.VLayout;

public class RatingDialog extends Window {
Expand Down Expand Up @@ -78,12 +76,8 @@ public RatingDialog(int documentRating, GUIRating rat) {
totalVotes.addClickHandler(event -> {
ListGridField vote = new ListGridField("vote", I18N.message("vote"), 94);
vote.setAlign(Alignment.CENTER);
vote.setCellFormatter(new CellFormatter() {

@Override
public String format(Object value, ListGridRecord rec, int rowNum, int colNum) {
return DocUtil.getRatingIcon((Integer) value);
}
vote.setCellFormatter((value, rec, rowNum, colNum) -> {
return DocUtil.getRatingIcon((Integer) value);
});

ListGridField user = new ListGridField("user", I18N.message("user"), 140);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import com.smartgwt.client.types.PickerIconName;
import com.smartgwt.client.types.TitleOrientation;
import com.smartgwt.client.util.SC;
import com.smartgwt.client.util.ValueCallback;
import com.smartgwt.client.widgets.form.DynamicForm;
import com.smartgwt.client.widgets.form.ValuesManager;
import com.smartgwt.client.widgets.form.fields.ColorItem;
Expand All @@ -39,7 +38,6 @@
import com.smartgwt.client.widgets.form.fields.events.ChangedHandler;
import com.smartgwt.client.widgets.form.fields.events.ClickEvent;
import com.smartgwt.client.widgets.form.fields.events.FormItemIconClickEvent;
import com.smartgwt.client.widgets.form.fields.events.KeyPressEvent;
import com.smartgwt.client.widgets.layout.HLayout;
import com.smartgwt.client.widgets.layout.Layout;
import com.smartgwt.client.widgets.layout.VLayout;
Expand Down Expand Up @@ -206,11 +204,8 @@ private LinkItem prepareFolderItem() {
copyPath.setWidth(16);
copyPath.setHeight(16);
copyPath.addFormItemClickHandler(event -> {
LD.askForValue(I18N.message("path"), I18N.message("path"), path, new ValueCallback() {
@Override
public void execute(final String value) {
// Nothing to do
}
LD.askForValue(I18N.message("path"), I18N.message("path"), path, value -> {
// Nothing to do
});
event.cancel();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.grid.ListGridField;
import com.smartgwt.client.widgets.grid.ListGridRecord;
import com.smartgwt.client.widgets.grid.events.CellContextClickEvent;
import com.smartgwt.client.widgets.grid.events.CellDoubleClickEvent;
import com.smartgwt.client.widgets.layout.VLayout;
import com.smartgwt.client.widgets.menu.Menu;
import com.smartgwt.client.widgets.menu.MenuItem;
Expand Down Expand Up @@ -122,7 +120,7 @@ private ToolStrip prepareButtons() {
}

private void addListHandlers() {
list.addCellDoubleClickHandler((CellDoubleClickEvent clickEvent) -> {
list.addCellDoubleClickHandler(clickEvent -> {
ListGridRecord rec = clickEvent.getRecord();
if (FolderController.get().getCurrentFolder().isDownload()
&& DOWNLOAD.equals(Session.get().getInfo().getConfig("gui.doubleclick")))
Expand All @@ -131,7 +129,7 @@ private void addListHandlers() {
onPreview(document, rec);
});

list.addCellContextClickHandler((CellContextClickEvent contextClickEvent) -> {
list.addCellContextClickHandler(contextClickEvent -> {
ListGridField field = list.getField(contextClickEvent.getColNum());
if (!PERMALINK.equals(field.getName())) {
prepareContextMenu().showContextMenu();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@
import com.smartgwt.client.widgets.drawing.LineToCommand;
import com.smartgwt.client.widgets.drawing.MoveToCommand;
import com.smartgwt.client.widgets.drawing.Point;
import com.smartgwt.client.widgets.drawing.events.MovedEvent;
import com.smartgwt.client.widgets.drawing.events.MovedHandler;
import com.smartgwt.client.widgets.drawing.events.ResizedEvent;
import com.smartgwt.client.widgets.drawing.events.ResizedHandler;
import com.smartgwt.client.widgets.form.fields.SliderItem;
import com.smartgwt.client.widgets.layout.VLayout;
import com.smartgwt.client.widgets.toolbar.ToolStrip;
Expand Down Expand Up @@ -413,20 +409,8 @@ protected DrawItem newAnnotationItem(GUIDocumentNote note) {
if (note.isShowKnobs())
showKnowbs(drawItem);

drawItem.addMovedHandler(new MovedHandler() {

@Override
public void onMoved(MovedEvent event) {
note.setMovedOrResized(true);
}
});
drawItem.addResizedHandler(new ResizedHandler() {

@Override
public void onResized(ResizedEvent event) {
note.setMovedOrResized(true);
}
});
drawItem.addMovedHandler(event -> note.setMovedOrResized(true));
drawItem.addResizedHandler(event -> note.setMovedOrResized(true));

return drawItem;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
import com.smartgwt.client.widgets.form.fields.ColorPickerItem;
import com.smartgwt.client.widgets.form.fields.FormItem;
import com.smartgwt.client.widgets.form.fields.SpinnerItem;
import com.smartgwt.client.widgets.form.fields.events.ChangedEvent;
import com.smartgwt.client.widgets.form.fields.events.ChangedHandler;
import com.smartgwt.client.widgets.layout.HStack;
import com.smartgwt.client.widgets.menu.Menu;
import com.smartgwt.client.widgets.menu.MenuItem;
Expand Down Expand Up @@ -106,13 +104,9 @@ protected void appendAdditionalItems(List<MenuItem> items) {

private MenuItem prepareFillMenuItem() {
ColorPickerItem fillColor = ItemFactory.newColorItemPicker("fillColor", I18N.message("color"), note.getColor(),
false, new ChangedHandler() {

@Override
public void onChanged(ChangedEvent event) {
note.setColor((String) event.getValue());
drawItem.setFillColor((String) event.getValue());
}
false, event -> {
note.setColor((String) event.getValue());
drawItem.setFillColor((String) event.getValue());
});
fillColor.setRequired(true);
fillColor.setDisabled(!editEnabled);
Expand All @@ -122,9 +116,9 @@ public void onChanged(ChangedEvent event) {
fillOpacity.setMin(0);
fillOpacity.setMax(100);
fillOpacity.setDisabled(!editEnabled);
fillOpacity.addChangedHandler( event -> {
note.setOpacity(Integer.parseInt(event.getValue().toString()));
drawItem.setFillOpacity((float) note.getOpacity() / 100f);
fillOpacity.addChangedHandler(event -> {
note.setOpacity(Integer.parseInt(event.getValue().toString()));
drawItem.setFillOpacity((float) note.getOpacity() / 100f);
});

final DynamicForm fillForm = new DynamicForm();
Expand Down Expand Up @@ -157,16 +151,16 @@ private MenuItem prepareContentMenuItem() {
form.setTitleOrientation(TitleOrientation.RIGHT);

FormItem contentArea = ItemFactory.newTextAreaItemForNote(CONTENT, I18N.message(CONTENT), note.getMessage(),
event -> {
form.setValue(CONTENT, (String) event.getValue());
note.setMessage((String) event.getValue());
event -> {
form.setValue(CONTENT, (String) event.getValue());
note.setMessage((String) event.getValue());

if (drawItem instanceof DrawLabel)
((DrawLabel) drawItem).setContents(Util.strip(note.getMessage()));
else
drawItem.setTitle(Util.strip(note.getMessage()));
if (drawItem instanceof DrawLabel)
((DrawLabel) drawItem).setContents(Util.strip(note.getMessage()));
else
drawItem.setTitle(Util.strip(note.getMessage()));

drawItem.setPrompt(note.getMessage());
drawItem.setPrompt(note.getMessage());
}, true);
contentArea.setRequired(false);
contentArea.setShowTitle(false);
Expand All @@ -191,8 +185,8 @@ private MenuItem prepareContentMenuItem() {
private MenuItem prepareLineMenuItem() {
ColorPickerItem lineColor = ItemFactory.newColorItemPicker("lineColor", I18N.message("color"),
note.getLineColor(), false, event -> {
note.setLineColor((String) event.getValue());
drawItem.setLineColor((String) event.getValue());
note.setLineColor((String) event.getValue());
drawItem.setLineColor((String) event.getValue());
});
lineColor.setRequired(true);
lineColor.setDisabled(!editEnabled);
Expand All @@ -201,9 +195,9 @@ private MenuItem prepareLineMenuItem() {
opacity.setRequired(true);
opacity.setMin(0);
opacity.setMax(100);
opacity.addChangedHandler( event -> {
note.setLineOpacity(Integer.parseInt(event.getValue().toString()));
drawItem.setLineOpacity((float) note.getLineOpacity() / 100f);
opacity.addChangedHandler(event -> {
note.setLineOpacity(Integer.parseInt(event.getValue().toString()));
drawItem.setLineOpacity((float) note.getLineOpacity() / 100f);
});
opacity.setVisible(!(drawItem instanceof DrawLabel));
opacity.setDisabled(!editEnabled);
Expand All @@ -214,12 +208,12 @@ private MenuItem prepareLineMenuItem() {
width.setMax(100);
width.setDisabled(!editEnabled);
width.addChangedHandler(event -> {
note.setLineWidth(Integer.parseInt(event.getValue().toString()));
note.setLineWidth(Integer.parseInt(event.getValue().toString()));

if (drawItem instanceof DrawLabel)
((DrawLabel) drawItem).setFontSize(note.getLineWidth());
else
drawItem.setLineWidth(note.getLineWidth());
if (drawItem instanceof DrawLabel)
((DrawLabel) drawItem).setFontSize(note.getLineWidth());
else
drawItem.setLineWidth(note.getLineWidth());
});

final DynamicForm lineForm = new DynamicForm();
Expand Down
Loading

0 comments on commit b29cc4e

Please sign in to comment.