Subversion Repositories SmartDukaan

Rev

Rev 25405 | Rev 25410 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 25405 Rev 25409
Line 85... Line 85...
85
 
85
 
86
	private static final String THUMBNAIL = "thumbnail";
86
	private static final String THUMBNAIL = "thumbnail";
87
	private static final String ICON = "icon";
87
	private static final String ICON = "icon";
88
	private static final String DEFAULT = "default";
88
	private static final String DEFAULT = "default";
89
	private static final String NONE = "";
89
	private static final String NONE = "";
90
	
90
 
91
	private static final Logger LOGGER = LogManager.getLogger(ContentController.class);
91
	private static final Logger LOGGER = LogManager.getLogger(ContentController.class);
92
 
92
 
93
	private String getFileName(int entityId, String description, String extension) {
93
	private String getFileName(int entityId, String description, String extension) {
94
		List<Item> items = itemRepository.selectAllByCatalogItemId(entityId);
94
		List<Item> items = itemRepository.selectAllByCatalogItemId(entityId);
95
		String imageString = items.get(0).getItemDescriptionNoColor() + " " + description + " "
95
		String imageString = getMediaPrefix(items.get(0).getItemDescriptionNoColor() + " " + description) + "-"
96
				+ LocalDateTime.now().toEpochSecond(ZoneOffset.ofHoursMinutes(5, 30));
96
				+ LocalDateTime.now().toEpochSecond(ZoneOffset.ofHoursMinutes(5, 30));
97
		return imageString.replaceAll("\\s+", " ") + "." + extension;
97
		return imageString.replaceAll("\\s+", " ") + "." + extension;
98
	}
98
	}
99
 
99
 
100
	@PostMapping(value = "/content/upload")
100
	@PostMapping(value = "/content/upload")
Line 122... Line 122...
122
 
122
 
123
	@GetMapping(value = "/content/media")
123
	@GetMapping(value = "/content/media")
124
	public String getMediaContent(HttpServletRequest request, Model model, @RequestParam int entityId)
124
	public String getMediaContent(HttpServletRequest request, Model model, @RequestParam int entityId)
125
			throws Exception {
125
			throws Exception {
126
		ContentPojo contentPojo = mongoClient.getEntityById(entityId);
126
		ContentPojo contentPojo = mongoClient.getEntityById(entityId);
127
		if(contentPojo==null) {
127
		if (contentPojo == null) {
128
			throw new Exception("Please add content first");
128
			throw new Exception("Please add content first");
129
		}
129
		}
130
		EntityMediaPojo empojo = getEntityMediaPojo(contentPojo);
130
		EntityMediaPojo empojo = getEntityMediaPojo(contentPojo);
131
		model.addAttribute("response", mvcResponseSender.createResponseString(empojo));
131
		model.addAttribute("response", mvcResponseSender.createResponseString(empojo));
132
		return "response";
132
		return "response";
133
	}
133
	}
134
 
134
 
135
	private EntityMediaPojo getEntityMediaPojo(ContentPojo contentPojo) {
135
	private EntityMediaPojo getEntityMediaPojo(ContentPojo contentPojo) {
136
		EntityMediaPojo ep = new EntityMediaPojo();
136
		EntityMediaPojo ep = new EntityMediaPojo();
137
		int defaultIndex = 0;
137
		int defaultIndex = 0;
138
		if(contentPojo.getImages()==null) {
138
		if (contentPojo.getImages() == null) {
139
			ep.setMediaPojos(new ArrayList<>());
139
			ep.setMediaPojos(new ArrayList<>());
140
		} else {
140
		} else {
141
			ep.setMediaPojos(contentPojo.getImages());
141
			ep.setMediaPojos(contentPojo.getImages());
142
			for (MediaPojo mediaPojo : contentPojo.getImages()) {
142
			for (MediaPojo mediaPojo : contentPojo.getImages()) {
143
				if(mediaPojo.getUrl()==null) continue;
143
				if (mediaPojo.getUrl() == null)
144
				
144
					continue;
-
 
145
 
145
				if (!mediaPojo.getUrl().equals(contentPojo.getDefaultImageUrl())) {
146
				if (!mediaPojo.getUrl().equals(contentPojo.getDefaultImageUrl())) {
146
					defaultIndex++;
147
					defaultIndex++;
147
				}
148
				}
148
			}
149
			}
149
		}
150
		}
Line 299... Line 300...
299
			channelSftp.rmdir(folderName);
300
			channelSftp.rmdir(folderName);
300
		}
301
		}
301
 
302
 
302
		channelSftp.mkdir(folderName);
303
		channelSftp.mkdir(folderName);
303
		channelSftp.cd(folderName);
304
		channelSftp.cd(folderName);
-
 
305
 
304
		channelSftp.chmod(755, ".");
306
		channelSftp.chmod(0755, ".");
305
 
307
 
306
		for (Map.Entry<String, InputStream> streamsFileEntry : streamsFileMap.entrySet()) {
308
		for (Map.Entry<String, InputStream> streamsFileEntry : streamsFileMap.entrySet()) {
307
			channelSftp.put(streamsFileEntry.getValue(), streamsFileEntry.getKey(), ChannelSftp.OVERWRITE);
309
			channelSftp.put(streamsFileEntry.getValue(), streamsFileEntry.getKey(), ChannelSftp.OVERWRITE);
308
		}
310
		}
309
 
311
 
Line 345... Line 347...
345
		contentPojo.setImages(entityMediaPojo.getMediaPojos());
347
		contentPojo.setImages(entityMediaPojo.getMediaPojos());
346
 
348
 
347
		return map;
349
		return map;
348
	}
350
	}
349
 
351
 
-
 
352
	private String getMediaPrefix(String productName) {
-
 
353
		String mediaPrefix = productName.toLowerCase().replace(' ', '-');
-
 
354
		mediaPrefix = mediaPrefix.replaceAll("/", "-");
-
 
355
		mediaPrefix = mediaPrefix.replaceAll("-+", "-");
-
 
356
		return mediaPrefix;
-
 
357
	}
-
 
358
 
350
}
359
}