use of org.bimserver.interfaces.objects.SProject in project BIMserver by opensourceBIM.
the class SyndicationServlet method writeProjectsFeed.
private void writeProjectsFeed(HttpServletRequest request, HttpServletResponse response, ServiceMap serviceMap) throws UserException, IOException, FeedException, PublicInterfaceNotFoundException {
SyndFeed feed = new SyndFeedImpl();
feed.setFeedType(FEED_TYPE);
feed.setTitle("BIMserver.org projects feed");
feed.setLink(request.getContextPath());
feed.setDescription("This feed represents all your available projects within this BIMserver");
List<SyndEntry> entries = new ArrayList<SyndEntry>();
try {
List<SProject> allProjects = serviceMap.getServiceInterface().getAllProjects(false, true);
for (SProject sProject : allProjects) {
SyndEntry entry = new SyndEntryImpl();
entry.setAuthor(serviceMap.getServiceInterface().getUserByUoid(sProject.getCreatedById()).getName());
entry.setTitle(sProject.getName());
entry.setLink(request.getContextPath() + "/project.jsp?poid=" + sProject.getOid());
entry.setPublishedDate(sProject.getCreatedDate());
SyndContent description = new SyndContentImpl();
description.setType("text/plain");
description.setValue(sProject.getDescription());
entry.setDescription(description);
entries.add(entry);
}
if (allProjects.size() == 0) {
SyndEntry entry = new SyndEntryImpl();
entry.setTitle("No projects found");
entry.setLink(request.getContextPath() + "/main.jsp");
entry.setPublishedDate(new Date());
SyndContent description = new SyndContentImpl();
description.setType("text/plain");
description.setValue("No projects found");
entry.setDescription(description);
entries.add(entry);
}
} catch (ServiceException e) {
LOGGER.error("", e);
}
feed.setEntries(entries);
SyndFeedOutput output = new SyndFeedOutput();
output.output(feed, response.getWriter());
}
use of org.bimserver.interfaces.objects.SProject in project BIMserver by opensourceBIM.
the class ServiceImpl method addProjectAsSubProject.
@Override
public SProject addProjectAsSubProject(String projectName, Long parentPoid, String schema) throws ServerException, UserException {
requireRealUserAuthentication();
DatabaseSession session = getBimServer().getDatabase().createSession();
try {
BimDatabaseAction<Project> action = new AddProjectDatabaseAction(getBimServer(), session, getInternalAccessMethod(), projectName, parentPoid, schema, getAuthorization());
return getBimServer().getSConverter().convertToSObject(session.executeAndCommitAction(action));
} catch (Exception e) {
return handleException(e);
} finally {
session.close();
}
}
use of org.bimserver.interfaces.objects.SProject in project BIMserver by opensourceBIM.
the class ServiceImpl method getAllProjects.
@Override
public List<SProject> getAllProjects(Boolean onlyTopLevel, Boolean onlyActive) throws ServerException, UserException {
requireRealUserAuthentication();
DatabaseSession session = getBimServer().getDatabase().createSession();
try {
BimDatabaseAction<Set<Project>> action = new GetAllProjectsDatabaseAction(session, getInternalAccessMethod(), onlyTopLevel, onlyActive, getAuthorization());
List<SProject> convertToSListProject = getBimServer().getSConverter().convertToSListProject(session.executeAndCommitAction(action));
Collections.sort(convertToSListProject, new SProjectComparator());
return convertToSListProject;
} catch (Exception e) {
return handleException(e);
} finally {
session.close();
}
}
use of org.bimserver.interfaces.objects.SProject in project BIMserver by opensourceBIM.
the class ServiceImpl method getSubProjectByName.
@Override
public SProject getSubProjectByName(Long parentProjectId, String name) throws UserException, ServerException {
requireRealUserAuthentication();
DatabaseSession session = getBimServer().getDatabase().createSession();
try {
BimDatabaseAction<Project> action = new GetSubProjectByNameDatabaseAction(session, getInternalAccessMethod(), parentProjectId, name, getAuthorization());
return getBimServer().getSConverter().convertToSObject(session.executeAndCommitAction(action));
} catch (Exception e) {
return handleException(e);
} finally {
session.close();
}
}
use of org.bimserver.interfaces.objects.SProject in project BIMserver by opensourceBIM.
the class BulkUploadServlet method service.
@Override
public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
if (request.getHeader("Origin") != null && !getBimServer().getServerSettingsCache().isHostAllowed(request.getHeader("Origin"))) {
response.setStatus(403);
return;
}
response.setHeader("Access-Control-Allow-Origin", request.getHeader("Origin"));
response.setHeader("Access-Control-Allow-Headers", "Content-Type");
String token = (String) request.getSession().getAttribute("token");
ObjectNode result = OBJECT_MAPPER.createObjectNode();
response.setContentType("text/json");
try {
boolean isMultipart = ServletFileUpload.isMultipartContent(request);
long poid = -1;
String comment = null;
if (isMultipart) {
ServletFileUpload upload = new ServletFileUpload();
FileItemIterator iter = upload.getItemIterator(request);
InputStream in = null;
String name = "";
while (iter.hasNext()) {
FileItemStream item = iter.next();
if (item.isFormField()) {
if ("token".equals(item.getFieldName())) {
token = Streams.asString(item.openStream());
} else if ("poid".equals(item.getFieldName())) {
poid = Long.parseLong(Streams.asString(item.openStream()));
} else if ("comment".equals(item.getFieldName())) {
comment = Streams.asString(item.openStream());
}
} else {
name = item.getName();
in = item.openStream();
if (poid != -1) {
ServiceInterface service = getBimServer().getServiceFactory().get(token, AccessMethod.INTERNAL).get(ServiceInterface.class);
SProject mainProject = service.getProjectByPoid(poid);
ZipInputStream zipInputStream = new ZipInputStream(in);
ZipEntry nextEntry = zipInputStream.getNextEntry();
while (nextEntry != null) {
String fullfilename = nextEntry.getName();
if (fullfilename.toLowerCase().endsWith(".ifc") || fullfilename.toLowerCase().endsWith("ifcxml") || fullfilename.toLowerCase().endsWith(".ifczip")) {
InputStreamDataSource inputStreamDataSource = new InputStreamDataSource(new FakeClosingInputStream(zipInputStream));
inputStreamDataSource.setName(name);
DataHandler ifcFile = new DataHandler(inputStreamDataSource);
if (fullfilename.contains("/")) {
String path = fullfilename.substring(0, fullfilename.lastIndexOf("/"));
String filename = fullfilename.substring(fullfilename.lastIndexOf("/") + 1);
String extension = filename.substring(filename.lastIndexOf(".") + 1);
SProject project = getOrCreatePath(service, mainProject, mainProject, path);
SDeserializerPluginConfiguration deserializer = service.getSuggestedDeserializerForExtension(extension, project.getOid());
long topicId = -1;
try {
topicId = service.checkin(project.getOid(), comment, deserializer.getOid(), -1L, filename, ifcFile, false, true);
} finally {
if (topicId != -1) {
service.cleanupLongAction(topicId);
}
}
}
} else {
if (!nextEntry.isDirectory()) {
LOGGER.info("Unknown fileextenstion " + fullfilename);
}
}
nextEntry = zipInputStream.getNextEntry();
}
// DataHandler ifcFile = new DataHandler(inputStreamDataSource);
//
// if (token != null) {
// if (topicId == -1) {
// long newTopicId = service.checkin(poid, comment, deserializerOid, -1L, name, ifcFile, merge, sync);
// result.put("topicId", newTopicId);
// } else {
// ServiceInterface service = getBimServer().getServiceFactory().get(token, AccessMethod.INTERNAL).get(ServiceInterface.class);
// long newTopicId = service.checkinInitiated(topicId, poid, comment, deserializerOid, -1L, name, ifcFile, merge, true);
// result.put("topicId", newTopicId);
// }
// }
} else {
result.put("exception", "No poid");
}
}
}
}
} catch (Exception e) {
LOGGER.error("", e);
// sendException(response, e);
return;
}
response.getWriter().write(result.toString());
}
Aggregations